bson 4.1.1 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +106 -7
  3. data/Rakefile +86 -43
  4. data/ext/bson/{native-endian.h → bson-endian.h} +14 -107
  5. data/ext/bson/bson-native.h +135 -0
  6. data/ext/bson/bytebuf.c +133 -0
  7. data/ext/bson/endian.c +117 -0
  8. data/ext/bson/extconf.rb +8 -3
  9. data/ext/bson/init.c +364 -0
  10. data/ext/bson/libbson-utf8.c +230 -0
  11. data/ext/bson/read.c +470 -0
  12. data/ext/bson/util.c +250 -0
  13. data/ext/bson/write.c +675 -0
  14. data/lib/bson/active_support.rb +19 -0
  15. data/lib/bson/array.rb +97 -30
  16. data/lib/bson/big_decimal.rb +77 -0
  17. data/lib/bson/binary.rb +510 -70
  18. data/lib/bson/boolean.rb +15 -4
  19. data/lib/bson/code.rb +25 -12
  20. data/lib/bson/code_with_scope.rb +41 -15
  21. data/lib/bson/config.rb +3 -28
  22. data/lib/bson/date.rb +16 -4
  23. data/lib/bson/date_time.rb +6 -4
  24. data/lib/bson/db_pointer.rb +110 -0
  25. data/lib/bson/dbref.rb +154 -0
  26. data/lib/bson/decimal128/builder.rb +456 -0
  27. data/lib/bson/decimal128.rb +272 -0
  28. data/lib/bson/document.rb +177 -7
  29. data/lib/bson/environment.rb +17 -2
  30. data/lib/bson/error/bson_decode_error.rb +11 -0
  31. data/lib/bson/error/ext_json_parse_error.rb +11 -0
  32. data/lib/bson/error/illegal_key.rb +23 -0
  33. data/lib/bson/error/invalid_binary_type.rb +37 -0
  34. data/lib/bson/error/invalid_dbref_argument.rb +12 -0
  35. data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
  36. data/lib/bson/error/invalid_decimal128_range.rb +27 -0
  37. data/lib/bson/error/invalid_decimal128_string.rb +26 -0
  38. data/lib/bson/error/invalid_key.rb +24 -0
  39. data/lib/bson/error/invalid_object_id.rb +11 -0
  40. data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
  41. data/lib/bson/error/unrepresentable_precision.rb +19 -0
  42. data/lib/bson/error/unserializable_class.rb +13 -0
  43. data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
  44. data/lib/bson/error/unsupported_type.rb +11 -0
  45. data/lib/bson/error.rb +22 -0
  46. data/lib/bson/ext_json.rb +389 -0
  47. data/lib/bson/false_class.rb +6 -4
  48. data/lib/bson/float.rb +43 -7
  49. data/lib/bson/hash.rb +152 -37
  50. data/lib/bson/int32.rb +104 -6
  51. data/lib/bson/int64.rb +111 -8
  52. data/lib/bson/integer.rb +43 -9
  53. data/lib/bson/json.rb +3 -1
  54. data/lib/bson/max_key.rb +21 -10
  55. data/lib/bson/min_key.rb +21 -10
  56. data/lib/bson/nil_class.rb +7 -3
  57. data/lib/bson/object.rb +25 -17
  58. data/lib/bson/object_id.rb +98 -113
  59. data/lib/bson/open_struct.rb +59 -0
  60. data/lib/bson/regexp.rb +129 -56
  61. data/lib/bson/registry.rb +7 -10
  62. data/lib/bson/specialized.rb +8 -4
  63. data/lib/bson/string.rb +12 -32
  64. data/lib/bson/symbol.rb +107 -11
  65. data/lib/bson/time.rb +68 -7
  66. data/lib/bson/time_with_zone.rb +67 -0
  67. data/lib/bson/timestamp.rb +50 -10
  68. data/lib/bson/true_class.rb +6 -4
  69. data/lib/bson/undefined.rb +28 -2
  70. data/lib/bson/vector.rb +44 -0
  71. data/lib/bson/version.rb +6 -14
  72. data/lib/bson.rb +22 -12
  73. data/spec/README.md +14 -0
  74. data/spec/bson/array_spec.rb +38 -62
  75. data/spec/bson/big_decimal_spec.rb +328 -0
  76. data/spec/bson/binary_spec.rb +199 -53
  77. data/spec/bson/binary_uuid_spec.rb +190 -0
  78. data/spec/bson/boolean_spec.rb +2 -1
  79. data/spec/bson/byte_buffer_read_spec.rb +198 -0
  80. data/spec/bson/byte_buffer_spec.rb +122 -381
  81. data/spec/bson/byte_buffer_write_spec.rb +855 -0
  82. data/spec/bson/code_spec.rb +6 -4
  83. data/spec/bson/code_with_scope_spec.rb +6 -4
  84. data/spec/bson/config_spec.rb +1 -35
  85. data/spec/bson/date_spec.rb +2 -1
  86. data/spec/bson/date_time_spec.rb +55 -1
  87. data/spec/bson/dbref_legacy_spec.rb +186 -0
  88. data/spec/bson/dbref_spec.rb +487 -0
  89. data/spec/bson/decimal128_spec.rb +1840 -0
  90. data/spec/bson/document_as_spec.rb +61 -0
  91. data/spec/bson/document_spec.rb +205 -32
  92. data/spec/bson/ext_json_parse_spec.rb +346 -0
  93. data/spec/bson/false_class_spec.rb +9 -1
  94. data/spec/bson/float_spec.rb +42 -1
  95. data/spec/bson/hash_as_spec.rb +58 -0
  96. data/spec/bson/hash_spec.rb +318 -66
  97. data/spec/bson/int32_spec.rb +248 -1
  98. data/spec/bson/int64_spec.rb +308 -1
  99. data/spec/bson/integer_spec.rb +61 -3
  100. data/spec/bson/json_spec.rb +2 -1
  101. data/spec/bson/max_key_spec.rb +6 -4
  102. data/spec/bson/min_key_spec.rb +6 -4
  103. data/spec/bson/nil_class_spec.rb +2 -1
  104. data/spec/bson/object_id_spec.rb +95 -5
  105. data/spec/bson/object_spec.rb +3 -2
  106. data/spec/bson/open_struct_spec.rb +87 -0
  107. data/spec/bson/raw_spec.rb +594 -0
  108. data/spec/bson/regexp_spec.rb +61 -8
  109. data/spec/bson/registry_spec.rb +3 -2
  110. data/spec/bson/string_spec.rb +26 -33
  111. data/spec/bson/symbol_raw_spec.rb +70 -0
  112. data/spec/bson/symbol_spec.rb +77 -20
  113. data/spec/bson/time_spec.rb +206 -2
  114. data/spec/bson/time_with_zone_spec.rb +69 -0
  115. data/spec/bson/timestamp_spec.rb +58 -2
  116. data/spec/bson/true_class_spec.rb +9 -1
  117. data/spec/bson/undefined_spec.rb +28 -1
  118. data/spec/bson/vector_spec.rb +33 -0
  119. data/spec/bson_spec.rb +2 -1
  120. data/spec/runners/binary_vector.rb +78 -0
  121. data/spec/runners/common_driver.rb +348 -0
  122. data/spec/runners/corpus.rb +191 -0
  123. data/spec/runners/corpus_legacy.rb +248 -0
  124. data/spec/shared/LICENSE +20 -0
  125. data/spec/shared/bin/get-mongodb-download-url +17 -0
  126. data/spec/shared/bin/s3-copy +45 -0
  127. data/spec/shared/bin/s3-upload +69 -0
  128. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  129. data/spec/shared/lib/mrss/cluster_config.rb +231 -0
  130. data/spec/shared/lib/mrss/constraints.rb +378 -0
  131. data/spec/shared/lib/mrss/docker_runner.rb +298 -0
  132. data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
  133. data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
  134. data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
  135. data/spec/shared/lib/mrss/release/candidate.rb +281 -0
  136. data/spec/shared/lib/mrss/release/product_data.rb +144 -0
  137. data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
  138. data/spec/shared/lib/mrss/session_registry.rb +69 -0
  139. data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
  140. data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
  141. data/spec/shared/lib/mrss/utils.rb +37 -0
  142. data/spec/shared/lib/tasks/candidate.rake +64 -0
  143. data/spec/shared/share/Dockerfile.erb +251 -0
  144. data/spec/shared/share/haproxy-1.conf +16 -0
  145. data/spec/shared/share/haproxy-2.conf +17 -0
  146. data/spec/shared/shlib/config.sh +27 -0
  147. data/spec/shared/shlib/distro.sh +84 -0
  148. data/spec/shared/shlib/server.sh +423 -0
  149. data/spec/shared/shlib/set_env.sh +110 -0
  150. data/spec/spec_helper.rb +61 -1
  151. data/spec/spec_tests/binary_vector_spec.rb +82 -0
  152. data/spec/spec_tests/common_driver_spec.rb +84 -0
  153. data/spec/spec_tests/corpus_legacy_spec.rb +72 -0
  154. data/spec/spec_tests/corpus_spec.rb +134 -0
  155. data/spec/spec_tests/data/binary_vector/README.md +61 -0
  156. data/spec/spec_tests/data/binary_vector/float32.json +65 -0
  157. data/spec/spec_tests/data/binary_vector/int8.json +57 -0
  158. data/spec/spec_tests/data/binary_vector/packed_bit.json +83 -0
  159. data/spec/spec_tests/data/corpus/README.md +15 -0
  160. data/spec/spec_tests/data/corpus/array.json +49 -0
  161. data/spec/spec_tests/data/corpus/binary.json +153 -0
  162. data/spec/spec_tests/data/corpus/boolean.json +27 -0
  163. data/spec/spec_tests/data/corpus/code.json +67 -0
  164. data/spec/spec_tests/data/corpus/code_w_scope.json +78 -0
  165. data/spec/spec_tests/data/corpus/datetime.json +42 -0
  166. data/spec/spec_tests/data/corpus/dbpointer.json +56 -0
  167. data/spec/spec_tests/data/corpus/dbref.json +51 -0
  168. data/spec/spec_tests/data/corpus/decimal128-1.json +317 -0
  169. data/spec/spec_tests/data/corpus/decimal128-2.json +793 -0
  170. data/spec/spec_tests/data/corpus/decimal128-3.json +1771 -0
  171. data/spec/spec_tests/data/corpus/decimal128-4.json +165 -0
  172. data/spec/spec_tests/data/corpus/decimal128-5.json +402 -0
  173. data/spec/spec_tests/data/corpus/decimal128-6.json +131 -0
  174. data/spec/spec_tests/data/corpus/decimal128-7.json +327 -0
  175. data/spec/spec_tests/data/corpus/document.json +60 -0
  176. data/spec/spec_tests/data/corpus/double.json +87 -0
  177. data/spec/spec_tests/data/corpus/int32.json +43 -0
  178. data/spec/spec_tests/data/corpus/int64.json +43 -0
  179. data/spec/spec_tests/data/corpus/maxkey.json +12 -0
  180. data/spec/spec_tests/data/corpus/minkey.json +12 -0
  181. data/spec/spec_tests/data/corpus/multi-type-deprecated.json +15 -0
  182. data/spec/spec_tests/data/corpus/multi-type.json +11 -0
  183. data/spec/spec_tests/data/corpus/null.json +12 -0
  184. data/spec/spec_tests/data/corpus/oid.json +28 -0
  185. data/spec/spec_tests/data/corpus/regex.json +65 -0
  186. data/spec/spec_tests/data/corpus/string.json +72 -0
  187. data/spec/spec_tests/data/corpus/symbol.json +80 -0
  188. data/spec/spec_tests/data/corpus/timestamp.json +34 -0
  189. data/spec/spec_tests/data/corpus/top.json +262 -0
  190. data/spec/spec_tests/data/corpus/undefined.json +15 -0
  191. data/spec/spec_tests/data/corpus_legacy/array.json +49 -0
  192. data/spec/spec_tests/data/corpus_legacy/binary.json +69 -0
  193. data/spec/spec_tests/data/corpus_legacy/boolean.json +27 -0
  194. data/spec/spec_tests/data/corpus_legacy/code.json +67 -0
  195. data/spec/spec_tests/data/corpus_legacy/code_w_scope.json +78 -0
  196. data/spec/spec_tests/data/corpus_legacy/document.json +36 -0
  197. data/spec/spec_tests/data/corpus_legacy/double.json +69 -0
  198. data/spec/spec_tests/data/corpus_legacy/failures/datetime.json +31 -0
  199. data/spec/spec_tests/data/corpus_legacy/failures/dbpointer.json +42 -0
  200. data/spec/spec_tests/data/corpus_legacy/failures/int64.json +38 -0
  201. data/spec/spec_tests/data/corpus_legacy/failures/symbol.json +62 -0
  202. data/spec/spec_tests/data/corpus_legacy/int32.json +38 -0
  203. data/spec/spec_tests/data/corpus_legacy/maxkey.json +12 -0
  204. data/spec/spec_tests/data/corpus_legacy/minkey.json +12 -0
  205. data/spec/spec_tests/data/corpus_legacy/null.json +12 -0
  206. data/spec/spec_tests/data/corpus_legacy/oid.json +28 -0
  207. data/spec/spec_tests/data/corpus_legacy/regex.json +37 -0
  208. data/spec/spec_tests/data/corpus_legacy/string.json +67 -0
  209. data/spec/spec_tests/data/corpus_legacy/timestamp.json +18 -0
  210. data/spec/spec_tests/data/corpus_legacy/top.json +62 -0
  211. data/spec/spec_tests/data/corpus_legacy/undefined.json +13 -0
  212. data/spec/spec_tests/data/decimal128/decimal128-1.json +363 -0
  213. data/spec/spec_tests/data/decimal128/decimal128-2.json +793 -0
  214. data/spec/spec_tests/data/decimal128/decimal128-3.json +1771 -0
  215. data/spec/spec_tests/data/decimal128/decimal128-4.json +165 -0
  216. data/spec/spec_tests/data/decimal128/decimal128-5.json +402 -0
  217. data/spec/spec_tests/data/decimal128/decimal128-6.json +131 -0
  218. data/spec/spec_tests/data/decimal128/decimal128-7.json +327 -0
  219. data/spec/support/shared_examples.rb +32 -11
  220. data/spec/support/spec_config.rb +17 -0
  221. data/spec/support/utils.rb +58 -0
  222. metadata +284 -45
  223. checksums.yaml.gz.sig +0 -3
  224. data/ext/bson/native.c +0 -722
  225. data.tar.gz.sig +0 -0
  226. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 31e82028a4dbdd0ee59ad09a19bc8d1dac7c3fcd
