fd6221d6ff96f30470681e3266904baaf2e0e3f8
[blender.git] / source / blender / python / intern / bpy_rna.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * Contributor(s): Campbell Barton
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include "bpy_rna.h"
26 #include "bpy_compat.h"
27 //#include "blendef.h"
28 #include "BLI_dynstr.h"
29
30 #include "MEM_guardedalloc.h"
31 #include "BKE_global.h" /* evil G.* */
32
33 /* There are 2 ways subclassing can work, PY_CLASS_SUBTYPE - Uses pythons internal subclassing
34  * - class MyClass(SomeClass): ...
35  * When PY_CLASS_SUBTYPE is not defined use a C subclass which copies the PyTypeObject and makes some changes.
36 */
37 #define PY_CLASS_SUBTYPE
38
39 static int pyrna_struct_compare( BPy_StructRNA * a, BPy_StructRNA * b )
40 {
41         return (a->ptr.data==b->ptr.data) ? 0 : -1;
42 }
43
44 static int pyrna_prop_compare( BPy_PropertyRNA * a, BPy_PropertyRNA * b )
45 {
46         return (a->prop==b->prop && a->ptr.data==b->ptr.data ) ? 0 : -1;
47 }
48
49
50 /* For some reason python3 needs these :/ */
51 static PyObject *pyrna_struct_richcmp(BPy_StructRNA * a, BPy_StructRNA * b, int op)
52 {
53         int cmp_result= -1; /* assume false */
54         if (BPy_StructRNA_Check(a) && BPy_StructRNA_Check(b)) {
55                 cmp_result= pyrna_struct_compare(a, b);
56         }
57
58         return Py_CmpToRich(op, cmp_result);
59 }
60
61 static PyObject *pyrna_prop_richcmp(BPy_PropertyRNA * a, BPy_PropertyRNA * b, int op)
62 {
63         int cmp_result= -1; /* assume false */
64         if (BPy_PropertyRNA_Check(a) && BPy_PropertyRNA_Check(b)) {
65                 cmp_result= pyrna_prop_compare(a, b);
66         }
67
68         return Py_CmpToRich(op, cmp_result);
69 }
70
71 /*----------------------repr--------------------------------------------*/
72 static PyObject *pyrna_struct_repr( BPy_StructRNA * self )
73 {
74         return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\"]", RNA_struct_identifier(&self->ptr));
75 }
76
77 static PyObject *pyrna_prop_repr( BPy_PropertyRNA * self )
78 {
79         return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\" ]", RNA_struct_identifier(&self->ptr), RNA_property_identifier(&self->ptr, self->prop) );
80 }
81
82 static long pyrna_struct_hash( BPy_StructRNA * self )
83 {
84         return (long)self->ptr.data;
85 }
86
87 /* use our own dealloc so we can free a property if we use one */
88 static void pyrna_struct_dealloc( BPy_StructRNA * self )
89 {
90         /* Note!! for some weired reason calling PyObject_DEL() directly crashes blender! */
91         if (self->freeptr && self->ptr.data) {
92                 IDP_FreeProperty(self->ptr.data);
93                 MEM_freeN(self->ptr.data);
94                 self->ptr.data= NULL;
95         }
96
97         ((PyObject *)self)->ob_type->tp_free(self);
98         return;
99 }
100
101 static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
102 {
103         const EnumPropertyItem *item;
104         int totitem, i;
105
106         DynStr *dynstr= BLI_dynstr_new();
107         char *cstring;
108
109         RNA_property_enum_items(ptr, prop, &item, &totitem);
110
111         for (i=0; i<totitem; i++) {
112                 
113                 BLI_dynstr_appendf(dynstr, i?", '%s'":"'%s'", item[i].identifier);
114         }
115         
116         cstring = BLI_dynstr_get_cstring(dynstr);
117         BLI_dynstr_free(dynstr);
118         return cstring;
119 }
120
121 PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
122 {
123         PyObject *ret;
124         int type = RNA_property_type(ptr, prop);
125         int len = RNA_property_array_length(ptr, prop);
126
127         if (len > 0) {
128                 /* resolve the array from a new pytype */
129                 return pyrna_prop_CreatePyObject(ptr, prop);
130         }
131         
132         /* see if we can coorce into a python type - PropertyType */
133         switch (type) {
134         case PROP_BOOLEAN:
135                 ret = PyBool_FromLong( RNA_property_boolean_get(ptr, prop) );
136                 break;
137         case PROP_INT:
138                 ret = PyLong_FromSize_t( (size_t)RNA_property_int_get(ptr, prop) );
139                 break;
140         case PROP_FLOAT:
141                 ret = PyFloat_FromDouble( RNA_property_float_get(ptr, prop) );
142                 break;
143         case PROP_STRING:
144         {
145                 char *buf;
146                 buf = RNA_property_string_get_alloc(ptr, prop, NULL, -1);
147                 ret = PyUnicode_FromString( buf );
148                 MEM_freeN(buf);
149                 break;
150         }
151         case PROP_ENUM:
152         {
153                 const char *identifier;
154                 int val = RNA_property_enum_get(ptr, prop);
155                 
156                 if (RNA_property_enum_identifier(ptr, prop, val, &identifier)) {
157                         ret = PyUnicode_FromString( identifier );
158                 } else {
159                         PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val);
160                         ret = NULL;
161                 }
162
163                 break;
164         }
165         case PROP_POINTER:
166         {
167                 PointerRNA newptr;
168                 newptr= RNA_property_pointer_get(ptr, prop);
169                 if (newptr.data) {
170                         ret = pyrna_struct_CreatePyObject(&newptr);
171                 } else {
172                         ret = Py_None;
173                         Py_INCREF(ret);
174                 }
175                 break;
176         }
177         case PROP_COLLECTION:
178                 ret = pyrna_prop_CreatePyObject(ptr, prop);
179                 break;
180         default:
181                 PyErr_Format(PyExc_AttributeError, "RNA Error: unknown type \"%d\" (pyrna_prop_to_py)", type);
182                 ret = NULL;
183                 break;
184         }
185         
186         return ret;
187 }
188
189
190 int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
191 {
192         int type = RNA_property_type(ptr, prop);
193         int len = RNA_property_array_length(ptr, prop);
194         
195         if (len > 0) {
196                 PyObject *item;
197                 int i;
198                 
199                 if (!PySequence_Check(value)) {
200                         PyErr_SetString(PyExc_TypeError, "expected a python sequence type assigned to an RNA array.");
201                         return -1;
202                 }
203                 
204                 if ((int)PySequence_Length(value) != len) {
205                         PyErr_SetString(PyExc_AttributeError, "python sequence length did not match the RNA array.");
206                         return -1;
207                 }
208                 
209                 /* for arrays we have a limited number of types */
210                 switch (type) {
211                 case PROP_BOOLEAN:
212                 {
213                         int *param_arr = MEM_mallocN(sizeof(char) * len, "pyrna bool array");
214                         
215                         /* collect the variables before assigning, incase one of them is incorrect */
216                         for (i=0; i<len; i++) {
217                                 item = PySequence_GetItem(value, i);
218                                 param_arr[i] = PyObject_IsTrue( item );
219                                 Py_DECREF(item);
220                                 
221                                 if (param_arr[i] < 0) {
222                                         MEM_freeN(param_arr);
223                                         PyErr_SetString(PyExc_AttributeError, "one or more of the values in the sequence is not a boolean");
224                                         return -1;
225                                 }
226                         }
227                         
228                         RNA_property_boolean_set_array(ptr, prop, param_arr);
229                         
230                         MEM_freeN(param_arr);
231                         break;
232                 }
233                 case PROP_INT:
234                 {
235                         int *param_arr = MEM_mallocN(sizeof(int) * len, "pyrna int array");
236                         
237                         /* collect the variables before assigning, incase one of them is incorrect */
238                         for (i=0; i<len; i++) {
239                                 item = PySequence_GetItem(value, i);
240                                 param_arr[i] = (int)PyLong_AsSsize_t(item); /* deal with any errors later */
241                                 Py_DECREF(item);
242                         }
243                         
244                         if (PyErr_Occurred()) {
245                                 MEM_freeN(param_arr);
246                                 PyErr_SetString(PyExc_AttributeError, "one or more of the values in the sequence could not be used as an int");
247                                 return -1;
248                         }
249                         
250                         RNA_property_int_set_array(ptr, prop, param_arr);
251                         
252                         MEM_freeN(param_arr);
253                         break;
254                 }
255                 case PROP_FLOAT:
256                 {
257                         float *param_arr = MEM_mallocN(sizeof(float) * len, "pyrna float array");
258                         
259                         /* collect the variables before assigning, incase one of them is incorrect */
260                         for (i=0; i<len; i++) {
261                                 item = PySequence_GetItem(value, i);
262                                 param_arr[i] = (float)PyFloat_AsDouble(item); /* deal with any errors later */
263                                 Py_DECREF(item);
264                         }
265                         
266                         if (PyErr_Occurred()) {
267                                 MEM_freeN(param_arr);
268                                 PyErr_SetString(PyExc_AttributeError, "one or more of the values in the sequence could not be used as a float");
269                                 return -1;
270                         }
271                         
272                         RNA_property_float_set_array(ptr, prop, param_arr);
273                         
274                         MEM_freeN(param_arr);
275                         break;
276                 }
277                 }
278         } else {
279                 /* Normal Property (not an array) */
280                 
281                 /* see if we can coorce into a python type - PropertyType */
282                 switch (type) {
283                 case PROP_BOOLEAN:
284                 {
285                         int param = PyObject_IsTrue( value );
286                         
287                         if( param < 0 ) {
288                                 PyErr_SetString(PyExc_TypeError, "expected True/False or 0/1");
289                                 return -1;
290                         } else {
291                                 RNA_property_boolean_set(ptr, prop, param);
292                         }
293                         break;
294                 }
295                 case PROP_INT:
296                 {
297                         int param = PyLong_AsSsize_t(value);
298                         if (PyErr_Occurred()) {
299                                 PyErr_SetString(PyExc_TypeError, "expected an int type");
300                                 return -1;
301                         } else {
302                                 RNA_property_int_set(ptr, prop, param);
303                         }
304                         break;
305                 }
306                 case PROP_FLOAT:
307                 {
308                         float param = PyFloat_AsDouble(value);
309                         if (PyErr_Occurred()) {
310                                 PyErr_SetString(PyExc_TypeError, "expected a float type");
311                                 return -1;
312                         } else {
313                                 RNA_property_float_set(ptr, prop, param);
314                         }
315                         break;
316                 }
317                 case PROP_STRING:
318                 {
319                         char *param = _PyUnicode_AsString(value);
320                         
321                         if (param==NULL) {
322                                 PyErr_SetString(PyExc_TypeError, "expected a string type");
323                                 return -1;
324                         } else {
325                                 RNA_property_string_set(ptr, prop, param);
326                         }
327                         break;
328                 }
329                 case PROP_ENUM:
330                 {
331                         char *param = _PyUnicode_AsString(value);
332                         
333                         if (param==NULL) {
334                                 char *enum_str= pyrna_enum_as_string(ptr, prop);
335                                 PyErr_Format(PyExc_TypeError, "expected a string enum type in (%s)", enum_str);
336                                 MEM_freeN(enum_str);
337                                 return -1;
338                         } else {
339                                 int val;
340                                 if (RNA_property_enum_value(ptr, prop, param, &val)) {
341                                         RNA_property_enum_set(ptr, prop, val);
342                                 } else {
343                                         char *enum_str= pyrna_enum_as_string(ptr, prop);
344                                         PyErr_Format(PyExc_AttributeError, "enum \"%s\" not found in (%s)", param, enum_str);
345                                         MEM_freeN(enum_str);
346                                         return -1;
347                                 }
348                         }
349                         
350                         break;
351                 }
352                 case PROP_POINTER:
353                 {
354                         PyErr_SetString(PyExc_AttributeError, "cant assign pointers yet");
355                         return -1;
356                         break;
357                 }
358                 case PROP_COLLECTION:
359                         PyErr_SetString(PyExc_AttributeError, "cant assign to collections");
360                         return -1;
361                         break;
362                 default:
363                         PyErr_SetString(PyExc_AttributeError, "unknown property type (pyrna_py_to_prop)");
364                         return -1;
365                         break;
366                 }
367         }
368         
369         return 0;
370 }
371
372
373 static PyObject * pyrna_prop_to_py_index(PointerRNA *ptr, PropertyRNA *prop, int index)
374 {
375         PyObject *ret;
376         int type = RNA_property_type(ptr, prop);
377         
378         /* see if we can coorce into a python type - PropertyType */
379         switch (type) {
380         case PROP_BOOLEAN:
381                 ret = PyBool_FromLong( RNA_property_boolean_get_index(ptr, prop, index) );
382                 break;
383         case PROP_INT:
384                 ret = PyLong_FromSize_t( (size_t)RNA_property_int_get_index(ptr, prop, index) );
385                 break;
386         case PROP_FLOAT:
387                 ret = PyFloat_FromDouble( RNA_property_float_get_index(ptr, prop, index) );
388                 break;
389         default:
390                 PyErr_SetString(PyExc_AttributeError, "not an array type");
391                 ret = NULL;
392                 break;
393         }
394         
395         return ret;
396 }
397
398 static int pyrna_py_to_prop_index(PointerRNA *ptr, PropertyRNA *prop, int index, PyObject *value)
399 {
400         int ret = 0;
401         int type = RNA_property_type(ptr, prop);
402         
403         /* see if we can coorce into a python type - PropertyType */
404         switch (type) {
405         case PROP_BOOLEAN:
406         {
407                 int param = PyObject_IsTrue( value );
408                 
409                 if( param < 0 ) {
410                         PyErr_SetString(PyExc_TypeError, "expected True/False or 0/1");
411                         ret = -1;
412                 } else {
413                         RNA_property_boolean_set_index(ptr, prop, index, param);
414                 }
415                 break;
416         }
417         case PROP_INT:
418         {
419                 int param = PyLong_AsSsize_t(value);
420                 if (PyErr_Occurred()) {
421                         PyErr_SetString(PyExc_TypeError, "expected an int type");
422                         ret = -1;
423                 } else {
424                         RNA_property_int_set_index(ptr, prop, index, param);
425                 }
426                 break;
427         }
428         case PROP_FLOAT:
429         {
430                 float param = PyFloat_AsDouble(value);
431                 if (PyErr_Occurred()) {
432                         PyErr_SetString(PyExc_TypeError, "expected a float type");
433                         ret = -1;
434                 } else {
435                         RNA_property_float_set_index(ptr, prop, index, param);
436                 }
437                 break;
438         }
439         default:
440                 PyErr_SetString(PyExc_AttributeError, "not an array type");
441                 ret = -1;
442                 break;
443         }
444         
445         return ret;
446 }
447
448 //---------------sequence-------------------------------------------
449 static Py_ssize_t pyrna_prop_len( BPy_PropertyRNA * self )
450 {
451         Py_ssize_t len;
452         
453         if (RNA_property_type(&self->ptr, self->prop) == PROP_COLLECTION) {
454                 len = RNA_property_collection_length(&self->ptr, self->prop);
455         } else {
456                 len = RNA_property_array_length(&self->ptr, self->prop);
457                 
458                 if (len==0) { /* not an array*/
459                         PyErr_SetString(PyExc_AttributeError, "len() only available for collection RNA types");
460                         return -1;
461                 }
462         }
463         
464         return len;
465 }
466
467 static PyObject *pyrna_prop_subscript( BPy_PropertyRNA * self, PyObject *key )
468 {
469         PyObject *ret;
470         PointerRNA newptr;
471         int keynum = 0;
472         char *keyname = NULL;
473         
474         if (PyUnicode_Check(key)) {
475                 keyname = _PyUnicode_AsString(key);
476         } else if (PyLong_Check(key)) {
477                 keynum = PyLong_AsSsize_t(key);
478         } else {
479                 PyErr_SetString(PyExc_AttributeError, "invalid key, key must be a string or an int");
480                 return NULL;
481         }
482         
483         if (RNA_property_type(&self->ptr, self->prop) == PROP_COLLECTION) {
484                 int ok;
485                 if (keyname)    ok = RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr);
486                 else                    ok = RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum, &newptr);
487                 
488                 if (ok) {
489                         ret = pyrna_struct_CreatePyObject(&newptr);
490                 } else {
491                         PyErr_SetString(PyExc_AttributeError, "out of range");
492                         ret = NULL;
493                 }
494                 
495         } else if (keyname) {
496                 PyErr_SetString(PyExc_AttributeError, "string keys are only supported for collections");
497                 ret = NULL;
498         } else {
499                 int len = RNA_property_array_length(&self->ptr, self->prop);
500                 
501                 if (len==0) { /* not an array*/
502                         PyErr_Format(PyExc_AttributeError, "not an array or collection %d", keynum);
503                         ret = NULL;
504                 }
505                 
506                 if (keynum >= len){
507                         PyErr_SetString(PyExc_AttributeError, "index out of range");
508                         ret = NULL;
509                 } else { /* not an array*/
510                         ret = pyrna_prop_to_py_index(&self->ptr, self->prop, keynum);
511                 }
512         }
513         
514         return ret;
515 }
516
517
518 static int pyrna_prop_assign_subscript( BPy_PropertyRNA * self, PyObject *key, PyObject *value )
519 {
520         int ret = 0;
521         int keynum = 0;
522         char *keyname = NULL;
523         
524         if (!RNA_property_editable(&self->ptr, self->prop)) {
525                 PyErr_Format( PyExc_AttributeError, "Attribute \"%s\" from \"%s\" is read-only", RNA_property_identifier(&self->ptr, self->prop), RNA_struct_identifier(&self->ptr) );
526                 return -1;
527         }
528         
529         if (PyUnicode_Check(key)) {
530                 keyname = _PyUnicode_AsString(key);
531         } else if (PyLong_Check(key)) {
532                 keynum = PyLong_AsSsize_t(key);
533         } else {
534                 PyErr_SetString(PyExc_AttributeError, "invalid key, key must be a string or an int");
535                 return -1;
536         }
537         
538         if (RNA_property_type(&self->ptr, self->prop) == PROP_COLLECTION) {
539                 PyErr_SetString(PyExc_AttributeError, "assignment is not supported for collections (yet)");
540                 ret = -1;
541         } else if (keyname) {
542                 PyErr_SetString(PyExc_AttributeError, "string keys are only supported for collections");
543                 ret = -1;
544         } else {
545                 int len = RNA_property_array_length(&self->ptr, self->prop);
546                 
547                 if (len==0) { /* not an array*/
548                         PyErr_Format(PyExc_AttributeError, "not an array or collection %d", keynum);
549                         ret = -1;
550                 }
551                 
552                 if (keynum >= len){
553                         PyErr_SetString(PyExc_AttributeError, "index out of range");
554                         ret = -1;
555                 } else {
556                         ret = pyrna_py_to_prop_index(&self->ptr, self->prop, keynum, value);
557                 }
558         }
559         
560         return ret;
561 }
562
563
564
565 static PyMappingMethods pyrna_prop_as_mapping = {
566         ( inquiry ) pyrna_prop_len,     /* mp_length */
567         ( binaryfunc ) pyrna_prop_subscript,    /* mp_subscript */
568         ( objobjargproc ) pyrna_prop_assign_subscript,  /* mp_ass_subscript */
569 };
570
571 static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
572 {
573         PyObject *ret, *dict;
574         PyObject *pystring = PyUnicode_FromString("__dict__");
575         
576         /* Include this incase this instance is a subtype of a python class
577          * In these instances we may want to return a function or variable provided by the subtype
578          * */
579         dict = PyObject_GenericGetAttr((PyObject *)self, pystring);
580         Py_DECREF(pystring);
581         
582         if (dict==NULL) {
583                 PyErr_Clear();
584                 ret = PyList_New(0);
585         }
586         else {
587                 ret = PyDict_Keys(dict);
588                 Py_DECREF(dict);
589         }
590         
591         /* Collect RNA items*/
592         {
593                 PropertyRNA *iterprop, *nameprop;
594                 CollectionPropertyIterator iter;
595                 char name[256], *nameptr;
596
597                 iterprop= RNA_struct_iterator_property(&self->ptr);
598                 RNA_property_collection_begin(&self->ptr, iterprop, &iter);
599
600                 for(; iter.valid; RNA_property_collection_next(&iter)) {
601                         if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) {
602                                 nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
603                                 
604                                 pystring = PyUnicode_FromString(nameptr);
605                                 PyList_Append(ret, pystring);
606                                 Py_DECREF(pystring);
607                                 
608                                 if ((char *)&name != nameptr)
609                                         MEM_freeN(nameptr);
610                         }
611                 }
612                 
613                 RNA_property_collection_end(&iter);
614         }
615         
616         return ret;
617 }
618
619
620 //---------------getattr--------------------------------------------
621 static PyObject *pyrna_struct_getattro( BPy_StructRNA * self, PyObject *pyname )
622 {
623         char *name = _PyUnicode_AsString(pyname);
624         PyObject *ret;
625         PropertyRNA *prop;
626         
627         /* Include this incase this instance is a subtype of a python class
628          * In these instances we may want to return a function or variable provided by the subtype
629          * */
630         ret = PyObject_GenericGetAttr((PyObject *)self, pyname);
631         if (ret)        return ret;
632         else            PyErr_Clear();
633         /* done with subtypes */
634
635         prop = RNA_struct_find_property(&self->ptr, name);
636         
637         if (prop) {
638                 ret = pyrna_prop_to_py(&self->ptr, prop);
639         }
640         else {
641                 PyErr_Format( PyExc_AttributeError, "Attribute \"%s\" not found", name);
642                 ret = NULL;
643         }
644         
645         return ret;
646 }
647
648 //--------------- setattr-------------------------------------------
649 static int pyrna_struct_setattro( BPy_StructRNA * self, PyObject *pyname, PyObject * value )
650 {
651         char *name = _PyUnicode_AsString(pyname);
652         PropertyRNA *prop = RNA_struct_find_property(&self->ptr, name);
653         
654         if (prop==NULL) {
655                 PyErr_Format( PyExc_AttributeError, "Attribute \"%s\" not found", name);
656                 return -1;
657         }               
658         
659         if (!RNA_property_editable(&self->ptr, prop)) {
660                 PyErr_Format( PyExc_AttributeError, "Attribute \"%s\" from \"%s\" is read-only", RNA_property_identifier(&self->ptr, prop), RNA_struct_identifier(&self->ptr) );
661                 return -1;
662         }
663                 
664         /* pyrna_py_to_prop sets its own exceptions */
665         return pyrna_py_to_prop(&self->ptr, prop, value);
666 }
667
668 PyObject *pyrna_prop_keys(BPy_PropertyRNA *self)
669 {
670         PyObject *ret;
671         if (RNA_property_type(&self->ptr, self->prop) != PROP_COLLECTION) {
672                 PyErr_SetString( PyExc_TypeError, "keys() is only valid for collection types" );
673                 ret = NULL;
674         } else {
675                 PyObject *item;
676                 CollectionPropertyIterator iter;
677                 PropertyRNA *nameprop;
678                 char name[256], *nameptr;
679
680                 ret = PyList_New(0);
681                 
682                 RNA_property_collection_begin(&self->ptr, self->prop, &iter);
683                 for(; iter.valid; RNA_property_collection_next(&iter)) {
684                         if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) {
685                                 nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));                                
686                                 
687                                 /* add to python list */
688                                 item = PyUnicode_FromString( nameptr );
689                                 PyList_Append(ret, item);
690                                 Py_DECREF(item);
691                                 /* done */
692                                 
693                                 if ((char *)&name != nameptr)
694                                         MEM_freeN(nameptr);
695                         }
696                 }
697                 RNA_property_collection_end(&iter);
698         }
699         
700         return ret;
701 }
702
703 PyObject *pyrna_prop_items(BPy_PropertyRNA *self)
704 {
705         PyObject *ret;
706         if (RNA_property_type(&self->ptr, self->prop) != PROP_COLLECTION) {
707                 PyErr_SetString( PyExc_TypeError, "items() is only valid for collection types" );
708                 ret = NULL;
709         } else {
710                 PyObject *item;
711                 CollectionPropertyIterator iter;
712                 PropertyRNA *nameprop;
713                 char name[256], *nameptr;
714
715                 ret = PyList_New(0);
716                 
717                 RNA_property_collection_begin(&self->ptr, self->prop, &iter);
718                 for(; iter.valid; RNA_property_collection_next(&iter)) {
719                         if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) {
720                                 nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
721                                 
722                                 /* add to python list */
723                                 item = Py_BuildValue("(NN)", PyUnicode_FromString( nameptr ), pyrna_struct_CreatePyObject(&iter.ptr));
724                                 PyList_Append(ret, item);
725                                 Py_DECREF(item);
726                                 /* done */
727                                 
728                                 if ((char *)&name != nameptr)
729                                         MEM_freeN(nameptr);
730                         }
731                 }
732                 RNA_property_collection_end(&iter);
733         }
734         
735         return ret;
736 }
737
738
739 PyObject *pyrna_prop_values(BPy_PropertyRNA *self)
740 {
741         PyObject *ret;
742         if (RNA_property_type(&self->ptr, self->prop) != PROP_COLLECTION) {
743                 PyErr_SetString( PyExc_TypeError, "values() is only valid for collection types" );
744                 ret = NULL;
745         } else {
746                 PyObject *item;
747                 CollectionPropertyIterator iter;
748                 PropertyRNA *nameprop;
749                 
750                 ret = PyList_New(0);
751                 
752                 RNA_property_collection_begin(&self->ptr, self->prop, &iter);
753                 for(; iter.valid; RNA_property_collection_next(&iter)) {
754                         if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) {
755                                 item = pyrna_struct_CreatePyObject(&iter.ptr);
756                                 PyList_Append(ret, item);
757                                 Py_DECREF(item);
758                         }
759                 }
760                 RNA_property_collection_end(&iter);
761         }
762         
763         return ret;
764 }
765
766 /* A bit of a kludge, make a list out of a collection or array,
767  * then return the lists iter function, not especially fast but convenient for now */
768 PyObject *pyrna_prop_iter(BPy_PropertyRNA *self)
769 {
770         /* Try get values from a collection */
771         PyObject *ret = pyrna_prop_values(self);
772         
773         if (ret==NULL) {
774                 /* collection did not work, try array */
775                 int len = RNA_property_array_length(&self->ptr, self->prop);
776                 
777                 if (len) {
778                         int i;
779                         PyErr_Clear();
780                         ret = PyList_New(len);
781                         
782                         for (i=0; i < len; i++) {
783                                 PyList_SET_ITEM(ret, i, pyrna_prop_to_py_index(&self->ptr, self->prop, i));
784                         }
785                 }
786         }
787         
788         if (ret) {
789                 /* we know this is a list so no need to PyIter_Check */
790                 PyObject *iter = PyObject_GetIter(ret); 
791                 Py_DECREF(ret);
792                 return iter;
793         }
794         
795         PyErr_SetString( PyExc_TypeError, "this BPy_PropertyRNA object is not iterable" );
796         return NULL;
797 }
798
799 static struct PyMethodDef pyrna_struct_methods[] = {
800         {"__dir__", (PyCFunction)pyrna_struct_dir, METH_NOARGS, ""},
801         {NULL, NULL, 0, NULL}
802 };
803
804 static struct PyMethodDef pyrna_prop_methods[] = {
805         {"keys", (PyCFunction)pyrna_prop_keys, METH_NOARGS, ""},
806         {"items", (PyCFunction)pyrna_prop_items, METH_NOARGS, ""},
807         {"values", (PyCFunction)pyrna_prop_values, METH_NOARGS, ""},
808         {NULL, NULL, 0, NULL}
809 };
810
811 /* only needed for subtyping, so a new class gets a valid BPy_StructRNA
812  * todo - also accept useful args */
813 static PyObject * pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
814
815         BPy_StructRNA *base = NULL;
816         
817         if (!PyArg_ParseTuple(args, "O!:Base BPy_StructRNA", &pyrna_struct_Type, &base))
818                 return NULL;
819         
820         if (type == &pyrna_struct_Type) {
821                 return pyrna_struct_CreatePyObject(&base->ptr);
822         } else {
823                 BPy_StructRNA *ret = (BPy_StructRNA *) type->tp_alloc(type, 0);
824                 ret->ptr = base->ptr;
825                 return (PyObject *)ret;
826         }
827 }
828
829 /* only needed for subtyping, so a new class gets a valid BPy_StructRNA
830  * todo - also accept useful args */
831 static PyObject * pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
832
833         BPy_PropertyRNA *base = NULL;
834         
835         if (!PyArg_ParseTuple(args, "O!:Base BPy_PropertyRNA", &pyrna_prop_Type, &base))
836                 return NULL;
837         
838         if (type == &pyrna_prop_Type) {
839                 return pyrna_prop_CreatePyObject(&base->ptr, base->prop);
840         } else {
841                 BPy_PropertyRNA *ret = (BPy_PropertyRNA *) type->tp_alloc(type, 0);
842                 ret->ptr = base->ptr;
843                 ret->prop = base->prop;
844                 return (PyObject *)ret;
845         }
846 }
847
848 /*-----------------------BPy_StructRNA method def------------------------------*/
849 PyTypeObject pyrna_struct_Type = {
850 #if (PY_VERSION_HEX >= 0x02060000)
851         PyVarObject_HEAD_INIT(NULL, 0)
852 #else
853         /* python 2.5 and below */
854         PyObject_HEAD_INIT( NULL )  /* required py macro */
855         0,                          /* ob_size */
856 #endif
857         "StructRNA",                    /* tp_name */
858         sizeof( BPy_StructRNA ),        /* tp_basicsize */
859         0,                      /* tp_itemsize */
860         /* methods */
861         ( destructor ) pyrna_struct_dealloc,/* tp_dealloc */
862         NULL,                       /* printfunc tp_print; */
863         NULL,                                           /* getattrfunc tp_getattr; */
864         NULL,                                           /* setattrfunc tp_setattr; */
865         NULL,                                           /* tp_compare */ /* DEPRECATED in python 3.0! */
866         ( reprfunc ) pyrna_struct_repr, /* tp_repr */
867
868         /* Method suites for standard classes */
869
870         NULL,                       /* PyNumberMethods *tp_as_number; */
871         NULL,                                           /* PySequenceMethods *tp_as_sequence; */
872         NULL,                                           /* PyMappingMethods *tp_as_mapping; */
873
874         /* More standard operations (here for binary compatibility) */
875
876         ( hashfunc )pyrna_struct_hash,  /* hashfunc tp_hash; */
877         NULL,                                           /* ternaryfunc tp_call; */
878         NULL,                       /* reprfunc tp_str; */
879         ( getattrofunc ) pyrna_struct_getattro, /* getattrofunc tp_getattro; */
880         ( setattrofunc ) pyrna_struct_setattro, /* setattrofunc tp_setattro; */
881
882         /* Functions to access object as input/output buffer */
883         NULL,                       /* PyBufferProcs *tp_as_buffer; */
884
885   /*** Flags to define presence of optional/expanded features ***/
886         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,         /* long tp_flags; */
887
888         NULL,                                           /*  char *tp_doc;  Documentation string */
889   /*** Assigned meaning in release 2.0 ***/
890         /* call function for all accessible objects */
891         NULL,                       /* traverseproc tp_traverse; */
892
893         /* delete references to contained objects */
894         NULL,                       /* inquiry tp_clear; */
895
896   /***  Assigned meaning in release 2.1 ***/
897   /*** rich comparisons ***/
898         (richcmpfunc)pyrna_struct_richcmp,      /* richcmpfunc tp_richcompare; */
899
900   /***  weak reference enabler ***/
901         0,                          /* long tp_weaklistoffset; */
902
903   /*** Added in release 2.2 ***/
904         /*   Iterators */
905         NULL,                       /* getiterfunc tp_iter; */
906         NULL,                       /* iternextfunc tp_iternext; */
907
908   /*** Attribute descriptor and subclassing stuff ***/
909         pyrna_struct_methods,                   /* struct PyMethodDef *tp_methods; */
910         NULL,                       /* struct PyMemberDef *tp_members; */
911         NULL,                                           /* struct PyGetSetDef *tp_getset; */
912         NULL,                       /* struct _typeobject *tp_base; */
913         NULL,                       /* PyObject *tp_dict; */
914         NULL,                       /* descrgetfunc tp_descr_get; */
915         NULL,                       /* descrsetfunc tp_descr_set; */
916         0,                          /* long tp_dictoffset; */
917         NULL,                       /* initproc tp_init; */
918         NULL,                       /* allocfunc tp_alloc; */
919         pyrna_struct_new,                       /* newfunc tp_new; */
920         /*  Low-level free-memory routine */
921         NULL,                       /* freefunc tp_free;  */
922         /* For PyObject_IS_GC */
923         NULL,                       /* inquiry tp_is_gc;  */
924         NULL,                       /* PyObject *tp_bases; */
925         /* method resolution order */
926         NULL,                       /* PyObject *tp_mro;  */
927         NULL,                       /* PyObject *tp_cache; */
928         NULL,                       /* PyObject *tp_subclasses; */
929         NULL,                       /* PyObject *tp_weaklist; */
930         NULL
931 };
932
933 /*-----------------------BPy_PropertyRNA method def------------------------------*/
934 PyTypeObject pyrna_prop_Type = {
935 #if (PY_VERSION_HEX >= 0x02060000)
936         PyVarObject_HEAD_INIT(NULL, 0)
937 #else
938         /* python 2.5 and below */
939         PyObject_HEAD_INIT( NULL )  /* required py macro */
940         0,                          /* ob_size */
941 #endif
942         
943         "PropertyRNA",          /* tp_name */
944         sizeof( BPy_PropertyRNA ),                      /* tp_basicsize */
945         0,                      /* tp_itemsize */
946         /* methods */
947         NULL,                                           /* tp_dealloc */
948         NULL,                       /* printfunc tp_print; */
949         NULL,                                           /* getattrfunc tp_getattr; */
950         NULL,                       /* setattrfunc tp_setattr; */
951         NULL,                                           /* tp_compare */ /* DEPRECATED in python 3.0! */
952         ( reprfunc ) pyrna_prop_repr,   /* tp_repr */
953
954         /* Method suites for standard classes */
955
956         NULL,                       /* PyNumberMethods *tp_as_number; */
957         NULL,                                           /* PySequenceMethods *tp_as_sequence; */
958         &pyrna_prop_as_mapping,         /* PyMappingMethods *tp_as_mapping; */
959
960         /* More standard operations (here for binary compatibility) */
961
962         NULL,                                           /* hashfunc tp_hash; */
963         NULL,                       /* ternaryfunc tp_call; */
964         NULL,                       /* reprfunc tp_str; */
965         NULL, /*PyObject_GenericGetAttr - MINGW Complains, assign later */      /* getattrofunc tp_getattro; */ /* will only use these if this is a subtype of a py class */
966         NULL, /*PyObject_GenericSetAttr - MINGW Complains, assign later */      /* setattrofunc tp_setattro; */
967
968         /* Functions to access object as input/output buffer */
969         NULL,                       /* PyBufferProcs *tp_as_buffer; */
970
971   /*** Flags to define presence of optional/expanded features ***/
972         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,         /* long tp_flags; */
973
974         NULL,                                           /*  char *tp_doc;  Documentation string */
975   /*** Assigned meaning in release 2.0 ***/
976         /* call function for all accessible objects */
977         NULL,                       /* traverseproc tp_traverse; */
978
979         /* delete references to contained objects */
980         NULL,                       /* inquiry tp_clear; */
981
982   /***  Assigned meaning in release 2.1 ***/
983   /*** rich comparisons ***/
984         (richcmpfunc)pyrna_prop_richcmp,        /* richcmpfunc tp_richcompare; */
985
986   /***  weak reference enabler ***/
987         0,                          /* long tp_weaklistoffset; */
988
989   /*** Added in release 2.2 ***/
990         /*   Iterators */
991         (getiterfunc)pyrna_prop_iter,   /* getiterfunc tp_iter; */
992         NULL,                       /* iternextfunc tp_iternext; */
993
994   /*** Attribute descriptor and subclassing stuff ***/
995         pyrna_prop_methods,                     /* struct PyMethodDef *tp_methods; */
996         NULL,                       /* struct PyMemberDef *tp_members; */
997         NULL,                                           /* struct PyGetSetDef *tp_getset; */
998         NULL,                       /* struct _typeobject *tp_base; */
999         NULL,                       /* PyObject *tp_dict; */
1000         NULL,                       /* descrgetfunc tp_descr_get; */
1001         NULL,                       /* descrsetfunc tp_descr_set; */
1002         0,                          /* long tp_dictoffset; */
1003         NULL,                       /* initproc tp_init; */
1004         NULL,                       /* allocfunc tp_alloc; */
1005         pyrna_prop_new,                         /* newfunc tp_new; */
1006         /*  Low-level free-memory routine */
1007         NULL,                       /* freefunc tp_free;  */
1008         /* For PyObject_IS_GC */
1009         NULL,                       /* inquiry tp_is_gc;  */
1010         NULL,                       /* PyObject *tp_bases; */
1011         /* method resolution order */
1012         NULL,                       /* PyObject *tp_mro;  */
1013         NULL,                       /* PyObject *tp_cache; */
1014         NULL,                       /* PyObject *tp_subclasses; */
1015         NULL,                       /* PyObject *tp_weaklist; */
1016         NULL
1017 };
1018
1019 /*-----------------------CreatePyObject---------------------------------*/
1020 PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr )
1021 {
1022         BPy_StructRNA *pyrna;
1023         
1024         if (ptr->data==NULL && ptr->type==NULL) {
1025                 Py_RETURN_NONE;
1026         }
1027         
1028 #ifdef PY_CLASS_SUBTYPE
1029         pyrna = ( BPy_StructRNA * ) PyObject_NEW( BPy_StructRNA, &pyrna_struct_Type );
1030         if (ptr->type && BPy_RNA_PYTYPE(ptr->type)) {
1031                 PyTypeObject *tp = BPy_RNA_PYTYPE(ptr->type);
1032                 pyrna = (BPy_StructRNA *) tp->tp_alloc(tp, 0);
1033         }
1034         else {
1035                 pyrna = ( BPy_StructRNA * ) PyObject_NEW( BPy_StructRNA, &pyrna_struct_Type );
1036         }
1037         
1038 #else
1039         /* get subtype from RNA struct if its been set */
1040         PyTypeObject *tp;
1041         if (ptr->type && ptr->type)
1042                 tp = BPy_RNA_PYTYPE(ptr->type);
1043         
1044         if (tp==NULL)
1045                 tp= &pyrna_struct_Type;
1046         
1047         pyrna = ( BPy_StructRNA * ) PyObject_NEW( BPy_StructRNA, tp );
1048 #endif  
1049         
1050         if( !pyrna ) {
1051                 PyErr_SetString( PyExc_MemoryError, "couldn't create BPy_StructRNA object" );
1052                 return NULL;
1053         }
1054         
1055         pyrna->ptr= *ptr;
1056         pyrna->freeptr= 0;
1057         
1058         return ( PyObject * ) pyrna;
1059 }
1060
1061 PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop )
1062 {
1063         BPy_PropertyRNA *pyrna;
1064
1065         pyrna = ( BPy_PropertyRNA * ) PyObject_NEW( BPy_PropertyRNA, &pyrna_prop_Type );
1066
1067         if( !pyrna ) {
1068                 PyErr_SetString( PyExc_MemoryError, "couldn't create BPy_rna object" );
1069                 return NULL;
1070         }
1071         
1072         pyrna->ptr = *ptr;
1073         pyrna->prop = prop;
1074                 
1075         return ( PyObject * ) pyrna;
1076 }
1077
1078
1079 PyObject *BPY_rna_module( void )
1080 {
1081         PointerRNA ptr;
1082         
1083         /* types init moved to BPY_rna_init_types */
1084         
1085         /* for now, return the base RNA type rather then a real module */
1086         RNA_main_pointer_create(G.main, &ptr);
1087         
1088         //submodule = Py_InitModule3( "rna", M_rna_methods, "rna module" );
1089         return pyrna_struct_CreatePyObject(&ptr);
1090 }
1091
1092 /* This is a way we can access docstrings for RNA types
1093  * without having the datatypes in blender */
1094 PyObject *BPY_rna_doc( void )
1095 {
1096         PointerRNA ptr;
1097         
1098         /* for now, return the base RNA type rather then a real module */
1099         RNA_blender_rna_pointer_create(&ptr);
1100         
1101         return pyrna_struct_CreatePyObject(&ptr);
1102 }
1103
1104 #ifdef PY_CLASS_SUBTYPE
1105 void BPY_rna_init_types(void)
1106 {       
1107         /* Now initialize new subtypes based on pyrna_struct_Type */
1108         char tp_name[64];
1109         PointerRNA ptr;
1110
1111         CollectionPropertyIterator iter;
1112         PropertyRNA *nameprop, *prop;
1113         char name[256], *nameptr;
1114
1115         
1116         /* This can't be set in the pytype struct because some compilers complain */
1117         pyrna_prop_Type.tp_getattro = PyObject_GenericGetAttr; 
1118         pyrna_prop_Type.tp_setattro = PyObject_GenericSetAttr; 
1119         
1120         if( PyType_Ready( &pyrna_struct_Type ) < 0 )
1121                 return;
1122         
1123         if( PyType_Ready( &pyrna_prop_Type ) < 0 )
1124                 return;
1125                 
1126         
1127         /* for now, return the base RNA type rather then a real module */
1128         RNA_blender_rna_pointer_create(&ptr);
1129         prop = RNA_struct_find_property(&ptr, "structs");
1130         
1131         RNA_property_collection_begin(&ptr, prop, &iter);
1132         for(; iter.valid; RNA_property_collection_next(&iter)) {
1133                 if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) {
1134                         
1135                         /* subclass = type(name='myClass', bases=(myBase,), dict={'some':'value'}) */
1136                         PyObject *args = PyTuple_New(3);
1137                         PyObject *bases = PyTuple_New(1);
1138                         PyObject *dict = PyDict_New();
1139                         PyObject *newclass;
1140                         
1141                         nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
1142                         snprintf(tp_name, 64, "BPyRNA_%s", nameptr);
1143                         
1144                         
1145                         // arg 1
1146                         PyTuple_SET_ITEM(args, 0, PyUnicode_FromString(tp_name));
1147                         
1148                         // arg 2
1149                         PyTuple_SET_ITEM(bases, 0, (PyObject *)&pyrna_struct_Type);
1150                         Py_INCREF(&pyrna_struct_Type);
1151                         PyTuple_SET_ITEM(args, 1, bases);
1152                         
1153                         // arg 3
1154                         PyTuple_SET_ITEM(args, 2, dict); // fill with useful subclass things!
1155                         
1156                         if (PyErr_Occurred()) {
1157                                 PyErr_Print();
1158                                 PyErr_Clear();
1159                         }
1160                         
1161                         newclass = PyObject_CallObject((PyObject *)&PyType_Type, args);
1162                         
1163                         Py_DECREF(args);
1164                         
1165                         BPy_RNA_PYTYPE(iter.ptr.data) = (void *         )newclass;
1166                         
1167                         // printf("BPyRNA_PyTypes: %s\n", tp_name);
1168                         
1169                         if ((char *)&name != nameptr)
1170                                 MEM_freeN(nameptr);
1171                 }
1172         }
1173         RNA_property_collection_end(&iter);
1174 }
1175
1176 void BPY_rna_free_types(void) {};
1177         
1178 #else // Other method uses C defined PyTypes
1179
1180 static void *tp_mem = NULL;
1181 void BPY_rna_init_types(void)
1182 {
1183         PyTypeObject init_struct_type = pyrna_struct_Type; /* store this type to make copies from */
1184         
1185         /* Now initialize new subtypes based on pyrna_struct_Type */
1186         typedef struct PyTypeObject_Name {PyTypeObject tp; char name[64];} PyTypeObject_Name;
1187         PyTypeObject_Name *tp_mem_ptr;
1188         PyTypeObject *tp;
1189         char *tp_name;
1190         PointerRNA ptr;
1191
1192         CollectionPropertyIterator iter;
1193         PropertyRNA *nameprop, *prop;
1194         char name[256], *nameptr;
1195
1196         
1197         /* This can't be set in the pytype struct because some compilers complain */
1198         pyrna_prop_Type.tp_getattro = PyObject_GenericGetAttr; 
1199         pyrna_prop_Type.tp_setattro = PyObject_GenericSetAttr; 
1200         
1201         if( PyType_Ready( &pyrna_struct_Type ) < 0 )
1202                 return;
1203         
1204         if( PyType_Ready( &pyrna_prop_Type ) < 0 )
1205                 return;
1206         
1207         /* Note, making subtypes could be done by using an equivelent of 
1208         class MyClass(RNA_Struct)
1209         */
1210         
1211         
1212         /* for now, return the base RNA type rather then a real module */
1213         RNA_blender_rna_pointer_create(&ptr);
1214         prop = RNA_struct_find_property(&ptr, "structs");
1215         
1216         tp_mem = tp_mem_ptr = MEM_mallocN(sizeof(PyTypeObject_Name) * RNA_property_collection_length(&ptr, prop), "BPyRNA_PyTypes");
1217         
1218         RNA_property_collection_begin(&ptr, prop, &iter);
1219         for(; iter.valid; RNA_property_collection_next(&iter)) {
1220                 if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) {
1221                         
1222                         nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
1223                         
1224                         //tp = MEM_mallocN(sizeof(PyTypeObject_Name), "pyrna");
1225                         tp = &(tp_mem_ptr->tp);
1226                         tp_name = tp_mem_ptr->name;
1227                         snprintf(tp_name, 64, "BPyRNA_%s", nameptr);
1228                         
1229                         
1230                         *tp= init_struct_type; /* Copy the uninitialized pyrna_struct_Type */
1231                         tp->tp_name= tp_name;
1232                         tp->tp_base= &pyrna_struct_Type;
1233                         
1234                         /* Todo - add special tp->tp_new function that lets us subtupe rna! */
1235                         
1236                         if( PyType_Ready( tp ) < 0 ) {
1237                                 printf("PyType_Ready failed\n");
1238                         }
1239                         
1240                         BPy_RNA_PYTYPE(iter.ptr.data) = tp;
1241                         
1242                         // printf("BPyRNA_PyTypes: %s\n", tp_name);
1243                         
1244                         if ((char *)&name != nameptr)
1245                                 MEM_freeN(nameptr);
1246                 }
1247                 tp_mem_ptr++;
1248         }
1249         RNA_property_collection_end(&iter);
1250 }
1251
1252 /* Runs after python is finished, dont use any python functions */
1253 void BPY_rna_free_types(void)
1254 {
1255         if (tp_mem==NULL)
1256                 return;
1257
1258         /* We dont really have to clear each structs type but may want to, also might allocate each type on its own */
1259 #if 0
1260         PointerRNA ptr;
1261
1262         CollectionPropertyIterator iter;
1263         PropertyRNA *prop;
1264         
1265         /* for now, return the base RNA type rather then a real module */
1266         RNA_blender_rna_pointer_create(&ptr);
1267         prop = RNA_struct_find_property(&ptr, "structs");
1268         
1269         RNA_property_collection_begin(&ptr, prop, &iter);
1270         for(; iter.valid; RNA_property_collection_next(&iter)) {
1271                 if(iter.ptr.data) {
1272                         if (BPy_RNA_PYTYPE(iter.ptr.data)) {
1273                                 /*
1274                                 PyTypeObject *tp = BPy_RNA_PYTYPE(iter.ptr.data);
1275                                 printf("BPyRNA clear: %s %d\n", tp->tp_name, (int)(long)BPy_RNA_PYTYPE(iter.ptr.data));
1276                                 */
1277                                 
1278                                 /* May want to alloc each type on its own however this makes it hard to know if RNA subtypes are using the type */
1279                                 
1280                                 /* PyMem_Free( BPy_RNA_PYTYPE(iter.ptr.data) );
1281                                 MEM_freeN( BPy_RNA_PYTYPE(iter.ptr.data) ); */
1282                                 BPy_RNA_PYTYPE(iter.ptr.data)= NULL;
1283                         }
1284                 }
1285         }
1286         RNA_property_collection_end(&iter);
1287 #endif
1288
1289         MEM_freeN( tp_mem );
1290         tp_mem = NULL;
1291 }
1292 #endif // END PYTYPE COPY METHOD
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303