forked from GitHub/gf-core
Working readType, functionType, unmarshaller for types (except exprs) in Python bindings
This commit is contained in:
@@ -3,34 +3,11 @@
|
||||
#include "structmember.h"
|
||||
|
||||
#include <pgf/pgf.h>
|
||||
#include "./compat.h"
|
||||
#include "./expr.h"
|
||||
#include "./marshaller.h"
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define PyIntObject PyLongObject
|
||||
#define PyInt_Type PyLong_Type
|
||||
#define PyInt_Check(op) PyLong_Check(op)
|
||||
#define PyInt_CheckExact(op) PyLong_CheckExact(op)
|
||||
#define PyInt_FromString PyLong_FromString
|
||||
#define PyInt_FromUnicode PyLong_FromUnicode
|
||||
#define PyInt_FromLong PyLong_FromLong
|
||||
#define PyInt_FromSize_t PyLong_FromSize_t
|
||||
#define PyInt_FromSsize_t PyLong_FromSsize_t
|
||||
#define PyInt_AsLong PyLong_AsLong
|
||||
#define PyInt_AS_LONG PyLong_AS_LONG
|
||||
#define PyInt_AsSsize_t PyLong_AsSsize_t
|
||||
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
|
||||
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define PyString_Check PyUnicode_Check
|
||||
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
|
||||
#define PyString_FromFormat PyUnicode_FromFormat
|
||||
#define PyString_Concat(ps,s) {PyObject* tmp = *(ps); *(ps) = PyUnicode_Concat(tmp,s); Py_DECREF(tmp);}
|
||||
#endif
|
||||
|
||||
static PyObject* PGFError;
|
||||
static PyObject *PGFError;
|
||||
|
||||
// static PyObject* ParseError;
|
||||
|
||||
@@ -38,7 +15,7 @@ static PyObject* PGFError;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PgfPGF* pgf;
|
||||
PgfPGF *pgf;
|
||||
} PGFObject;
|
||||
|
||||
// typedef struct IterObject {
|
||||
@@ -1983,33 +1960,25 @@ PGF_functionsByCat(PGFObject* self, PyObject *args)
|
||||
return functions;
|
||||
}
|
||||
|
||||
static TypeObject*
|
||||
PGF_functionType(PGFObject* self, PyObject *args)
|
||||
static TypeObject *
|
||||
PGF_functionType(PGFObject *self, PyObject *args)
|
||||
{
|
||||
const char* s;
|
||||
const char *s;
|
||||
Py_ssize_t size;
|
||||
if (!PyArg_ParseTuple(args, "s#", &s, &size))
|
||||
return NULL;
|
||||
|
||||
PgfText* funname = (PgfText*) alloca(sizeof(PgfText)+size+1);
|
||||
PgfText *funname = (PgfText *)alloca(sizeof(PgfText)+size+1);
|
||||
memcpy(funname->text, s, size+1);
|
||||
funname->size = size;
|
||||
|
||||
PgfType type = pgf_function_type(self->pgf, funname, &unmarshaller);
|
||||
// if (type == NULL) {
|
||||
// PyErr_Format(PyExc_KeyError, "Function '%s' is not defined", funname->text);
|
||||
// return NULL;
|
||||
// }
|
||||
//
|
||||
// TypeObject* pytype = (TypeObject*) pgf_TypeType.tp_alloc(&pgf_TypeType, 0);
|
||||
// if (pytype == NULL)
|
||||
// return NULL;
|
||||
// // pytype->pool = NULL;
|
||||
// pytype->type = &type;
|
||||
// pytype->master = (PyObject*) self;
|
||||
// Py_XINCREF(self);
|
||||
// return pytype;
|
||||
return (TypeObject*) type;
|
||||
if (type == 0) {
|
||||
PyErr_Format(PyExc_KeyError, "Function '%s' is not defined", funname->text);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (TypeObject *)type;
|
||||
}
|
||||
|
||||
// static IterObject*
|
||||
@@ -2525,15 +2494,15 @@ pgf_readNGF(PyObject *self, PyObject *args)
|
||||
// return pyexpr;
|
||||
// }
|
||||
|
||||
static TypeObject*
|
||||
static TypeObject *
|
||||
pgf_readType(PyObject *self, PyObject *args)
|
||||
{
|
||||
const char* s;
|
||||
const char *s;
|
||||
Py_ssize_t size;
|
||||
if (!PyArg_ParseTuple(args, "s#", &s, &size))
|
||||
return NULL;
|
||||
|
||||
PgfText* input = (PgfText*) alloca(sizeof(PgfText)+size+1);
|
||||
PgfText *input = (PgfText *)alloca(sizeof(PgfText)+size+1);
|
||||
memcpy(input->text, s, size+1);
|
||||
input->size = size;
|
||||
|
||||
@@ -2543,16 +2512,7 @@ pgf_readType(PyObject *self, PyObject *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TypeObject* pytype = (TypeObject*) pgf_TypeType.tp_alloc(&pgf_TypeType, 0);
|
||||
// if (pytype == NULL)
|
||||
// return NULL;
|
||||
// // pytype->pool = NULL;
|
||||
// pytype->type = &type;
|
||||
// pytype->master = (PyObject*) self;
|
||||
// Py_XINCREF(self);
|
||||
// return pytype;
|
||||
|
||||
return (TypeObject*) type;
|
||||
return (TypeObject *)type;
|
||||
}
|
||||
|
||||
static PyMethodDef module_methods[] = {
|
||||
|
||||
Reference in New Issue
Block a user