Skip to content

Commit

Permalink
remove labels to exit cs
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannguyen4 committed Nov 1, 2024
1 parent f509e06 commit da2ca4d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
4 changes: 1 addition & 3 deletions src/include/pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,7 @@ static inline int PyDict_SetDefaultRef(PyObject *d, PyObject *key,

#if PY_VERSION_HEX < 0x030D00B3
#define Py_BEGIN_CRITICAL_SECTION(op) {
#define Py_END_CRITICAL_SECTION() \
; \
}
#define Py_END_CRITICAL_SECTION() }
#define Py_BEGIN_CRITICAL_SECTION2(a, b) {
#define Py_END_CRITICAL_SECTION2() }
#endif
Expand Down
7 changes: 3 additions & 4 deletions src/main/client/operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static inline bool isExprOp(int op);
#define CONVERT_PY_CTX_TO_AS_CTX() \
if (get_cdt_ctx(self, err, &ctx, py_val, &ctx_in_use, static_pool, \
SERIALIZER_PYTHON) != AEROSPIKE_OK) { \
goto EXIT_CS; \
break; \
}

#define CONVERT_RANGE_TO_AS_VAL() \
Expand Down Expand Up @@ -392,7 +392,7 @@ as_status add_op(AerospikeClient *self, as_error *err, PyObject *py_val,
if (!PyUnicode_Check(key_op)) {
as_error_update(err, AEROSPIKE_ERR_CLIENT,
"An operation key must be a string.");
goto EXIT_CS;
break;
}
else {
char *name = (char *)PyUnicode_AsUTF8(key_op);
Expand Down Expand Up @@ -438,11 +438,10 @@ as_status add_op(AerospikeClient *self, as_error *err, PyObject *py_val,
err, AEROSPIKE_ERR_PARAM,
"Operation can contain only op, bin, index, key, val, "
"return_type and map_policy keys");
goto EXIT_CS;
break;
}
}
}
EXIT_CS:
Py_END_CRITICAL_SECTION();
if (err->code != AEROSPIKE_OK) {
goto CLEANUP;
Expand Down
29 changes: 17 additions & 12 deletions src/main/conversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,33 +1306,34 @@ as_status pyobject_to_record(AerospikeClient *self, as_error *err,
as_error_update(
err, AEROSPIKE_ERR_CLIENT,
"A bin name must be a string or unicode string.");
goto EXIT_CS;
break;
}

name = PyUnicode_AsUTF8(key);
if (!name) {
as_error_update(err, AEROSPIKE_ERR_CLIENT,
"Unable to convert unicode object to C string");
goto EXIT_CS;
break;
}

if (self->strict_types) {
if (strlen(name) > AS_BIN_NAME_MAX_LEN) {
as_error_update(
err, AEROSPIKE_ERR_BIN_NAME,
"A bin name should not exceed 15 characters limit");
goto EXIT_CS;
break;
}
}

if (!value) {
// this should never happen, but if it did...
as_error_update(err, AEROSPIKE_ERR_CLIENT, "record is null");
goto EXIT_CS;
break;
}
else if (
PyBool_Check(
value)) { //TODO Change to true bool support post jump version.
bool error_raised = false;
switch (self->send_bool_as) {
case SEND_BOOL_AS_AS_BOOL:;
bool converted_value = (Py_IsTrue(value));
Expand All @@ -1342,15 +1343,20 @@ as_status pyobject_to_record(AerospikeClient *self, as_error *err,
as_integer *converted_integer = NULL;
if (py_bool_to_as_integer(err, value, &converted_integer) !=
AEROSPIKE_OK) {
goto EXIT_CS;
error_raised = true;
}
ret_val =
as_record_set_integer(rec, name, converted_integer);
break;
default:
as_error_update(err, AEROSPIKE_ERR_CLIENT,
"Unknown value for send_bool_as.");
goto EXIT_CS;
error_raised = true;
break;
}

if (error_raised == true) {
break;
}
}
else if (PyLong_Check(value)) {
Expand All @@ -1359,7 +1365,7 @@ as_status pyobject_to_record(AerospikeClient *self, as_error *err,
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
as_error_update(err, AEROSPIKE_ERR_PARAM,
"integer value exceeds sys.maxsize");
goto EXIT_CS;
break;
}
}
ret_val = as_record_set_int64(rec, name, val);
Expand All @@ -1378,7 +1384,7 @@ as_status pyobject_to_record(AerospikeClient *self, as_error *err,
if (!py_ustr) {
as_error_update(err, AEROSPIKE_ERR_CLIENT,
"Unicode value not encoded in utf-8.");
goto EXIT_CS;
break;
}
geo_value = PyBytes_AsString(py_ustr);
}
Expand All @@ -1399,7 +1405,7 @@ as_status pyobject_to_record(AerospikeClient *self, as_error *err,
if (!py_ustr) {
as_error_update(err, AEROSPIKE_ERR_CLIENT,
"Unicode value not encoded in utf-8.");
goto EXIT_CS;
break;
}
char *val = PyBytes_AsString(py_ustr);
ret_val = as_record_set_strp(rec, name, strdup(val), true);
Expand Down Expand Up @@ -1462,7 +1468,7 @@ as_status pyobject_to_record(AerospikeClient *self, as_error *err,
if (serialize_based_on_serializer_policy(
self, serializer_type, &bytes, value, err) !=
AEROSPIKE_OK) {
goto EXIT_CS;
break;
}
ret_val = as_record_set_bytes(rec, name, bytes);
}
Expand All @@ -1473,11 +1479,10 @@ as_status pyobject_to_record(AerospikeClient *self, as_error *err,
if (!ret_val) {
as_error_update(err, AEROSPIKE_ERR_BIN_NAME,
"Unable to set key-value pair");
goto EXIT_CS;
break;
}
}
}
EXIT_CS:
Py_END_CRITICAL_SECTION();
if (err->code != AEROSPIKE_OK) {
return err->code;
Expand Down

0 comments on commit da2ca4d

Please sign in to comment.