| 1 | /* |
| 2 | * Copyright 2009, R. Tyler Ballance <[email protected]> |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in |
| 13 | * the documentation and/or other materials provided with the |
| 14 | * distribution. |
| 15 | * |
| 16 | * 3. Neither the name of R. Tyler Ballance nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived |
| 18 | * from this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 23 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | * POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
| 32 | |
| 33 | #ifndef _CHEETAH_H_ |
| 34 | #define _CHEETAH_H_ |
| 35 | |
| 36 | #include <Python.h> |
| 37 | |
| 38 | #if PY_MAJOR_VERSION >= 3 |
| 39 | #define IS_PYTHON3 |
| 40 | #endif |
| 41 | |
| 42 | #define TRUE 1 |
| 43 | #define FALSE 0 |
| 44 | |
| 45 | #define PYARGS PyObject *self, PyObject *args, PyObject *kwargs |
| 46 | |
| 47 | |
| 48 | /* |
| 49 | * _namemapper.c specific definitions |
| 50 | */ |
| 51 | #define MAXCHUNKS 15 /* max num of nameChunks for the arrays */ |
| 52 | #define ALLOW_WRAPPING_OF_NOTFOUND_EXCEPTIONS 1 |
| 53 | #define createNameCopyAndChunks() {\ |
| 54 | nameCopy = malloc(strlen(name) + 1);\ |
| 55 | tmpPntr1 = name; \ |
| 56 | tmpPntr2 = nameCopy;\ |
| 57 | while ((*tmpPntr2++ = *tmpPntr1++)); \ |
| 58 | numChunks = getNameChunks(nameChunks, name, nameCopy); \ |
| 59 | if (PyErr_Occurred()) { /* there might have been TooManyPeriods */\ |
| 60 | free(nameCopy);\ |
| 61 | return NULL;\ |
| 62 | }\ |
| 63 | } |
| 64 | |
| 65 | #define checkForNameInNameSpaceAndReturnIfFound(namespace_decref) { \ |
| 66 | if ( PyNamemapper_hasKey(nameSpace, nameChunks[0]) ) {\ |
| 67 | theValue = PyNamemapper_valueForName(nameSpace, nameChunks, numChunks, executeCallables);\ |
| 68 | if (namespace_decref) {\ |
| 69 | Py_DECREF(nameSpace);\ |
| 70 | }\ |
| 71 | if (wrapInternalNotFoundException(name, nameSpace)) {\ |
| 72 | theValue = NULL;\ |
| 73 | }\ |
| 74 | goto done;\ |
| 75 | }\ |
| 76 | } |
| 77 | |
| 78 | #endif |