Skip to content

Commit c0b10e1

Browse files
NyanFisherMaksim Zaikin
authored andcommitted
try fix seg err v2
1 parent ed4a086 commit c0b10e1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/msgspec/_core.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9663,7 +9663,6 @@ Encoder_init(Encoder *self, PyObject *args, PyObject *kwds)
96639663
PyErr_SetString(PyExc_TypeError, "`decimal_quantize` must be a Decimal");
96649664
return -1;
96659665
}
9666-
Py_XDECREF(type);
96679666
Py_INCREF(decimal_quantize);
96689667
}
96699668

@@ -11863,47 +11862,55 @@ quantize_decimal_obj(EncoderState *self, PyObject *obj)
1186311862
if (self->decimal_quantize == NULL) {
1186411863
return NULL;
1186511864
}
11866-
11865+
1186711866
PyObject *quantize_method = PyObject_GetAttrString(obj, "quantize");
1186811867
if (quantize_method == NULL) {
1186911868
return NULL;
1187011869
}
1187111870

1187211871
// Create rounding constant as string object
1187311872
PyObject *rounding_const_obj = NULL;
11873+
int need_decref_rounding = 0;
1187411874
switch (self->decimal_rounding) {
1187511875
case ROUND_DEFAULT:
1187611876
rounding_const_obj = Py_None;
1187711877
break;
1187811878
case ROUND_DOWN:
1187911879
rounding_const_obj = PyUnicode_InternFromString("ROUND_DOWN");
11880+
need_decref_rounding = 1;
1188011881
break;
1188111882
case ROUND_HALF_UP:
1188211883
rounding_const_obj = PyUnicode_InternFromString("ROUND_HALF_UP");
11884+
need_decref_rounding = 1;
1188311885
break;
1188411886
case ROUND_HALF_EVEN:
1188511887
rounding_const_obj = PyUnicode_InternFromString("ROUND_HALF_EVEN");
11888+
need_decref_rounding = 1;
1188611889
break;
1188711890
case ROUND_CEILING:
1188811891
rounding_const_obj = PyUnicode_InternFromString("ROUND_CEILING");
11892+
need_decref_rounding = 1;
1188911893
break;
1189011894
case ROUND_FLOOR:
1189111895
rounding_const_obj = PyUnicode_InternFromString("ROUND_FLOOR");
11896+
need_decref_rounding = 1;
1189211897
break;
1189311898
case ROUND_UP:
1189411899
rounding_const_obj = PyUnicode_InternFromString("ROUND_UP");
11900+
need_decref_rounding = 1;
1189511901
break;
1189611902
case ROUND_HALF_DOWN:
1189711903
rounding_const_obj = PyUnicode_InternFromString("ROUND_HALF_DOWN");
11904+
need_decref_rounding = 1;
1189811905
break;
1189911906
case ROUND_05UP:
1190011907
rounding_const_obj = PyUnicode_InternFromString("ROUND_05UP");
11908+
need_decref_rounding = 1;
1190111909
break;
1190211910
default:
1190311911
rounding_const_obj = NULL;
1190411912
break;
1190511913
}
11906-
Py_XINCREF(rounding_const_obj);
1190711914

1190811915
if (rounding_const_obj == NULL) {
1190911916
Py_DECREF(quantize_method);
@@ -11919,10 +11926,8 @@ quantize_decimal_obj(EncoderState *self, PyObject *obj)
1191911926
);
1192011927

1192111928
Py_DECREF(quantize_method);
11922-
Py_XDECREF(rounding_const_obj);
11923-
11924-
if (quantized_obj == NULL) {
11925-
return NULL;
11929+
if (need_decref_rounding) {
11930+
Py_DECREF(rounding_const_obj);
1192611931
}
1192711932

1192811933
return quantized_obj;

0 commit comments

Comments
 (0)