diff --git a/.gitignore b/.gitignore index 567609b..cd144e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ -build/ +/build/msvc_2010/Debug +/build/msvc_2010/Release +/build/msvc_2010/libbson-cpp/Debug +/build/msvc_2010/libbson-cpp/Release +/build/msvc_2010/libbson-cpp-test/Debug +/build/msvc_2010/libbson-cpp-test/Release \ No newline at end of file diff --git a/bson-cpp.sln b/bson-cpp.sln new file mode 100644 index 0000000..a8e6d5a --- /dev/null +++ b/bson-cpp.sln @@ -0,0 +1,29 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbson-cpp", "build\msvc_2010\libbson-cpp\libbson-cpp.vcxproj", "{D4B94116-FDF8-496C-BF5D-219664A9B54B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbson-cpp-test", "build\msvc_2010\libbson-cpp-test\libbson-cpp-test.vcxproj", "{7387F355-BD5D-4AD9-9721-2CBF22B7E4AE}" + ProjectSection(ProjectDependencies) = postProject + {D4B94116-FDF8-496C-BF5D-219664A9B54B} = {D4B94116-FDF8-496C-BF5D-219664A9B54B} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D4B94116-FDF8-496C-BF5D-219664A9B54B}.Debug|Win32.ActiveCfg = Debug|Win32 + {D4B94116-FDF8-496C-BF5D-219664A9B54B}.Debug|Win32.Build.0 = Debug|Win32 + {D4B94116-FDF8-496C-BF5D-219664A9B54B}.Release|Win32.ActiveCfg = Release|Win32 + {D4B94116-FDF8-496C-BF5D-219664A9B54B}.Release|Win32.Build.0 = Release|Win32 + {7387F355-BD5D-4AD9-9721-2CBF22B7E4AE}.Debug|Win32.ActiveCfg = Debug|Win32 + {7387F355-BD5D-4AD9-9721-2CBF22B7E4AE}.Debug|Win32.Build.0 = Debug|Win32 + {7387F355-BD5D-4AD9-9721-2CBF22B7E4AE}.Release|Win32.ActiveCfg = Release|Win32 + {7387F355-BD5D-4AD9-9721-2CBF22B7E4AE}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..96f8975 --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,4 @@ +m4 +autogen.sh +configure.ac +Makefile.am \ No newline at end of file diff --git a/build/msvc_2010/libbson-cpp-test/libbson-cpp-test.vcxproj b/build/msvc_2010/libbson-cpp-test/libbson-cpp-test.vcxproj new file mode 100644 index 0000000..e8677db --- /dev/null +++ b/build/msvc_2010/libbson-cpp-test/libbson-cpp-test.vcxproj @@ -0,0 +1,83 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {7387F355-BD5D-4AD9-9721-2CBF22B7E4AE} + libbsoncpptest + + + + Application + true + MultiByte + v140 + + + Application + false + true + MultiByte + v140 + + + + + + + + + + + + + $(SolutionDir)build\msvc_2010\$(Configuration) + + + $(SolutionDir)build\msvc_2010\$(Configuration) + + + + Level3 + Disabled + $(BOOST);$(SolutionDir)/src;$(SolutionDir) + + + true + $(BOOST)\stage\lib;$(SolutionDir)build\msvc_2010\$(Configuration) + libbson-cpp.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + $(BOOST);$(SolutionDir)/src;$(SolutionDir) + + + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/msvc_2010/libbson-cpp-test/libbson-cpp-test.vcxproj.filters b/build/msvc_2010/libbson-cpp-test/libbson-cpp-test.vcxproj.filters new file mode 100644 index 0000000..1eb74ec --- /dev/null +++ b/build/msvc_2010/libbson-cpp-test/libbson-cpp-test.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + + + src + + + src + + + + + src + + + \ No newline at end of file diff --git a/build/msvc_2010/libbson-cpp-test/libbson-cpp-test.vcxproj.user b/build/msvc_2010/libbson-cpp-test/libbson-cpp-test.vcxproj.user new file mode 100644 index 0000000..695b5c7 --- /dev/null +++ b/build/msvc_2010/libbson-cpp-test/libbson-cpp-test.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/build/msvc_2010/libbson-cpp/libbson-cpp.vcxproj b/build/msvc_2010/libbson-cpp/libbson-cpp.vcxproj new file mode 100644 index 0000000..1e20985 --- /dev/null +++ b/build/msvc_2010/libbson-cpp/libbson-cpp.vcxproj @@ -0,0 +1,111 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {D4B94116-FDF8-496C-BF5D-219664A9B54B} + libbsoncpp + + + + StaticLibrary + true + MultiByte + v140 + + + StaticLibrary + false + true + MultiByte + v140 + + + + + + + + + + + + + $(SolutionDir)build\msvc_2010\$(Configuration) + + + $(SolutionDir)build\msvc_2010\$(Configuration) + + + + Level3 + Disabled + $(BOOST);$(SolutionDir);S:\Github\boost\boost_1_59_0;$(SolutionDir)/src + + + true + + + + + Level3 + MaxSpeed + true + true + $(BOOST);$(SolutionDir);$(SolutionDir)/src/util + + + true + true + true + $(BOOST)\stage\lib;%(AdditionalLibraryDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/msvc_2010/libbson-cpp/libbson-cpp.vcxproj.filters b/build/msvc_2010/libbson-cpp/libbson-cpp.vcxproj.filters new file mode 100644 index 0000000..040e082 --- /dev/null +++ b/build/msvc_2010/libbson-cpp/libbson-cpp.vcxproj.filters @@ -0,0 +1,115 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {7a8bcc94-72c6-460d-845f-dd90bf761a1d} + + + {77863e1f-b2e6-42e5-b659-ea07ff03148e} + + + + + src + + + src + + + src\util + + + lib + + + lib + + + lib + + + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src\util + + + src\util + + + src\util + + + src\util + + + src\util + + + src\util + + + src\util + + + lib + + + lib + + + lib + + + lib + + + lib + + + \ No newline at end of file diff --git a/build/msvc_2010/libbson-cpp/libbson-cpp.vcxproj.user b/build/msvc_2010/libbson-cpp/libbson-cpp.vcxproj.user new file mode 100644 index 0000000..695b5c7 --- /dev/null +++ b/build/msvc_2010/libbson-cpp/libbson-cpp.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/lib/base64.h b/lib/base64.h index ea192cf..6a66884 100644 --- a/lib/base64.h +++ b/lib/base64.h @@ -21,6 +21,7 @@ #include #include #include +#include namespace base64 { diff --git a/lib/nonce.cpp b/lib/nonce.cpp index 3cfbc56..9394e89 100644 --- a/lib/nonce.cpp +++ b/lib/nonce.cpp @@ -14,8 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#if defined(_WIN32) + #define _CRT_RAND_S + #include +#endif #include "nonce.h" + #include #include @@ -34,8 +39,8 @@ namespace Nonce { if( _initialized ) return; _initialized = true; - #if defined(__linux__) || defined(__sunos__) - _devrandom = new ifstream("/dev/urandom", ios::binary|ios::in); + #if defined(__linux__) || defined(__sunos__) || defined(__CYGWIN__) + _devrandom = new std::ifstream("/dev/urandom", std::ios::binary|std::ios::in); assert(_devrandom->is_open() && "can't open dev/urandom"); #elif defined(_WIN32) srand(time(NULL)); @@ -57,6 +62,9 @@ namespace Nonce { _devrandom->read((char*)&n, sizeof(n)); assert(!_devrandom->fail() && "devrandom failed"); #elif defined(_WIN32) + #define _CRT_RAND_S + #include + unsigned a=0, b=0; assert( rand_s(&a) == 0 ); assert( rand_s(&b) == 0 ); diff --git a/lib/nonce.h b/lib/nonce.h index 2149b72..47784f3 100644 --- a/lib/nonce.h +++ b/lib/nonce.h @@ -18,6 +18,7 @@ #pragma once #include +#include namespace Nonce { diff --git a/src/bsonobj.h b/src/bsonobj.h index 10cf3e1..1ab76f2 100644 --- a/src/bsonobj.h +++ b/src/bsonobj.h @@ -21,7 +21,7 @@ #include #include #include -#include "lib/atomic_int.h" +#include "../lib/atomic_int.h" #include "util/builder.h" #include "stringdata.h" #include "bsonelement.h" diff --git a/src/oid.cpp b/src/oid.cpp index f5a2251..9c48da9 100644 --- a/src/oid.cpp +++ b/src/oid.cpp @@ -34,7 +34,7 @@ namespace bson { unsigned pid; #if defined(_WIN32) pid = (unsigned short) GetCurrentProcessId(); -#elif defined(__linux__) || defined(__APPLE__) || defined(__sunos__) +#elif defined(__linux__) || defined(__APPLE__) || defined(__sunos__) || defined(__CYGWIN__) pid = (unsigned short) getpid(); #else pid = (unsigned short) Security::getNonce(); @@ -47,8 +47,9 @@ namespace bson { x._pid ^= (unsigned short) p; // when the pid is greater than 16 bits, let the high bits modulate the // machine id field. - unsigned short& rest = (unsigned short &) x._machineNumber[1]; - rest ^= p >> 16; + void* mn = (void*)&(x._machineNumber[1]); + unsigned short* rest = (unsigned short *) mn; + (*rest) ^= p >> 16; } OID::MachineAndPid OID::genMachineAndPid() { @@ -88,7 +89,8 @@ namespace bson { x[1] = ourMachineAndPid._machineNumber[1]; x[2] = ourMachineAndPid._machineNumber[2]; x[3] = 0; - return (unsigned&) x[0]; + unsigned *ux = (unsigned *)&x; + return *ux; } void OID::justForked() { diff --git a/src/util/json.cpp b/src/util/json.cpp index 2978325..726e742 100644 --- a/src/util/json.cpp +++ b/src/util/json.cpp @@ -18,7 +18,7 @@ #define BOOST_SPIRIT_THREADSAFE //#if BOOST_VERSION >= 103800 -#if true +#if 1 #define BOOST_SPIRIT_USE_OLD_NAMESPACE #include #include @@ -30,9 +30,9 @@ #endif #include "json.h" -#include "util/builder.h" -#include "util/hex.h" -#include "lib/base64.h" +#include "builder.h" +#include "hex.h" +#include "../../lib/base64.h" using namespace boost::spirit; diff --git a/src/util/optime.h b/src/util/optime.h index c1d8ea9..262c460 100644 --- a/src/util/optime.h +++ b/src/util/optime.h @@ -87,11 +87,11 @@ namespace bson { the cleanest choice, lacking a true unsigned64 datatype, but BinData has 5 bytes of overhead. */ - unsigned long long asDate() const { - return reinterpret_cast(&i)[0]; + unsigned long long asDate() const { + return i; } long long asLL() const { - return reinterpret_cast(&i)[0]; + return i; } bool isNull() const { return secs == 0; } diff --git a/src/util/time_support.h b/src/util/time_support.h index 185a04a..2a28914 100644 --- a/src/util/time_support.h +++ b/src/util/time_support.h @@ -20,6 +20,7 @@ #include // sscanf #include #include +#include #include namespace bson { @@ -99,7 +100,7 @@ namespace bson { if ( s <= 0 ) return; boost::xtime xt; - boost::xtime_get(&xt, boost::TIME_UTC); + boost::xtime_get(&xt, boost::TIME_UTC_); xt.sec += (int)( s / 1000000 ); xt.nsec += (int)(( s % 1000000 ) * 1000); if ( xt.nsec >= 1000000000 ) { @@ -173,7 +174,7 @@ namespace bson { about that. */ inline unsigned curTimeMillis() { boost::xtime xt; - boost::xtime_get(&xt, boost::TIME_UTC); + boost::xtime_get(&xt, boost::TIME_UTC_); unsigned t = xt.nsec / 1000000; return (xt.sec & 0xfffff) * 1000 + t; } @@ -181,14 +182,14 @@ namespace bson { /** Date_t is milliseconds since epoch */ inline Date_t jsTime() { boost::xtime xt; - boost::xtime_get(&xt, boost::TIME_UTC); + boost::xtime_get(&xt, boost::TIME_UTC_); unsigned long long t = xt.nsec / 1000000; return ((unsigned long long) xt.sec * 1000) + t; } inline unsigned long long curTimeMicros64() { boost::xtime xt; - boost::xtime_get(&xt, boost::TIME_UTC); + boost::xtime_get(&xt, boost::TIME_UTC_); unsigned long long t = xt.nsec / 1000; return (((unsigned long long) xt.sec) * 1000000) + t; } @@ -196,7 +197,7 @@ namespace bson { // measures up to 1024 seconds. or, 512 seconds with tdiff that is... inline unsigned curTimeMicros() { boost::xtime xt; - boost::xtime_get(&xt, boost::TIME_UTC); + boost::xtime_get(&xt, boost::TIME_UTC_); unsigned t = xt.nsec / 1000; unsigned secs = xt.sec % 1024; return secs*1000000 + t;