Skip to content

Commit

Permalink
Merge branch 'master' into PYTHON-4784
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahStapp committed Oct 3, 2024
2 parents cefeb32 + b111cbf commit 191f6ca
Show file tree
Hide file tree
Showing 24 changed files with 688 additions and 218 deletions.
24 changes: 12 additions & 12 deletions bson/_cbsonmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static PyObject* _test_long_long_to_str(PyObject* self, PyObject* args) {
*
* Returns a new ref */
static PyObject* _error(char* name) {
PyObject* error;
PyObject* error = NULL;
PyObject* errors = PyImport_ImportModule("bson.errors");
if (!errors) {
return NULL;
Expand Down Expand Up @@ -279,7 +279,7 @@ static PyObject* datetime_from_millis(long long millis) {
* micros = diff * 1000 111000
* Resulting in datetime(1, 1, 1, 1, 1, 1, 111000) -- the expected result
*/
PyObject* datetime;
PyObject* datetime = NULL;
int diff = (int)(((millis % 1000) + 1000) % 1000);
int microseconds = diff * 1000;
Time64_T seconds = (millis - diff) / 1000;
Expand All @@ -294,7 +294,7 @@ static PyObject* datetime_from_millis(long long millis) {
timeinfo.tm_sec,
microseconds);
if(!datetime) {
PyObject *etype, *evalue, *etrace;
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;

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

PyObject* dt;
PyObject* ll_millis;
PyObject* dt = NULL;
PyObject* ll_millis = NULL;

if (!(ll_millis = PyLong_FromLongLong(millis))){
return NULL;
Expand Down Expand Up @@ -1790,7 +1790,7 @@ static PyObject* _cbson_dict_to_bson(PyObject* self, PyObject* args) {
PyObject* result;
unsigned char check_keys;
unsigned char top_level = 1;
PyObject* options_obj;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer;
PyObject* raw_bson_document_bytes_obj;
Expand Down Expand Up @@ -2512,8 +2512,8 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,
* Wrap any non-InvalidBSON errors in InvalidBSON.
*/
if (PyErr_Occurred()) {
PyObject *etype, *evalue, *etrace;
PyObject *InvalidBSON;
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
PyObject *InvalidBSON = NULL;

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

PyErr_Fetch(&etype, &evalue, &etrace);
if (PyErr_GivenExceptionMatches(etype, PyExc_Exception)) {
Expand Down Expand Up @@ -2620,7 +2620,7 @@ static PyObject* _cbson_element_to_dict(PyObject* self, PyObject* args) {
/* TODO: Support buffer protocol */
char* string;
PyObject* bson;
PyObject* options_obj;
PyObject* options_obj = NULL;
codec_options_t options;
unsigned position;
unsigned max;
Expand Down Expand Up @@ -2732,7 +2732,7 @@ static PyObject* _cbson_bson_to_dict(PyObject* self, PyObject* args) {
int32_t size;
Py_ssize_t total_size;
const char* string;
PyObject* bson;
PyObject* bson = NULL;
codec_options_t options;
PyObject* result = NULL;
PyObject* options_obj;
Expand Down
11 changes: 7 additions & 4 deletions bson/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def from_vector(
raise NotImplementedError("%s not yet supported" % dtype)

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

def as_vector(self) -> BinaryVector:
Expand All @@ -454,7 +454,7 @@ def as_vector(self) -> BinaryVector:

if dtype == BinaryVectorDtype.INT8:
dtype_format = "b"
format_string = f"{n_values}{dtype_format}"
format_string = f"<{n_values}{dtype_format}"
vector = list(struct.unpack_from(format_string, self, position))
return BinaryVector(vector, dtype, padding)

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

elif dtype == BinaryVectorDtype.PACKED_BIT:
# data packed as uint8
dtype_format = "B"
unpacked_uint8s = list(struct.unpack_from(f"{n_values}{dtype_format}", self, position))
format_string = f"<{n_values}{dtype_format}"
unpacked_uint8s = list(struct.unpack_from(format_string, self, position))
return BinaryVector(unpacked_uint8s, dtype, padding)

else:
Expand Down
47 changes: 47 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
Changelog
=========

Changes in Version 4.10.1
-------------------------

Version 4.10.1 is a bug fix release.

- Fixed a bug where :meth:`~pymongo.results.UpdateResult.did_upsert` would raise a ``TypeError``.
- Fixed Binary BSON subtype (9) support on big-endian operating systems (such as zSeries).

Issues Resolved
...............

See the `PyMongo 4.10.1 release notes in JIRA`_ for the list of resolved issues
in this release.

.. _PyMongo 4.10.1 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=40788


Changes in Version 4.10.0
-------------------------

Expand All @@ -19,6 +36,36 @@ in this release.

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

Changes in Version 4.9.2
-------------------------

- Fixed a bug where :class:`~pymongo.asynchronous.mongo_client.AsyncMongoClient` could deadlock.
- Fixed a bug where PyMongo could fail to import on Windows if ``asyncio`` is misconfigured.
- Fixed a bug where :meth:`~pymongo.results.UpdateResult.did_upsert` would raise a ``TypeError``.

Issues Resolved
...............

See the `PyMongo 4.9.2 release notes in JIRA`_ for the list of resolved issues
in this release.

.. _PyMongo 4.9.2 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=40732


Changes in Version 4.9.1
-------------------------

- Add missing documentation about the fact the async API is in beta state.

Issues Resolved
...............

See the `PyMongo 4.9.1 release notes in JIRA`_ for the list of resolved issues
in this release.

.. _PyMongo 4.9.1 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=40720


Changes in Version 4.9.0
-------------------------

Expand Down
2 changes: 1 addition & 1 deletion hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ features = ["test"]
test = "pytest -v --durations=5 --maxfail=10 {args}"
test-eg = "bash ./.evergreen/run-tests.sh {args}"
test-async = "pytest -v --durations=5 --maxfail=10 -m default_async {args}"
test-mockupdb = ["pip install -U git+https://github.com/ajdavis/mongo-mockup-db@master", "test -m mockupdb"]
test-mockupdb = ["pip install -U git+https://github.com/mongodb-labs/mongo-mockup-db@master", "test -m mockupdb"]

[envs.encryption]
skip-install = true
Expand Down
34 changes: 17 additions & 17 deletions pymongo/_cmessagemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct module_state {
*
* Returns a new ref */
static PyObject* _error(char* name) {
PyObject* error;
PyObject* error = NULL;
PyObject* errors = PyImport_ImportModule("pymongo.errors");
if (!errors) {
return NULL;
Expand Down Expand Up @@ -75,9 +75,9 @@ static PyObject* _cbson_query_message(PyObject* self, PyObject* args) {
int begin, cur_size, max_size = 0;
int num_to_skip;
int num_to_return;
PyObject* query;
PyObject* field_selector;
PyObject* options_obj;
PyObject* query = NULL;
PyObject* field_selector = NULL;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer = NULL;
int length_location, message_length;
Expand Down Expand Up @@ -221,12 +221,12 @@ static PyObject* _cbson_op_msg(PyObject* self, PyObject* args) {
/* NOTE just using a random number as the request_id */
int request_id = rand();
unsigned int flags;
PyObject* command;
PyObject* command = NULL;
char* identifier = NULL;
Py_ssize_t identifier_length = 0;
PyObject* docs;
PyObject* doc;
PyObject* options_obj;
PyObject* docs = NULL;
PyObject* doc = NULL;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer = NULL;
int length_location, message_length;
Expand Down Expand Up @@ -535,12 +535,12 @@ static PyObject*
_cbson_encode_batched_op_msg(PyObject* self, PyObject* args) {
unsigned char op;
unsigned char ack;
PyObject* command;
PyObject* docs;
PyObject* command = NULL;
PyObject* docs = NULL;
PyObject* ctx = NULL;
PyObject* to_publish = NULL;
PyObject* result = NULL;
PyObject* options_obj;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer;
struct module_state *state = GETSTATE(self);
Expand Down Expand Up @@ -592,12 +592,12 @@ _cbson_batched_op_msg(PyObject* self, PyObject* args) {
unsigned char ack;
int request_id;
int position;
PyObject* command;
PyObject* docs;
PyObject* command = NULL;
PyObject* docs = NULL;
PyObject* ctx = NULL;
PyObject* to_publish = NULL;
PyObject* result = NULL;
PyObject* options_obj;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer;
struct module_state *state = GETSTATE(self);
Expand Down Expand Up @@ -868,12 +868,12 @@ _cbson_encode_batched_write_command(PyObject* self, PyObject* args) {
char *ns = NULL;
unsigned char op;
Py_ssize_t ns_len;
PyObject* command;
PyObject* docs;
PyObject* command = NULL;
PyObject* docs = NULL;
PyObject* ctx = NULL;
PyObject* to_publish = NULL;
PyObject* result = NULL;
PyObject* options_obj;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer;
struct module_state *state = GETSTATE(self);
Expand Down
Loading

0 comments on commit 191f6ca

Please sign in to comment.