remove nasty hack which made StructRNA class instaces have no __dict__,

use __slots__, it seems all the parent classes need to have slots as well for this to work.
all python defined srna classes are checked for this too
This commit is contained in:
2009-12-05 23:41:45 +00:00
parent 5ebe54f470
commit 062cf438ce
3 changed files with 22 additions and 15 deletions

View File

@@ -757,6 +757,7 @@ class PovrayRender(bpy.types.RenderEngine):
pov_binary = winreg.QueryValueEx(regKey, 'Home')[0] + '\\bin\\pvengine'
if 1:
# TODO, when povray isnt found this gives a cryptic error, would be nice to be able to detect if it exists
self._process = subprocess.Popen([pov_binary, self._temp_file_ini]) # stdout=subprocess.PIPE, stderr=subprocess.PIPE
else:
# This works too but means we have to wait until its done

View File

@@ -25,6 +25,7 @@ StructRNA = bpy_types.Struct.__bases__[0]
class Context(StructRNA):
__slots__ = ()
def copy(self):
new_context = {}
@@ -37,6 +38,7 @@ class Context(StructRNA):
class Object(bpy_types.ID):
__slots__ = ()
@property
def children(self):
@@ -49,6 +51,7 @@ class _GenericBone:
functions for bones, common between Armature/Pose/Edit bones.
internal subclassing use only.
'''
__slots__ = ()
def translate(self, vec):
self.head += vec
@@ -158,15 +161,15 @@ class _GenericBone:
class PoseBone(StructRNA, _GenericBone):
pass
__slots__ = ()
class Bone(StructRNA, _GenericBone):
pass
__slots__ = ()
class EditBone(StructRNA, _GenericBone):
pass
__slots__ = ()
def ord_ind(i1, i2):
@@ -176,6 +179,7 @@ def ord_ind(i1, i2):
class Mesh(bpy_types.ID):
__slots__ = ()
def from_pydata(self, verts, edges, faces):
'''
@@ -227,6 +231,7 @@ class Mesh(bpy_types.ID):
class MeshEdge(StructRNA):
__slots__ = ()
@property
def key(self):
@@ -234,6 +239,7 @@ class MeshEdge(StructRNA):
class MeshFace(StructRNA):
__slots__ = ()
@property
def edge_keys(self):
@@ -259,12 +265,13 @@ class OrderedMeta(type):
# Only defined so operators members can be used by accessing self.order
class Operator(StructRNA, metaclass=OrderedMeta):
pass
__slots__ = ()
class Macro(StructRNA, metaclass=OrderedMeta):
# bpy_types is imported before ops is defined
# so we have to do a local import on each run
__slots__ = ()
@classmethod
def define(self, opname):
@@ -273,6 +280,7 @@ class Macro(StructRNA, metaclass=OrderedMeta):
class Menu(StructRNA):
__slots__ = ()
def path_menu(self, searchpaths, operator):
layout = self.layout

View File

@@ -2986,16 +2986,18 @@ static PyObject* pyrna_srna_ExternalType(StructRNA *srna)
if(newclass) {
PyObject *base_compare= pyrna_srna_PyBase(srna);
PyObject *bases= PyObject_GetAttrString(newclass, "__bases__");
//PyObject *slots= PyObject_GetAttrString(newclass, "__slots__"); // cant do this because it gets superclasses values!
PyObject *slots = PyDict_GetItemString(((PyTypeObject *)newclass)->tp_dict, "__slots__");
// XXX - highly dodgy!, this stops blender from creating __dict__ in instances
((PyTypeObject *)newclass)->tp_dictoffset = 0;
if(PyTuple_GET_SIZE(bases)) {
if(slots==NULL) {
fprintf(stderr, "pyrna_srna_ExternalType: expected class '%s' to have __slots__ defined\n\nSee bpy_types.py\n", idname);
newclass= NULL;
}
else if(PyTuple_GET_SIZE(bases)) {
PyObject *base= PyTuple_GET_ITEM(bases, 0);
if(base_compare != base) {
PyLineSpit();
fprintf(stderr, "pyrna_srna_ExternalType: incorrect subclassing of SRNA '%s'\n", idname);
fprintf(stderr, "pyrna_srna_ExternalType: incorrect subclassing of SRNA '%s'\nSee bpy_types.py\n", idname);
PyObSpit("Expected! ", base_compare);
newclass= NULL;
}
@@ -3038,16 +3040,12 @@ static PyObject* pyrna_srna_Subtype(StructRNA *srna)
if(!descr) descr= "(no docs)";
/* always use O not N when calling, N causes refcount errors */
newclass = PyObject_CallFunction( (PyObject*)&PyType_Type, "s(O){ssss}", idname, py_base, "__module__","bpy.types", "__doc__",descr);
newclass = PyObject_CallFunction( (PyObject*)&PyType_Type, "s(O){sssss()}", idname, py_base, "__module__","bpy.types", "__doc__",descr, "__slots__");
/* newclass will now have 2 ref's, ???, probably 1 is internal since decrefing here segfaults */
/* PyObSpit("new class ref", newclass); */
if (newclass) {
// XXX - highly dodgy!, this stops blender from creating __dict__ in instances
((PyTypeObject *)newclass)->tp_dictoffset = 0;
/* srna owns one, and the other is owned by the caller */
pyrna_subtype_set_rna(newclass, srna);