Minimal code changes to allow msvc compilation #11558

pull sipsorcery wants to merge 1 commits into bitcoin:master from sipsorcery:code_msvc changing 8 files +23 −9
  1. sipsorcery commented at 12:48 pm on October 25, 2017: member

    These changes are required to allow the Bitcoin source to build with Microsoft’s C++ compiler (#11562 is also required).

    I looked around for a better place for the typedef of ssize_t which is in random.h. The best candidate looks like src/compat.h but I figured including that header in random.h is a bigger change than the typedef. Note that the same typedef is in at least two other places including the OpenSSL and Berkeley DB headers so some of the Bitcoin code already picks it up.

  2. fanquake added the label Windows on Oct 25, 2017
  3. in src/bench/bench.cpp:44 in aebadac0d6 outdated
    39+
    40+    tp->tv_sec = (long)((time - EPOCH) / 10000000L);
    41+    tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
    42+    return 0;
    43+}
    44+#endif
    


    theuni commented at 3:50 pm on October 25, 2017:
    Let’s just drop gettimedouble() and switch this to std::chrono::steady_clock. That should eliminate the non-portable code.
  4. in src/random.h:22 in aebadac0d6 outdated
    17+typedef int64_t ssize_t;
    18+#else
    19+typedef int32_t ssize_t;
    20+#endif
    21+#endif
    22+
    


    theuni commented at 3:51 pm on October 25, 2017:
    I think just making MAX_TRIES an int should remove the need for this?

    ryanofsky commented at 6:31 pm on October 25, 2017:

    I think just making MAX_TRIES an int should remove the need for this?

    Yes this would be better than adding a top-level definition that could conflict with other libraries. (Also, if we did need a top-level definition, compat.h would probably be a better place to put it.)


    sipsorcery commented at 10:14 pm on October 25, 2017:
    @ryanofsky I agree it’s very clunky to add yet another ssize_t typedef. I did consider adding to compat.h, see the main PR comment. Happy to go with whatever the consensus is.

    ryanofsky commented at 8:08 pm on October 31, 2017:

    Happy to go with whatever the consensus is.

    I think you should just make MAX_TRIES an int like Cory suggested.

  5. in src/support/cleanse.cpp:35 in aebadac0d6 outdated
    35@@ -32,7 +36,7 @@ void memory_cleanse(void *ptr, size_t len)
    36        might try to eliminate "superfluous" memsets. If there's an easy way to
    37        detect memset_s, it would be better to use that. */
    38 #if defined(_MSC_VER)
    39-    __asm;
    


    theuni commented at 4:03 pm on October 25, 2017:
    See the discussion here #11196 for context here. Now would be a good time to reassess.

    sipsorcery commented at 9:16 pm on October 25, 2017:
    Note that __asm is not supported with msvc when targeting x64, that’s the only reason for this change.
  6. theuni commented at 4:08 pm on October 25, 2017: member
    The rest of the changes look good to me.
  7. in src/support/cleanse.cpp:11 in aebadac0d6 outdated
     6@@ -7,6 +7,10 @@
     7 
     8 #include <cstring>
     9 
    10+#if defined(_MSC_VER)
    11+#include <Windows.h>	// For SecureZeroMemory.
    


    ryanofsky commented at 6:34 pm on October 25, 2017:
    Need to get replace the tab on this line with spaces to fix travis error.
  8. ryanofsky commented at 6:38 pm on October 25, 2017: member
    Looks good if ssize_t, gettimeofday, and tab character comments are addressed.
  9. theuni commented at 9:10 pm on October 25, 2017: member
    See #11562, which should eliminate the need for the gettimeofday() patch.
  10. sipsorcery force-pushed on Oct 25, 2017
  11. ryanofsky commented at 8:10 pm on October 31, 2017: member
    utACK a80e0c591b5b56111bdb1d42ff0449dede61810b. Seems fine now without gettimeofday implementation. Would be nice to get rid of ssize_t too.
  12. sipsorcery force-pushed on Oct 31, 2017
  13. sipsorcery force-pushed on Nov 1, 2017
  14. sipsorcery force-pushed on Nov 1, 2017
  15. sipsorcery force-pushed on Nov 1, 2017
  16. sipsorcery commented at 10:36 am on November 1, 2017: member

    Working around the use of the non-portable ssize_t definition is proving to be a bit tricky. Adding a typedef to random.h allows the code to build but as some reviewers pointed out it was a clunky fix.

    Switching from ssize_t to int in random.h and random.cpp is not sufficient. There are also multiple uses of ssize_t in netbase.cpp and test/util_tests.cpp. A side effect of the definition in random.h was that those two classes picked up the definition.

    Adding a typedef to compat.h and also adding an include for compat.h to random.h gets the definition to the missing spots BUT it introduces a re-definition compilation error because the db.h header from BerkeleyDB already has the same typedef.

    After some gymnastics I have managed to come up with a set of directives that allow successful compilation, see below, however if portable code is a goal for the future it may be worth steering away from non-C++ standard types, such as ssize_t, outside of any platform specific classes?

    0#ifdef _MSC_VER
    1#if !defined(ssize_t)
    2#ifdef _WIN64
    3typedef int64_t ssize_t;
    4#else
    5typedef int32_t ssize_t;
    6#endif
    7#endif
    8#endif
    
  17. laanwj referenced this in commit 5776582b7f on Nov 8, 2017
  18. laanwj commented at 5:04 pm on November 9, 2017: member

    however if portable code is a goal for the future it may be worth steering away from non-C++ standard types, such as ssize_t, outside of any platform specific classes?

    Agree, ssize_t should be used in POSIX code, as some of the POSIX functions such as read() return it. But outside it it’s better not to.

    utACK, changes look sane (or at least harmless) to me now. https://github.com/bitcoin/bitcoin/pull/11558/commits/af824151d65e66e1d16e43ef00bd613e644c7fcb

  19. ryanofsky commented at 5:13 pm on November 9, 2017: member
    0
    1EDIT: Never mind. I see there were other uses of ssize_t outside of random.h/cpp. Still would be good to stop using ssize_t in inappropriate places.
    
  20. Minimal code changes to allow msvc compilation. fbf327b138
  21. in src/random.h:12 in af824151d6 outdated
     8@@ -9,6 +9,7 @@
     9 #include "crypto/chacha20.h"
    10 #include "crypto/common.h"
    11 #include "uint256.h"
    12+#include "compat.h"
    


    theuni commented at 6:54 pm on November 9, 2017:
    Please just make NUM_OS_RANDOM_BYTES an int to keep the compat.h include out of this header. I realize it’s still needed in the cpp, but let’s try not to spread the use further than necessary.
  22. sipsorcery force-pushed on Nov 9, 2017
  23. laanwj merged this on Dec 13, 2017
  24. laanwj closed this on Dec 13, 2017

  25. laanwj referenced this in commit 68e021e3a3 on Dec 13, 2017
  26. MarcoFalke commented at 3:04 pm on December 13, 2017: member
    Post merge Concept ACK fbf327b
  27. sipsorcery deleted the branch on Dec 13, 2017
  28. MarcoFalke referenced this in commit afa9600020 on Aug 13, 2018
  29. laanwj referenced this in commit 7f985d6c81 on Jul 3, 2019
  30. PastaPastaPasta referenced this in commit 6d02d0b8e3 on Jul 18, 2019
  31. PastaPastaPasta referenced this in commit 6a18c3645e on Dec 22, 2019
  32. PastaPastaPasta referenced this in commit 4607b9eb3c on Jan 2, 2020
  33. PastaPastaPasta referenced this in commit 55e7cfd604 on Jan 4, 2020
  34. PastaPastaPasta referenced this in commit 66f8045fe7 on Jan 12, 2020
  35. PastaPastaPasta referenced this in commit b8243e7644 on Jan 12, 2020
  36. PastaPastaPasta referenced this in commit 896e5a9717 on Jan 12, 2020
  37. PastaPastaPasta referenced this in commit d7c8ef3653 on Jan 12, 2020
  38. PastaPastaPasta referenced this in commit efe3b9e1ca on Jan 12, 2020
  39. PastaPastaPasta referenced this in commit 97df283547 on Jan 12, 2020
  40. PastaPastaPasta referenced this in commit 6d749f8d2a on Jan 16, 2020
  41. PastaPastaPasta referenced this in commit 410113b7e3 on Jan 31, 2020
  42. PastaPastaPasta referenced this in commit 577f597e99 on Jan 31, 2020
  43. PastaPastaPasta referenced this in commit b12538634b on Feb 4, 2020
  44. PastaPastaPasta referenced this in commit 304f012632 on Feb 9, 2020
  45. PastaPastaPasta referenced this in commit 3b439789c6 on Feb 13, 2020
  46. PastaPastaPasta referenced this in commit 9d9d1499b0 on Feb 27, 2020
  47. PastaPastaPasta referenced this in commit 39a8e20de6 on Feb 27, 2020
  48. zkbot referenced this in commit 17324f085f on Apr 30, 2020
  49. zkbot referenced this in commit 7a0fe273d8 on Apr 30, 2020
  50. jasonbcox referenced this in commit 9290b899e4 on Nov 13, 2020
  51. ckti referenced this in commit 4a4ccdfe65 on Mar 28, 2021
  52. ckti referenced this in commit 26a91e1270 on Mar 28, 2021
  53. PastaPastaPasta referenced this in commit ffb6b7c210 on May 26, 2021
  54. gades referenced this in commit e391a0081c on Jun 26, 2021
  55. PastaPastaPasta referenced this in commit 0687c9a9f5 on Jun 27, 2021
  56. PastaPastaPasta referenced this in commit 7efdda4676 on Jun 27, 2021
  57. PastaPastaPasta referenced this in commit af67ca3268 on Jun 28, 2021
  58. PastaPastaPasta referenced this in commit 5c0bf5a9fb on Jun 28, 2021
  59. PastaPastaPasta referenced this in commit f4d7177988 on Jun 29, 2021
  60. PastaPastaPasta referenced this in commit f95eee6bf5 on Jun 29, 2021
  61. PastaPastaPasta referenced this in commit 2618b52d3c on Jun 29, 2021
  62. PastaPastaPasta referenced this in commit fd2b028aba on Jun 29, 2021
  63. PastaPastaPasta referenced this in commit 07e1a914af on Jun 29, 2021
  64. PastaPastaPasta referenced this in commit a9bf129d18 on Jun 29, 2021
  65. gades referenced this in commit ad3bab0111 on Jun 30, 2021
  66. PastaPastaPasta referenced this in commit 38567ca4d7 on Jul 1, 2021
  67. PastaPastaPasta referenced this in commit c2143f62fc on Jul 1, 2021
  68. PastaPastaPasta referenced this in commit 99ec02f43c on Jul 12, 2021
  69. PastaPastaPasta referenced this in commit 6fd162e296 on Jul 13, 2021
  70. linuxsh2 referenced this in commit 78e9c711a6 on Jul 29, 2021
  71. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me