/*----- Abstract fields ---------------------------------------------------*/
typedef struct field_pyobj {
- PyTypeObject ty;
+ PyHeapTypeObject ty;
field *f;
} field_pyobj;
extern int convec(PyObject *, void *);
typedef struct eccurve_pyobj {
- PyTypeObject ty;
+ PyHeapTypeObject ty;
ec_curve *c;
PyObject *fobj;
} eccurve_pyobj;
extern PyObject *ge_pywrap(PyObject *, ge *);
typedef struct group_pyobj {
- PyTypeObject ty;
+ PyHeapTypeObject ty;
group *g;
} group_pyobj;
/*----- Symmetric cryptography --------------------------------------------*/
typedef struct gccipher_pyobj {
- PyTypeObject ty;
+ PyHeapTypeObject ty;
gccipher *cc;
} gccipher_pyobj;
extern int convgcipher(PyObject *, void *);
typedef struct gchash_pyobj {
- PyTypeObject ty;
+ PyHeapTypeObject ty;
gchash *ch;
} gchash_pyobj;
extern int convgmhash(PyObject *, void *);
typedef struct gcmac_pyobj {
- PyTypeObject ty;
+ PyHeapTypeObject ty;
gcmac *cm;
} gcmac_pyobj;
extern int convgcmac(PyObject *, void *);
typedef struct gmac_pyobj {
- PyTypeObject ty;
+ PyHeapTypeObject ty;
unsigned f;
gmac *m;
- PyObject *nameobj;
} gmac_pyobj;
extern PyTypeObject *gmac_pytype;
#define GMAC_PYCHECK(o) PyObject_TypeCheck((o), gmac_pytype)
#define GMAC_M(o) (((gmac_pyobj *)(o))->m)
-#define GMAC_NAMEOBJ(o) (((gmac_pyobj *)(o))->nameobj)
#define GMAC_F(o) (((gmac_pyobj *)(o))->f)
extern PyObject *gmac_pywrap(PyObject *, gmac *, unsigned);
extern int convgmac(PyObject *, void *);
extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *);
extern PyObject *getbool(int);
extern PyObject *getu32(uint32);
-extern void *newtype(PyTypeObject *, const PyTypeObject *);
+extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *);
extern PyTypeObject *inittype(PyTypeObject *);
extern void addmethods(const PyMethodDef *);
static const PyTypeObject emptytype = { 0 };
-void *newtype(PyTypeObject *metaty, const PyTypeObject *skel)
+void *newtype(PyTypeObject *metaty,
+ const PyTypeObject *skel,
+ const char *name)
{
- PyTypeObject *ty =
-#if PY_VERSION_HEX < 0x02030000
- (PyTypeObject *)_PyObject_GC_Malloc(metaty, 0);
-#else
- (PyTypeObject *)_PyObject_GC_Malloc(_PyObject_VAR_SIZE(metaty, 0));
-#endif
+ PyHeapTypeObject *ty =
+ (PyHeapTypeObject *)_PyObject_GC_Malloc(_PyObject_VAR_SIZE(metaty, 0));
if (!skel) skel = &emptytype;
memcpy(ty, skel, sizeof(*skel));
- if (ty->tp_base) Py_INCREF(ty->tp_base);
- PyObject_INIT(ty, metaty);
+ if (ty->type.tp_base) Py_INCREF(ty->type.tp_base);
+#define COPY(blah) do { \
+ if (ty->type.tp_as_##blah) { \
+ memcpy(&ty->as_##blah, \
+ ty->type.tp_as_##blah, \
+ sizeof(ty->as_##blah)); \
+ ty->type.tp_as_##blah = &ty->as_##blah; \
+ } \
+ } while (0)
+ COPY(number);
+ COPY(sequence);
+ COPY(mapping);
+ COPY(buffer);
+#undef COPY
+ if (name)
+ ty->name = PyString_FromString(name);
+ else if (ty->type.tp_name)
+ ty->name = PyString_FromString(ty->type.tp_name);
+ if (ty->name)
+ ty->type.tp_name = PyString_AS_STRING(ty->name);
+ PyObject_INIT(&ty->type, metaty);
Py_INCREF(metaty);
return (ty);
}
PyTypeObject *inittype(PyTypeObject *tyskel)
{
- PyTypeObject *ty = newtype(&PyType_Type, tyskel);
+ PyTypeObject *ty = newtype(&PyType_Type, tyskel, 0);
ty->tp_flags |= Py_TPFLAGS_HEAPTYPE;
PyType_Ready(ty);
return (ty);