Skip to content
This repository has been archived by the owner on Mar 8, 2018. It is now read-only.

Commit

Permalink
Since functions are properly objects in Python 3, need to start detec…
Browse files Browse the repository at this point in the history
…ting them differently for auto-calling
  • Loading branch information
R. Tyler Ballance committed Dec 27, 2009
1 parent 0c35ef9 commit 142b834
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions cheetah/c/_namemapper.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,22 +81,31 @@ static int isInstanceOrClass(PyObject *nextVal) {
} }
#endif #endif


if(PyObject_HasAttrString(nextVal, "__class__")) { if (!PyObject_HasAttrString(nextVal, "__class__")) {
/* new style classes or instances */ return 0;
if(PyType_Check(nextVal) || PyObject_HasAttrString(nextVal, "mro")) {
return 1;
}
if(PyObject_HasAttrString(nextVal, "im_func")
|| PyObject_HasAttrString(nextVal, "func_code")
|| PyObject_HasAttrString(nextVal, "__self__")) {
/* method, func, or builtin func */
return 0;
}
if ((!PyObject_HasAttrString(nextVal, "mro")) && PyObject_HasAttrString(nextVal, "__init__")) {
/* instance */
return 1;
}
} }

/* new style classes or instances */
if (PyType_Check(nextVal) || PyObject_HasAttrString(nextVal, "mro")) {
return 1;
}

if (strncmp(nextVal->ob_type->tp_name, "function", 9) == 0)
return 0;

/* method, func, or builtin func */
if (PyObject_HasAttrString(nextVal, "im_func")
|| PyObject_HasAttrString(nextVal, "func_code")
|| PyObject_HasAttrString(nextVal, "__self__")) {
return 0;
}

/* instance */
if ((!PyObject_HasAttrString(nextVal, "mro")) &&
PyObject_HasAttrString(nextVal, "__init__")) {
return 1;
}

return 0; return 0;
} }


Expand Down Expand Up @@ -154,10 +163,7 @@ static PyObject *PyNamemapper_valueForKey(PyObject *obj, char *key)
return theValue; return theValue;
} }


static PyObject * static PyObject *PyNamemapper_valueForName(PyObject *obj, char *nameChunks[], int numChunks, int executeCallables)
PyNamemapper_valueForName(PyObject *obj, char *nameChunks[],
int numChunks,
int executeCallables)
{ {
int i; int i;
char *currentKey; char *currentKey;
Expand Down Expand Up @@ -196,14 +202,12 @@ PyNamemapper_valueForName(PyObject *obj, char *nameChunks[],
Py_DECREF(currentVal); Py_DECREF(currentVal);
} }


if (executeCallables && PyCallable_Check(nextVal) && (!isInstanceOrClass(nextVal)) ) { if (executeCallables && PyCallable_Check(nextVal) &&
//if (executeCallables && PyCallable_Check(nextVal) && (!PyInstance_Check(nextVal)) (isInstanceOrClass(nextVal) == 0) ) {
//&& (!PyClass_Check(nextVal)) && (!PyType_Check(nextVal)) ) {
if (!(currentVal = PyObject_CallObject(nextVal, NULL))) { if (!(currentVal = PyObject_CallObject(nextVal, NULL))) {
Py_DECREF(nextVal); Py_DECREF(nextVal);
return NULL; return NULL;
} }

Py_DECREF(nextVal); Py_DECREF(nextVal);
} else { } else {
currentVal = nextVal; currentVal = nextVal;
Expand Down

0 comments on commit 142b834

Please sign in to comment.