field.c: Delete the completely unused `getfe' function.
[pyke] / catacomb-python.h
index 2890289..c272b53 100644 (file)
 
 /*----- Header files ------------------------------------------------------*/
 
+#define PY_SSIZE_T_CLEAN
+
 #include <Python.h>
 #include <longintrepr.h>
 #include <structmember.h>
 
-#undef ULLONG_MAX
-#undef ULONG_LONG_MAX
-
 #include <mLib/darray.h>
 #include <mLib/dstr.h>
 #include <mLib/macros.h>
 #include <mLib/quis.h>
+#include <mLib/unihash.h>
 
 #include <catacomb/buf.h>
+#include <catacomb/ct.h>
 
 #include <catacomb/grand.h>
 #include <catacomb/rand.h>
 #include <catacomb/gmac.h>
 #include <catacomb/md5.h>
 #include <catacomb/md5-hmac.h>
+#include <catacomb/poly1305.h>
 #include <catacomb/sha.h>
 #include <catacomb/sha-mgf.h>
 #include <catacomb/sha-hmac.h>
+#include <catacomb/keccak1600.h>
+#include <catacomb/sha3.h>
 
 #include <catacomb/mp.h>
 #include <catacomb/mpint.h>
 #include <catacomb/ptab.h>
 #include <catacomb/bintab.h>
 #include <catacomb/dsa.h>
+#include <catacomb/x25519.h>
+#include <catacomb/x448.h>
+#include <catacomb/ed25519.h>
+#include <catacomb/ed448.h>
 
 #include <catacomb/gf.h>
 #include <catacomb/gfreduce.h>
 #define VALERR(str) EXCERR(PyExc_ValueError, str)
 #define TYERR(str) EXCERR(PyExc_TypeError, str)
 #define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str)
-#define SYNERR(str) EXCERR(PyExc_SyntaxError, str)
 #define SYSERR(str) EXCERR(PyExc_SystemError, str)
 #define NIERR(str) EXCERR(PyExc_NotImplementedError, str)
 #define INDEXERR(idx) do {                                             \
   PyErr_SetFromErrnoWithFilename(PyExc_OSError, name);                 \
   goto end;                                                            \
 } while (0)
-#define PGENERR do { pgenerr(); goto end; } while (0)
+#define PGENERR(exc) do { pgenerr(exc); goto end; } while (0)
 
 #define CONVFUNC(ty, cty, ext)                                         \
   int conv##ty(PyObject *o, void *p)                                   \
 
 #define root_pytype 0
 #define type_pytype &PyType_Type
-#define INITTYPE(ty, base) do {                                                \
+#define INITTYPE_META(ty, base, meta) do {                             \
   ty##_pytype_skel.tp_base = base##_pytype;                            \
-  ty##_pytype = inittype(&ty##_pytype_skel);                           \
+  ty##_pytype = inittype(&ty##_pytype_skel, meta##_pytype);            \
 } while (0)
+#define INITTYPE(ty, base) INITTYPE_META(ty, base, type)
+
+extern PyObject *home_module;
 
-#define INSERT(name, ob) do {                                          \
+#define INSERT(name, ob) do {  \
   PyObject *_o = (PyObject *)(ob);                                     \
   Py_INCREF(_o);                                                       \
   PyModule_AddObject(mod, name, _o);                                   \
   { #name, ty, offsetof(MEMBERSTRUCT, name), f, doc },
 
 #define MODULES(_)                                                     \
+  _(util)                                                              \
   _(bytestring) _(buffer)                                              \
   _(rand) _(algorithms) _(pubkey) _(pgen)                              \
   _(mp) _(field) _(ec) _(group)                                                \
-  _(passphrase) _(share) _(key)                                                \
-  _(util)
+  _(passphrase) _(share) _(key)
 #define DOMODINIT(m) m##_pyinit();
 #define DOMODINSERT(m) m##_pyinsert(mod);
 #define INIT_MODULES do { MODULES(DOMODINIT) } while (0)
@@ -238,15 +248,45 @@ extern int convulong(PyObject *, void *);
 DOUINTSZ(DECL_CONVU_)
 extern int convmpw(PyObject *, void *);
 extern int convuint(PyObject *, void *);
+extern int convk64(PyObject *, void *);
 extern int convszt(PyObject *, void *);
 extern int convbool(PyObject *, void *);
 extern PyObject *abstract_pynew(PyTypeObject *, PyObject *, PyObject *);
 extern PyObject *getbool(int);
 extern PyObject *getulong(unsigned long);
+extern PyObject *getk64(kludge64);
 extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *);
 
-extern PyObject * mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
-extern PyTypeObject *inittype(PyTypeObject *);
+struct excinfo { PyObject *ty, *val, *tb; };
+#define EXCINFO_INIT { 0, 0, 0 }
+
+extern PyObject *mkexc(PyObject *, PyObject *, const char *, PyMethodDef *);
+#define INIT_EXCINFO(exc) do {                                         \
+  struct excinfo *_exc = (exc); _exc->ty = _exc->val = _exc->tb = 0;   \
+} while (0)
+#define RELEASE_EXCINFO(exc) do {                                      \
+  struct excinfo *_exc = (exc);                                                \
+  Py_XDECREF(_exc->ty);         _exc->ty  = 0;                                 \
+  Py_XDECREF(_exc->val); _exc->val = 0;                                        \
+  Py_XDECREF(_exc->tb);         _exc->tb  = 0;                                 \
+} while (0)
+#define STASH_EXCINFO(exc) do {                                                \
+  struct excinfo *_exc = (exc);                                                \
+  PyErr_Fetch(&_exc->ty, &_exc->val, &_exc->tb);                       \
+  PyErr_NormalizeException(&_exc->ty, &_exc->val, &_exc->tb);          \
+} while (0)
+#define RESTORE_EXCINFO(exc) do {                                      \
+  struct excinfo *_exc = (exc);                                                \
+  PyErr_Restore(_exc->ty, _exc->val, _exc->tb);                                \
+  _exc->ty = _exc->val = _exc->tb = 0;                                 \
+} while (0)
+extern void report_lost_exception(struct excinfo *, const char *, ...);
+extern void report_lost_exception_v(struct excinfo *, const char *, va_list);
+extern void stash_exception(struct excinfo *, const char *, ...);
+extern void restore_exception(struct excinfo *, const char *, ...);
+
+extern void typeready(PyTypeObject *);
+extern PyTypeObject *inittype(PyTypeObject *, PyTypeObject *);
 extern void addmethods(const PyMethodDef *);
 extern PyMethodDef *donemethods(void);
 
@@ -281,7 +321,7 @@ extern PyMethodDef *donemethods(void);
 GMAP_DOMETHODS(GMAP_METHDECL, GMAP_KWMETHDECL)
 #define GMAP_ROMETHODS GMAP_DOROMETHODS(GMAP_METH, GMAP_KWMETH)
 #define GMAP_METHODS GMAP_DOMETHODS(GMAP_METH, GMAP_KWMETH)
-extern int gmap_pysize(PyObject *);
+extern Py_ssize_t gmap_pysize(PyObject *);
 extern PySequenceMethods gmap_pysequence;
 extern PyMethodDef gmap_pymethods[];
 
@@ -313,10 +353,11 @@ extern mp *getgf(PyObject *);
 extern int convgf(PyObject *, void *);
 extern PyObject *mp_pywrap(mp *);
 extern PyObject *gf_pywrap(mp *);
+extern long mphash(mp *);
 extern mp *mp_frompyobject(PyObject *, int);
 extern PyObject *mp_topystring(mp *, int,
                               const char *, const char *, const char *);
-extern int mp_tolong_checked(mp *, long *);
+extern int mp_tolong_checked(mp *, long *, int);
 
 /*----- Abstract fields ---------------------------------------------------*/
 
@@ -331,7 +372,6 @@ extern PyTypeObject *fe_pytype;
 #define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
 #define FE_X(o) (((fe_pyobj *)(o))->x)
 extern PyObject *fe_pywrap(PyObject *, mp *);
-extern mp *getfe(field *, PyObject *);
 
 typedef struct fe_pyobj {
   PyObject_HEAD
@@ -583,9 +623,15 @@ extern PyTypeObject *pgev_pytype;
 #define PGEV_PYCHECK(o) PyObject_TypeCheck(o, pgev_pytype)
 #define PGEV_PG(o) (&((pgev_pyobj *)(o))->pg)
 
+typedef struct pypgev {
+  pgev ev;
+  PyObject *obj;
+  struct excinfo *exc;
+} pypgev;
+
 extern int convpgev(PyObject *, void *);
-extern void droppgev(pgev *);
-extern void pgenerr(void);
+extern void droppgev(pypgev *);
+extern void pgenerr(struct excinfo *exc);
 
 /*----- That's all, folks -------------------------------------------------*/