Crossfire Server, Trunk  R20513
Data Structures | Macros | Typedefs | Functions | Variables
cjson.c File Reference
#include <cfpython.h>
#include <Python.h>
#include <stddef.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
Include dependency graph for cjson.c:

Go to the source code of this file.

Data Structures

struct  JSONData
 

Macros

#define _PyBytes_Join   _PyString_Join
 
#define _PyBytes_Resize   _PyString_Resize
 
#define cjson_PyObject_Str   PyObject_Str
 
#define False   0
 
#define INFINITY   HUGE_VAL
 
#define MODULE_VERSION   "1.0.5"
 
#define NAN   (HUGE_VAL-HUGE_VAL)
 
#define Py_IS_NAN(X)   ((X) != (X))
 
#define PY_SSIZE_T_MAX   INT_MAX
 
#define PY_SSIZE_T_MIN   INT_MIN
 
#define PyBytes_AS_STRING   PyString_AS_STRING
 
#define PyBytes_AsString   PyString_AsString
 
#define PyBytes_AsStringAndSize   PyString_AsStringAndSize
 
#define PyBytes_Check   PyString_Check
 
#define PyBytes_Concat   PyString_Concat
 
#define PyBytes_ConcatAndDel   PyString_ConcatAndDel
 
#define PyBytes_DecodeEscape   PyString_DecodeEscape
 
#define PyBytes_FromString   PyString_FromString
 
#define PyBytes_FromStringAndSize   PyString_FromStringAndSize
 
#define PyBytes_GET_SIZE   PyString_GET_SIZE
 
#define PyBytes_Size   PyString_Size
 
#define PyBytesObject   PyStringObject
 
#define skipSpaces(d)   while (*((d)->ptr) && isspace(*((d)->ptr))) (d)->ptr++
 
#define SSIZE_T_F   "%d"
 
#define True   1
 

Typedefs

typedef struct JSONData JSONData
 
typedef int Py_ssize_t
 

Functions

static PyObject * decode_array (JSONData *jsondata)
 
static PyObject * decode_bool (JSONData *jsondata)
 
static PyObject * decode_inf (JSONData *jsondata)
 
static PyObject * decode_json (JSONData *jsondata)
 
static PyObject * decode_nan (JSONData *jsondata)
 
static PyObject * decode_null (JSONData *jsondata)
 
static PyObject * decode_number (JSONData *jsondata)
 
static PyObject * decode_object (JSONData *jsondata)
 
static PyObject * decode_string (JSONData *jsondata)
 
static PyObject * encode_dict (PyObject *object)
 
static PyObject * encode_list (PyObject *object)
 
static PyObject * encode_object (PyObject *object)
 
static PyObject * encode_string (PyObject *object)
 
static PyObject * encode_tuple (PyObject *object)
 
static PyObject * encode_unicode (PyObject *object)
 
static void getRowAndCol (char *begin, char *current, int *row, int *col)
 
PyMODINIT_FUNC initcjson (void)
 
static void initcjson_shared (PyObject *m)
 
static PyObject * JSON_decode (PyObject *self, PyObject *args, PyObject *kwargs)
 
static PyObject * JSON_encode (PyObject *self, PyObject *object)
 
 PyDoc_STRVAR (module_doc,"Fast JSON encoder/decoder module.")
 

Variables

static PyMethodDef cjson_methods []
 
static PyObject * JSON_DecodeError
 
static PyObject * JSON_EncodeError
 
static PyObject * JSON_Error
 

Macro Definition Documentation

#define _PyBytes_Join   _PyString_Join

Definition at line 34 of file cjson.c.

Referenced by encode_dict(), encode_list(), and encode_tuple().

#define _PyBytes_Resize   _PyString_Resize

Definition at line 32 of file cjson.c.

Referenced by encode_string().

#define cjson_PyObject_Str   PyObject_Str

Definition at line 108 of file cjson.c.

Referenced by encode_object().

#define False   0

Definition at line 78 of file cjson.c.

Referenced by decode_array(), decode_number(), decode_object(), decode_string(), and JSON_decode().

#define INFINITY   HUGE_VAL

Definition at line 81 of file cjson.c.

Referenced by decode_inf().

#define MODULE_VERSION   "1.0.5"

Definition at line 1335 of file cjson.c.

Referenced by initcjson_shared().

#define NAN   (HUGE_VAL-HUGE_VAL)

Definition at line 85 of file cjson.c.

Referenced by decode_nan().

#define Py_IS_NAN (   X)    ((X) != (X))

Definition at line 89 of file cjson.c.

Referenced by encode_object().

#define PY_SSIZE_T_MAX   INT_MAX

Definition at line 69 of file cjson.c.

Referenced by encode_string(), and encode_unicode().

#define PY_SSIZE_T_MIN   INT_MIN

Definition at line 70 of file cjson.c.

#define PyBytes_AS_STRING   PyString_AS_STRING

