Skip to content

Commit 191f6ca

Browse files
committed
Merge branch 'master' into PYTHON-4784
2 parents cefeb32 + b111cbf commit 191f6ca

24 files changed

+688
-218
lines changed

bson/_cbsonmodule.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static PyObject* _test_long_long_to_str(PyObject* self, PyObject* args) {
207207
*
208208
* Returns a new ref */
209209
static PyObject* _error(char* name) {
210-
PyObject* error;
210+
PyObject* error = NULL;
211211
PyObject* errors = PyImport_ImportModule("bson.errors");
212212
if (!errors) {
213213
return NULL;
@@ -279,7 +279,7 @@ static PyObject* datetime_from_millis(long long millis) {
279279
* micros = diff * 1000 111000
280280
* Resulting in datetime(1, 1, 1, 1, 1, 1, 111000) -- the expected result
281281
*/
282-
PyObject* datetime;
282+
PyObject* datetime = NULL;
283283
int diff = (int)(((millis % 1000) + 1000) % 1000);
284284
int microseconds = diff * 1000;
285285
Time64_T seconds = (millis - diff) / 1000;
@@ -294,7 +294,7 @@ static PyObject* datetime_from_millis(long long millis) {
294294
timeinfo.tm_sec,
295295
microseconds);
296296
if(!datetime) {
297-
PyObject *etype, *evalue, *etrace;
297+
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
298298

299299
/*
300300
* Calling _error clears the error state, so fetch it first.
@@ -350,8 +350,8 @@ static PyObject* datetime_ms_from_millis(PyObject* self, long long millis){
350350
return NULL;
351351
}
352352

353-
PyObject* dt;
354-
PyObject* ll_millis;
353+
PyObject* dt = NULL;
354+
PyObject* ll_millis = NULL;
355355

356356
if (!(ll_millis = PyLong_FromLongLong(millis))){
357357
return NULL;
@@ -1790,7 +1790,7 @@ static PyObject* _cbson_dict_to_bson(PyObject* self, PyObject* args) {
17901790
PyObject* result;
17911791
unsigned char check_keys;
17921792
unsigned char top_level = 1;
1793-
PyObject* options_obj;
1793+
PyObject* options_obj = NULL;
17941794
codec_options_t options;
17951795
buffer_t buffer;
17961796
PyObject* raw_bson_document_bytes_obj;
@@ -2512,8 +2512,8 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,
25122512
* Wrap any non-InvalidBSON errors in InvalidBSON.
25132513
*/
25142514
if (PyErr_Occurred()) {
2515-
PyObject *etype, *evalue, *etrace;
2516-
PyObject *InvalidBSON;
2515+
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
2516+
PyObject *InvalidBSON = NULL;
25172517

25182518
/*
25192519
* Calling _error clears the error state, so fetch it first.
@@ -2585,8 +2585,8 @@ static int _element_to_dict(PyObject* self, const char* string,
25852585
if (!*name) {
25862586
/* If NULL is returned then wrap the UnicodeDecodeError
25872587
in an InvalidBSON error */
2588-
PyObject *etype, *evalue, *etrace;
2589-
PyObject *InvalidBSON;
2588+
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
2589+
PyObject *InvalidBSON = NULL;
25902590

25912591
PyErr_Fetch(&etype, &evalue, &etrace);
25922592
if (PyErr_GivenExceptionMatches(etype, PyExc_Exception)) {
@@ -2620,7 +2620,7 @@ static PyObject* _cbson_element_to_dict(PyObject* self, PyObject* args) {
26202620
/* TODO: Support buffer protocol */
26212621
char* string;
26222622
PyObject* bson;
2623-
PyObject* options_obj;
2623+
PyObject* options_obj = NULL;
26242624
codec_options_t options;
26252625
unsigned position;
26262626
unsigned max;
@@ -2732,7 +2732,7 @@ static PyObject* _cbson_bson_to_dict(PyObject* self, PyObject* args) {
27322732
int32_t size;
27332733
Py_ssize_t total_size;
27342734
const char* string;
2735-
PyObject* bson;
2735+
PyObject* bson = NULL;
27362736
codec_options_t options;
27372737
PyObject* result = NULL;
27382738
PyObject* options_obj;

bson/binary.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def from_vector(
432432
raise NotImplementedError("%s not yet supported" % dtype)
433433

434434
metadata = struct.pack("<sB", dtype.value, padding)
435-
data = struct.pack(f"{len(vector)}{format_str}", *vector)
435+
data = struct.pack(f"<{len(vector)}{format_str}", *vector)
436436
return cls(metadata + data, subtype=VECTOR_SUBTYPE)
437437

438438
def as_vector(self) -> BinaryVector:
@@ -454,7 +454,7 @@ def as_vector(self) -> BinaryVector:
454454

455455
if dtype == BinaryVectorDtype.INT8:
456456
dtype_format = "b"
457-
format_string = f"{n_values}{dtype_format}"
457+
format_string = f"<{n_values}{dtype_format}"
458458
vector = list(struct.unpack_from(format_string, self, position))
459459
return BinaryVector(vector, dtype, padding)
460460

@@ -465,13 +465,16 @@ def as_vector(self) -> BinaryVector:
465465
raise ValueError(
466466
"Corrupt data. N bytes for a float32 vector must be a multiple of 4."
467467
)
468-
vector = list(struct.unpack_from(f"{n_values}f", self, position))
468+
dtype_format = "f"
469+
format_string = f"<{n_values}{dtype_format}"
470+
vector = list(struct.unpack_from(format_string, self, position))
469471
return BinaryVector(vector, dtype, padding)
470472

471473
elif dtype == BinaryVectorDtype.PACKED_BIT:
472474
# data packed as uint8
473475
dtype_format = "B"
474-
unpacked_uint8s = list(struct.unpack_from(f"{n_values}{dtype_format}", self, position))
476+
format_string = f"<{n_values}{dtype_format}"
477+
unpacked_uint8s = list(struct.unpack_from(format_string, self, position))
475478
return BinaryVector(unpacked_uint8s, dtype, padding)
476479

477480
else:

doc/changelog.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
Changelog
22
=========
33

4+
Changes in Version 4.10.1
5+
-------------------------
6+
7+
Version 4.10.1 is a bug fix release.
8+
9+
- Fixed a bug where :meth:`~pymongo.results.UpdateResult.did_upsert` would raise a ``TypeError``.
10+
- Fixed Binary BSON subtype (9) support on big-endian operating systems (such as zSeries).
11+
12+
Issues Resolved
13+
...............
14+
15+
See the `PyMongo 4.10.1 release notes in JIRA`_ for the list of resolved issues
16+
in this release.
17+
18+
.. _PyMongo 4.10.1 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=40788
19+
20+
421
Changes in Version 4.10.0
522
-------------------------
623

@@ -19,6 +36,36 @@ in this release.
1936

2037
.. _PyMongo 4.10 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=40553
2138

39+
Changes in Version 4.9.2
40+
-------------------------
41+
42+
- Fixed a bug where :class:`~pymongo.asynchronous.mongo_client.AsyncMongoClient` could deadlock.
43+
- Fixed a bug where PyMongo could fail to import on Windows if ``asyncio`` is misconfigured.
44+
- Fixed a bug where :meth:`~pymongo.results.UpdateResult.did_upsert` would raise a ``TypeError``.
45+
46+
Issues Resolved
47+
...............
48+
49+
See the `PyMongo 4.9.2 release notes in JIRA`_ for the list of resolved issues
50+
in this release.
51+
52+
.. _PyMongo 4.9.2 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=40732
53+
54+
55+
Changes in Version 4.9.1
56+
-------------------------
57+
58+
- Add missing documentation about the fact the async API is in beta state.
59+
60+
Issues Resolved
61+
...............
62+
63+
See the `PyMongo 4.9.1 release notes in JIRA`_ for the list of resolved issues
64+
in this release.
65+
66+
.. _PyMongo 4.9.1 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=40720
67+
68+
2269
Changes in Version 4.9.0
2370
-------------------------
2471

hatch.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ features = ["test"]
4343
test = "pytest -v --durations=5 --maxfail=10 {args}"
4444
test-eg = "bash ./.evergreen/run-tests.sh {args}"
4545
test-async = "pytest -v --durations=5 --maxfail=10 -m default_async {args}"
46-
test-mockupdb = ["pip install -U git+https://github.com/ajdavis/mongo-mockup-db@master", "test -m mockupdb"]
46+
test-mockupdb = ["pip install -U git+https://github.com/mongodb-labs/mongo-mockup-db@master", "test -m mockupdb"]
4747

4848
[envs.encryption]
4949
skip-install = true

pymongo/_cmessagemodule.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct module_state {
4545
*
4646
* Returns a new ref */
4747
static PyObject* _error(char* name) {
48-
PyObject* error;
48+
PyObject* error = NULL;
4949
PyObject* errors = PyImport_ImportModule("pymongo.errors");
5050
if (!errors) {
5151
return NULL;
@@ -75,9 +75,9 @@ static PyObject* _cbson_query_message(PyObject* self, PyObject* args) {
7575
int begin, cur_size, max_size = 0;
7676
int num_to_skip;
7777
int num_to_return;
78-
PyObject* query;
79-
PyObject* field_selector;
80-
PyObject* options_obj;
78+
PyObject* query = NULL;
79+
PyObject* field_selector = NULL;
80+
PyObject* options_obj = NULL;
8181
codec_options_t options;
8282
buffer_t buffer = NULL;
8383
int length_location, message_length;
@@ -221,12 +221,12 @@ static PyObject* _cbson_op_msg(PyObject* self, PyObject* args) {
221221
/* NOTE just using a random number as the request_id */
222222
int request_id = rand();
223223
unsigned int flags;
224-
PyObject* command;
224+
PyObject* command = NULL;
225225
char* identifier = NULL;
226226
Py_ssize_t identifier_length = 0;
227-
PyObject* docs;
228-
PyObject* doc;
229-
PyObject* options_obj;
227+
PyObject* docs = NULL;
228+
PyObject* doc = NULL;
229+
PyObject* options_obj = NULL;
230230
codec_options_t options;
231231
buffer_t buffer = NULL;
232232
int length_location, message_length;
@@ -535,12 +535,12 @@ static PyObject*
535535
_cbson_encode_batched_op_msg(PyObject* self, PyObject* args) {
536536
unsigned char op;
537537
unsigned char ack;
538-
PyObject* command;
539-
PyObject* docs;
538+
PyObject* command = NULL;
539+
PyObject* docs = NULL;
540540
PyObject* ctx = NULL;
541541
PyObject* to_publish = NULL;
542542
PyObject* result = NULL;
543-
PyObject* options_obj;
543+
PyObject* options_obj = NULL;
544544
codec_options_t options;
545545
buffer_t buffer;
546546
struct module_state *state = GETSTATE(self);
@@ -592,12 +592,12 @@ _cbson_batched_op_msg(PyObject* self, PyObject* args) {
592592
unsigned char ack;
593593
int request_id;
594594
int position;
595-
PyObject* command;
596-
PyObject* docs;
595+
PyObject* command = NULL;
596+
PyObject* docs = NULL;
597597
PyObject* ctx = NULL;
598598
PyObject* to_publish = NULL;
599599
PyObject* result = NULL;
600-
PyObject* options_obj;
600+
PyObject* options_obj = NULL;
601601
codec_options_t options;
602602
buffer_t buffer;
603603
struct module_state *state = GETSTATE(self);
@@ -868,12 +868,12 @@ _cbson_encode_batched_write_command(PyObject* self, PyObject* args) {
868868
char *ns = NULL;
869869
unsigned char op;
870870
Py_ssize_t ns_len;
871-
PyObject* command;
872-
PyObject* docs;
871+
PyObject* command = NULL;
872+
PyObject* docs = NULL;
873873
PyObject* ctx = NULL;
874874
PyObject* to_publish = NULL;
875875
PyObject* result = NULL;
876-
PyObject* options_obj;
876+
PyObject* options_obj = NULL;
877877
codec_options_t options;
878878
buffer_t buffer;
879879
struct module_state *state = GETSTATE(self);

0 commit comments

Comments
 (0)