@@@ py_buffer/freebin wip
[catacomb-python] / catacomb-python.h
index da6a8fe..e74e048 100644 (file)
@@ -70,6 +70,7 @@ PUBLIC_SYMBOLS;
 #include <catacomb/sha-hmac.h>
 #include <catacomb/keccak1600.h>
 #include <catacomb/sha3.h>
+#include <catacomb/strobe.h>
 
 #include <catacomb/mp.h>
 #include <catacomb/mpint.h>
@@ -81,6 +82,7 @@ PUBLIC_SYMBOLS;
 #include <catacomb/mp-fibonacci.h>
 
 #include <catacomb/pgen.h>
+#include <catacomb/primeiter.h>
 #include <catacomb/pfilt.h>
 #include <catacomb/strongprime.h>
 #include <catacomb/limlee.h>
@@ -150,7 +152,7 @@ extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
                             PyObject *(*id)(PyObject *),
                             int (*fill)(void *, PyObject *,
                                         PyObject *, PyObject *),
-                            PyObject *(*exp)(PyObject *, void *, int),
+                            PyObject *(*exp)(PyObject *, void *, size_t),
                             void (*drop)(void *));
 
 /*----- Bytestrings -------------------------------------------------------*/
@@ -158,6 +160,27 @@ extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
 PyObject *bytestring_pywrap(const void *, size_t);
 PyObject *bytestring_pywrapbuf(buf *);
 
+/*----- Buffers -----------------------------------------------------------*/
+
+typedef struct buf_pyobj {
+  PyObject_HEAD
+  buf b;
+  PyObject *sub;
+  unsigned lk;
+} buf_pyobj;
+
+extern PyTypeObject *rbuf_pytype, *wbuf_pytype;
+#define RBUF_PYCHECK(o) PyObject_TypeCheck((o), rbuf_pytype)
+#define WBUF_PYCHECK(o) PyObject_TypeCheck((o), wbuf_pytype)
+#define BUF_B(o) (&((buf_pyobj *)(o))->b)
+#define BUF_SUB(o) (((buf_pyobj *)(o))->sub)
+#define BUF_LK(o) (((buf_pyobj *)(o))->lk)
+
+extern PyObject *buferr;
+#define BUFERR(str) do { PyErr_SetString(buferr, str); goto end; } while (0)
+
+extern int ensurebuf(PyObject *, size_t);
+
 /*----- Multiprecision arithmetic -----------------------------------------*/
 
 typedef struct mp_pyobj {
@@ -174,13 +197,15 @@ extern PyTypeObject *gf_pytype;
 extern mp *mp_frompylong(PyObject *);
 extern PyObject *mp_topylong(mp *);
 extern mp *tomp(PyObject *);
+extern mp *implicitmp(PyObject *);
 extern mp *getmp(PyObject *);
 extern int convmp(PyObject *, void *);
+extern mp *implicitgf(PyObject *);
 extern mp *getgf(PyObject *);
 extern int convgf(PyObject *, void *);
 extern PyObject *mp_pywrap(mp *);
 extern PyObject *gf_pywrap(mp *);
-extern long mphash(mp *);
+extern Py_hash_t mphash(mp *);
 extern mp *mp_frompyobject(PyObject *, int);
 extern PyObject *mp_topystring(mp *, int,
                               const char *, const char *, const char *);
@@ -213,7 +238,7 @@ typedef struct fe_pyobj {
 extern PyTypeObject *fe_pytype;
 #define FE_PYCHECK(o) PyObject_TypeCheck((o), fe_pytype)
 #define FE_F(o) (((fe_pyobj *)(o))->f)
-#define FE_FOBJ(o) ((PyObject *)(o)->ob_type)
+#define FE_FOBJ(o) ((PyObject *)Py_TYPE(o))
 #define FE_X(o) (((fe_pyobj *)(o))->x)
 extern PyObject *fe_pywrap(PyObject *, mp *);
 
@@ -246,7 +271,7 @@ extern PyTypeObject *ecpt_pytype, *ecptcurve_pytype;
 #define ECPT_PYCHECK(o) PyObject_TypeCheck((o), ecpt_pytype)
 #define ECPTCURVE_PYCHECK(o) PyObject_TypeCheck((o), ecptcurve_pytype)
 #define ECPT_C(o) (((ecpt_pyobj *)(o))->c)
-#define ECPT_COBJ(o) ((PyObject *)(o)->ob_type)
+#define ECPT_COBJ(o) ((PyObject *)Py_TYPE(o))
 #define ECPT_FOBJ(o) ECCURVE_FOBJ(ECPT_COBJ((o)))
 #define ECPT_P(o) (&((ecpt_pyobj *)(o))->p)
 extern PyObject *ecpt_pywrap(PyObject *, ec *);
@@ -281,7 +306,7 @@ extern PyTypeObject *ge_pytype;
 #define GE_PYCHECK(o) PyObject_TypeCheck((o), ge_pytype)
 #define GE_X(o) (((ge_pyobj *)(o))->x)
 #define GE_G(o) (((ge_pyobj *)(o))->g)
-#define GE_GOBJ(o) ((PyObject *)(group_pyobj *)(o)->ob_type)
+#define GE_GOBJ(o) (PyObject *)(Py_TYPE(o))
 extern PyObject *ge_pywrap(PyObject *, ge *);
 
 typedef struct group_pyobj {