Definition at line 23 of file cjson.c.

Referenced by decode_number(), and encode_string().

#define PyBytes_AsString   PyString_AsString

Definition at line 29 of file cjson.c.

Referenced by decode_string().

#define PyBytes_AsStringAndSize   PyString_AsStringAndSize

Definition at line 35 of file cjson.c.

Referenced by JSON_decode().

#define PyBytes_Check   PyString_Check

Definition at line 22 of file cjson.c.

Referenced by encode_dict(), and encode_object().

#define PyBytes_Concat   PyString_Concat

Definition at line 30 of file cjson.c.

Referenced by encode_dict().

#define PyBytes_ConcatAndDel   PyString_ConcatAndDel

Definition at line 31 of file cjson.c.

Referenced by encode_dict(), encode_list(), and encode_tuple().

#define PyBytes_DecodeEscape   PyString_DecodeEscape

Definition at line 33 of file cjson.c.

Referenced by decode_string().

#define PyBytes_FromString   PyString_FromString

Definition at line 27 of file cjson.c.

Referenced by encode_dict(), encode_list(), encode_object(), and encode_tuple().

#define PyBytes_FromStringAndSize   PyString_FromStringAndSize

Definition at line 26 of file cjson.c.

Referenced by decode_number(), decode_string(), and encode_string().

#define PyBytes_GET_SIZE   PyString_GET_SIZE

Definition at line 24 of file cjson.c.

#define PyBytes_Size   PyString_Size

Definition at line 28 of file cjson.c.

#define PyBytesObject   PyStringObject

Definition at line 20 of file cjson.c.

Referenced by encode_string().

#define skipSpaces (   d)    while (*((d)->ptr) && isspace(*((d)->ptr))) (d)->ptr++

Definition at line 92 of file cjson.c.

Referenced by decode_array(), decode_json(), decode_object(), and JSON_decode().

#define SSIZE_T_F   "%d"
#define True   1

Definition at line 77 of file cjson.c.

Referenced by decode_array(), decode_number(), decode_object(), decode_string(), and JSON_decode().

Typedef Documentation

typedef struct JSONData JSONData
typedef int Py_ssize_t

Definition at line 67 of file cjson.c.

Function Documentation

static PyObject * decode_array ( JSONData jsondata)
static

Definition at line 385 of file cjson.c.

References decode_json(), False, getRowAndCol(), JSON_DecodeError, JSONData::ptr, skipSpaces, SSIZE_T_F, JSONData::str, and True.

Referenced by decode_json().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * decode_bool ( JSONData jsondata)
static

Definition at line 142 of file cjson.c.

References JSONData::end, getRowAndCol(), JSON_DecodeError, JSONData::ptr, SSIZE_T_F, and JSONData::str.

Referenced by decode_json().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * decode_inf ( JSONData jsondata)
static

Definition at line 266 of file cjson.c.

References JSONData::end, getRowAndCol(), INFINITY, JSON_DecodeError, JSONData::ptr, SSIZE_T_F, and JSONData::str.

Referenced by decode_json().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * decode_json ( JSONData jsondata)
static

Definition at line 544 of file cjson.c.

References decode_array(), decode_bool(), decode_inf(), decode_nan(), decode_null(), decode_number(), decode_object(), decode_string(), JSON_DecodeError, JSONData::ptr, and skipSpaces.

Referenced by decode_array(), decode_object(), and JSON_decode().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * decode_nan ( JSONData jsondata)
static

Definition at line 293 of file cjson.c.

References JSONData::end, getRowAndCol(), JSON_DecodeError, NAN, JSONData::ptr, SSIZE_T_F, and JSONData::str.

Referenced by decode_json().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * decode_null ( JSONData jsondata)
static

Definition at line 124 of file cjson.c.

References JSONData::end, getRowAndCol(), JSON_DecodeError, JSONData::ptr, SSIZE_T_F, and JSONData::str.

Referenced by decode_json().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * decode_number ( JSONData jsondata)
static

Definition at line 311 of file cjson.c.

References False, getRowAndCol(), JSON_DecodeError, JSONData::ptr, PyBytes_AS_STRING, PyBytes_FromStringAndSize, SSIZE_T_F, JSONData::str, and True.

Referenced by decode_json().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * decode_object ( JSONData jsondata)
static

Definition at line 449 of file cjson.c.

References decode_json(), False, getRowAndCol(), JSON_DecodeError, JSONData::ptr, skipSpaces, SSIZE_T_F, JSONData::str, and True.

Referenced by decode_json().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * decode_string ( JSONData jsondata)
static

Definition at line 164 of file cjson.c.

References JSONData::all_unicode, False, getRowAndCol(), JSON_DecodeError, JSONData::ptr, PyBytes_AsString, PyBytes_DecodeEscape, PyBytes_FromStringAndSize, SSIZE_T_F, JSONData::str, and True.

