Use members rather than code in tp_getattro to fetch the members for the

external object variable which enables better code going forward into Python
3.0. Thanks to Amaury Forgeot d'Arc once again.
This commit is contained in:
Anthony Tuininga 2008-10-03 04:13:51 +00:00
parent 8e506ceeea
commit 83371127bc

View File

@ -25,6 +25,14 @@ static PyObject *ExternalObjectVar_GetAttr(udt_ExternalObjectVar*, PyObject*);
static PyObject *ExternalObjectVar_ConvertToPython(udt_Environment*, static PyObject *ExternalObjectVar_ConvertToPython(udt_Environment*,
OCITypeCode, dvoid*, dvoid*, PyObject*, udt_ObjectType*); OCITypeCode, dvoid*, dvoid*, PyObject*, udt_ObjectType*);
//-----------------------------------------------------------------------------
// Declaration of external object variable members.
//-----------------------------------------------------------------------------
static PyMemberDef g_ExternalObjectVarMembers[] = {
{ "type", T_OBJECT, offsetof(udt_ExternalObjectVar, objectType),
READONLY },
{ NULL }
};
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Python type declaration // Python type declaration
@ -52,7 +60,15 @@ static PyTypeObject g_ExternalObjectVarType = {
0, // tp_setattro 0, // tp_setattro
0, // tp_as_buffer 0, // tp_as_buffer
Py_TPFLAGS_DEFAULT, // tp_flags Py_TPFLAGS_DEFAULT, // tp_flags
0 // tp_doc 0, // tp_doc
0, // tp_traverse
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
0, // tp_methods
g_ExternalObjectVarMembers // tp_members
}; };
@ -272,19 +288,12 @@ static PyObject *ExternalObjectVar_GetAttr(
PyObject *nameObject) // name of attribute PyObject *nameObject) // name of attribute
{ {
udt_ObjectAttribute *attribute; udt_ObjectAttribute *attribute;
char *name;
attribute = (udt_ObjectAttribute*) attribute = (udt_ObjectAttribute*)
PyDict_GetItem(self->objectType->attributesByName, nameObject); PyDict_GetItem(self->objectType->attributesByName, nameObject);
if (attribute) if (attribute)
return ExternalObjectVar_GetAttributeValue(self, attribute); return ExternalObjectVar_GetAttributeValue(self, attribute);
name = PyString_AS_STRING(nameObject);
if (name[0] == 't' && strcmp(name, "type") == 0) {
Py_INCREF(self->objectType);
return (PyObject*) self->objectType;
}
PyErr_SetString(PyExc_AttributeError, name); return PyObject_GenericGetAttr( (PyObject*) self, nameObject);
return NULL;
} }