Skip to content

Commit

Permalink
Attempt 5
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Sep 25, 2024
1 parent b14a591 commit 97d4c90
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/jsonyx/_speedups.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,20 +1303,27 @@ encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (s->Decimal == NULL) {
goto bail;
}
s->indent = Py_NewRef(indent);
s->mapping_types = Py_NewRef(mapping_types);
s->seq_types = Py_NewRef(seq_types);
s->end = Py_NewRef(end);
s->item_separator = Py_NewRef(item_separator);
s->long_item_separator = Py_NewRef(long_item_separator);
s->key_separator = Py_NewRef(key_separator);
s->indent = indent;
s->mapping_types = mapping_types;
s->seq_types = seq_types;
s->end = end;
s->item_separator = item_separator;
s->long_item_separator = long_item_separator;
s->key_separator = key_separator;
s->allow_nan_and_infinity = allow_nan_and_infinity;
s->allow_surrogates = allow_surrogates;
s->ensure_ascii = ensure_ascii;
s->indent_leaves = indent_leaves;
s->quoted_keys = quoted_keys;
s->sort_keys = sort_keys;
s->trailing_comma = trailing_comma;
Py_INCREF(s->indent);
Py_INCREF(s->mapping_types);
Py_INCREF(s->seq_types);
Py_INCREF(s->end);
Py_INCREF(s->item_separator);
Py_INCREF(s->long_item_separator);
Py_INCREF(s->key_separator);
return (PyObject *)s;

bail:
Expand Down Expand Up @@ -1541,7 +1548,8 @@ encoder_encode_key_value(PyEncoderObject *s, PyObject *markers, _PyUnicodeWriter
PyObject *encoded;

if (PyUnicode_Check(key)) {
keystr = Py_NewRef(key);
keystr = key;
Py_INCREF(keystr);
}
else {
PyErr_Format(PyExc_TypeError,
Expand Down Expand Up @@ -1914,30 +1922,23 @@ static int
_json_exec(PyObject *module)
{
PyObject *PyScannerType = PyType_FromSpec(&PyScannerType_spec);
if (PyScannerType == NULL) {
return -1;
}
int rc = PyModule_AddObjectRef(module, "make_scanner", PyScannerType);
Py_DECREF(PyScannerType);
int rc = PyModule_AddObject(module, "make_scanner", PyScannerType);
if (rc < 0) {
Py_XDECREF(PyScannerType);
return -1;
}

PyObject *PyEncoderType = PyType_FromSpec(&PyEncoderType_spec);
if (PyEncoderType == NULL) {
return -1;
}
rc = PyModule_AddObjectRef(module, "make_encoder", PyEncoderType);
Py_DECREF(PyEncoderType);
rc = PyModule_AddObject(module, "make_encoder", PyEncoderType);
if (rc < 0) {
Py_XDECREF(PyEncoderType);
return -1;
}

PyDuplicateKeyType.tp_base = &PyUnicode_Type;
if (PyType_Ready(&PyDuplicateKeyType) < 0) {
return -1;
}
Py_INCREF(&PyDuplicateKeyType);
rc = PyModule_AddObject(module, "DuplicateKey", (PyObject *) &PyDuplicateKeyType);
if (rc < 0) {
Py_DECREF(&PyDuplicateKeyType);
Expand Down

0 comments on commit 97d4c90

Please sign in to comment.