Referenced by decode_json().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * encode_dict ( PyObject *  object)
static

Definition at line 1107 of file cjson.c.

References _PyBytes_Join, encode_object(), JSON_EncodeError, PyBytes_Check, PyBytes_Concat, PyBytes_ConcatAndDel, and PyBytes_FromString.

Referenced by encode_object().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * encode_list ( PyObject *  object)
static

Definition at line 1028 of file cjson.c.

References _PyBytes_Join, encode_object(), JSON_EncodeError, Py_SIZE, PyBytes_ConcatAndDel, and PyBytes_FromString.

Referenced by encode_object().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * encode_object ( PyObject *  object)
static

Definition at line 1195 of file cjson.c.

References cjson_PyObject_Str, encode_dict(), encode_list(), encode_string(), encode_tuple(), encode_unicode(), JSON_EncodeError, Py_IS_NAN, PyBytes_Check, and PyBytes_FromString.

Referenced by encode_dict(), encode_list(), encode_tuple(), and JSON_encode().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * encode_string ( PyObject *  object)
static

Definition at line 622 of file cjson.c.

References _PyBytes_Resize, encode_unicode(), Py_SIZE, PY_SSIZE_T_MAX, PyBytes_AS_STRING, PyBytes_FromStringAndSize, and PyBytesObject.

Referenced by encode_object().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * encode_tuple ( PyObject *  object)
static

Definition at line 965 of file cjson.c.

References _PyBytes_Join, encode_object(), Py_SIZE, PyBytes_ConcatAndDel, and PyBytes_FromString.

Referenced by encode_object().

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * encode_unicode ( PyObject *  object)
static

Definition at line 822 of file cjson.c.

References PY_SSIZE_T_MAX.

Referenced by encode_object(), and encode_string().

Here is the caller graph for this function:

static void getRowAndCol ( char *  begin,
char *  current,
int *  row,
int *  col 
)
static

Definition at line 113 of file cjson.c.

Referenced by decode_array(), decode_bool(), decode_inf(), decode_nan(), decode_null(), decode_number(), decode_object(), and decode_string().

Here is the caller graph for this function:

PyMODINIT_FUNC initcjson ( void  )

Definition at line 1389 of file cjson.c.

References cjson_methods, and initcjson_shared().

Referenced by cfpython_init_types(), and initPlugin().

Here is the call graph for this function:

Here is the caller graph for this function:

static void initcjson_shared ( PyObject *  m)
static

Definition at line 1337 of file cjson.c.

References cjson_methods, JSON_DecodeError, JSON_EncodeError, JSON_Error, and MODULE_VERSION.

Referenced by initcjson().

Here is the caller graph for this function:

static PyObject* JSON_decode ( PyObject *  self,
PyObject *  args,
PyObject *  kwargs 
)
static

Definition at line 1249 of file cjson.c.

References JSONData::all_unicode, decode_json(), JSONData::end, False, JSON_DecodeError, JSONData::ptr, PyBytes_AsStringAndSize, skipSpaces, SSIZE_T_F, JSONData::str, and True.

Here is the call graph for this function:

static PyObject* JSON_encode ( PyObject *  self,
PyObject *  object 
)
static

Definition at line 1243 of file cjson.c.

References encode_object().

Here is the call graph for this function:

PyDoc_STRVAR ( module_doc  ,
"Fast JSON encoder/decoder module."   
)

Variable Documentation

PyMethodDef cjson_methods[]
static
Initial value:
= {
{ "encode", (PyCFunction)JSON_encode, METH_O,
PyDoc_STR("encode(object) -> generate the JSON representation for object.") },
{ "decode", (PyCFunction)JSON_decode, METH_VARARGS|METH_KEYWORDS,
PyDoc_STR("decode(string, all_unicode=False) -> parse the JSON representation into\n"
"python objects. The optional argument `all_unicode', specifies how to\n"
"convert the strings in the JSON representation into python objects.\n"
"If it is False (default on Python 2.x), it will return strings/bytes\n"
"everywhere possible and unicode objects only where necessary, else\n"
"it will return unicode objects everywhere (this is slower, but default\n"
"on Python 3.x).")
},
{ NULL, NULL, 0, NULL }
}
static PyObject * JSON_encode(PyObject *self, PyObject *object)
Definition: cjson.c:1243
static PyObject * JSON_decode(PyObject *self, PyObject *args, PyObject *kwargs)
Definition: cjson.c:1249

Definition at line 1306 of file cjson.c.

Referenced by initcjson(), and initcjson_shared().

PyObject* JSON_DecodeError
static
PyObject* JSON_EncodeError
static

Definition at line 63 of file cjson.c.

Referenced by encode_dict(), encode_list(), encode_object(), and initcjson_shared().

PyObject* JSON_Error
static

Definition at line 62 of file cjson.c.

Referenced by initcjson_shared().