X-Git-Url: https://git.distorted.org.uk/~mdw/pyke/blobdiff_plain/54ae5879b39214704112ecfebd410a9ea57b6e6c..8963e6870299fa42fe81f2b6acc3fcddf2058a9b:/catacomb-python.h diff --git a/catacomb-python.h b/catacomb-python.h index df29099..6c1ae21 100644 --- a/catacomb-python.h +++ b/catacomb-python.h @@ -134,6 +134,7 @@ goto end; \ } while (0) #define VALERR(str) EXCERR(PyExc_ValueError, str) +#define OVFERR(str) EXCERR(PyExc_OverflowError, str) #define TYERR(str) EXCERR(PyExc_TypeError, str) #define IXERR(str) EXCERR(PyExc_IndexError, str) #define ZDIVERR(str) EXCERR(PyExc_ZeroDivisionError, str) @@ -147,7 +148,7 @@ 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) \ @@ -173,7 +174,9 @@ } while (0) #define INITTYPE(ty, base) INITTYPE_META(ty, base, type) -#define INSERT(name, ob) do { \ +extern PyObject *home_module; + +#define INSERT(name, ob) do { \ PyObject *_o = (PyObject *)(ob); \ Py_INCREF(_o); \ PyModule_AddObject(mod, name, _o); \ @@ -235,7 +238,8 @@ MODULES(DO) #define KWLIST (/*unconst*/ char **)kwlist -struct nameval { const char *name; unsigned long value; }; +struct nameval { const char *name; unsigned f; unsigned long value; }; +#define CF_SIGNED 1u extern void setconstants(PyObject *, const struct nameval *); extern PyObject *mexp_common(PyObject *, PyObject *, size_t, @@ -259,7 +263,34 @@ extern PyObject *getulong(unsigned long); extern PyObject *getk64(kludge64); extern void *newtype(PyTypeObject *, const PyTypeObject *, const char *); +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 *); @@ -328,6 +359,7 @@ 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 *); @@ -346,7 +378,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 @@ -700,9 +731,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 -------------------------------------------------*/