diff options
author | R. Tyler Ballance <tyler@monkeypox.org> | 2009-12-26 23:26:40 -0800 |
---|---|---|
committer | R. Tyler Ballance <tyler@monkeypox.org> | 2009-12-27 15:55:13 -0800 |
commit | 571608122feda45e00937484322cfaec82e5cd65 (patch) | |
tree | dfe8f0973d6ba1bfc9bfe10629cddc635ebabdc1 /cheetah | |
parent | 61c539dec01fb3e85ee37afbec28650f3204ea45 (diff) | |
download | python-cheetah-571608122feda45e00937484322cfaec82e5cd65.tar.gz |
Move macros into header file
Diffstat (limited to 'cheetah')
-rw-r--r-- | cheetah/c/_namemapper.c | 44 | ||||
-rw-r--r-- | cheetah/c/cheetah.h | 32 |
2 files changed, 35 insertions, 41 deletions
diff --git a/cheetah/c/_namemapper.c b/cheetah/c/_namemapper.c index c5549c7..9c54f4d 100644 --- a/cheetah/c/_namemapper.c +++ b/cheetah/c/_namemapper.c @@ -26,46 +26,7 @@ extern "C" { static PyObject *NotFound; /* locally-raised exception */ static PyObject *TooManyPeriods; /* locally-raised exception */ static PyObject* pprintMod_pformat; /* used for exception formatting */ -#define MAXCHUNKS 15 /* max num of nameChunks for the arrays */ - -#define ALLOW_WRAPPING_OF_NOTFOUND_EXCEPTIONS 1 -#define INCLUDE_NAMESPACE_REPR_IN_NOTFOUND_EXCEPTIONS 0 - -# define createNameCopyAndChunks() {\ - nameCopy = malloc(strlen(name) + 1);\ - tmpPntr1 = name; \ - tmpPntr2 = nameCopy;\ - while ((*tmpPntr2++ = *tmpPntr1++)); \ - numChunks = getNameChunks(nameChunks, name, nameCopy); \ - if (PyErr_Occurred()) { /* there might have been TooManyPeriods */\ - free(nameCopy);\ - return NULL;\ - }\ -} -#define OLD_checkForNameInNameSpaceAndReturnIfFound() { \ - if ( PyNamemapper_hasKey(nameSpace, nameChunks[0]) ) {\ - theValue = PyNamemapper_valueForName(nameSpace, nameChunks, numChunks, executeCallables);\ - free(nameCopy);\ - if (wrapInternalNotFoundException(name, nameSpace)) {\ - theValue = NULL;\ - }\ - return theValue;\ - }\ -} - -#define checkForNameInNameSpaceAndReturnIfFound(namespace_decref) { \ - if ( PyNamemapper_hasKey(nameSpace, nameChunks[0]) ) {\ - theValue = PyNamemapper_valueForName(nameSpace, nameChunks, numChunks, executeCallables);\ - if (namespace_decref) {\ - Py_DECREF(nameSpace);\ - }\ - if (wrapInternalNotFoundException(name, nameSpace)) {\ - theValue = NULL;\ - }\ - goto done;\ - }\ -} /* *************************************************************************** */ /* First the c versions of the functions */ @@ -107,7 +68,8 @@ static int wrapInternalNotFoundException(char *fullName, PyObject *namespace) isAlreadyWrapped = PyObject_CallMethod(excValue, "find", "s", "while searching"); if (isAlreadyWrapped != NULL) { - if (PyInt_AsLong(isAlreadyWrapped)==-1) { /* only wrap once */ + if (PyLong_AsLong(isAlreadyWrapped) == -1) { + /* only wrap once */ PyString_ConcatAndDel(&excValue, Py_BuildValue("s", " while searching for '")); PyString_ConcatAndDel(&excValue, Py_BuildValue("s", fullName)); PyString_ConcatAndDel(&excValue, Py_BuildValue("s", "'")); @@ -344,7 +306,7 @@ static PyObject *namemapper_valueFromSearchList(PYARGS) goto done; } - while ( (nameSpace = PyIter_Next(iterator)) ) { + while ((nameSpace = PyIter_Next(iterator))) { checkForNameInNameSpaceAndReturnIfFound(TRUE); Py_DECREF(nameSpace); if(PyErr_CheckSignals()) { diff --git a/cheetah/c/cheetah.h b/cheetah/c/cheetah.h index 0168fec..c02781c 100644 --- a/cheetah/c/cheetah.h +++ b/cheetah/c/cheetah.h @@ -44,4 +44,36 @@ #define PYARGS PyObject *self, PyObject *args, PyObject *kwargs + +/* + * _namemapper.c specific definitions + */ +#define MAXCHUNKS 15 /* max num of nameChunks for the arrays */ +#define ALLOW_WRAPPING_OF_NOTFOUND_EXCEPTIONS 1 +#define INCLUDE_NAMESPACE_REPR_IN_NOTFOUND_EXCEPTIONS 0 +#define createNameCopyAndChunks() {\ + nameCopy = malloc(strlen(name) + 1);\ + tmpPntr1 = name; \ + tmpPntr2 = nameCopy;\ + while ((*tmpPntr2++ = *tmpPntr1++)); \ + numChunks = getNameChunks(nameChunks, name, nameCopy); \ + if (PyErr_Occurred()) { /* there might have been TooManyPeriods */\ + free(nameCopy);\ + return NULL;\ + }\ +} + +#define checkForNameInNameSpaceAndReturnIfFound(namespace_decref) { \ + if ( PyNamemapper_hasKey(nameSpace, nameChunks[0]) ) {\ + theValue = PyNamemapper_valueForName(nameSpace, nameChunks, numChunks, executeCallables);\ + if (namespace_decref) {\ + Py_DECREF(nameSpace);\ + }\ + if (wrapInternalNotFoundException(name, nameSpace)) {\ + theValue = NULL;\ + }\ + goto done;\ + }\ +} + #endif |