1
0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-11-24 05:12:02 +01:00

- Fixed some more gcc and msvc9 compiler warnings

- Code cleanups
- FIXME cleanups
This commit is contained in:
Jonas Tärnström 2011-03-21 15:33:19 +01:00
parent f3b2aed86a
commit 101bb3e7f7
6 changed files with 30 additions and 60 deletions

@ -24,27 +24,27 @@ JSOBJ Object_newString(char *start, char *end)
return PyString_FromStringAndSize(start, (end - start));
}
JSOBJ Object_newTrue()
JSOBJ Object_newTrue(void)
{
Py_RETURN_TRUE;
}
JSOBJ Object_newFalse()
JSOBJ Object_newFalse(void)
{
Py_RETURN_FALSE;
}
JSOBJ Object_newNull()
JSOBJ Object_newNull(void)
{
Py_RETURN_NONE;
}
JSOBJ Object_newObject()
JSOBJ Object_newObject(void)
{
return PyDict_New();
}
JSOBJ Object_newArray()
JSOBJ Object_newArray(void)
{
return PyList_New(0);
}

Binary file not shown.

@ -18,8 +18,8 @@ typedef struct __TypeContext
PFN_PyTypeToJSON PyTypeToJSON;
PyObject *newObj;
PyObject *dictObj;
size_t index;
size_t size;
Py_ssize_t index;
Py_ssize_t size;
PyObject *itemValue;
PyObject *itemName;
PyObject *attrList;
@ -73,21 +73,6 @@ void initObjToJSON()
}
static void *PyNoneToNULL(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_t *_outLen)
{
return NULL;
}
static void *PyBoolToBOOLEAN(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_t *_outLen)
{
PyObject *obj = (PyObject *) _obj;
//FIXME: Perhaps we can use the PyBoolObject->ival directly here?
*((int *) outValue) = (obj == Py_True) ? 1 : 0;
return NULL;
}
static void *PyIntToINT32(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_t *_outLen)
{
PyObject *obj = (PyObject *) _obj;
@ -244,8 +229,6 @@ int Dir_iterNext(JSOBJ _obj, JSONTypeContext *tc)
GET_TC(tc)->itemValue = itemValue = NULL;
}
//fprintf (stderr, "%s: ti=%p obj=%p, i=%u, sz=%u\n", __FUNCTION__, ti, _obj, i, sz);
for (; GET_TC(tc)->index < GET_TC(tc)->size; GET_TC(tc)->index ++)
{
PyObject* attr = PyList_GET_ITEM(GET_TC(tc)->attrList, GET_TC(tc)->index);
@ -360,7 +343,6 @@ void Dict_iterBegin(JSOBJ obj, JSONTypeContext *tc)
int Dict_iterNext(JSOBJ obj, JSONTypeContext *tc)
{
//fprintf (stderr, "%s: ti=%p obj=%p, i=%u, sz=%u\n", __FUNCTION__, ti, _obj, i, sz);
if (GET_TC(tc)->itemName)
{
Py_DECREF(GET_TC(tc)->itemName);
@ -405,7 +387,7 @@ char *Dict_iterGetName(JSOBJ obj, JSONTypeContext *tc, size_t *outLen)
}
static void Object_beginTypeContext (PyObject *obj, JSONTypeContext *tc)
void Object_beginTypeContext (PyObject *obj, JSONTypeContext *tc)
{
TypeContext *pc = (TypeContext *) tc->prv;
PyObject *toDictFunc;
@ -425,8 +407,6 @@ static void Object_beginTypeContext (PyObject *obj, JSONTypeContext *tc)
tc->prv[12] = 0;
tc->prv[13] = 0;
tc->prv[14] = 0;
//memset (pc, 0, sizeof (TypeContext));
if (PyIter_Check(obj))
{
@ -457,7 +437,7 @@ static void Object_beginTypeContext (PyObject *obj, JSONTypeContext *tc)
if (PyString_Check(obj))
{
PRINTMARK();
pc->PyTypeToJSON = (void *) PyStringToUTF8; tc->type = JT_UTF8;
pc->PyTypeToJSON = PyStringToUTF8; tc->type = JT_UTF8;
return;
}
else
@ -688,7 +668,7 @@ PyObject* objToJSON(PyObject* self, PyObject *arg)
encoder.free (ret);
}
PyErr_Format (PyExc_OverflowError, encoder.errorMsg);
PyErr_Format (PyExc_OverflowError, "%s", encoder.errorMsg);
return NULL;
}

@ -229,6 +229,7 @@ typedef struct __JSONObjectEncoder
Return type of object as JSTYPES enum
Implementors should setup necessary pointers or state in ti->prv
*/
void (*beginTypeContext)(JSOBJ obj, JSONTypeContext *tc);
void (*endTypeContext)(JSOBJ obj, JSONTypeContext *tc);
@ -351,11 +352,11 @@ typedef struct __JSONObjectDecoder
JSOBJ (*newString)(char *start, char *end);
void (*objectAddKey)(JSOBJ obj, JSOBJ name, JSOBJ value);
void (*arrayAddItem)(JSOBJ obj, JSOBJ value);
JSOBJ (*newTrue)();
JSOBJ (*newFalse)();
JSOBJ (*newNull)();
JSOBJ (*newObject)();
JSOBJ (*newArray)();
JSOBJ (*newTrue)(void);
JSOBJ (*newFalse)(void);
JSOBJ (*newNull)(void);
JSOBJ (*newObject)(void);
JSOBJ (*newArray)(void);
JSOBJ (*newInt)(JSINT32 value);
JSOBJ (*newLong)(JSINT64 value);
JSOBJ (*newDouble)(double value);

@ -56,21 +56,6 @@ JSOBJ FASTCALL_MSVC decode_any( struct DecoderState *ds) FASTCALL_ATTR;
typedef JSOBJ (*PFN_DECODER)( struct DecoderState *ds);
PFN_DECODER g_identTable[256] = { NULL };
/*
FIXME: Maybe move this to inside of createDouble function. Might increase memory locality and worst case
possibly polute the global namespace less */
/*
#define RETURN_JSOBJ_NULLCHECK(_expr)\
{ \
JSOBJ obj__ = (_expr); \
if (obj__ == NULL) \
fprintf (stderr, "Function at %s:%d returned NULL", __FUNCTION__, __LINE__); \
return obj__; \
} \
*/
#define RETURN_JSOBJ_NULLCHECK(_expr) return(_expr);
double createDouble(double intNeg, double intValue, double frcValue, int frcDecimalCount)
@ -173,8 +158,6 @@ BREAK_INT_LOOP:
//dbg1 = (intValue * intNeg);
//dbg2 = (JSLONG) dbg1;
//FIXME: Check value size here, don't decode everything as 64-bit
if (intValue > (INT_MAX - 1))
{
RETURN_JSOBJ_NULLCHECK(ds->dec->newLong( (JSINT64) (intValue * intNeg)));

@ -47,11 +47,15 @@ Copyright (c) 2007 Nick Galbreath -- nickg [at] modp [dot] com. All rights rese
#ifndef FALSE
#define FALSE 0
#endif
static const double g_pow10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
static const char g_hexChars[] = "0123456789abcdef";
static const char g_escapeChars[] = "0123456789\\b\\t\\n\\f\\r\\\"\\\\";
/*
FIXME: While this is fine dandy and working it's a magic value mess which probably only the author understands.
Needs a cleanup and more documentation */
static const JSUINT8 g_utf8LengthLookup[256] =
{
/* 0x00 */ 0, 30, 30, 30, 30, 30, 30, 30, 10, 12, 14, 30, 16, 18, 30, 30,
@ -80,7 +84,7 @@ static void SetError (JSOBJ obj, JSONObjectEncoder *enc, const char *message)
/*
FIXME: Keep track of how big these get across several encoder calls and try to make an estimate
They way we won't run our head into the wall each call */
That way we won't run our head into the wall each call */
void Buffer_Realloc (JSONObjectEncoder *enc, size_t cbNeeded)
{
size_t curSize = enc->end - enc->start;
@ -123,8 +127,12 @@ There's a preprocessor check for this so you really can't compile on non little
FIXME: The JSON spec says escape "/" but non of the others do and we don't
want to be left alone doing it so we don't :)
FIXME: I guess it would be possible to combine the UTF-8 length lookup with escaping lookup
to make one bug super lookup table!
FIXME: It should be faster to do SHIFT and then AND instead of AND and SHIFT.
Example:
(x & 0x3f00) >> 8) => Longer/more opcodes than below
(x >> 8) & 0x3f) => Probably faster/smaller
Seems that atleast MSVC9 does this optimization by itself from time to time. Not sure really
*/
int Buffer_EscapeString (JSOBJ obj, JSONObjectEncoder *enc, const char *io, const char *end)
@ -474,14 +482,12 @@ void Buffer_AppendDoubleUnchecked(JSONObjectEncoder *enc, double value)
/*
FIXME:
Handle functions actually returning NULL here */
Handle integration functions returning NULL here */
/*
FIXME:
Perhaps implement recursion detection */
void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t cbName)
{
JSONTypeContext tc;