Skip to content

Commit 31effee

Browse files
committed
fix seg err
1 parent 076b58c commit 31effee

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/msgspec/_core.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11874,6 +11874,7 @@ quantize_decimal_obj(EncoderState *self, PyObject *obj)
1187411874
switch (self->decimal_rounding) {
1187511875
case ROUND_DEFAULT:
1187611876
rounding_const_obj = Py_None;
11877+
Py_INCREF(rounding_const_obj);
1187711878
break;
1187811879
case ROUND_DOWN:
1187911880
rounding_const_obj = PyUnicode_InternFromString("ROUND_DOWN");
@@ -11918,7 +11919,7 @@ quantize_decimal_obj(EncoderState *self, PyObject *obj)
1191811919
);
1191911920

1192011921
Py_DECREF(quantize_method);
11921-
Py_DECREF(rounding_const_obj);
11922+
Py_XDECREF(rounding_const_obj);
1192211923

1192311924
if (quantized_obj == NULL) {
1192411925
return NULL;
@@ -13537,13 +13538,13 @@ mpack_encode_decimal(EncoderState *self, PyObject *obj)
1353713538
}
1353813539

1353913540
if (MS_LIKELY(self->decimal_format == DECIMAL_FORMAT_STRING)) {
13540-
temp = (quantize_obj != NULL) ? PyObject_Str(quantize_obj) : PyObject_Str(obj);
13541+
temp = MS_LIKELY(quantize_obj == NULL) ? PyObject_Str(obj) : PyObject_Str(quantize_obj);
1354113542
Py_XDECREF(quantize_obj);
1354213543
if (temp == NULL) return -1;
1354313544
out = mpack_encode_str(self, temp);
1354413545
}
1354513546
else {
13546-
temp = (quantize_obj != NULL) ? PyNumber_Float(quantize_obj) : PyNumber_Float(obj);
13547+
temp = MS_LIKELY(quantize_obj == NULL) ? PyNumber_Float(obj) : PyNumber_Float(quantize_obj);
1354713548
Py_XDECREF(quantize_obj);
1354813549
if (temp == NULL) return -1;
1354913550
out = mpack_encode_float(self, temp);
@@ -14198,16 +14199,13 @@ json_encode_decimal(EncoderState *self, PyObject *obj)
1419814199
{
1419914200
PyObject *temp = NULL;
1420014201

14201-
if (self->decimal_quantize != NULL) {
14202+
if (MS_LIKELY(self->decimal_quantize == NULL)) {
14203+
temp = PyObject_Str(obj);
14204+
} else {
1420214205
PyObject *quantize_obj = quantize_decimal_obj(self, obj);
14203-
1420414206
if (quantize_obj == NULL) return -1;
14205-
1420614207
temp = PyObject_Str(quantize_obj);
14207-
1420814208
Py_DECREF(quantize_obj);
14209-
} else {
14210-
temp = PyObject_Str(obj);
1421114209
}
1421214210

1421314211
if (temp == NULL) return -1;

0 commit comments

Comments
 (0)