Crossfire Server  1.75.0
cjson.cpp File Reference
#include <cfpython.h>
#include <stddef.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>

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)
 Same as PyObject_Str but return a UTF-8 encoded Bytes object instead. More...
 
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.

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

◆ INFINITY

#define INFINITY   HUGE_VAL

Definition at line 66 of file cjson.cpp.

Referenced by decode_inf().

◆ MODULE_VERSION

#define MODULE_VERSION   "1.0.5"

Definition at line 1127 of file cjson.cpp.

Referenced by initcjson_shared().

◆ NAN

#define NAN   (HUGE_VAL-HUGE_VAL)

Definition at line 70 of file cjson.cpp.

Referenced by decode_nan().

◆ Py_IS_NAN

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

Definition at line 74 of file cjson.cpp.

Referenced by encode_object().

◆ PY_SSIZE_T_MAX

#define PY_SSIZE_T_MAX   INT_MAX

Definition at line 54 of file cjson.cpp.

Referenced by encode_string(), and encode_unicode().

◆ 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.

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

◆ SSIZE_T_F

#define SSIZE_T_F   "%d"

◆ True

#define True   1

Definition at line 62 of file cjson.cpp.

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

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.

Referenced by encode_object().

◆ decode_array()

static PyObject * decode_array ( JSONData jsondata)
static

Definition at line 356 of file cjson.cpp.

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

Referenced by decode_json().

◆ 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().

◆ 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().

◆ decode_json()

static PyObject * decode_json ( JSONData jsondata)
static

◆ 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().

◆ 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().

◆ 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, and True.

Referenced by decode_json().

◆ 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, skipSpaces, SSIZE_T_F, JSONData::str, and True.

Referenced by decode_json().

◆ decode_string()

static PyObject * decode_string ( JSONData jsondata)
static

◆ encode_dict()

static PyObject * encode_dict ( PyObject *  object)
static

Definition at line 915 of file cjson.cpp.

References encode_object(), and JSON_EncodeError.

Referenced by encode_object().

◆ encode_list()

static PyObject * encode_list ( PyObject *  object)
static

Definition at line 836 of file cjson.cpp.

References encode_object(), and JSON_EncodeError.

Referenced by encode_object().

◆ encode_object()

static PyObject * encode_object ( PyObject *  object)
static

◆ encode_string()

static PyObject * encode_string ( PyObject *  object)
static

Definition at line 593 of file cjson.cpp.

References c, and PY_SSIZE_T_MAX.

Referenced by encode_object().

◆ encode_tuple()

static PyObject * encode_tuple ( PyObject *  object)
static

Definition at line 773 of file cjson.cpp.

References encode_object().

Referenced by encode_object().

◆ encode_unicode()

static PyObject * encode_unicode ( PyObject *  object)
static

Definition at line 658 of file cjson.cpp.

References PY_SSIZE_T_MAX.

Referenced by encode_object().

◆ getRowAndCol()

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

◆ initcjson_shared()

static void initcjson_shared ( PyObject *  m)
static

Definition at line 1129 of file cjson.cpp.

References JSON_DecodeError, JSON_EncodeError, JSON_Error, and MODULE_VERSION.

Referenced by PyInit_cjson().

◆ 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().

◆ 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 cfpython_init_types(), and initPlugin().

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 }
}
static PyObject * JSON_decode(PyObject *self, PyObject *args, PyObject *kwargs)
Definition: cjson.cpp:1052
static PyObject * JSON_encode(PyObject *self, PyObject *object)
Definition: cjson.cpp:1045

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
}
static PyMethodDef cjson_methods[]
Definition: cjson.cpp:1108

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().