Crossfire Server, Trunk
cjson.cpp File Reference
#include <cfpython.h>
#include <stddef.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
+ Include dependency graph for cjson.cpp:

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 63 of file cjson.cpp.

◆ INFINITY

#define INFINITY   HUGE_VAL

Definition at line 66 of file cjson.cpp.

◆ MODULE_VERSION

#define MODULE_VERSION   "1.0.5"

Definition at line 1127 of file cjson.cpp.

◆ NAN

#define NAN   (HUGE_VAL-HUGE_VAL)

Definition at line 70 of file cjson.cpp.

◆ Py_IS_NAN

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

Definition at line 74 of file cjson.cpp.

◆ PY_SSIZE_T_MAX

#define PY_SSIZE_T_MAX   INT_MAX

Definition at line 54 of file cjson.cpp.

◆ PY_SSIZE_T_MIN

#define PY_SSIZE_T_MIN   INT_MIN

Definition at line 55 of file cjson.cpp.

◆ skipSpaces

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

Definition at line 77 of file cjson.cpp.

◆ SSIZE_T_F

#define SSIZE_T_F   "%d"

Definition at line 57 of file cjson.cpp.

◆ True

#define True   1

Definition at line 62 of file cjson.cpp.

Typedef Documentation

◆ JSONData

typedef struct JSONData JSONData

◆ Py_ssize_t

typedef int Py_ssize_t

Definition at line 52 of file cjson.cpp.

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 82 of file cjson.cpp.

References altar_valkyrie::obj, and rotate-tower::result.

Referenced by encode_object().

+ Here is the caller graph for this function:

◆ decode_array()

static PyObject * decode_array ( JSONData jsondata)
static

Definition at line 356 of file cjson.cpp.

References c, decode_json(), False, getRowAndCol(), say::item, JSON_DecodeError, JSONData::ptr, rotate-tower::result, 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 123 of file cjson.cpp.

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 245 of file cjson.cpp.

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 515 of file cjson.cpp.

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 272 of file cjson.cpp.

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 105 of file cjson.cpp.

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 290 of file cjson.cpp.

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 420 of file cjson.cpp.

References c, decode_json(), False, getRowAndCol(), JSON_DecodeError, JSONData::ptr, rotate-tower::result, 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_string()

static PyObject * decode_string ( JSONData jsondata)
static

Definition at line 145 of file cjson.cpp.

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

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 915 of file cjson.cpp.

References autojail::dict, encode_object(), JSON_EncodeError, rotate-tower::result, 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_list()

static PyObject * encode_list ( PyObject *  object)
static

Definition at line 836 of file cjson.cpp.

References encode_object(), JSON_EncodeError, guildoracle::list, rotate-tower::result, 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 1003 of file cjson.cpp.

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 593 of file cjson.cpp.

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 773 of file cjson.cpp.

References encode_object(), rotate-tower::result, 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 658 of file cjson.cpp.

References navar-midane_time::data, PY_SSIZE_T_MAX, and rotate-tower::result.

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 94 of file cjson.cpp.

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 1129 of file cjson.cpp.

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 1045 of file cjson.cpp.

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 1165 of file cjson.cpp.

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 1108 of file cjson.cpp.

◆ cjsonModule

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

Definition at line 1153 of file cjson.cpp.

Referenced by PyInit_cjson().

◆ JSON_DecodeError

◆ JSON_EncodeError

PyObject* JSON_EncodeError
static

Definition at line 48 of file cjson.cpp.

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

◆ JSON_Error

PyObject* JSON_Error
static

Definition at line 47 of file cjson.cpp.

Referenced by initcjson_shared().

JSON_decode
static PyObject * JSON_decode(PyObject *self, PyObject *args, PyObject *kwargs)
Definition: cjson.cpp:1052
cjson_methods
static PyMethodDef cjson_methods[]
Definition: cjson.cpp:1108
JSON_encode
static PyObject * JSON_encode(PyObject *self, PyObject *object)
Definition: cjson.cpp:1045