Skip to content

Commit

Permalink
Fix compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic authored and bwoodsend committed Apr 5, 2022
1 parent 2ddc65b commit 8c35a44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/ultrajsonenc.c
Expand Up @@ -551,6 +551,7 @@ static void Buffer_AppendIndentUnchecked(JSONObjectEncoder *enc, JSINT32 value)
{
int i;
if (enc->indent > 0)
{
if (enc->indent_chars == NULL)
{
while (value-- > 0)
Expand All @@ -563,6 +564,7 @@ static void Buffer_AppendIndentUnchecked(JSONObjectEncoder *enc, JSINT32 value)
for (i = 0; i < enc->indent; i++)
Buffer_AppendCharUnchecked(enc, enc->indent_chars[i]);
}
}
}

static void Buffer_AppendLongUnchecked(JSONObjectEncoder *enc, JSINT64 value)
Expand Down
10 changes: 6 additions & 4 deletions python/objToJSON.c
Expand Up @@ -122,7 +122,7 @@ static void *PyUnicodeToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue, si
if (PyUnicode_IS_COMPACT_ASCII(obj))
{
Py_ssize_t len;
char *data = PyUnicode_AsUTF8AndSize(obj, &len);
const char *data = PyUnicode_AsUTF8AndSize(obj, &len);
*_outLen = len;
return data;
}
Expand Down Expand Up @@ -747,15 +747,15 @@ static char *Object_iterGetName(JSOBJ obj, JSONTypeContext *tc, size_t *outLen)
}


static void *_PyUnicodeToChars(PyObject *obj, size_t *_outLen)
static const char *_PyUnicodeToChars(PyObject *obj, size_t *_outLen)
{
// helper for indent only
PyObject *newObj;
#ifndef Py_LIMITED_API
if (PyUnicode_IS_COMPACT_ASCII(obj))
{
Py_ssize_t len;
char *data = PyUnicode_AsUTF8AndSize(obj, &len);
const char *data = PyUnicode_AsUTF8AndSize(obj, &len);
*_outLen = len;
return data;
}
Expand Down Expand Up @@ -859,7 +859,9 @@ PyObject* objToJSON(PyObject* self, PyObject *args, PyObject *kwargs)
else if (PyUnicode_Check(oindent))
{
// set a custom indent string
encoder.indent_chars = _PyUnicodeToChars(oindent, &encoder.indent);
size_t olen = 0;
encoder.indent_chars = _PyUnicodeToChars(oindent, &olen);
encoder.indent = (int) olen;
if(encoder.indent_chars == NULL)
{
PyErr_SetString(PyExc_ValueError, "indent was malformed");
Expand Down

0 comments on commit 8c35a44

Please sign in to comment.