chiark
/
gitweb
/
~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mp.c: Factor out and export `mphash'.
[catacomb-python]
/
field.c
diff --git
a/field.c
b/field.c
index a18a94250b4350477b568c4b38877cd196134b61..0a5d908f805dcff2ffe04b2f8d29899bcc14fcec 100644
(file)
--- a/
field.c
+++ b/
field.c
@@
-66,7
+66,7
@@
static PyObject *field_dopywrap(PyTypeObject *ty, field *f)
fobj->ty.ht_type.tp_alloc = PyType_GenericAlloc;
fobj->ty.ht_type.tp_free = 0;
fobj->ty.ht_type.tp_new = fe_pynew;
fobj->ty.ht_type.tp_alloc = PyType_GenericAlloc;
fobj->ty.ht_type.tp_free = 0;
fobj->ty.ht_type.tp_new = fe_pynew;
-
PyType_R
eady(&fobj->ty.ht_type);
+
typer
eady(&fobj->ty.ht_type);
return ((PyObject *)fobj);
}
return ((PyObject *)fobj);
}
@@
-230,11
+230,13
@@
end:
static long fe_pyhash(PyObject *me)
{
static long fe_pyhash(PyObject *me)
{
- long i = mp_tolong(FE_X(me));
- i ^= 0xdcf62d6c; /* random perturbance */
- if (i == -1)
- i = -2;
- return (i);
+ size_t sz = FE_F(me)->noctets;
+ uint32 h = 0xe0c127ca + FE_F(me)->ops->ty;
+ octet *p = xmalloc(sz);
+ mp_storeb(FE_X(me), p, sz);
+ h = unihash_hash(&unihash_global, h, p, sz);
+ xfree(p);
+ return (h % LONG_MAX);
}
static int fe_pycoerce(PyObject **x, PyObject **y)
}
static int fe_pycoerce(PyObject **x, PyObject **y)
@@
-261,10
+263,12
@@
end:
static PyObject *fe_pyint(PyObject *x)
{
long l;
static PyObject *fe_pyint(PyObject *x)
{
long l;
+ PyObject *rc;
mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x));
mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x));
- if (mp_tolong_checked(xx, &l)) { MP_DROP(xx); return (0); }
+ if (!mp_tolong_checked(xx, &l, 0)) rc = PyInt_FromLong(l);
+ else rc = mp_topylong(xx);
MP_DROP(xx);
MP_DROP(xx);
- return (
PyInt_FromLong(l)
);
+ return (
rc
);
}
static PyObject *fe_pylong(PyObject *x)
}
static PyObject *fe_pylong(PyObject *x)
@@
-956,7
+960,7
@@
static PyObject *meth__Field_parse(PyObject *me, PyObject *arg)
qd.p = p;
qd.e = 0;
if ((f = field_parse(&qd)) == 0)
qd.p = p;
qd.e = 0;
if ((f = field_parse(&qd)) == 0)
-
SYN
ERR(qd.e);
+
VAL
ERR(qd.e);
rc = Py_BuildValue("(Ns)", field_pywrap(f), qd.p);
end:
return (rc);
rc = Py_BuildValue("(Ns)", field_pywrap(f), qd.p);
end:
return (rc);