Modernize Bongo 0.7.0 foundation
This commit is contained in:
+46
-150
@@ -17,51 +17,24 @@ static PyMethodDef JsonObject_methods[] = {
|
||||
};
|
||||
|
||||
static PyMappingMethods JsonObject_mapping = {
|
||||
JsonObject_length,
|
||||
JsonObject_subscript,
|
||||
JsonObject_subscript_assign
|
||||
.mp_length = JsonObject_length,
|
||||
.mp_subscript = JsonObject_subscript,
|
||||
.mp_ass_subscript = JsonObject_subscript_assign
|
||||
};
|
||||
|
||||
PyTypeObject JsonObjectType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"libs.JsonObject",
|
||||
sizeof(JsonObject),
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)JsonObject_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
&JsonObject_mapping, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
JsonObject_str, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Bongo Json Object", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
JsonObject_methods, /* tp_methods */
|
||||
JsonObject_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)JsonObject_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
JsonObject_new, /* tp_new */
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = "libs.JsonObject",
|
||||
.tp_basicsize = sizeof(JsonObject),
|
||||
.tp_dealloc = (destructor)JsonObject_dealloc,
|
||||
.tp_as_mapping = &JsonObject_mapping,
|
||||
.tp_str = JsonObject_str,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
||||
.tp_doc = "Bongo Json Object",
|
||||
.tp_methods = JsonObject_methods,
|
||||
.tp_members = JsonObject_members,
|
||||
.tp_init = (initproc)JsonObject_init,
|
||||
.tp_new = JsonObject_new,
|
||||
};
|
||||
|
||||
|
||||
@@ -75,16 +48,8 @@ static PyMethodDef JsonArray_methods[] = {
|
||||
};
|
||||
|
||||
static PySequenceMethods JsonArray_sequence = {
|
||||
JsonArray_length,
|
||||
JsonArray_concat,
|
||||
JsonArray_repeat,
|
||||
JsonArray_item,
|
||||
JsonArray_slice,
|
||||
JsonArray_assign,
|
||||
JsonArray_assign_slice,
|
||||
JsonArray_contains,
|
||||
JsonArray_inplace_concat,
|
||||
JsonArray_inplace_repeat,
|
||||
.sq_length = JsonArray_length,
|
||||
.sq_item = JsonArray_item,
|
||||
};
|
||||
|
||||
#if 0
|
||||
@@ -103,45 +68,18 @@ static PySequenceMethods JsonArray_sequence = {
|
||||
|
||||
|
||||
PyTypeObject JsonArrayType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"libs.JsonArray",
|
||||
sizeof(JsonArray),
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)JsonArray_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
&JsonArray_sequence, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
JsonArray_str, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Bongo Json Array", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
JsonArray_methods, /* tp_methods */
|
||||
JsonArray_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)JsonArray_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
JsonArray_new, /* tp_new */
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = "libs.JsonArray",
|
||||
.tp_basicsize = sizeof(JsonArray),
|
||||
.tp_dealloc = (destructor)JsonArray_dealloc,
|
||||
.tp_as_sequence = &JsonArray_sequence,
|
||||
.tp_str = JsonArray_str,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
||||
.tp_doc = "Bongo Json Array",
|
||||
.tp_methods = JsonArray_methods,
|
||||
.tp_members = JsonArray_members,
|
||||
.tp_init = (initproc)JsonArray_init,
|
||||
.tp_new = JsonArray_new,
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -291,7 +229,8 @@ JsonNodeToPy(BongoJsonNode *node, BOOL own, BOOL native)
|
||||
ret = (PyObject*)PyObject_New(JsonArray, &JsonArrayType);
|
||||
((JsonArray*)ret)->own = own;
|
||||
((JsonArray*)ret)->array = BongoJsonNodeAsArray(node);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BONGO_JSON_BOOL :
|
||||
if (BongoJsonNodeAsBool(node)) {
|
||||
ret = Py_True;
|
||||
@@ -327,13 +266,16 @@ JsonArray_dealloc(JsonArray *self)
|
||||
BongoJsonArrayFree(self->array);
|
||||
}
|
||||
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
JsonArray_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
JsonArray *self;
|
||||
|
||||
(void)args;
|
||||
(void)kwds;
|
||||
|
||||
self = (JsonArray*)type->tp_alloc(type, 0);
|
||||
self->own = FALSE;
|
||||
@@ -348,6 +290,8 @@ JsonArray_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
int
|
||||
JsonArray_init(JsonArray *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
(void)args;
|
||||
(void)kwds;
|
||||
self->own = TRUE;
|
||||
self->array = g_array_sized_new(FALSE, FALSE, sizeof(BongoJsonNode*), 16);
|
||||
return 0;
|
||||
@@ -400,20 +344,6 @@ JsonArray_length(PyObject *selfp)
|
||||
return (self->array->len > 0) ? (Py_ssize_t)self->array->len : 0;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
JsonArray_concat(PyObject *selfp, PyObject *b)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
JsonArray_repeat(PyObject *selfp, Py_ssize_t i)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
JsonArray_item(PyObject *selfp, Py_ssize_t i)
|
||||
{
|
||||
@@ -430,48 +360,6 @@ JsonArray_item(PyObject *selfp, Py_ssize_t i)
|
||||
return JsonNodeToPy(node, FALSE, FALSE);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
JsonArray_slice(PyObject *selfp, Py_ssize_t i1, Py_ssize_t i2)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
JsonArray_assign(PyObject *selfp, Py_ssize_t i, PyObject *obj)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
JsonArray_assign_slice(PyObject *selfp, Py_ssize_t i1, Py_ssize_t i2, PyObject *obj)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
JsonArray_contains(PyObject *selfp, PyObject *b)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
JsonArray_inplace_concat(PyObject *selfp, PyObject *b)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
JsonArray_inplace_repeat(PyObject *selfp, Py_ssize_t i)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*** JsonObject ***/
|
||||
|
||||
void
|
||||
@@ -483,7 +371,7 @@ JsonObject_dealloc(JsonObject *self)
|
||||
}
|
||||
#endif
|
||||
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
|
||||
@@ -492,6 +380,9 @@ JsonObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
JsonObject *self;
|
||||
|
||||
(void)args;
|
||||
(void)kwds;
|
||||
|
||||
self = (JsonObject*)type->tp_alloc(type, 0);
|
||||
self->obj = NULL;
|
||||
self->own = FALSE;
|
||||
@@ -506,6 +397,8 @@ JsonObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
int
|
||||
JsonObject_init(JsonObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
(void)args;
|
||||
(void)kwds;
|
||||
self->obj = BongoJsonObjectNew();
|
||||
self->own = TRUE;
|
||||
self->valid = TRUE;
|
||||
@@ -531,6 +424,7 @@ JsonObject_str(PyObject *selfp)
|
||||
Py_ssize_t
|
||||
JsonObject_length(PyObject *self)
|
||||
{
|
||||
(void)self;
|
||||
/* FIXME */
|
||||
return 1;
|
||||
}
|
||||
@@ -618,6 +512,7 @@ BongoJsonPostInit(PyObject *module)
|
||||
static PyObject *
|
||||
bongojson_BongoJsonParseString(PyObject *self, PyObject *args)
|
||||
{
|
||||
(void)self;
|
||||
char *jsonStr;
|
||||
BongoJsonNode *node;
|
||||
BongoJsonResult res;
|
||||
@@ -665,6 +560,7 @@ bongojson_BongoJsonParseString(PyObject *self, PyObject *args)
|
||||
static PyObject *
|
||||
bongojson_ToPy(PyObject *self, PyObject *args)
|
||||
{
|
||||
(void)self;
|
||||
PyObject *obj;
|
||||
PyObject *ret;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user