forked from GitHub/gf-core
Remove int tag from ExprLitObject
This commit is contained in:
@@ -129,16 +129,17 @@ static PyObject *
|
||||
ExprLit_richcompare(ExprLitObject *t1, ExprLitObject *t2, int op)
|
||||
{
|
||||
bool same = false;
|
||||
if (t1->type != t2->type) goto done;
|
||||
|
||||
if (t1->type == 0) {
|
||||
if (PyLong_Check(t1->value)) {
|
||||
if (!PyLong_Check(t2->value)) goto done;
|
||||
int o1, o2;
|
||||
int l1 = PyLong_AsLongAndOverflow(t1->value, &o1);
|
||||
int l2 = PyLong_AsLongAndOverflow(t2->value, &o2);
|
||||
if (!(l1 == l2 && o1 == o2)) goto done;
|
||||
} else if (t1->type == 1) {
|
||||
} else if (PyFloat_Check(t1->value)) {
|
||||
if (!PyFloat_Check(t2->value)) goto done;
|
||||
if (PyFloat_AsDouble(t1->value) != PyFloat_AsDouble(t2->value)) goto done;
|
||||
} else if (t1->type == 2) {
|
||||
} else if (PyString_Check(t1->value)) {
|
||||
if (!PyString_Check(t2->value)) goto done;
|
||||
if (PyString_Compare(t1->value, t2->value) != 0) goto done;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "unknown literal type");
|
||||
|
||||
@@ -23,8 +23,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
int type; // 0 = int, 1 = float, 2 = str
|
||||
PyObject *value; // depends on type
|
||||
PyObject *value;
|
||||
} ExprLitObject;
|
||||
|
||||
extern PyTypeObject pgf_ExprType;
|
||||
|
||||
@@ -28,21 +28,8 @@ PgfExpr eapp(PgfUnmarshaller *this, PgfExpr fun, PgfExpr arg)
|
||||
PgfExpr elit(PgfUnmarshaller *this, PgfLiteral lit)
|
||||
{
|
||||
ExprLitObject *pyexpr = (ExprLitObject *)pgf_ExprLitType.tp_alloc(&pgf_ExprLitType, 0);
|
||||
|
||||
PyObject *pyobj = (PyObject *)lit;
|
||||
pyexpr->value = pyobj;
|
||||
|
||||
if (PyLong_Check(pyobj)) {
|
||||
pyexpr->type = 0;
|
||||
} else if (PyFloat_Check(pyobj)) {
|
||||
pyexpr->type = 1;
|
||||
} else if (PyString_Check(pyobj)) {
|
||||
pyexpr->type = 2;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "unable to unmarshall literal");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Py_INCREF(pyobj);
|
||||
return (PgfExpr) pyexpr;
|
||||
}
|
||||
@@ -208,6 +195,8 @@ object match_expr(PgfUnmarshaller *u, PgfExpr expr)
|
||||
|
||||
object match_type(PgfUnmarshaller *u, PgfType ty)
|
||||
{
|
||||
// PySys_WriteStdout(">match_type<\n");
|
||||
|
||||
TypeObject *type = (TypeObject *)ty;
|
||||
|
||||
// PySys_WriteStdout(">%s<\n", PyUnicode_AS_DATA(type->cat));
|
||||
|
||||
Reference in New Issue
Block a user