diff options
author | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-07-14 11:34:50 -0700 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-07-14 18:34:45 -0700 |
commit | 406158b882c5233575ae860aea662de148d2a8cc (patch) | |
tree | 4bde64da4d8412d6136bb4f2d9d59940436ade4d /src/_counter.c | |
parent | b6ad2b47d9b7f3799c29097b4324dff2540fe77d (diff) | |
download | pycrypto-406158b882c5233575ae860aea662de148d2a8cc.tar.gz |
Add ABI check when importing _counter from block_template
Diffstat (limited to 'src/_counter.c')
-rw-r--r-- | src/_counter.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/_counter.c b/src/_counter.c index 729fc9e..f82c378 100644 --- a/src/_counter.c +++ b/src/_counter.c @@ -32,6 +32,13 @@ #define PyLong_FromLong PyInt_FromLong #endif +/* Deal with old API in Python 2.1 */ +#if PYTHON_API_VERSION < 1011 +#define PyModule_AddIntConstant(m,n,v) {PyObject *o=PyInt_FromLong(v); \ + if (o!=NULL) \ + {PyDict_SetItemString(PyModule_GetDict(m),n,o); Py_DECREF(o);}} +#endif + /* NB: This can be called multiple times for a given object, via the __init__ method. Be careful. */ static int CounterObject_init(PCT_CounterObject *self, PyObject *args, PyObject *kwargs) @@ -566,6 +573,9 @@ init_counter(void) PyObject_SetAttrString(m, "CounterBE", (PyObject *)&PCT_CounterBEType); PyObject_SetAttrString(m, "CounterLE", (PyObject *)&PCT_CounterLEType); + /* Allow block_template.c to do an ABI check */ + PyModule_AddIntConstant(m, "_PCT_CTR_ABI_VERSION", PCT_CTR_ABI_VERSION); + #ifdef IS_PY3K return m; #endif |