PYTHON-2110 Refactored some C to avoid symbol conflicts (#968)
* Refactored to avoid symbol conflicts * Forgot a replacement * Found a symbol * Undid symbol replacement for PyInit__cmessage * Changed cbson too Co-authored-by: Ben Warner <ben.warner@mongodb.com>
This commit is contained in:
parent
b8653b018d
commit
be3008aa11
@ -153,7 +153,7 @@ static PyObject* datetime_from_millis(long long millis) {
|
||||
int microseconds = diff * 1000;
|
||||
Time64_T seconds = (millis - diff) / 1000;
|
||||
struct TM timeinfo;
|
||||
gmtime64_r(&seconds, &timeinfo);
|
||||
cbson_gmtime64_r(&seconds, &timeinfo);
|
||||
|
||||
return PyDateTime_FromDateAndTime(timeinfo.tm_year + 1900,
|
||||
timeinfo.tm_mon + 1,
|
||||
@ -175,14 +175,14 @@ static long long millis_from_datetime(PyObject* datetime) {
|
||||
timeinfo.tm_min = PyDateTime_DATE_GET_MINUTE(datetime);
|
||||
timeinfo.tm_sec = PyDateTime_DATE_GET_SECOND(datetime);
|
||||
|
||||
millis = timegm64(&timeinfo) * 1000;
|
||||
millis = cbson_timegm64(&timeinfo) * 1000;
|
||||
millis += PyDateTime_DATE_GET_MICROSECOND(datetime) / 1000;
|
||||
return millis;
|
||||
}
|
||||
|
||||
/* Just make this compatible w/ the old API. */
|
||||
int buffer_write_bytes(buffer_t buffer, const char* data, int size) {
|
||||
if (buffer_write(buffer, data, size)) {
|
||||
if (pymongo_buffer_write(buffer, data, size)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -207,7 +207,7 @@ void buffer_write_int32_at_position(buffer_t buffer,
|
||||
int position,
|
||||
int32_t data) {
|
||||
uint32_t data_le = BSON_UINT32_TO_LE(data);
|
||||
memcpy(buffer_get_buffer(buffer) + position, &data_le, 4);
|
||||
memcpy(pymongo_buffer_get_buffer(buffer) + position, &data_le, 4);
|
||||
}
|
||||
|
||||
static int write_unicode(buffer_t buffer, PyObject* py_string) {
|
||||
@ -419,7 +419,7 @@ static long _type_marker(PyObject* object) {
|
||||
* Return 1 on success. options->document_class is a new reference.
|
||||
* Return 0 on failure.
|
||||
*/
|
||||
int convert_type_registry(PyObject* registry_obj, type_registry_t* registry) {
|
||||
int cbson_convert_type_registry(PyObject* registry_obj, type_registry_t* registry) {
|
||||
registry->encoder_map = NULL;
|
||||
registry->decoder_map = NULL;
|
||||
registry->fallback_encoder = NULL;
|
||||
@ -481,7 +481,7 @@ int convert_codec_options(PyObject* options_obj, void* p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!convert_type_registry(type_registry_obj,
|
||||
if (!cbson_convert_type_registry(type_registry_obj,
|
||||
&options->type_registry)) {
|
||||
return 0;
|
||||
}
|
||||
@ -597,7 +597,7 @@ static int _write_regex_to_buffer(
|
||||
Py_DECREF(encoded_pattern);
|
||||
return 0;
|
||||
}
|
||||
status = check_string((const unsigned char*)pattern_data,
|
||||
status = cbson_check_string((const unsigned char*)pattern_data,
|
||||
pattern_length, check_utf8, 1);
|
||||
if (status == NOT_UTF_8) {
|
||||
PyObject* InvalidStringData = _error("InvalidStringData");
|
||||
@ -649,7 +649,7 @@ static int _write_regex_to_buffer(
|
||||
if (!buffer_write_bytes(buffer, flags, flags_length)) {
|
||||
return 0;
|
||||
}
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x0B;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x0B;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -687,7 +687,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
const char* data;
|
||||
int size;
|
||||
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x05;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x05;
|
||||
subtype_object = PyObject_GetAttrString(value, "subtype");
|
||||
if (!subtype_object) {
|
||||
return 0;
|
||||
@ -750,7 +750,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
return 0;
|
||||
}
|
||||
Py_DECREF(pystring);
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x07;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x07;
|
||||
return 1;
|
||||
}
|
||||
case 11:
|
||||
@ -772,15 +772,15 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
|
||||
if (scope == Py_None) {
|
||||
Py_DECREF(scope);
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x0D;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x0D;
|
||||
return write_string(buffer, value);
|
||||
}
|
||||
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x0F;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x0F;
|
||||
|
||||
start_position = buffer_get_position(buffer);
|
||||
start_position = pymongo_buffer_get_position(buffer);
|
||||
/* save space for length */
|
||||
length_location = buffer_save_space(buffer, 4);
|
||||
length_location = pymongo_buffer_save_space(buffer, 4);
|
||||
if (length_location == -1) {
|
||||
Py_DECREF(scope);
|
||||
return 0;
|
||||
@ -797,7 +797,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
}
|
||||
Py_DECREF(scope);
|
||||
|
||||
length = buffer_get_position(buffer) - start_position;
|
||||
length = pymongo_buffer_get_position(buffer) - start_position;
|
||||
buffer_write_int32_at_position(
|
||||
buffer, length_location, (int32_t)length);
|
||||
return 1;
|
||||
@ -834,7 +834,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
return 0;
|
||||
}
|
||||
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x11;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x11;
|
||||
return 1;
|
||||
}
|
||||
case 18:
|
||||
@ -849,7 +849,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
if (!buffer_write_int64(buffer, (int64_t)ll)) {
|
||||
return 0;
|
||||
}
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x12;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x12;
|
||||
return 1;
|
||||
}
|
||||
case 19:
|
||||
@ -870,7 +870,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
return 0;
|
||||
}
|
||||
Py_DECREF(pystring);
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x13;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x13;
|
||||
return 1;
|
||||
}
|
||||
case 100:
|
||||
@ -885,7 +885,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
return 0;
|
||||
}
|
||||
Py_DECREF(as_doc);
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x03;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x03;
|
||||
return 1;
|
||||
}
|
||||
case 101:
|
||||
@ -894,19 +894,19 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
if (!write_raw_doc(buffer, value)) {
|
||||
return 0;
|
||||
}
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x03;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x03;
|
||||
return 1;
|
||||
}
|
||||
case 255:
|
||||
{
|
||||
/* MinKey */
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0xFF;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0xFF;
|
||||
return 1;
|
||||
}
|
||||
case 127:
|
||||
{
|
||||
/* MaxKey */
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x7F;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x7F;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -915,7 +915,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
|
||||
if (PyBool_Check(value)) {
|
||||
const char c = (value == Py_True) ? 0x01 : 0x00;
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x08;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x08;
|
||||
return buffer_write_bytes(buffer, &c, 1);
|
||||
}
|
||||
else if (PyLong_Check(value)) {
|
||||
@ -931,20 +931,20 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
"MongoDB can only handle up to 8-byte ints");
|
||||
return 0;
|
||||
}
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x12;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x12;
|
||||
return buffer_write_int64(buffer, (int64_t)long_long_value);
|
||||
}
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x10;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x10;
|
||||
return buffer_write_int32(buffer, (int32_t)int_value);
|
||||
} else if (PyFloat_Check(value)) {
|
||||
const double d = PyFloat_AsDouble(value);
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x01;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x01;
|
||||
return buffer_write_double(buffer, d);
|
||||
} else if (value == Py_None) {
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x0A;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x0A;
|
||||
return 1;
|
||||
} else if (PyDict_Check(value)) {
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x03;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x03;
|
||||
return write_dict(self, buffer, value, check_keys, options, 0);
|
||||
} else if (PyList_Check(value) || PyTuple_Check(value)) {
|
||||
Py_ssize_t items, i;
|
||||
@ -953,11 +953,11 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
length;
|
||||
char zero = 0;
|
||||
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x04;
|
||||
start_position = buffer_get_position(buffer);
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x04;
|
||||
start_position = pymongo_buffer_get_position(buffer);
|
||||
|
||||
/* save space for length */
|
||||
length_location = buffer_save_space(buffer, 4);
|
||||
length_location = pymongo_buffer_save_space(buffer, 4);
|
||||
if (length_location == -1) {
|
||||
return 0;
|
||||
}
|
||||
@ -972,7 +972,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
return 0;
|
||||
}
|
||||
for(i = 0; i < items; i++) {
|
||||
int list_type_byte = buffer_save_space(buffer, 1);
|
||||
int list_type_byte = pymongo_buffer_save_space(buffer, 1);
|
||||
char name[16];
|
||||
PyObject* item_value;
|
||||
|
||||
@ -999,7 +999,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
if (!buffer_write_bytes(buffer, &zero, 1)) {
|
||||
return 0;
|
||||
}
|
||||
length = buffer_get_position(buffer) - start_position;
|
||||
length = pymongo_buffer_get_position(buffer) - start_position;
|
||||
buffer_write_int32_at_position(
|
||||
buffer, length_location, (int32_t)length);
|
||||
return 1;
|
||||
@ -1012,7 +1012,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
return 0;
|
||||
if ((size = _downcast_and_check(PyBytes_GET_SIZE(value), 0)) == -1)
|
||||
return 0;
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x05;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x05;
|
||||
if (!buffer_write_int32(buffer, (int32_t)size)) {
|
||||
return 0;
|
||||
}
|
||||
@ -1024,7 +1024,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
}
|
||||
return 1;
|
||||
} else if (PyUnicode_Check(value)) {
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x02;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x02;
|
||||
return write_unicode(buffer, value);
|
||||
} else if (PyDateTime_Check(value)) {
|
||||
long long millis;
|
||||
@ -1042,7 +1042,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
} else {
|
||||
millis = millis_from_datetime(value);
|
||||
}
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x09;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x09;
|
||||
return buffer_write_int64(buffer, (int64_t)millis);
|
||||
} else if (PyObject_TypeCheck(value, state->REType)) {
|
||||
return _write_regex_to_buffer(buffer, type_byte, value);
|
||||
@ -1059,7 +1059,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
|
||||
if (PyErr_Occurred()) {
|
||||
return 0;
|
||||
}
|
||||
*(buffer_get_buffer(buffer) + type_byte) = 0x03;
|
||||
*(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x03;
|
||||
return write_dict(self, buffer, value, check_keys, options, 0);
|
||||
}
|
||||
|
||||
@ -1189,7 +1189,7 @@ int write_pair(PyObject* self, buffer_t buffer, const char* name, int name_lengt
|
||||
return 1;
|
||||
}
|
||||
|
||||
type_byte = buffer_save_space(buffer, 1);
|
||||
type_byte = pymongo_buffer_save_space(buffer, 1);
|
||||
if (type_byte == -1) {
|
||||
return 0;
|
||||
}
|
||||
@ -1362,7 +1362,7 @@ int write_dict(PyObject* self, buffer_t buffer,
|
||||
}
|
||||
}
|
||||
|
||||
length_location = buffer_save_space(buffer, 4);
|
||||
length_location = pymongo_buffer_save_space(buffer, 4);
|
||||
if (length_location == -1) {
|
||||
return 0;
|
||||
}
|
||||
@ -1429,7 +1429,7 @@ int write_dict(PyObject* self, buffer_t buffer,
|
||||
if (!buffer_write_bytes(buffer, &zero, 1)) {
|
||||
return 0;
|
||||
}
|
||||
length = buffer_get_position(buffer) - length_location;
|
||||
length = pymongo_buffer_get_position(buffer) - length_location;
|
||||
buffer_write_int32_at_position(
|
||||
buffer, length_location, (int32_t)length);
|
||||
return length;
|
||||
@ -1464,7 +1464,7 @@ static PyObject* _cbson_dict_to_bson(PyObject* self, PyObject* args) {
|
||||
return raw_bson_document_bytes_obj;
|
||||
}
|
||||
|
||||
buffer = buffer_new();
|
||||
buffer = pymongo_buffer_new();
|
||||
if (!buffer) {
|
||||
destroy_codec_options(&options);
|
||||
return NULL;
|
||||
@ -1472,15 +1472,15 @@ static PyObject* _cbson_dict_to_bson(PyObject* self, PyObject* args) {
|
||||
|
||||
if (!write_dict(self, buffer, dict, check_keys, &options, top_level)) {
|
||||
destroy_codec_options(&options);
|
||||
buffer_free(buffer);
|
||||
pymongo_buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* objectify buffer */
|
||||
result = Py_BuildValue("y#", buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)buffer_get_position(buffer));
|
||||
result = Py_BuildValue("y#", pymongo_buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)pymongo_buffer_get_position(buffer));
|
||||
destroy_codec_options(&options);
|
||||
buffer_free(buffer);
|
||||
pymongo_buffer_free(buffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ static void set_memory_error(void) {
|
||||
|
||||
/* Allocate and return a new buffer.
|
||||
* Return NULL and sets MemoryError on allocation failure. */
|
||||
buffer_t buffer_new(void) {
|
||||
buffer_t pymongo_buffer_new(void) {
|
||||
buffer_t buffer;
|
||||
buffer = (buffer_t)malloc(sizeof(struct buffer));
|
||||
if (buffer == NULL) {
|
||||
@ -61,7 +61,7 @@ buffer_t buffer_new(void) {
|
||||
|
||||
/* Free the memory allocated for `buffer`.
|
||||
* Return non-zero on failure. */
|
||||
int buffer_free(buffer_t buffer) {
|
||||
int pymongo_buffer_free(buffer_t buffer) {
|
||||
if (buffer == NULL) {
|
||||
return 1;
|
||||
}
|
||||
@ -122,7 +122,7 @@ static int buffer_assure_space(buffer_t buffer, int size) {
|
||||
/* Save `size` bytes from the current position in `buffer` (and grow if needed).
|
||||
* Return offset for writing, or -1 on failure.
|
||||
* Sets MemoryError or ValueError on failure. */
|
||||
buffer_position buffer_save_space(buffer_t buffer, int size) {
|
||||
buffer_position pymongo_buffer_save_space(buffer_t buffer, int size) {
|
||||
int position = buffer->position;
|
||||
if (buffer_assure_space(buffer, size) != 0) {
|
||||
return -1;
|
||||
@ -134,7 +134,7 @@ buffer_position buffer_save_space(buffer_t buffer, int size) {
|
||||
/* Write `size` bytes from `data` to `buffer` (and grow if needed).
|
||||
* Return non-zero on failure.
|
||||
* Sets MemoryError or ValueError on failure. */
|
||||
int buffer_write(buffer_t buffer, const char* data, int size) {
|
||||
int pymongo_buffer_write(buffer_t buffer, const char* data, int size) {
|
||||
if (buffer_assure_space(buffer, size) != 0) {
|
||||
return 1;
|
||||
}
|
||||
@ -144,14 +144,14 @@ int buffer_write(buffer_t buffer, const char* data, int size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int buffer_get_position(buffer_t buffer) {
|
||||
int pymongo_buffer_get_position(buffer_t buffer) {
|
||||
return buffer->position;
|
||||
}
|
||||
|
||||
char* buffer_get_buffer(buffer_t buffer) {
|
||||
char* pymongo_buffer_get_buffer(buffer_t buffer) {
|
||||
return buffer->buffer;
|
||||
}
|
||||
|
||||
void buffer_update_position(buffer_t buffer, buffer_position new_position) {
|
||||
void pymongo_buffer_update_position(buffer_t buffer, buffer_position new_position) {
|
||||
buffer->position = new_position;
|
||||
}
|
||||
|
||||
@ -27,25 +27,25 @@ typedef int buffer_position;
|
||||
|
||||
/* Allocate and return a new buffer.
|
||||
* Return NULL on allocation failure. */
|
||||
buffer_t buffer_new(void);
|
||||
buffer_t pymongo_buffer_new(void);
|
||||
|
||||
/* Free the memory allocated for `buffer`.
|
||||
* Return non-zero on failure. */
|
||||
int buffer_free(buffer_t buffer);
|
||||
int pymongo_buffer_free(buffer_t buffer);
|
||||
|
||||
/* Save `size` bytes from the current position in `buffer` (and grow if needed).
|
||||
* Return offset for writing, or -1 on allocation failure. */
|
||||
buffer_position buffer_save_space(buffer_t buffer, int size);
|
||||
buffer_position pymongo_buffer_save_space(buffer_t buffer, int size);
|
||||
|
||||
/* Write `size` bytes from `data` to `buffer` (and grow if needed).
|
||||
* Return non-zero on allocation failure. */
|
||||
int buffer_write(buffer_t buffer, const char* data, int size);
|
||||
int pymongo_buffer_write(buffer_t buffer, const char* data, int size);
|
||||
|
||||
/* Getters for the internals of a buffer_t.
|
||||
* Should try to avoid using these as much as possible
|
||||
* since they break the abstraction. */
|
||||
buffer_position buffer_get_position(buffer_t buffer);
|
||||
char* buffer_get_buffer(buffer_t buffer);
|
||||
void buffer_update_position(buffer_t buffer, buffer_position new_position);
|
||||
buffer_position pymongo_buffer_get_position(buffer_t buffer);
|
||||
char* pymongo_buffer_get_buffer(buffer_t buffer);
|
||||
void pymongo_buffer_update_position(buffer_t buffer, buffer_position new_position);
|
||||
|
||||
#endif
|
||||
|
||||
@ -87,7 +87,7 @@ static unsigned char isLegalUTF8(const unsigned char* source, int length) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
result_t check_string(const unsigned char* string, const int length,
|
||||
result_t cbson_check_string(const unsigned char* string, const int length,
|
||||
const char check_utf8, const char check_null) {
|
||||
int position = 0;
|
||||
/* By default we go character by character. Will be different for checking
|
||||
|
||||
@ -23,7 +23,7 @@ typedef enum {
|
||||
HAS_NULL
|
||||
} result_t;
|
||||
|
||||
result_t check_string(const unsigned char* string, const int length,
|
||||
result_t cbson_check_string(const unsigned char* string, const int length,
|
||||
const char check_utf8, const char check_null);
|
||||
|
||||
#endif
|
||||
|
||||
@ -29,13 +29,13 @@ THE SOFTWARE.
|
||||
/*
|
||||
|
||||
Programmers who have available to them 64-bit time values as a 'long
|
||||
long' type can use localtime64_r() and gmtime64_r() which correctly
|
||||
long' type can use cbson_localtime64_r() and cbson_gmtime64_r() which correctly
|
||||
converts the time even on 32-bit systems. Whether you have 64-bit time
|
||||
values will depend on the operating system.
|
||||
|
||||
localtime64_r() is a 64-bit equivalent of localtime_r().
|
||||
cbson_localtime64_r() is a 64-bit equivalent of localtime_r().
|
||||
|
||||
gmtime64_r() is a 64-bit equivalent of gmtime_r().
|
||||
cbson_gmtime64_r() is a 64-bit equivalent of gmtime_r().
|
||||
|
||||
*/
|
||||
|
||||
@ -158,7 +158,7 @@ static int is_exception_century(Year year)
|
||||
The result is like cmp.
|
||||
Ignores things like gmtoffset and dst
|
||||
*/
|
||||
int cmp_date( const struct TM* left, const struct tm* right ) {
|
||||
int cbson_cmp_date( const struct TM* left, const struct tm* right ) {
|
||||
if( left->tm_year > right->tm_year )
|
||||
return 1;
|
||||
else if( left->tm_year < right->tm_year )
|
||||
@ -196,11 +196,11 @@ int cmp_date( const struct TM* left, const struct tm* right ) {
|
||||
/* Check if a date is safely inside a range.
|
||||
The intention is to check if its a few days inside.
|
||||
*/
|
||||
int date_in_safe_range( const struct TM* date, const struct tm* min, const struct tm* max ) {
|
||||
if( cmp_date(date, min) == -1 )
|
||||
int cbson_date_in_safe_range( const struct TM* date, const struct tm* min, const struct tm* max ) {
|
||||
if( cbson_cmp_date(date, min) == -1 )
|
||||
return 0;
|
||||
|
||||
if( cmp_date(date, max) == 1 )
|
||||
if( cbson_cmp_date(date, max) == 1 )
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
@ -209,9 +209,9 @@ int date_in_safe_range( const struct TM* date, const struct tm* min, const struc
|
||||
|
||||
/* timegm() is not in the C or POSIX spec, but it is such a useful
|
||||
extension I would be remiss in leaving it out. Also I need it
|
||||
for localtime64()
|
||||
for cbson_localtime64()
|
||||
*/
|
||||
Time64_T timegm64(const struct TM *date) {
|
||||
Time64_T cbson_timegm64(const struct TM *date) {
|
||||
Time64_T days = 0;
|
||||
Time64_T seconds = 0;
|
||||
Year year;
|
||||
@ -376,7 +376,7 @@ static int safe_year(const Year year)
|
||||
}
|
||||
|
||||
|
||||
void copy_tm_to_TM64(const struct tm *src, struct TM *dest) {
|
||||
void pymongo_copy_tm_to_TM64(const struct tm *src, struct TM *dest) {
|
||||
if( src == NULL ) {
|
||||
memset(dest, 0, sizeof(*dest));
|
||||
}
|
||||
@ -408,7 +408,7 @@ void copy_tm_to_TM64(const struct tm *src, struct TM *dest) {
|
||||
}
|
||||
|
||||
|
||||
void copy_TM64_to_tm(const struct TM *src, struct tm *dest) {
|
||||
void cbson_copy_TM64_to_tm(const struct TM *src, struct tm *dest) {
|
||||
if( src == NULL ) {
|
||||
memset(dest, 0, sizeof(*dest));
|
||||
}
|
||||
@ -441,7 +441,7 @@ void copy_TM64_to_tm(const struct TM *src, struct tm *dest) {
|
||||
|
||||
|
||||
/* Simulate localtime_r() to the best of our ability */
|
||||
struct tm * fake_localtime_r(const time_t *time, struct tm *result) {
|
||||
struct tm * cbson_fake_localtime_r(const time_t *time, struct tm *result) {
|
||||
const struct tm *static_result = localtime(time);
|
||||
|
||||
assert(result != NULL);
|
||||
@ -458,7 +458,7 @@ struct tm * fake_localtime_r(const time_t *time, struct tm *result) {
|
||||
|
||||
|
||||
/* Simulate gmtime_r() to the best of our ability */
|
||||
struct tm * fake_gmtime_r(const time_t *time, struct tm *result) {
|
||||
struct tm * cbson_fake_gmtime_r(const time_t *time, struct tm *result) {
|
||||
const struct tm *static_result = gmtime(time);
|
||||
|
||||
assert(result != NULL);
|
||||
@ -499,22 +499,22 @@ static Time64_T seconds_between_years(Year left_year, Year right_year) {
|
||||
}
|
||||
|
||||
|
||||
Time64_T mktime64(const struct TM *input_date) {
|
||||
Time64_T cbson_mktime64(const struct TM *input_date) {
|
||||
struct tm safe_date;
|
||||
struct TM date;
|
||||
Time64_T time;
|
||||
Year year = input_date->tm_year + 1900;
|
||||
|
||||
if( date_in_safe_range(input_date, &SYSTEM_MKTIME_MIN, &SYSTEM_MKTIME_MAX) )
|
||||
if( cbson_date_in_safe_range(input_date, &SYSTEM_MKTIME_MIN, &SYSTEM_MKTIME_MAX) )
|
||||
{
|
||||
copy_TM64_to_tm(input_date, &safe_date);
|
||||
cbson_copy_TM64_to_tm(input_date, &safe_date);
|
||||
return (Time64_T)mktime(&safe_date);
|
||||
}
|
||||
|
||||
/* Have to make the year safe in date else it won't fit in safe_date */
|
||||
date = *input_date;
|
||||
date.tm_year = safe_year(year) - 1900;
|
||||
copy_TM64_to_tm(&date, &safe_date);
|
||||
cbson_copy_TM64_to_tm(&date, &safe_date);
|
||||
|
||||
time = (Time64_T)mktime(&safe_date);
|
||||
|
||||
@ -526,11 +526,11 @@ Time64_T mktime64(const struct TM *input_date) {
|
||||
|
||||
/* Because I think mktime() is a crappy name */
|
||||
Time64_T timelocal64(const struct TM *date) {
|
||||
return mktime64(date);
|
||||
return cbson_mktime64(date);
|
||||
}
|
||||
|
||||
|
||||
struct TM *gmtime64_r (const Time64_T *in_time, struct TM *p)
|
||||
struct TM *cbson_gmtime64_r (const Time64_T *in_time, struct TM *p)
|
||||
{
|
||||
int v_tm_sec, v_tm_min, v_tm_hour, v_tm_mon, v_tm_wday;
|
||||
Time64_T v_tm_tday;
|
||||
@ -549,7 +549,7 @@ struct TM *gmtime64_r (const Time64_T *in_time, struct TM *p)
|
||||
struct tm safe_date;
|
||||
GMTIME_R(&safe_time, &safe_date);
|
||||
|
||||
copy_tm_to_TM64(&safe_date, p);
|
||||
pymongo_copy_tm_to_TM64(&safe_date, p);
|
||||
assert(check_tm(p));
|
||||
|
||||
return p;
|
||||
@ -659,7 +659,7 @@ struct TM *gmtime64_r (const Time64_T *in_time, struct TM *p)
|
||||
}
|
||||
|
||||
|
||||
struct TM *localtime64_r (const Time64_T *time, struct TM *local_tm)
|
||||
struct TM *cbson_localtime64_r (const Time64_T *time, struct TM *local_tm)
|
||||
{
|
||||
time_t safe_time;
|
||||
struct tm safe_date;
|
||||
@ -678,15 +678,15 @@ struct TM *localtime64_r (const Time64_T *time, struct TM *local_tm)
|
||||
|
||||
LOCALTIME_R(&safe_time, &safe_date);
|
||||
|
||||
copy_tm_to_TM64(&safe_date, local_tm);
|
||||
pymongo_copy_tm_to_TM64(&safe_date, local_tm);
|
||||
assert(check_tm(local_tm));
|
||||
|
||||
return local_tm;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( gmtime64_r(time, &gm_tm) == NULL ) {
|
||||
TIME64_TRACE1("gmtime64_r returned null for %lld\n", *time);
|
||||
if( cbson_gmtime64_r(time, &gm_tm) == NULL ) {
|
||||
TIME64_TRACE1("cbson_gmtime64_r returned null for %lld\n", *time);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -700,13 +700,13 @@ struct TM *localtime64_r (const Time64_T *time, struct TM *local_tm)
|
||||
gm_tm.tm_year = safe_year((Year)(gm_tm.tm_year + 1900)) - 1900;
|
||||
}
|
||||
|
||||
safe_time = (time_t)timegm64(&gm_tm);
|
||||
safe_time = (time_t)cbson_timegm64(&gm_tm);
|
||||
if( LOCALTIME_R(&safe_time, &safe_date) == NULL ) {
|
||||
TIME64_TRACE1("localtime_r(%d) returned NULL\n", (int)safe_time);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
copy_tm_to_TM64(&safe_date, local_tm);
|
||||
pymongo_copy_tm_to_TM64(&safe_date, local_tm);
|
||||
|
||||
local_tm->tm_year = (int)orig_year;
|
||||
if( local_tm->tm_year != orig_year ) {
|
||||
@ -751,14 +751,14 @@ struct TM *localtime64_r (const Time64_T *time, struct TM *local_tm)
|
||||
}
|
||||
|
||||
|
||||
int valid_tm_wday( const struct TM* date ) {
|
||||
int cbson_valid_tm_wday( const struct TM* date ) {
|
||||
if( 0 <= date->tm_wday && date->tm_wday <= 6 )
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int valid_tm_mon( const struct TM* date ) {
|
||||
int cbson_valid_tm_mon( const struct TM* date ) {
|
||||
if( 0 <= date->tm_mon && date->tm_mon <= 11 )
|
||||
return 1;
|
||||
else
|
||||
@ -767,15 +767,15 @@ int valid_tm_mon( const struct TM* date ) {
|
||||
|
||||
|
||||
/* Non-thread safe versions of the above */
|
||||
struct TM *localtime64(const Time64_T *time) {
|
||||
struct TM *cbson_localtime64(const Time64_T *time) {
|
||||
#ifdef _MSC_VER
|
||||
_tzset();
|
||||
#else
|
||||
tzset();
|
||||
#endif
|
||||
return localtime64_r(time, &Static_Return_Date);
|
||||
return cbson_localtime64_r(time, &Static_Return_Date);
|
||||
}
|
||||
|
||||
struct TM *gmtime64(const Time64_T *time) {
|
||||
return gmtime64_r(time, &Static_Return_Date);
|
||||
struct TM *cbson_gmtime64(const Time64_T *time) {
|
||||
return cbson_gmtime64_r(time, &Static_Return_Date);
|
||||
}
|
||||
|
||||
@ -41,13 +41,13 @@ struct TM64 {
|
||||
|
||||
|
||||
/* Declare public functions */
|
||||
struct TM *gmtime64_r (const Time64_T *, struct TM *);
|
||||
struct TM *localtime64_r (const Time64_T *, struct TM *);
|
||||
struct TM *gmtime64 (const Time64_T *);
|
||||
struct TM *localtime64 (const Time64_T *);
|
||||
struct TM *cbson_gmtime64_r (const Time64_T *, struct TM *);
|
||||
struct TM *cbson_localtime64_r (const Time64_T *, struct TM *);
|
||||
struct TM *cbson_gmtime64 (const Time64_T *);
|
||||
struct TM *cbson_localtime64 (const Time64_T *);
|
||||
|
||||
Time64_T timegm64 (const struct TM *);
|
||||
Time64_T mktime64 (const struct TM *);
|
||||
Time64_T cbson_timegm64 (const struct TM *);
|
||||
Time64_T cbson_mktime64 (const struct TM *);
|
||||
Time64_T timelocal64 (const struct TM *);
|
||||
|
||||
|
||||
@ -55,12 +55,12 @@ Time64_T timelocal64 (const struct TM *);
|
||||
#ifdef HAS_LOCALTIME_R
|
||||
# define LOCALTIME_R(clock, result) localtime_r(clock, result)
|
||||
#else
|
||||
# define LOCALTIME_R(clock, result) fake_localtime_r(clock, result)
|
||||
# define LOCALTIME_R(clock, result) cbson_fake_localtime_r(clock, result)
|
||||
#endif
|
||||
#ifdef HAS_GMTIME_R
|
||||
# define GMTIME_R(clock, result) gmtime_r(clock, result)
|
||||
#else
|
||||
# define GMTIME_R(clock, result) fake_gmtime_r(clock, result)
|
||||
# define GMTIME_R(clock, result) cbson_fake_gmtime_r(clock, result)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@ -92,3 +92,4 @@ The following is a list of people who have contributed to
|
||||
- Henri Froese (henrifroese)
|
||||
- Ishmum Jawad Khan (ishmum123)
|
||||
- Arie Bovenberg (ariebovenberg)
|
||||
- Ben Warner (bcwarner)
|
||||
|
||||
@ -90,13 +90,13 @@ static PyObject* _cbson_query_message(PyObject* self, PyObject* args) {
|
||||
convert_codec_options, &options)) {
|
||||
return NULL;
|
||||
}
|
||||
buffer = buffer_new();
|
||||
buffer = pymongo_buffer_new();
|
||||
if (!buffer) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// save space for message length
|
||||
length_location = buffer_save_space(buffer, 4);
|
||||
length_location = pymongo_buffer_save_space(buffer, 4);
|
||||
if (length_location == -1) {
|
||||
goto fail;
|
||||
}
|
||||
@ -111,37 +111,37 @@ static PyObject* _cbson_query_message(PyObject* self, PyObject* args) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
begin = buffer_get_position(buffer);
|
||||
begin = pymongo_buffer_get_position(buffer);
|
||||
if (!write_dict(state->_cbson, buffer, query, 0, &options, 1)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
max_size = buffer_get_position(buffer) - begin;
|
||||
max_size = pymongo_buffer_get_position(buffer) - begin;
|
||||
|
||||
if (field_selector != Py_None) {
|
||||
begin = buffer_get_position(buffer);
|
||||
begin = pymongo_buffer_get_position(buffer);
|
||||
if (!write_dict(state->_cbson, buffer, field_selector, 0,
|
||||
&options, 1)) {
|
||||
goto fail;
|
||||
}
|
||||
cur_size = buffer_get_position(buffer) - begin;
|
||||
cur_size = pymongo_buffer_get_position(buffer) - begin;
|
||||
max_size = (cur_size > max_size) ? cur_size : max_size;
|
||||
}
|
||||
|
||||
message_length = buffer_get_position(buffer) - length_location;
|
||||
message_length = pymongo_buffer_get_position(buffer) - length_location;
|
||||
buffer_write_int32_at_position(
|
||||
buffer, length_location, (int32_t)message_length);
|
||||
|
||||
/* objectify buffer */
|
||||
result = Py_BuildValue("iy#i", request_id,
|
||||
buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)buffer_get_position(buffer),
|
||||
pymongo_buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)pymongo_buffer_get_position(buffer),
|
||||
max_size);
|
||||
fail:
|
||||
PyMem_Free(collection_name);
|
||||
destroy_codec_options(&options);
|
||||
if (buffer) {
|
||||
buffer_free(buffer);
|
||||
pymongo_buffer_free(buffer);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -165,13 +165,13 @@ static PyObject* _cbson_get_more_message(PyObject* self, PyObject* args) {
|
||||
&cursor_id)) {
|
||||
return NULL;
|
||||
}
|
||||
buffer = buffer_new();
|
||||
buffer = pymongo_buffer_new();
|
||||
if (!buffer) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// save space for message length
|
||||
length_location = buffer_save_space(buffer, 4);
|
||||
length_location = pymongo_buffer_save_space(buffer, 4);
|
||||
if (length_location == -1) {
|
||||
goto fail;
|
||||
}
|
||||
@ -188,18 +188,18 @@ static PyObject* _cbson_get_more_message(PyObject* self, PyObject* args) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
message_length = buffer_get_position(buffer) - length_location;
|
||||
message_length = pymongo_buffer_get_position(buffer) - length_location;
|
||||
buffer_write_int32_at_position(
|
||||
buffer, length_location, (int32_t)message_length);
|
||||
|
||||
/* objectify buffer */
|
||||
result = Py_BuildValue("iy#", request_id,
|
||||
buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)buffer_get_position(buffer));
|
||||
pymongo_buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)pymongo_buffer_get_position(buffer));
|
||||
fail:
|
||||
PyMem_Free(collection_name);
|
||||
if (buffer) {
|
||||
buffer_free(buffer);
|
||||
pymongo_buffer_free(buffer);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -239,13 +239,13 @@ static PyObject* _cbson_op_msg(PyObject* self, PyObject* args) {
|
||||
convert_codec_options, &options)) {
|
||||
return NULL;
|
||||
}
|
||||
buffer = buffer_new();
|
||||
buffer = pymongo_buffer_new();
|
||||
if (!buffer) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// save space for message length
|
||||
length_location = buffer_save_space(buffer, 4);
|
||||
length_location = pymongo_buffer_save_space(buffer, 4);
|
||||
if (length_location == -1) {
|
||||
goto fail;
|
||||
}
|
||||
@ -273,7 +273,7 @@ static PyObject* _cbson_op_msg(PyObject* self, PyObject* args) {
|
||||
goto fail;
|
||||
}
|
||||
/* save space for payload 0 length */
|
||||
payload_one_length_location = buffer_save_space(buffer, 4);
|
||||
payload_one_length_location = pymongo_buffer_save_space(buffer, 4);
|
||||
/* C string identifier */
|
||||
if (!buffer_write_bytes_ssize_t(buffer, identifier, identifier_length + 1)) {
|
||||
goto fail;
|
||||
@ -295,26 +295,26 @@ static PyObject* _cbson_op_msg(PyObject* self, PyObject* args) {
|
||||
Py_CLEAR(doc);
|
||||
}
|
||||
|
||||
payload_length = buffer_get_position(buffer) - payload_one_length_location;
|
||||
payload_length = pymongo_buffer_get_position(buffer) - payload_one_length_location;
|
||||
buffer_write_int32_at_position(
|
||||
buffer, payload_one_length_location, (int32_t)payload_length);
|
||||
total_size += payload_length;
|
||||
}
|
||||
|
||||
message_length = buffer_get_position(buffer) - length_location;
|
||||
message_length = pymongo_buffer_get_position(buffer) - length_location;
|
||||
buffer_write_int32_at_position(
|
||||
buffer, length_location, (int32_t)message_length);
|
||||
|
||||
/* objectify buffer */
|
||||
result = Py_BuildValue("iy#ii", request_id,
|
||||
buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)buffer_get_position(buffer),
|
||||
pymongo_buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)pymongo_buffer_get_position(buffer),
|
||||
total_size,
|
||||
max_doc_size);
|
||||
fail:
|
||||
Py_XDECREF(iterator);
|
||||
if (buffer) {
|
||||
buffer_free(buffer);
|
||||
pymongo_buffer_free(buffer);
|
||||
}
|
||||
PyMem_Free(identifier);
|
||||
destroy_codec_options(&options);
|
||||
@ -400,7 +400,7 @@ _batched_op_msg(
|
||||
return 0;
|
||||
}
|
||||
/* Save space for size */
|
||||
size_location = buffer_save_space(buffer, 4);
|
||||
size_location = pymongo_buffer_save_space(buffer, 4);
|
||||
if (size_location == -1) {
|
||||
return 0;
|
||||
}
|
||||
@ -445,17 +445,17 @@ _batched_op_msg(
|
||||
return 0;
|
||||
}
|
||||
while ((doc = PyIter_Next(iterator)) != NULL) {
|
||||
int cur_doc_begin = buffer_get_position(buffer);
|
||||
int cur_doc_begin = pymongo_buffer_get_position(buffer);
|
||||
int cur_size;
|
||||
int doc_too_large = 0;
|
||||
int unacked_doc_too_large = 0;
|
||||
if (!write_dict(state->_cbson, buffer, doc, 0, &options, 1)) {
|
||||
goto fail;
|
||||
}
|
||||
cur_size = buffer_get_position(buffer) - cur_doc_begin;
|
||||
cur_size = pymongo_buffer_get_position(buffer) - cur_doc_begin;
|
||||
|
||||
/* Does the first document exceed max_message_size? */
|
||||
doc_too_large = (idx == 0 && (buffer_get_position(buffer) > max_message_size));
|
||||
doc_too_large = (idx == 0 && (pymongo_buffer_get_position(buffer) > max_message_size));
|
||||
/* When OP_MSG is used unacknowledged we have to check
|
||||
* document size client side or applications won't be notified.
|
||||
* Otherwise we let the server deal with documents that are too large
|
||||
@ -483,12 +483,12 @@ _batched_op_msg(
|
||||
goto fail;
|
||||
}
|
||||
/* We have enough data, return this batch. */
|
||||
if (buffer_get_position(buffer) > max_message_size) {
|
||||
if (pymongo_buffer_get_position(buffer) > max_message_size) {
|
||||
/*
|
||||
* Roll the existing buffer back to the beginning
|
||||
* of the last document encoded.
|
||||
*/
|
||||
buffer_update_position(buffer, cur_doc_begin);
|
||||
pymongo_buffer_update_position(buffer, cur_doc_begin);
|
||||
Py_CLEAR(doc);
|
||||
break;
|
||||
}
|
||||
@ -508,7 +508,7 @@ _batched_op_msg(
|
||||
goto fail;
|
||||
}
|
||||
|
||||
position = buffer_get_position(buffer);
|
||||
position = pymongo_buffer_get_position(buffer);
|
||||
length = position - size_location;
|
||||
buffer_write_int32_at_position(buffer, size_location, (int32_t)length);
|
||||
return 1;
|
||||
@ -538,7 +538,7 @@ _cbson_encode_batched_op_msg(PyObject* self, PyObject* args) {
|
||||
&ctx)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(buffer = buffer_new())) {
|
||||
if (!(buffer = pymongo_buffer_new())) {
|
||||
destroy_codec_options(&options);
|
||||
return NULL;
|
||||
}
|
||||
@ -560,12 +560,12 @@ _cbson_encode_batched_op_msg(PyObject* self, PyObject* args) {
|
||||
}
|
||||
|
||||
result = Py_BuildValue("y#O",
|
||||
buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)buffer_get_position(buffer),
|
||||
pymongo_buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)pymongo_buffer_get_position(buffer),
|
||||
to_publish);
|
||||
fail:
|
||||
destroy_codec_options(&options);
|
||||
buffer_free(buffer);
|
||||
pymongo_buffer_free(buffer);
|
||||
Py_XDECREF(to_publish);
|
||||
return result;
|
||||
}
|
||||
@ -591,12 +591,12 @@ _cbson_batched_op_msg(PyObject* self, PyObject* args) {
|
||||
&ctx)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(buffer = buffer_new())) {
|
||||
if (!(buffer = pymongo_buffer_new())) {
|
||||
destroy_codec_options(&options);
|
||||
return NULL;
|
||||
}
|
||||
/* Save space for message length and request id */
|
||||
if ((buffer_save_space(buffer, 8)) == -1) {
|
||||
if ((pymongo_buffer_save_space(buffer, 8)) == -1) {
|
||||
goto fail;
|
||||
}
|
||||
if (!buffer_write_bytes(buffer,
|
||||
@ -623,16 +623,16 @@ _cbson_batched_op_msg(PyObject* self, PyObject* args) {
|
||||
}
|
||||
|
||||
request_id = rand();
|
||||
position = buffer_get_position(buffer);
|
||||
position = pymongo_buffer_get_position(buffer);
|
||||
buffer_write_int32_at_position(buffer, 0, (int32_t)position);
|
||||
buffer_write_int32_at_position(buffer, 4, (int32_t)request_id);
|
||||
result = Py_BuildValue("iy#O", request_id,
|
||||
buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)buffer_get_position(buffer),
|
||||
pymongo_buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)pymongo_buffer_get_position(buffer),
|
||||
to_publish);
|
||||
fail:
|
||||
destroy_codec_options(&options);
|
||||
buffer_free(buffer);
|
||||
pymongo_buffer_free(buffer);
|
||||
Py_XDECREF(to_publish);
|
||||
return result;
|
||||
}
|
||||
@ -702,14 +702,14 @@ _batched_write_command(
|
||||
}
|
||||
|
||||
/* Position of command document length */
|
||||
cmd_len_loc = buffer_get_position(buffer);
|
||||
cmd_len_loc = pymongo_buffer_get_position(buffer);
|
||||
if (!write_dict(state->_cbson, buffer, command, 0,
|
||||
&options, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Write type byte for array */
|
||||
*(buffer_get_buffer(buffer) + (buffer_get_position(buffer) - 1)) = 0x4;
|
||||
*(pymongo_buffer_get_buffer(buffer) + (pymongo_buffer_get_position(buffer) - 1)) = 0x4;
|
||||
|
||||
switch (op) {
|
||||
case _INSERT:
|
||||
@ -742,7 +742,7 @@ _batched_write_command(
|
||||
}
|
||||
|
||||
/* Save space for list document */
|
||||
lst_len_loc = buffer_save_space(buffer, 4);
|
||||
lst_len_loc = pymongo_buffer_save_space(buffer, 4);
|
||||
if (lst_len_loc == -1) {
|
||||
return 0;
|
||||
}
|
||||
@ -757,7 +757,7 @@ _batched_write_command(
|
||||
return 0;
|
||||
}
|
||||
while ((doc = PyIter_Next(iterator)) != NULL) {
|
||||
int sub_doc_begin = buffer_get_position(buffer);
|
||||
int sub_doc_begin = pymongo_buffer_get_position(buffer);
|
||||
int cur_doc_begin;
|
||||
int cur_size;
|
||||
int enough_data = 0;
|
||||
@ -767,7 +767,7 @@ _batched_write_command(
|
||||
!buffer_write_bytes(buffer, key, (int)strlen(key) + 1)) {
|
||||
goto fail;
|
||||
}
|
||||
cur_doc_begin = buffer_get_position(buffer);
|
||||
cur_doc_begin = pymongo_buffer_get_position(buffer);
|
||||
if (!write_dict(state->_cbson, buffer, doc, 0, &options, 1)) {
|
||||
goto fail;
|
||||
}
|
||||
@ -775,7 +775,7 @@ _batched_write_command(
|
||||
/* We have enough data, return this batch.
|
||||
* max_cmd_size accounts for the two trailing null bytes.
|
||||
*/
|
||||
cur_size = buffer_get_position(buffer) - cur_doc_begin;
|
||||
cur_size = pymongo_buffer_get_position(buffer) - cur_doc_begin;
|
||||
/* This single document is too large for the command. */
|
||||
if (cur_size > max_cmd_size) {
|
||||
if (op == _INSERT) {
|
||||
@ -797,13 +797,13 @@ _batched_write_command(
|
||||
goto fail;
|
||||
}
|
||||
enough_data = (idx >= 1 &&
|
||||
(buffer_get_position(buffer) > max_split_size));
|
||||
(pymongo_buffer_get_position(buffer) > max_split_size));
|
||||
if (enough_data) {
|
||||
/*
|
||||
* Roll the existing buffer back to the beginning
|
||||
* of the last document encoded.
|
||||
*/
|
||||
buffer_update_position(buffer, sub_doc_begin);
|
||||
pymongo_buffer_update_position(buffer, sub_doc_begin);
|
||||
Py_CLEAR(doc);
|
||||
break;
|
||||
}
|
||||
@ -827,7 +827,7 @@ _batched_write_command(
|
||||
goto fail;
|
||||
}
|
||||
|
||||
position = buffer_get_position(buffer);
|
||||
position = pymongo_buffer_get_position(buffer);
|
||||
length = position - lst_len_loc - 1;
|
||||
buffer_write_int32_at_position(buffer, lst_len_loc, (int32_t)length);
|
||||
length = position - cmd_len_loc;
|
||||
@ -860,7 +860,7 @@ _cbson_encode_batched_write_command(PyObject* self, PyObject* args) {
|
||||
&ctx)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(buffer = buffer_new())) {
|
||||
if (!(buffer = pymongo_buffer_new())) {
|
||||
PyMem_Free(ns);
|
||||
destroy_codec_options(&options);
|
||||
return NULL;
|
||||
@ -884,13 +884,13 @@ _cbson_encode_batched_write_command(PyObject* self, PyObject* args) {
|
||||
}
|
||||
|
||||
result = Py_BuildValue("y#O",
|
||||
buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)buffer_get_position(buffer),
|
||||
pymongo_buffer_get_buffer(buffer),
|
||||
(Py_ssize_t)pymongo_buffer_get_position(buffer),
|
||||
to_publish);
|
||||
fail:
|
||||
PyMem_Free(ns);
|
||||
destroy_codec_options(&options);
|
||||
buffer_free(buffer);
|
||||
pymongo_buffer_free(buffer);
|
||||
Py_XDECREF(to_publish);
|
||||
return result;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user