Crossfire Server, Trunk
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 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 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 * cjson_PyObject_Str (PyObject *obj)
 
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)
 
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.")
 
PyObject * PyInit_cjson (void)
 

Variables

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

Macro Definition Documentation

◆ False

#define False   0

Definition at line 56 of file cjson.c.

◆ INFINITY

#define INFINITY   HUGE_VAL

Definition at line 59 of file cjson.c.

◆ MODULE_VERSION

#define MODULE_VERSION   "1.0.5"

Definition at line 1147 of file cjson.c.

◆ NAN

#define NAN   (HUGE_VAL-HUGE_VAL)

Definition at line 63 of file cjson.c.

◆ Py_IS_NAN

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

Definition at line 67 of file cjson.c.

◆ PY_SSIZE_T_MAX

#define PY_SSIZE_T_MAX   INT_MAX

Definition at line 47 of file cjson.c.

◆ PY_SSIZE_T_MIN

#define PY_SSIZE_T_MIN   INT_MIN

Definition at line 48 of file cjson.c.

◆ skipSpaces

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

Definition at line 70 of file cjson.c.

◆ SSIZE_T_F

#define SSIZE_T_F   "%d"

Definition at line 50 of file cjson.c.

◆ True

#define True   1

Definition at line 55 of file cjson.c.

Typedef Documentation

◆ JSONData

typedef struct JSONData JSONData

◆ Py_ssize_t

typedef int Py_ssize_t

Definition at line 45 of file cjson.c.

Function Documentation

◆ cjson_PyObject_Str()

static PyObject* cjson_PyObject_Str ( PyObject *  obj)
static

Same as PyObject_Str but return a UTF-8 encoded Bytes object instead.

Definition at line 75 of file cjson.c.

Referenced by encode_object().

+ Here is the caller graph for this function:

◆ decode_array()

static PyObject * decode_array ( JSONData jsondata)
static

Definition at line 349 of file cjson.c.

References c, decode_json(), False, getRowAndCol(), say::item, 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:

◆ decode_bool()

static PyObject * decode_bool ( JSONData jsondata)
static

Definition at line 116 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:

◆ decode_inf()

static PyObject * decode_inf ( JSONData jsondata)
static

Definition at line 238 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:

◆ decode_json()

static PyObject * decode_json ( JSONData jsondata)
static

Definition at line 508 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:

◆ decode_nan()

static PyObject * decode_nan ( JSONData jsondata)
static

Definition at line 265 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:

◆ decode_null()

static PyObject * decode_null ( JSONData jsondata)
static

Definition at line 98 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:

◆ decode_number()

static PyObject * decode_number ( JSONData jsondata)
static

Definition at line 283 of file cjson.c.

References c, False, getRowAndCol(), JSON_DecodeError, JSONData::ptr, SSIZE_T_F, JSONData::str, make_face_from_files::str, and True.

Referenced by decode_json().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decode_object()

static PyObject * decode_object ( JSONData jsondata)
static

Definition at line 413 of file cjson.c.

References c, decode_json(), False, getRowAndCol(), JSON_DecodeError, castle_read::key, JSONData::ptr, skipSpaces, SSIZE_T_F, JSONData::str, True, and autojail::value.

Referenced by decode_json().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decode_string()

static PyObject * decode_string ( JSONData jsondata)
static

Definition at line 138 of file cjson.c.

References JSONData::all_unicode, c, False, getRowAndCol(), JSON_DecodeError, JSONData::ptr, SSIZE_T_F, JSONData::str, True, is_valid_types_gen::type, and autojail::value.

Referenced by decode_json().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_dict()

static PyObject * encode_dict ( PyObject *  object)
static

Definition at line 935 of file cjson.c.

References autojail::dict, encode_object(), JSON_EncodeError, castle_read::key, takeitem::status, guildbuy::temp, and autojail::value.

Referenced by encode_object().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_list()

static PyObject * encode_list ( PyObject *  object)
static

Definition at line 856 of file cjson.c.

References encode_object(), JSON_EncodeError, guildoracle::list, takeitem::status, and guildbuy::temp.

Referenced by encode_object().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_object()

static PyObject * encode_object ( PyObject *  object)
static

Definition at line 1023 of file cjson.c.

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

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:

◆ encode_string()

static PyObject * encode_string ( PyObject *  object)
static

Definition at line 586 of file cjson.c.

References c, give::op, and PY_SSIZE_T_MAX.

Referenced by encode_object().

+ Here is the caller graph for this function:

◆ encode_tuple()

static PyObject * encode_tuple ( PyObject *  object)
static

Definition at line 793 of file cjson.c.

References encode_object(), and guildbuy::temp.

Referenced by encode_object().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_unicode()

static PyObject * encode_unicode ( PyObject *  object)
static

Definition at line 651 of file cjson.c.

References PY_SSIZE_T_MAX.

Referenced by encode_object().

+ Here is the caller graph for this function:

◆ getRowAndCol()

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

Definition at line 87 of file cjson.c.

References replace::current.

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:

◆ initcjson_shared()

static void initcjson_shared ( PyObject *  m)
static

Definition at line 1149 of file cjson.c.

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

Referenced by PyInit_cjson().

+ Here is the caller graph for this function:

◆ JSON_decode()

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

◆ JSON_encode()

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

Definition at line 1065 of file cjson.c.

References encode_object(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ PyDoc_STRVAR()

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

◆ PyInit_cjson()

PyObject* PyInit_cjson ( void  )

Definition at line 1185 of file cjson.c.

References cjsonModule, initcjson_shared(), and m.

Referenced by initPlugin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ cjson_methods

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=True) -> 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 }
}

Definition at line 1128 of file cjson.c.

◆ cjsonModule

PyModuleDef cjsonModule
static
Initial value:
= {
PyModuleDef_HEAD_INIT,
"cjson",
module_doc,
-1,
NULL,
NULL,
NULL,
NULL
}

Definition at line 1173 of file cjson.c.

Referenced by PyInit_cjson().

◆ JSON_DecodeError

◆ JSON_EncodeError

PyObject* JSON_EncodeError
static

Definition at line 41 of file cjson.c.

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

◆ JSON_Error

PyObject* JSON_Error
static

Definition at line 40 of file cjson.c.

Referenced by initcjson_shared().

JSON_decode
static PyObject * JSON_decode(PyObject *self, PyObject *args, PyObject *kwargs)
Definition: cjson.c:1072
cjson_methods
static PyMethodDef cjson_methods[]
Definition: cjson.c:1128
JSON_encode
static PyObject * JSON_encode(PyObject *self, PyObject *object)
Definition: cjson.c:1065