4
- data.tar.gz: 9773de56e955e3b0545804de618692bcd9bd74b7
2
+ SHA256:
3
+ metadata.gz: f383730000f9b08a131535250a7855d8ec8dcb0e3bb334f4779dcdcc95b56023
4
+ data.tar.gz: 57cb5e6db027b6982263d4f4eb0228968b6fc71e6b6499ef5563c0a160a3b2b0
5
5
  SHA512:
6
- metadata.gz: 8fb4637938de67b08963c79e02aef0e32050e27229c17cd09bb1d0c69072f528f861fdd0759b46ec9ed70353ebcc6f55e32530b30e8cba5f76445338ab8f0903
7
- data.tar.gz: cdac6674f943e86cfe45e5742a9a361a3cc83ba5222ca82c5bf4b5ac50c7a43f8e70aa2804c63d233c6c2c2461627f116c63aee9c6c37e7a26ce9c67dcccf282
6
+ metadata.gz: 433d3758ccd6ad9222b98bf43a4746b71b5966d6eb01321dff869eca61acef89e58b42baae0bd9c979d41cc922b4baf227ae0b71fdc4f21d37b0d3ec7137a85b
7
+ data.tar.gz: 7f61000684c0acb7af4d2d50c3e2cbc1e47ab342c415fc91addf7e1c5533cb3e23cfe4d16ba2ccd5dea72d70d8a89698eec3f4520fee3320c3c64c7aec95f10d
data/README.md CHANGED
@@ -1,38 +1,132 @@
1
- BSON [![Build Status](https://secure.travis-ci.org/mongodb/bson-ruby.png?branch=master&.png)](http://travis-ci.org/mongodb/bson-ruby) [![Code Climate](https://codeclimate.com/github/mongodb/bson-ruby.png)](https://codeclimate.com/github/mongodb/bson-ruby) [![Coverage Status](https://coveralls.io/repos/mongodb/bson-ruby/badge.png?branch=master)](https://coveralls.io/r/mongodb/bson-ruby?branch=master) [![Inline docs](http://inch-ci.org/github/mongodb/bson-ruby.svg?branch=master)](http://inch-ci.org/github/mongodb/bson-ruby)
1
+ BSON
2
+ [![Gem Version][rubygems-img]][rubygems-url]
3
+ [![Build Status][ghactions-img]][ghactions-url]
2
4
  ====
3
5
 
4
6
  An implementation of the BSON specification in Ruby.
5
7
 
8
+ Installation
9
+ ------------
10
+
11
+ BSON can be installed via RubyGems:
12
+
13
+ ```
14
+ > gem install bson
15
+ ```
16
+
17
+ Or by adding it to your project's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'bson'
21
+ ```
22
+
23
+ ### Release Integrity
24
+
25
+ Each release of the BSON library for Ruby after version 5.0.0 has been automatically built and signed using the team's GPG key.
26
+
27
+ To verify the bson gem file:
28
+
29
+ 1. [Download the GPG key](https://pgp.mongodb.com/ruby-driver.asc).
30
+ 2. Import the key into your GPG keyring with `gpg --import ruby-driver.asc`.
31
+ 3. Download the gem file (if you don't already have it). You can download it from RubyGems with `gem fetch bson`, or you can download it from the [releases page](https://github.com/mongodb/bson-ruby/releases) on GitHub.
32
+ 4. Download the corresponding detached signature file from the [same release](https://github.com/mongodb/bson-ruby/releases). Look at the bottom of the release that corresponds to the gem file, under the 'Assets' list, for a `.sig` file with the same version number as the gem you wish to install.
33
+ 5. Verify the gem with `gpg --verify bson-X.Y.Z.gem.sig bson-X.Y.Z.gem` (replacing `X.Y.Z` with the actual version number).
34
+
35
+ You are looking for text like "Good signature from "MongoDB Ruby Driver Release Signing Key <packaging@mongodb.com>" in the output. If you see that, the signature was found to correspond to the given gem file.
36
+
37
+ (Note that other output, like "This key is not certified with a trusted signature!", is related to *web of trust* and depends on how strongly you, personally, trust the `ruby-driver.asc` key that you downloaded from us. To learn more, see https://www.gnupg.org/gph/en/manual/x334.html)
38
+
39
+ ### Why not use RubyGems' gem-signing functionality?
40
+
41
+ RubyGems' own gem signing is problematic, most significantly because there is no established chain of trust related to the keys used to sign gems. RubyGems' own documentation admits that "this method of signing gems is not widely used" (see https://guides.rubygems.org/security/). Discussions about this in the RubyGems community have been off-and-on for more than a decade, and while a solution will eventually arrive, we have settled on using GPG instead for the following reasons:
42
+
43
+ 1. Many of the other driver teams at MongoDB are using GPG to sign their product releases. Consistency with the other teams means that we can reuse existing tooling for our own product releases.
44
+ 2. GPG is widely available and has existing tools and procedures for dealing with web of trust (though they are admittedly quite arcane and intimidating to the uninitiated, unfortunately).
45
+
46
+ Ultimately, most users do not bother to verify gems, and will not be impacted by our choice of GPG over RubyGems' native method.
47
+
6
48
  Compatibility
7
49
  -------------
8
50
 
9
- BSON is tested against MRI (1.9.2+), JRuby (1.7.0+) and Rubinius (2.0.0+).
51
+ BSON is tested against MRI (2.7+) and JRuby (9.3+).
10
52
 
11
53
  Documentation
12
54
  -------------
13
55
 
14
- Current documentation can be found [here](http://docs.mongodb.org/ecosystem/tutorial/ruby-bson-tutorial/#ruby-bson-tutorial)
56
+ Current documentation can be found
57
+ [here](https://www.mongodb.com/docs/ruby-driver/current/bson-tutorials/).
15
58
 
16
59
  API Documentation
17
60
  -----------------
18
61
 
19
- The [API Documentation](http://rdoc.info/github/mongodb/bson-ruby/master/frames) is
20
- located at rdoc.info.
62
+ The [API Documentation](https://www.mongodb.com/docs/ruby-driver/master/api/) is
63
+ located at mongodb.com/docs.
21
64
 
22
65
  BSON Specification
23
66
  ------------------
24
67
 
25
68
  The [BSON specification](http://bsonspec.org) is at bsonspec.org.
26
69
 
70
+ ## Bugs & Feature Requests
71
+
72
+ To report a bug in the `bson` gem or request a feature:
73
+
74
+ 1. Visit [our issue tracker](https://jira.mongodb.org/) and login
75
+ (or create an account if you do not have one already).
76
+ 2. Navigate to the [RUBY project](https://jira.mongodb.org/browse/RUBY).
77
+ 3. Click 'Create Issue' and fill out all of the applicable form fields, making
78
+ sure to select `BSON` in the _Component/s_ field.
79
+
80
+ When creating an issue, please keep in mind that all information in JIRA
81
+ for the RUBY project, as well as the core server (the SERVER project),
82
+ is publicly visible.
83
+
84
+ **PLEASE DO:**
85
+
86
+ - Provide as much information as possible about the issue.
87
+ - Provide detailed steps for reproducing the issue.
88
+ - Provide any applicable code snippets, stack traces and log data.
89
+ - Specify version numbers of the `bson` gem and/or Ruby driver and MongoDB
90
+ server.
91
+
92
+ **PLEASE DO NOT:**
93
+
94
+ - Provide any sensitive data or server logs.
95
+ - Report potential security issues publicly (see 'Security Issues' below).
96
+
97
+ ## Security Issues
98
+
99
+ If you have identified a potential security-related issue in the `bson` gem
100
+ (or any other MongoDB product), please report it by following the
101
+ [instructions here](https://www.mongodb.com/docs/manual/tutorial/create-a-vulnerability-report).
102
+
103
+ ## Product Feature Requests
104
+
105
+ To request a feature which is not specific to the `bson` gem, or which
106
+ affects more than the `bson` gem and/or Ruby driver alone (for example, a
107
+ feature which requires MongoDB server support), please submit your idea through
108
+ the [MongoDB Feedback Forum](https://feedback.mongodb.com/forums/924286-drivers).
109
+
110
+ ## Maintenance and Bug Fix Policy
111
+
112
+ New library functionality is generally added in a backwards-compatible manner
113
+ and results in new minor releases. Bug fixes are generally made on
114
+ master first and are backported to the current minor library release. Exceptions
115
+ may be made on a case-by-case basis, for example security fixes may be
116
+ backported to older stable branches. Only the most recent minor release
117
+ is officially supported. Customers should use the most recent release in
118
+ their applications.
119
+
27
120
  Versioning
28
121
  ----------
29
122
 
30
- As of 2.0.0, this project adheres to the [Semantic Versioning Specification](http://semver.org/).
123
+ As of 2.0.0, this project adheres to the
124
+ [Semantic Versioning Specification](http://semver.org/).
31
125
 
32
126
  License
33
127
  -------
34
128
 
35
- Copyright (C) 2009-2016 MongoDB Inc.
129
+ Copyright (C) 2009-2020 MongoDB Inc.
36
130
 
37
131
  Licensed under the Apache License, Version 2.0 (the "License");
38
132
  you may not use this file except in compliance with the License.
@@ -45,3 +139,8 @@ distributed under the License is distributed on an "AS IS" BASIS,
45
139
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46
140
  See the License for the specific language governing permissions and
47
141
  limitations under the License.
142
+
143
+ [rubygems-img]: https://badge.fury.io/rb/bson.svg
144
+ [rubygems-url]: http://badge.fury.io/rb/bson
145
+ [ghactions-img]: https://github.com/mongodb/bson-ruby/actions/workflows/bson-ruby.yml/badge.svg?query=branch%3Amaster
146
+ [ghactions-url]: https://github.com/mongodb/bson-ruby/actions/workflows/bson-ruby.yml?query=branch%3Amaster
data/Rakefile CHANGED
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+ # rubocop:todo all
3
+
1
4
  # Copyright (C) 2009-2013 MongoDB Inc.
2
5
  #
3
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,6 +23,11 @@ $LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
20
23
  require "rake"
21
24
  require "rake/extensiontask"
22
25
  require "rspec/core/rake_task"
26
+ require 'fileutils'
27
+
28
+ if File.exist?('./spec/shared/lib/tasks/candidate.rake')
29
+ load './spec/shared/lib/tasks/candidate.rake'
30
+ end
23
31
 
24
32
  def jruby?
25
33
  defined?(JRUBY_VERSION)
@@ -31,45 +39,40 @@ if jruby?
31
39
  ext.name = "bson-ruby"
32
40
  ext.ext_dir = "src"
33
41
  ext.lib_dir = "lib"
42
+ ext.target_version = ENV['TARGET_VERSION'] if ENV['TARGET_VERSION']
43
+ ext.source_version = ENV['SOURCE_VERSION'] if ENV['SOURCE_VERSION']
34
44
  end
35
45
  else
36
46
  require "rake/extensiontask"
37
47
  Rake::ExtensionTask.new do |ext|
38
- ext.name = "native"
48
+ ext.name = "bson_native"
39
49
  ext.ext_dir = "ext/bson"
40
50
  ext.lib_dir = "lib"
41
51
  end
42
52
  end
43
53
 
44
- require "bson/version"
54
+ RSpec::Core::RakeTask.new(:rspec)
45
55
 
46
- def extension
47
- RUBY_PLATFORM =~ /darwin/ ? "bundle" : "so"
56
+ desc 'Build the bson gem'
57
+ task :build => [ :clean_all, *(jruby? ? :compile : nil) ] do
58
+ command = [ 'gem', 'build' ]
59
+ command << "--output=#{ENV['GEM_FILE_NAME']}" if ENV['GEM_FILE_NAME']
60
+ command << ENV['GEMSPEC'] || 'bson.gemspec'
61
+ system(*command)
48
62
  end
49
63
 
50
- require_relative "perf/bench"
51
-
52
- RSpec::Core::RakeTask.new(:rspec)
53
-
54
- if jruby?
55
- task :build => [ :clean_all, :compile ] do
56
- system "gem build bson.gemspec"
57
- end
58
- else
59
- task :build => :clean_all do
60
- system "gem build bson.gemspec"
61
- end
64
+ # `rake version` is used by the deployment system so get the release version
65
+ # of the product beng deployed. It must do nothing more than just print the
66
+ # product version number.
67
+ desc 'Print the current version of the Ruby-BSON library'
68
+ task :version do
69
+ require 'bson/version'
70
+ puts BSON::VERSION
62
71
  end
63
72
 
64
73
  task :clean_all => :clean do
65
- begin
66
- Dir.chdir(Pathname(__FILE__).dirname + "lib") do
67
- `rm native.#{extension}`
68
- `rm native.o`
69
- `rm bson-ruby.jar`
70
- end
71
- rescue Exception => e
72
- puts e.message
74
+ %w[ bson-ruby.jar bson_native.bundle bson_native.so bson_native.o ].each do |file|
75
+ FileUtils.rm_f(File.join(File.dirname(__FILE__), 'lib', file))
73
76
  end
74
77
  end
75
78
 
@@ -77,37 +80,77 @@ task :spec => :compile do
77
80
  Rake::Task["rspec"].invoke
78
81
  end
79
82
 
80
- # Run bundle exec rake release with mri and jruby. Ex:
81
- #
82
- # rvm use 2.1.0@bson
83
- # bundle exec rake release
84
- # rvm use jruby@bson
85
- # bundle exec rake release
86
- task :release => :build do
87
- system "git tag -a v#{BSON::VERSION} -m 'Tagging release: #{BSON::VERSION}'"
88
- system "git push --tags"
89
- if jruby?
90
- system "gem push bson-#{BSON::VERSION}-java.gem"
91
- system "rm bson-#{BSON::VERSION}-java.gem"
92
- else
93
- system "gem push bson-#{BSON::VERSION}.gem"
94
- system "rm bson-#{BSON::VERSION}.gem"
83
+ # overrides the default Bundler-provided `release` task, which also
84
+ # builds the gem. Our release process assumes the gem has already
85
+ # been built (and signed via GPG), so we just need `rake release` to
86
+ # push the gem to rubygems.
87
+ task :release do
88
+ if ENV['GITHUB_ACTION'].nil?
89
+ abort <<~WARNING
90
+ `rake release` must be invoked from the `BSON Release` GitHub action,
91
+ and must not be invoked locally. This ensures the gem is properly signed
92
+ and distributed by the appropriate user.
93
+
94
+ Note that it is the `rubygems/release-gem@v1` step in the `BSON Release`
95
+ action that invokes this task. Do not rename or remove this task, or the
96
+ release-gem step will fail. Reimplement this task with caution.
97
+
98
+ NO GEMS were pushed to RubyGems.
99
+ WARNING
100
+ end
101
+
102
+ # confirm: there ought to be two gems, one for MRI, and one for Java. These
103
+ # will have been previously generated by the 'build' job.
104
+ gems = Dir['*.gem']
105
+ if gems.length != 2
106
+ abort "Expected two gem files to be ready to release; got #{gems.inspect}"
107
+ end
108
+
109
+ gems.each do |gem|
110
+ system 'gem', 'push', gem
95
111
  end
96
112
  end
97
113
 
98
114
  namespace :benchmark do
99
115
 
100
- task :ruby => :clean_all do
116
+ task :prep do
117
+ require_relative "perf/bench"
118
+ end
119
+
120
+ task ruby: [ :clean_all, 'benchmark:prep' ] do
101
121
  puts "Benchmarking pure Ruby..."
102
- require "bson"
103
122
  benchmark!
104
123
  end
105
124
 
106
- task :native => :compile do
125
+ task native: [ :compile, 'benchmark:prep' ] do
107
126
  puts "Benchmarking with native extensions..."
108
- require "bson"
109
127
  benchmark!
110
128
  end
129
+
130
+ namespace :decimal128 do
131
+ task from_string: 'benchmark:prep' do
132
+ puts "Benchmarking creating Decimal128 objects from a string"
133
+ benchmark_decimal128_from_string!
134
+ end
135
+
136
+ task to_string: 'benchmark:prep' do
137
+ puts "Benchmarking getting a string representation of a Decimal128"
138
+ benchmark_decimal128_to_string!
139
+ end
140
+ end
111
141
  end
112
142
 
113
143
  task :default => [ :clean_all, :spec ]
144
+
145
+ desc "Generate all documentation"
146
+ task :docs => 'docs:yard'
147
+
148
+ namespace :docs do
149
+ desc "Generate yard documention"
150
+ task :yard do
151
+ require 'bson/version'
152
+ out = File.join('yard-docs', BSON::VERSION)
153
+ FileUtils.rm_rf(out)
154
+ system "yardoc -o #{out} --title bson-#{BSON::VERSION}"
155
+ end
156
+ end
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2015 MongoDB, Inc.
2
+ * Copyright (C) 2015-2020 MongoDB Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -35,13 +35,14 @@
35
35
  # endif
36
36
  #endif
37
37
 
38
- #ifndef BSON_BYTE_ORDER
39
- # if BYTE_ORDER == LITTLE_ENDIAN
40
- # define BSON_BYTE_ORDER 1234
41
- # elif BYTE_ORDER == BIG_ENDIAN
42
- # define BSON_BYTE_ORDER 4321
43
- # endif
44
- #endif
38
+ /* See a similar check in ruby's sha2.h */
39
+ # ifndef BSON_BYTE_ORDER
40
+ # ifdef WORDS_BIGENDIAN
41
+ # define BSON_BYTE_ORDER BSON_BIG_ENDIAN
42
+ # else
43
+ # define BSON_BYTE_ORDER BSON_LITTLE_ENDIAN
44
+ # endif
45
+ # endif /* BSON_BYTE_ORDER */
45
46
 
46
47
  #if defined(__sun)
47
48
  # define BSON_UINT16_SWAP_LE_BE(v) __bson_uint16_swap_slow((uint16_t)v)
@@ -59,7 +60,7 @@
59
60
  # define BSON_UINT64_SWAP_LE_BE(v) __builtin_bswap64(v)
60
61
  # endif
61
62
  #elif defined(__GNUC__) && (__GNUC__ >= 4)
62
- # if __GNUC__ >= 4 && defined (__GNUC_MINOR__) && __GNUC_MINOR__ >= 3
63
+ # if __GNUC__ > 4 || (defined (__GNUC_MINOR__) && __GNUC_MINOR__ >= 3)
63
64
  # define BSON_UINT32_SWAP_LE_BE(v) __builtin_bswap32 ((uint32_t)v)
64
65
  # define BSON_UINT64_SWAP_LE_BE(v) __builtin_bswap64 ((uint64_t)v)
65
66
  # endif
@@ -105,101 +106,7 @@
105
106
  # error "The endianness of target architecture is unknown."
106
107
  #endif
107
108
 
108
- /*
109
- *--------------------------------------------------------------------------
110
- *
111
- * __bson_uint16_swap_slow --
112
- *
113
- * Fallback endianness conversion for 16-bit integers.
114
- *
115
- * Returns:
116
- * The endian swapped version.
117
- *
118
- * Side effects:
119
- * None.
120
- *
121
- *--------------------------------------------------------------------------
122
- */
123
- static uint16_t __bson_uint16_swap_slow(uint16_t v)
124
- {
125
- return ((v & 0x00FF) << 8) |
126
- ((v & 0xFF00) >> 8);
127
- }
128
-
129
- /*
130
- *--------------------------------------------------------------------------
131
- *
132
- * __bson_uint32_swap_slow --
133
- *
134
- * Fallback endianness conversion for 32-bit integers.
135
- *
136
- * Returns:
137
- * The endian swapped version.
138
- *
139
- * Side effects:
140
- * None.
141
- *
142
- *--------------------------------------------------------------------------
143
- */
144
- static uint32_t __bson_uint32_swap_slow(uint32_t v)
145
- {
146
- return ((v & 0x000000FFU) << 24) |
147
- ((v & 0x0000FF00U) << 8) |
148
- ((v & 0x00FF0000U) >> 8) |
149
- ((v & 0xFF000000U) >> 24);
150
- }
151
-
152
-
153
- /*
154
- *--------------------------------------------------------------------------
155
- *
156
- * __bson_uint64_swap_slow --
157
- *
158
- * Fallback endianness conversion for 64-bit integers.
159
- *
160
- * Returns:
161
- * The endian swapped version.
162
- *
163
- * Side effects:
164
- * None.
165
- *
166
- *--------------------------------------------------------------------------
167
- */
168
- static uint64_t __bson_uint64_swap_slow(uint64_t v)
169
- {
170
- return ((v & 0x00000000000000FFULL) << 56) |
171
- ((v & 0x000000000000FF00ULL) << 40) |
172
- ((v & 0x0000000000FF0000ULL) << 24) |
173
- ((v & 0x00000000FF000000ULL) << 8) |
174
- ((v & 0x000000FF00000000ULL) >> 8) |
175
- ((v & 0x0000FF0000000000ULL) >> 24) |
176
- ((v & 0x00FF000000000000ULL) >> 40) |
177
- ((v & 0xFF00000000000000ULL) >> 56);
178
- }
179
-
180
- /*
181
- *--------------------------------------------------------------------------
182
- *
183
- * __bson_double_swap_slow --
184
- *
185
- * Fallback endianness conversion for double floating point.
186
- *
187
- * Returns:
188
- * The endian swapped version.
189
- *
190
- * Side effects:
191
- * None.
192
- *
193
- *--------------------------------------------------------------------------
194
- */
195
- static double __bson_double_swap_slow(double v)
196
- {
197
- uint64_t uv;
198
-
199
- memcpy(&uv, &v, sizeof(v));
200
- uv = BSON_UINT64_SWAP_LE_BE(uv);
201
- memcpy(&v, &uv, sizeof(v));
202
-
203
- return v;
204
- }
205
-
109
+ uint16_t __bson_uint16_swap_slow(uint16_t v);
110
+ uint32_t __bson_uint32_swap_slow(uint32_t v);
111
+ uint64_t __bson_uint64_swap_slow(uint64_t v);
112
+ double __bson_double_swap_slow(double v);
@@ -0,0 +1,135 @@
1
+ /*
2
+ * Copyright (C) 2009-2020 MongoDB Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #include <ruby.h>
18
+ #include <stdbool.h>
19
+ #include <stdint.h>
20
+ #include <stdlib.h>
21
+ #include <unistd.h>
22
+ #include <time.h>
23
+ #include "bson-endian.h"
24
+
25
+ void
26
+ rb_bson_utf8_validate (const char *utf8, /* IN */
27
+ size_t utf8_len, /* IN */
28
+ bool allow_null, /* IN */
29
+ const char *data_type); /* IN */
30
+
31
+ #define BSON_BYTE_BUFFER_SIZE 1024
32
+
33
+ #ifndef HOST_NAME_HASH_MAX
34
+ #define HOST_NAME_HASH_MAX 256
35
+ #endif
36
+
37
+ /* See the type list in http://bsonspec.org/spec.html. */
38
+ #define BSON_TYPE_DOUBLE 1
39
+ #define BSON_TYPE_STRING 2
40
+ #define BSON_TYPE_DOCUMENT 3
41
+ #define BSON_TYPE_ARRAY 4
42
+ #define BSON_TYPE_BOOLEAN 8
43
+ #define BSON_TYPE_SYMBOL 0x0E
44
+ #define BSON_TYPE_INT32 0x10
45
+ #define BSON_TYPE_INT64 0x12
46
+
47
+ typedef struct {
48
+ size_t size;
49
+ size_t write_position;
50
+ size_t read_position;
51
+ char buffer[BSON_BYTE_BUFFER_SIZE];
52
+ char *b_ptr;
53
+ } byte_buffer_t;
54
+
55
+ #define READ_PTR(byte_buffer_ptr) \
56
+ (byte_buffer_ptr->b_ptr + byte_buffer_ptr->read_position)
57
+
58
+ #define READ_SIZE(byte_buffer_ptr) \
59
+ (byte_buffer_ptr->write_position - byte_buffer_ptr->read_position)
60
+
61
+ #define WRITE_PTR(byte_buffer_ptr) \
62
+ (byte_buffer_ptr->b_ptr + byte_buffer_ptr->write_position)
63
+
64
+ #define ENSURE_BSON_WRITE(buffer_ptr, length) \
65
+ { if (buffer_ptr->write_position + length > buffer_ptr->size) rb_bson_expand_buffer(buffer_ptr, length); }
66
+
67
+ #define ENSURE_BSON_READ(buffer_ptr, length) \
68
+ { if (buffer_ptr->read_position + length > buffer_ptr->write_position) \
69
+ rb_raise(rb_eRangeError, "Attempted to read %zu bytes, but only %zu bytes remain", (size_t)length, READ_SIZE(buffer_ptr)); }
70
+
71
+ VALUE rb_bson_byte_buffer_allocate(VALUE klass);
72
+ VALUE rb_bson_byte_buffer_initialize(int argc, VALUE *argv, VALUE self);
73
+ VALUE rb_bson_byte_buffer_length(VALUE self);
74
+ VALUE rb_bson_byte_buffer_get_byte(VALUE self);
75
+ VALUE rb_bson_byte_buffer_get_bytes(VALUE self, VALUE i);
76
+ VALUE rb_bson_byte_buffer_get_cstring(VALUE self);
77
+ VALUE rb_bson_byte_buffer_get_decimal128_bytes(VALUE self);
78
+ VALUE rb_bson_byte_buffer_get_double(VALUE self);
79
+ VALUE rb_bson_byte_buffer_get_int32(VALUE self);
80
+ VALUE rb_bson_byte_buffer_get_uint32(VALUE self);
81
+ VALUE rb_bson_byte_buffer_get_int64(VALUE self);
82
+ VALUE rb_bson_byte_buffer_get_string(VALUE self);
83
+ VALUE rb_bson_byte_buffer_get_hash(int argc, VALUE *argv, VALUE self);
84
+ VALUE rb_bson_byte_buffer_get_array(int argc, VALUE *argv, VALUE self);
85
+ VALUE rb_bson_byte_buffer_put_byte(VALUE self, VALUE byte);
86
+ VALUE rb_bson_byte_buffer_put_bytes(VALUE self, VALUE bytes);
87
+ VALUE rb_bson_byte_buffer_put_cstring(VALUE self, VALUE string);
88
+ VALUE rb_bson_byte_buffer_put_decimal128(VALUE self, VALUE low, VALUE high);
89
+ VALUE rb_bson_byte_buffer_put_double(VALUE self, VALUE f);
90
+ VALUE rb_bson_byte_buffer_put_int32(VALUE self, VALUE i);
91
+ VALUE rb_bson_byte_buffer_put_uint32(VALUE self, VALUE i);
92
+ VALUE rb_bson_byte_buffer_put_int64(VALUE self, VALUE i);
93
+ VALUE rb_bson_byte_buffer_put_string(VALUE self, VALUE string);
94
+ VALUE rb_bson_byte_buffer_put_symbol(VALUE self, VALUE symbol);
95
+ VALUE rb_bson_byte_buffer_put_hash(VALUE self, VALUE hash);
96
+ VALUE rb_bson_byte_buffer_put_array(VALUE self, VALUE array);
97
+ VALUE rb_bson_byte_buffer_read_position(VALUE self);
98
+ VALUE rb_bson_byte_buffer_replace_int32(VALUE self, VALUE index, VALUE i);
99
+ VALUE rb_bson_byte_buffer_rewind(VALUE self);
100
+ VALUE rb_bson_byte_buffer_write_position(VALUE self);
101
+ VALUE rb_bson_byte_buffer_to_s(VALUE self);
102
+
103
+ VALUE rb_bson_object_id_generator_next(int argc, VALUE* args, VALUE self);
104
+ VALUE rb_bson_object_id_generator_reset_counter(int argc, VALUE* args, VALUE self);
105
+
106
+ size_t rb_bson_byte_buffer_memsize(const void *ptr);
107
+ void rb_bson_byte_buffer_free(void *ptr);
108
+ void rb_bson_expand_buffer(byte_buffer_t* buffer_ptr, size_t length);
109
+ void rb_bson_generate_machine_id(VALUE rb_md5_class, char *rb_bson_machine_id);
110
+
111
+ VALUE pvt_const_get_2(const char *c1, const char *c2);
112
+ VALUE pvt_const_get_3(const char *c1, const char *c2, const char *c3);
113
+
114
+ #define BSON_MODE_DEFAULT 0
115
+ #define BSON_MODE_BSON 1
116
+
117
+ int pvt_get_mode_option(int argc, VALUE *argv);
118
+
119
+ #define BSON_OBJECT_ID_RANDOM_VALUE_LENGTH ( 5 )
120
+
121
+ uint8_t* pvt_get_object_id_random_value();
122
+ void pvt_init_rand();
123
+ void pvt_rand_buf(uint8_t* bytes, int len, int pid);
124
+ int pvt_rand();
125
+
126
+ /**
127
+ * The counter for incrementing object ids.
128
+ */
129
+ extern uint32_t rb_bson_object_id_counter;
130
+
131
+ extern VALUE rb_bson_registry;
132
+
133
+ extern const rb_data_type_t rb_byte_buffer_data_type;
134
+
135
+ extern VALUE _ref_str, _id_str, _db_str;