From 6ab2d7ad659606cbf2a315ef9a576c364e6ec9bb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 21 Mar 2009 06:55:30 +0000 Subject: - lazy subtype initialization rna, was initializing every type in bpy.types at startup, which is slow and doesn't allow access to dynamically added types. - bpy.types isnt a module anymore, defined as its own PyType, getattr looks up the rna collection each time. - refcounting fixes - fixe epydoc generation with undefined values --- source/blender/python/intern/bpy_operator.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'source/blender/python/intern/bpy_operator.c') diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index a35c5ed2cb4..b40d4640bcb 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -108,8 +108,10 @@ int PYOP_props_from_dict(PointerRNA *ptr, PyObject *kw) } static PyObject *pyop_base_dir(PyObject *self); +static PyObject *pyop_base_rna(PyObject *self, PyObject *pyname); static struct PyMethodDef pyop_base_methods[] = { {"__dir__", (PyCFunction)pyop_base_dir, METH_NOARGS, ""}, + {"__rna__", (PyCFunction)pyop_base_rna, METH_O, ""}, {"add", (PyCFunction)PYOP_wrap_add, METH_O, ""}, {"remove", (PyCFunction)PYOP_wrap_remove, METH_O, ""}, {NULL, NULL, 0, NULL} @@ -199,8 +201,9 @@ static PyObject *pyop_base_getattro( BPy_OperatorBase * self, PyObject *pyname ) { char *name = _PyUnicode_AsString(pyname); PyObject *ret; + wmOperatorType *ot; - if ((WM_operatortype_find(name))) { + if ((ot= WM_operatortype_find(name))) { ret = PyCFunction_New( pyop_base_call_meth, pyname); /* set the name string as self, PyCFunction_New incref's self */ } else if ((ret = PyObject_GenericGetAttr((PyObject *)self, pyname))) { @@ -235,6 +238,28 @@ static PyObject *pyop_base_dir(PyObject *self) return list; } +static PyObject *pyop_base_rna(PyObject *self, PyObject *pyname) +{ + char *name = _PyUnicode_AsString(pyname); + wmOperatorType *ot; + + if ((ot= WM_operatortype_find(name))) { + BPy_StructRNA *pyrna; + PointerRNA ptr; + + /* XXX POINTER - if this 'ot' is python generated, it could be free'd */ + RNA_pointer_create(NULL, ot->srna, NULL, &ptr); + + pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); /* were not really using &ptr, overwite next */ + //pyrna->freeptr= 1; + return pyrna; + } + else { + PyErr_SetString(PyExc_AttributeError, "Operator not found"); + return NULL; + } +} + PyTypeObject pyop_base_Type = {NULL}; PyObject *BPY_operator_module( bContext *C ) -- cgit v1.2.3