remove unused rna includes
[blender.git] / source / blender / makesrna / intern / makesrna.c
index b467c2d20c2a78fd94379b7126b4f1947a955367..c9db05c30b13fee31c6d02470a23816cfce213db 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * Contributor(s): Blender Foundation (2008).
  *
@@ -30,9 +30,7 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "RNA_access.h"
 #include "RNA_define.h"
-#include "RNA_types.h"
 
 #include "rna_internal.h"
 
 #endif
 #endif
 
+/* Replace if different */
+#define TMP_EXT ".tmp"
+
+static int replace_if_different(char *tmpfile)
+{
+
+#define REN_IF_DIFF \
+       remove(orgfile); \
+       if(rename(tmpfile, orgfile) != 0) { \
+               fprintf(stderr, "%s:%d, rename error: \"%s\" -> \"%s\"\n", __FILE__, __LINE__, tmpfile, orgfile); \
+               return -1; \
+       } \
+       remove(tmpfile); \
+       return 1; \
+/* end REN_IF_DIFF */
+
+
+       FILE *fp_new, *fp_org;
+       int len_new, len_org;
+       char *arr_new, *arr_org;
+       int cmp;
+
+       char orgfile[4096];
+
+       strcpy(orgfile, tmpfile);
+       orgfile[strlen(orgfile) - strlen(TMP_EXT)] = '\0'; /* strip '.tmp' */
+
+       fp_org= fopen(orgfile, "rb");
+
+       if(fp_org==NULL) {
+               REN_IF_DIFF;
+       }
+
+       fp_new= fopen(tmpfile, "rb");
+
+       if(fp_new==NULL) {
+               /* shouldn't happen, just to be safe */
+               fprintf(stderr, "%s:%d, open error: \"%s\"\n", __FILE__, __LINE__, tmpfile);
+               return -1;
+       }
+
+       fseek(fp_new, 0L, SEEK_END); len_new = ftell(fp_new); fseek(fp_new, 0L, SEEK_SET);
+       fseek(fp_org, 0L, SEEK_END); len_org = ftell(fp_org); fseek(fp_org, 0L, SEEK_SET);
+
+
+       if(len_new != len_org) {
+               fclose(fp_new);
+               fclose(fp_org);
+               REN_IF_DIFF;
+       }
+
+       /* now compare the files... */
+       arr_new= MEM_mallocN(sizeof(char)*len_new, "rna_cmp_file_new");
+       arr_org= MEM_mallocN(sizeof(char)*len_org, "rna_cmp_file_org");
+
+       if(fread(arr_new, sizeof(char), len_new, fp_new) != len_new)
+               fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, tmpfile);
+       if(fread(arr_org, sizeof(char), len_org, fp_org) != len_org)
+               fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, orgfile);
+
+       fclose(fp_new);
+       fclose(fp_org);
+
+       cmp= memcmp(arr_new, arr_org, len_new);
+
+       MEM_freeN(arr_new);
+       MEM_freeN(arr_org);
+
+       if(cmp) {
+               REN_IF_DIFF;
+       }
+       else {
+               remove(tmpfile);
+               return 0;
+       }
+
+#undef REN_IF_DIFF
+}
+
+
+
 /* Sorting */
 
 static int cmp_struct(const void *a, const void *b)
@@ -144,6 +223,11 @@ static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
                fprintf(f, "    %s *data= (%s*)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
 }
 
+static void rna_print_id_get(FILE *f, PropertyDefRNA *dp)
+{
+       fprintf(f, "    ID *id= ptr->id.data;\n");
+}
+
 static char *rna_alloc_function_name(const char *structname, const char *propname, const char *type)
 {
        AllocDefRNA *alloc;
@@ -306,11 +390,10 @@ static void rna_int_print(FILE *f, int num)
 static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
 {
        char *func;
-       int i;
 
        if(prop->flag & PROP_IDPROPERTY)
                return NULL;
-       
+
        if(!manualfunc) {
                if(!dp->dnastructname || !dp->dnaname) {
                        fprintf(stderr, "rna_def_property_get_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
@@ -365,7 +448,7 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                if(strcmp(manualfunc, "rna_iterator_listbase_get") == 0 ||
                                   strcmp(manualfunc, "rna_iterator_array_get") == 0 ||
                                   strcmp(manualfunc, "rna_iterator_array_dereference_get") == 0)
-                                       fprintf(f, "    return rna_pointer_inherit_refine(&iter->parent, &RNA_%s, %s(iter));\n", (cprop->type)? (char*)cprop->type: "UnknownType", manualfunc);
+                                       fprintf(f, "    return rna_pointer_inherit_refine(&iter->parent, &RNA_%s, %s(iter));\n", (cprop->item_type)? (char*)cprop->item_type: "UnknownType", manualfunc);
                                else
                                        fprintf(f, "    return %s(iter);\n", manualfunc);
                        }
@@ -373,8 +456,11 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                        break;
                }
                default:
-                       if(prop->arraylength) {
-                               fprintf(f, "void %s(PointerRNA *ptr, %s values[%d])\n", func, rna_type_type(prop), prop->arraylength);
+                       if(prop->arraydimension) {
+                               if(prop->flag & PROP_DYNAMIC)
+                                       fprintf(f, "void %s(PointerRNA *ptr, %s values[])\n", func, rna_type_type(prop));
+                               else
+                                       fprintf(f, "void %s(PointerRNA *ptr, %s values[%d])\n", func, rna_type_type(prop), prop->totarraylength);
                                fprintf(f, "{\n");
 
                                if(manualfunc) {
@@ -383,27 +469,38 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                else {
                                        rna_print_data_get(f, dp);
 
-                                       for(i=0; i<prop->arraylength; i++) {
-                                               if(dp->dnaarraylength == 1) {
-                                                       if(prop->type == PROP_BOOLEAN && dp->booleanbit)
-                                                               fprintf(f, "    values[%d]= (%s(data->%s & (%d<<%d)) != 0);\n", i, (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit, i);
-                                                       else
-                                                               fprintf(f, "    values[%d]= (%s)%s((&data->%s)[%d]);\n", i, rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname, i);
-                                               }
-                                               else {
-                                                       if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
-                                                               fprintf(f, "    values[%d]= (%s(data->%s[%d] & ", i, (dp->booleannegative)? "!": "", dp->dnaname, i);
-                                                               rna_int_print(f, dp->booleanbit);
-                                                               fprintf(f, ") != 0);\n");
-                                                       }
-                                                       else if(rna_color_quantize(prop, dp))
-                                                               fprintf(f, "    values[%d]= (%s)(data->%s[%d]*(1.0f/255.0f));\n", i, rna_type_type(prop), dp->dnaname, i);
-                                                       else if(dp->dnatype)
-                                                               fprintf(f, "    values[%d]= (%s)%s(((%s*)data->%s)[%d]);\n", i, rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnatype, dp->dnaname, i);
-                                                       else
-                                                               fprintf(f, "    values[%d]= (%s)%s((data->%s)[%d]);\n", i, rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname, i);
+                                       if(prop->flag & PROP_DYNAMIC) {
+                                               char *lenfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get_length");
+                                               fprintf(f, "    int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
+                                               fprintf(f, "    int len= %s(ptr, arraylen);\n\n", lenfunc);
+                                               fprintf(f, "    for(i=0; i<len; i++) {\n");
+                                               MEM_freeN(lenfunc);
+                                       }
+                                       else {
+                                               fprintf(f, "    int i;\n\n");
+                                               fprintf(f, "    for(i=0; i<%d; i++) {\n", prop->totarraylength);
+                                       }
+
+                                       if(dp->dnaarraylength == 1) {
+                                               if(prop->type == PROP_BOOLEAN && dp->booleanbit)
+                                                       fprintf(f, "            values[i]= (%s(data->%s & (%d<<i)) != 0);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
+                                               else
+                                                       fprintf(f, "            values[i]= (%s)%s((&data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
+                                       }
+                                       else {
+                                               if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
+                                                       fprintf(f, "            values[i]= (%s(data->%s[i] & ", (dp->booleannegative)? "!": "", dp->dnaname);
+                                                       rna_int_print(f, dp->booleanbit);
+                                                       fprintf(f, ") != 0);\n");
                                                }
+                                               else if(rna_color_quantize(prop, dp))
+                                                       fprintf(f, "            values[i]= (%s)(data->%s[i]*(1.0f/255.0f));\n", rna_type_type(prop), dp->dnaname);
+                                               else if(dp->dnatype)
+                                                       fprintf(f, "            values[i]= (%s)%s(((%s*)data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnatype, dp->dnaname);
+                                               else
+                                                       fprintf(f, "            values[i]= (%s)%s((data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
                                        }
+                                       fprintf(f, "    }\n");
                                }
                                fprintf(f, "}\n\n");
                        }
@@ -438,13 +535,13 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
        return func;
 }
 
-static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array, int i)
+static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
 {
        if(prop->type == PROP_INT) {
                IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
 
                if(iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX) {
-                       if(array) fprintf(f, "CLAMPIS(values[%d], ", i);
+                       if(array) fprintf(f, "CLAMPIS(values[i], ");
                        else fprintf(f, "CLAMPIS(value, ");
                        rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
                        rna_int_print(f, iprop->hardmax); fprintf(f, ");\n");
@@ -455,7 +552,7 @@ static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array, int i)
                FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
 
                if(fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX) {
-                       if(array) fprintf(f, "CLAMPIS(values[%d], ", i);
+                       if(array) fprintf(f, "CLAMPIS(values[i], ");
                        else fprintf(f, "CLAMPIS(value, ");
                        rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
                        rna_float_print(f, fprop->hardmax); fprintf(f, ");\n");
@@ -464,7 +561,7 @@ static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array, int i)
        }
 
        if(array)
-               fprintf(f, "values[%d];\n", i);
+               fprintf(f, "values[i];\n");
        else
                fprintf(f, "value;\n");
 }
@@ -472,7 +569,6 @@ static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array, int i)
 static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
 {
        char *func;
-       int i;
 
        if(!(prop->flag & PROP_EDITABLE))
                return NULL;
@@ -518,6 +614,11 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                        else {
                                rna_print_data_get(f, dp);
 
+                               if(prop->flag & PROP_ID_SELF_CHECK) {
+                                       rna_print_id_get(f, dp);
+                                       fprintf(f, "    if(id==value.data) return;\n\n");
+                               }
+
                                if(prop->flag & PROP_ID_REFCOUNT) {
                                        fprintf(f, "\n  if(data->%s)\n", dp->dnaname);
                                        fprintf(f, "            id_us_min((ID*)data->%s);\n", dp->dnaname);
@@ -532,8 +633,11 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                        break;
                }
                default:
-                       if(prop->arraylength) {
-                               fprintf(f, "void %s(PointerRNA *ptr, const %s values[%d])\n", func, rna_type_type(prop), prop->arraylength);
+                       if(prop->arraydimension) {
+                               if(prop->flag & PROP_DYNAMIC)
+                                       fprintf(f, "void %s(PointerRNA *ptr, const %s values[])\n", func, rna_type_type(prop));
+                               else
+                                       fprintf(f, "void %s(PointerRNA *ptr, const %s values[%d])\n", func, rna_type_type(prop), prop->totarraylength);
                                fprintf(f, "{\n");
 
                                if(manualfunc) {
@@ -542,38 +646,49 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                else {
                                        rna_print_data_get(f, dp);
 
-                                       for(i=0; i<prop->arraylength; i++) {
-                                               if(dp->dnaarraylength == 1) {
-                                                       if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
-                                                               fprintf(f, "    if(%svalues[%d]) data->%s |= (%d<<%d);\n", (dp->booleannegative)? "!": "", i, dp->dnaname, dp->booleanbit, i);
-                                                               fprintf(f, "    else data->%s &= ~(%d<<%d);\n", dp->dnaname, dp->booleanbit, i);
-                                                       }
-                                                       else {
-                                                               fprintf(f, "    (&data->%s)[%d]= %s", dp->dnaname, i, (dp->booleannegative)? "!": "");
-                                                               rna_clamp_value(f, prop, 1, i);
-                                                       }
+                                       if(prop->flag & PROP_DYNAMIC) {
+                                               char *lenfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "set_length");
+                                               fprintf(f, "    int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
+                                               fprintf(f, "    int len= %s(ptr, arraylen);\n\n", lenfunc);
+                                               fprintf(f, "    for(i=0; i<len; i++) {\n");
+                                               MEM_freeN(lenfunc);
+                                       }
+                                       else {
+                                               fprintf(f, "    int i;\n\n");
+                                               fprintf(f, "    for(i=0; i<%d; i++) {\n", prop->totarraylength);
+                                       }
+
+                                       if(dp->dnaarraylength == 1) {
+                                               if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
+                                                       fprintf(f, "            if(%svalues[i]) data->%s |= (%d<<i);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
+                                                       fprintf(f, "            else data->%s &= ~(%d<<i);\n", dp->dnaname, dp->booleanbit);
                                                }
                                                else {
-                                                       if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
-                                                               fprintf(f, "    if(%svalues[%d]) data->%s[%d] |= ", (dp->booleannegative)? "!": "", i, dp->dnaname, i);
-                                                               rna_int_print(f, dp->booleanbit);
-                                                               fprintf(f, ";\n");
-                                                               fprintf(f, "    else data->%s[%d] &= ~", dp->dnaname, i);
-                                                               rna_int_print(f, dp->booleanbit);
-                                                               fprintf(f, ";\n");
-                                                       }
-                                                       else if(rna_color_quantize(prop, dp)) {
-                                                               fprintf(f, "    data->%s[%d]= FTOCHAR(values[%d]);\n", dp->dnaname, i, i);
-                                                       }
-                                                       else {
-                                                               if(dp->dnatype)
-                                                                       fprintf(f, "    ((%s*)data->%s)[%d]= %s", dp->dnatype, dp->dnaname, i, (dp->booleannegative)? "!": "");
-                                                               else
-                                                                       fprintf(f, "    (data->%s)[%d]= %s", dp->dnaname, i, (dp->booleannegative)? "!": "");
-                                                               rna_clamp_value(f, prop, 1, i);
-                                                       }
+                                                       fprintf(f, "            (&data->%s)[i]= %s", dp->dnaname, (dp->booleannegative)? "!": "");
+                                                       rna_clamp_value(f, prop, 1);
                                                }
                                        }
+                                       else {
+                                               if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
+                                                       fprintf(f, "            if(%svalues[i]) data->%s[i] |= ", (dp->booleannegative)? "!": "", dp->dnaname);
+                                                       rna_int_print(f, dp->booleanbit);
+                                                       fprintf(f, ";\n");
+                                                       fprintf(f, "            else data->%s[i] &= ~", dp->dnaname);
+                                                       rna_int_print(f, dp->booleanbit);
+                                                       fprintf(f, ";\n");
+                                               }
+                                               else if(rna_color_quantize(prop, dp)) {
+                                                       fprintf(f, "            data->%s[i]= FTOCHAR(values[i]);\n", dp->dnaname);
+                                               }
+                                               else {
+                                                       if(dp->dnatype)
+                                                               fprintf(f, "            ((%s*)data->%s)[i]= %s", dp->dnatype, dp->dnaname, (dp->booleannegative)? "!": "");
+                                                       else
+                                                               fprintf(f, "            (data->%s)[i]= %s", dp->dnaname, (dp->booleannegative)? "!": "");
+                                                       rna_clamp_value(f, prop, 1);
+                                               }
+                                       }
+                                       fprintf(f, "    }\n");
                                }
                                fprintf(f, "}\n\n");
                        }
@@ -602,7 +717,7 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
                                        }
                                        else {
                                                fprintf(f, "    data->%s= %s", dp->dnaname, (dp->booleannegative)? "!": "");
-                                               rna_clamp_value(f, prop, 0, 0);
+                                               rna_clamp_value(f, prop, 0);
                                        }
                                }
                                fprintf(f, "}\n\n");
@@ -729,6 +844,98 @@ static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *
        return func;
 }
 
+static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc, char *nextfunc)
+{
+       char *func;
+
+       if(prop->flag & PROP_IDPROPERTY)
+               return NULL;
+
+       if(!manualfunc) {
+               if(!dp->dnastructname || !dp->dnaname)
+                       return NULL;
+
+               /* only supported in case of standard next functions */
+               if(strcmp(nextfunc, "rna_iterator_array_next") == 0);
+               else if(strcmp(nextfunc, "rna_iterator_listbase_next") == 0);
+               else return NULL;
+       }
+
+       func= rna_alloc_function_name(srna->identifier, prop->identifier, "lookup_int");
+
+       fprintf(f, "PointerRNA %s(PointerRNA *ptr, int index)\n", func);
+       fprintf(f, "{\n");
+
+       if(manualfunc) {
+               fprintf(f, "\n  return %s(ptr, index);\n", manualfunc);
+               fprintf(f, "}\n\n");
+               return func;
+       }
+
+       fprintf(f, "    PointerRNA r_ptr;\n");
+       fprintf(f, "    CollectionPropertyIterator iter;\n\n");
+
+       fprintf(f, "    %s_%s_begin(&iter, ptr);\n\n", srna->identifier, prop->identifier);
+       fprintf(f, "    {\n");
+
+       if(strcmp(nextfunc, "rna_iterator_array_next") == 0) {
+               fprintf(f, "            ArrayIterator *internal= iter.internal;\n");
+               fprintf(f, "            if(internal->skip) {\n");
+               fprintf(f, "                    while(index-- > 0) {\n");
+               fprintf(f, "                            do {\n");
+               fprintf(f, "                                    internal->ptr += internal->itemsize;\n");
+               fprintf(f, "                            } while(internal->skip(&iter, internal->ptr));\n");
+               fprintf(f, "                    }\n");
+               fprintf(f, "            }\n");
+               fprintf(f, "            else {\n");
+               fprintf(f, "                    internal->ptr += internal->itemsize*index;\n");
+               fprintf(f, "            }\n");
+       }
+       else if(strcmp(nextfunc, "rna_iterator_listbase_next") == 0) {
+               fprintf(f, "            ListBaseIterator *internal= iter.internal;\n");
+               fprintf(f, "            if(internal->skip) {\n");
+               fprintf(f, "                    while(index-- > 0) {\n");
+               fprintf(f, "                            do {\n");
+               fprintf(f, "                                    internal->link= internal->link->next;\n");
+               fprintf(f, "                            } while(internal->skip(&iter, internal->link));\n");
+               fprintf(f, "                    }\n");
+               fprintf(f, "            }\n");
+               fprintf(f, "            else {\n");
+               fprintf(f, "                    while(index-- > 0)\n");
+               fprintf(f, "                            internal->link= internal->link->next;\n");
+               fprintf(f, "            }\n");
+       }
+
+       fprintf(f, "    }\n\n");
+
+       fprintf(f, "    r_ptr = %s_%s_get(&iter);\n", srna->identifier, prop->identifier);
+       fprintf(f, "    %s_%s_end(&iter);\n\n", srna->identifier, prop->identifier);
+
+       fprintf(f, "    return r_ptr;\n");
+
+#if 0
+       rna_print_data_get(f, dp);
+       item_type= (cprop->item_type)? (char*)cprop->item_type: "UnknownType";
+
+       if(dp->dnalengthname || dp->dnalengthfixed) {
+               if(dp->dnalengthname)
+                       fprintf(f, "\n  rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), data->%s, index);\n", item_type, dp->dnaname, dp->dnaname, dp->dnalengthname);
+               else
+                       fprintf(f, "\n  rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), %d, index);\n", item_type, dp->dnaname, dp->dnaname, dp->dnalengthfixed);
+       }
+       else {
+               if(dp->dnapointerlevel == 0)
+                       fprintf(f, "\n  return rna_listbase_lookup_int(ptr, &RNA_%s, &data->%s, index);\n", item_type, dp->dnaname);
+               else
+                       fprintf(f, "\n  return rna_listbase_lookup_int(ptr, &RNA_%s, data->%s, index);\n", item_type, dp->dnaname);
+       }
+#endif
+
+       fprintf(f, "}\n\n");
+
+       return func;
+}
+
 static char *rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
 {
        char *func, *getfunc;
@@ -819,7 +1026,7 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
                case PROP_BOOLEAN: {
                        BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
 
-                       if(!prop->arraylength) {
+                       if(!prop->arraydimension) {
                                if(!bprop->get && !bprop->set && !dp->booleanbit)
                                        rna_set_raw_property(dp, prop);
 
@@ -835,7 +1042,7 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
                case PROP_INT: {
                        IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
 
-                       if(!prop->arraylength) {
+                       if(!prop->arraydimension) {
                                if(!iprop->get && !iprop->set)
                                        rna_set_raw_property(dp, prop);
 
@@ -854,7 +1061,7 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
                case PROP_FLOAT: {
                        FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
 
-                       if(!prop->arraylength) {
+                       if(!prop->arraydimension) {
                                if(!fprop->get && !fprop->set)
                                        rna_set_raw_property(dp, prop);
 
@@ -898,6 +1105,7 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
                }
                case PROP_COLLECTION: {
                        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
+                       char *nextfunc= (char*)cprop->next;
 
                        if(dp->dnatype && strcmp(dp->dnatype, "ListBase")==0);
                        else if(dp->dnalengthname || dp->dnalengthfixed)
@@ -914,6 +1122,7 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
                        cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp, (char*)cprop->begin);
                        cprop->next= (void*)rna_def_property_next_func(f, srna, prop, dp, (char*)cprop->next);
                        cprop->end= (void*)rna_def_property_end_func(f, srna, prop, dp, (char*)cprop->end);
+                       cprop->lookupint= (void*)rna_def_property_lookup_int_func(f, srna, prop, dp, (char*)cprop->lookupint, nextfunc);
 
                        if(!(prop->flag & PROP_IDPROPERTY)) {
                                if(!cprop->begin) {
@@ -929,7 +1138,7 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
                                        DefRNA.error= 1;
                                }
                        }
-                       if(!cprop->type) {
+                       if(!cprop->item_type) {
                                fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a struct type.\n", srna->identifier, prop->identifier);
                                DefRNA.error= 1;
                        }
@@ -953,23 +1162,23 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR
        switch(prop->type) {
                case PROP_BOOLEAN:
                case PROP_INT: {
-                       if(!prop->arraylength) {
+                       if(!prop->arraydimension) {
                                fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
                                //fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
                        }
                        else {
-                               fprintf(f, "void %sget(PointerRNA *ptr, int values[%d]);\n", func, prop->arraylength);
+                               fprintf(f, "void %sget(PointerRNA *ptr, int values[%d]);\n", func, prop->totarraylength);
                                //fprintf(f, "void %sset(PointerRNA *ptr, const int values[%d]);\n", func, prop->arraylength);
                        }
                        break;
                }
                case PROP_FLOAT: {
-                       if(!prop->arraylength) {
+                       if(!prop->arraydimension) {
                                fprintf(f, "float %sget(PointerRNA *ptr);\n", func);
                                //fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func);
                        }
                        else {
-                               fprintf(f, "void %sget(PointerRNA *ptr, float values[%d]);\n", func, prop->arraylength);
+                               fprintf(f, "void %sget(PointerRNA *ptr, float values[%d]);\n", func, prop->totarraylength);
                                //fprintf(f, "void %sset(PointerRNA *ptr, const float values[%d]);\n", func, prop->arraylength);
                        }
                        break;
@@ -1043,24 +1252,24 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property
 
        switch(prop->type) {
                case PROP_BOOLEAN: {
-                       if(!prop->arraylength)
+                       if(!prop->arraydimension)
                                fprintf(f, "\tbool %s(void);", prop->identifier);
                        else
-                               fprintf(f, "\tArray<int, %d> %s(void);", prop->arraylength, prop->identifier);
+                               fprintf(f, "\tArray<int, %d> %s(void);", prop->totarraylength, prop->identifier);
                        break;
                }
                case PROP_INT: {
-                       if(!prop->arraylength)
+                       if(!prop->arraydimension)
                                fprintf(f, "\tint %s(void);", prop->identifier);
                        else
-                               fprintf(f, "\tArray<int, %d> %s(void);", prop->arraylength, prop->identifier);
+                               fprintf(f, "\tArray<int, %d> %s(void);", prop->totarraylength, prop->identifier);
                        break;
                }
                case PROP_FLOAT: {
-                       if(!prop->arraylength)
+                       if(!prop->arraydimension)
                                fprintf(f, "\tfloat %s(void);", prop->identifier);
                        else
-                               fprintf(f, "\tArray<float, %d> %s(void);", prop->arraylength, prop->identifier);
+                               fprintf(f, "\tArray<float, %d> %s(void);", prop->totarraylength, prop->identifier);
                        break;
                }
                case PROP_ENUM: {
@@ -1096,8 +1305,8 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property
                case PROP_COLLECTION: {
                        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
 
-                       if(cprop->type)
-                               fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (char*)cprop->type, srna->identifier, prop->identifier);
+                       if(cprop->item_type)
+                               fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (char*)cprop->item_type, srna->identifier, prop->identifier);
                        else
                                fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);
                        break;
@@ -1118,24 +1327,24 @@ static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDe
 
        switch(prop->type) {
                case PROP_BOOLEAN: {
-                       if(!prop->arraylength)
+                       if(!prop->arraydimension)
                                fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
                        else
-                               fprintf(f, "\tBOOLEAN_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->arraylength, prop->identifier);
+                               fprintf(f, "\tBOOLEAN_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->totarraylength, prop->identifier);
                        break;
                }
                case PROP_INT: {
-                       if(!prop->arraylength)
+                       if(!prop->arraydimension)
                                fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
                        else
-                               fprintf(f, "\tINT_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->arraylength, prop->identifier);
+                               fprintf(f, "\tINT_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->totarraylength, prop->identifier);
                        break;
                }
                case PROP_FLOAT: {
-                       if(!prop->arraylength)
+                       if(!prop->arraydimension)
                                fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
                        else
-                               fprintf(f, "\tFLOAT_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->arraylength, prop->identifier);
+                               fprintf(f, "\tFLOAT_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->totarraylength, prop->identifier);
                        break;
                }
                case PROP_ENUM: {
@@ -1175,13 +1384,14 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
        StructRNA *srna;
        FunctionRNA *func;
        PropertyDefRNA *dparm;
-       char *funcname, *ptrstr;
-       int first;
+       PropertyType type;
+       char *funcname, *ptrstr, *valstr;
+       int flag, pout, cptr, first;
 
        srna= dsrna->srna;
        func= dfunc->func;
 
-       if(func->flag & FUNC_REGISTER)
+       if(!dfunc->call)
                return;
 
        funcname= rna_alloc_function_name(srna->identifier, func->identifier, "call");
@@ -1192,24 +1402,51 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
 
        /* variable definitions */
        if((func->flag & FUNC_NO_SELF)==0) {
+               if(func->flag & FUNC_USE_SELF_ID)
+                       fprintf(f, "\tstruct ID *_selfid;\n");
+
                if(dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname);
                else fprintf(f, "\tstruct %s *_self;\n", srna->identifier);
        }
 
        dparm= dfunc->cont.properties.first;
        for(; dparm; dparm= dparm->next) {
-               ptrstr= (dparm->prop->type == PROP_POINTER || dparm->prop->arraylength > 0)? "*" : "";
+               type = dparm->prop->type;
+               flag = dparm->prop->flag;
+               pout = (flag & PROP_OUTPUT);
+               cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
+
+               if(dparm->prop==func->c_ret)
+                       ptrstr= cptr || dparm->prop->arraydimension ? "*" : "";
+               /* XXX only arrays and strings are allowed to be dynamic, is this checked anywhere? */
+               else if (cptr || (flag & PROP_DYNAMIC))
+                       ptrstr= pout ? "**" : "*";
+               /* fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack, pass a pointer to it */
+               else if (type == PROP_POINTER || dparm->prop->arraydimension)
+                       ptrstr= "*";
+               /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack, but type name for string props is already char*, so leave empty */
+               else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
+                       ptrstr= "";
+               else
+                       ptrstr= pout ? "*" : "";
+
                fprintf(f, "\t%s%s %s%s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier);
+
+               /* for dynamic parameters we pass an additional int for the length of the parameter */
+               if (flag & PROP_DYNAMIC)
+                       fprintf(f, "\tint %s%s_len;\n", pout ? "*" : "", dparm->prop->identifier);
        }
 
        fprintf(f, "\tchar *_data");
-       if(func->ret) fprintf(f, ", *_retdata");
+       if(func->c_ret) fprintf(f, ", *_retdata");
        fprintf(f, ";\n");
-       if(func->ret && (func->ret->flag & PROP_DYNAMIC_ARRAY)) fprintf(f, "\tint _ret_array_length;\n");
        fprintf(f, "\t\n");
 
        /* assign self */
        if((func->flag & FUNC_NO_SELF)==0) {
+               if(func->flag & FUNC_USE_SELF_ID)
+                       fprintf(f, "\t_selfid= (struct ID*)_ptr->id.data;\n");
+
                if(dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname);
                else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier);
        }
@@ -1218,32 +1455,59 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
 
        dparm= dfunc->cont.properties.first;
        for(; dparm; dparm= dparm->next) {
-               if(dparm->prop==func->ret) 
+               type = dparm->prop->type;
+               flag = dparm->prop->flag;
+               pout = (flag & PROP_OUTPUT);
+               cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
+
+               if(dparm->prop==func->c_ret)
                        fprintf(f, "\t_retdata= _data;\n");
-               else if(dparm->prop->arraylength)
-                       fprintf(f, "\t%s= ((%s%s*)_data);\n", dparm->prop->identifier, rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
-               else if(dparm->prop->type == PROP_POINTER) {
-                       if(dparm->prop->flag & PROP_RNAPTR)
-                               fprintf(f, "\t%s= ((%s%s*)_data);\n", dparm->prop->identifier, rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
-                       else
-                               fprintf(f, "\t%s= *((%s%s**)_data);\n", dparm->prop->identifier, rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
+               else  {
+                       if (cptr || (flag & PROP_DYNAMIC)) {
+                               ptrstr= "**";
+                               valstr= "*";
+                       }
+                       else if (type == PROP_POINTER || dparm->prop->arraydimension) {
+                               ptrstr= "*";
+                               valstr= "";
+                       }
+                       else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
+                               ptrstr= "";
+                               valstr= "";
+                       }
+                       else {
+                               ptrstr= "*";
+                               valstr= "*";
+                       }
+
+                       fprintf(f, "\t%s= ", dparm->prop->identifier);
+
+                       if (!pout)
+                               fprintf(f, "%s", valstr);
+
+                       fprintf(f, "((%s%s%s)_data);\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr);
+
+                       /* this must be kept in sync with RNA_parameter_length_get_data, we could just call the function directly, but this is faster */
+                       if (flag & PROP_DYNAMIC)
+                               fprintf(f, "\t%s_len= %s((int *)(_data+%d));\n", dparm->prop->identifier, pout ? "" : "*", rna_parameter_size(dparm->prop));
                }
-               else
-                       fprintf(f, "\t%s= *((%s%s*)_data);\n", dparm->prop->identifier, rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
 
                if(dparm->next)
-                       fprintf(f, "\t_data+= %d;\n", rna_parameter_size(dparm->prop));
+                       fprintf(f, "\t_data+= %d;\n", rna_parameter_size_alloc(dparm->prop));
        }
 
        if(dfunc->call) {
                fprintf(f, "\t\n");
                fprintf(f, "\t");
-               if(func->ret) fprintf(f, "%s= ", func->ret->identifier);
+               if(func->c_ret) fprintf(f, "%s= ", func->c_ret->identifier);
                fprintf(f, "%s(", dfunc->call);
 
                first= 1;
 
                if((func->flag & FUNC_NO_SELF)==0) {
+                       if(func->flag & FUNC_USE_SELF_ID)
+                               fprintf(f, "_selfid, ");
+
                        fprintf(f, "_self");
                        first= 0;
                }
@@ -1260,33 +1524,26 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
                        fprintf(f, "reports");
                }
 
-               if(func->ret && (func->ret->flag & PROP_DYNAMIC_ARRAY)) {
-                       if(!first) fprintf(f, ", ");
-                       first= 0;
-                       fprintf(f, "&_ret_array_length");
-               }
-
                dparm= dfunc->cont.properties.first;
                for(; dparm; dparm= dparm->next) {
-                       if(dparm->prop==func->ret)
+                       if(dparm->prop==func->c_ret)
                                continue;
 
                        if(!first) fprintf(f, ", ");
                        first= 0;
 
                        fprintf(f, "%s", dparm->prop->identifier);
+
+                       if (dparm->prop->flag & PROP_DYNAMIC)
+                               fprintf(f, ", %s_len", dparm->prop->identifier);
                }
 
                fprintf(f, ");\n");
 
-               if(func->ret) {
-                       dparm= rna_find_parameter_def(func->ret);
-                       ptrstr= dparm->prop->type == PROP_POINTER || dparm->prop->arraylength > 0 ? "*" : "";
-                       fprintf(f, "\t*((%s%s%s*)_retdata)= %s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, func->ret->identifier);
-
-                       if(func->ret && (func->ret->flag & PROP_DYNAMIC_ARRAY)) {
-                               fprintf(f, "\t_parms->func->ret->arraylength= _ret_array_length;\n");
-                       }
+               if(func->c_ret) {
+                       dparm= rna_find_parameter_def(func->c_ret);
+                       ptrstr= (((dparm->prop->type == PROP_POINTER) && !(dparm->prop->flag & PROP_RNAPTR)) || (dparm->prop->arraydimension))? "*": "";
+                       fprintf(f, "\t*((%s%s%s*)_retdata)= %s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, func->c_ret->identifier);
                }
        }
 
@@ -1326,8 +1583,8 @@ static void rna_auto_types()
                                else if(dp->prop->type== PROP_COLLECTION) {
                                        CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
 
-                                       if(!cprop->type && !cprop->get && strcmp(dp->dnatype, "ListBase")==0)
-                                               cprop->type= (StructRNA*)rna_find_type(dp->dnatype);
+                                       if(!cprop->item_type && !cprop->get && strcmp(dp->dnatype, "ListBase")==0)
+                                               cprop->item_type= (StructRNA*)rna_find_type(dp->dnatype);
                                }
                        }
                }
@@ -1381,15 +1638,52 @@ static const char *rna_property_subtypename(PropertyType type)
 {
        switch(type) {
                case PROP_NONE: return "PROP_NONE";
-               case PROP_UNSIGNED: return "PROP_UNSIGNED";
                case PROP_FILEPATH: return "PROP_FILEPATH";
+               case PROP_FILENAME: return "PROP_FILENAME";
                case PROP_DIRPATH: return "PROP_DIRPATH";
+               case PROP_UNSIGNED: return "PROP_UNSIGNED";
+               case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
+               case PROP_FACTOR: return "PROP_FACTOR";
+               case PROP_ANGLE: return "PROP_ANGLE";
+               case PROP_TIME: return "PROP_TIME";
+               case PROP_DISTANCE: return "PROP_DISTANCE";
                case PROP_COLOR: return "PROP_COLOR";
-               case PROP_VECTOR: return "PROP_VECTOR";
+               case PROP_TRANSLATION: return "PROP_TRANSLATION";
+               case PROP_DIRECTION: return "PROP_DIRECTION";
                case PROP_MATRIX: return "PROP_MATRIX";
-               case PROP_ROTATION: return "PROP_ROTATION";
-               case PROP_NEVER_NULL: return "PROP_NEVER_NULL";
-               case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
+               case PROP_EULER: return "PROP_EULER";
+               case PROP_QUATERNION: return "PROP_QUATERNION";
+               case PROP_AXISANGLE: return "PROP_AXISANGLE";
+               case PROP_VELOCITY: return "PROP_VELOCITY";
+               case PROP_ACCELERATION: return "PROP_ACCELERATION";
+               case PROP_XYZ: return "PROP_XYZ";
+               case PROP_COLOR_GAMMA: return "PROP_COLOR_GAMMA";
+               case PROP_LAYER: return "PROP_LAYER";
+               case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
+               default: {
+                       /* incase we dont have a type preset that includes the subtype */
+                       if(RNA_SUBTYPE_UNIT(type)) {
+                               return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
+                       }
+                       else {
+                               return "PROP_SUBTYPE_UNKNOWN";
+                       }
+               }
+       }
+}
+
+static const char *rna_property_subtype_unit(PropertyType type)
+{
+       switch(RNA_SUBTYPE_UNIT(type)) {
+               case PROP_UNIT_NONE:            return "PROP_UNIT_NONE";
+               case PROP_UNIT_LENGTH:          return "PROP_UNIT_LENGTH";
+               case PROP_UNIT_AREA:            return "PROP_UNIT_AREA";
+               case PROP_UNIT_VOLUME:          return "PROP_UNIT_VOLUME";
+               case PROP_UNIT_MASS:            return "PROP_UNIT_MASS";
+               case PROP_UNIT_ROTATION:        return "PROP_UNIT_ROTATION";
+               case PROP_UNIT_TIME:            return "PROP_UNIT_TIME";
+               case PROP_UNIT_VELOCITY:        return "PROP_UNIT_VELOCITY";
+               case PROP_UNIT_ACCELERATION:return "PROP_UNIT_ACCELERATION";
                default: return "PROP_UNKNOWN";
        }
 }
@@ -1484,17 +1778,19 @@ static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA
        FunctionRNA *func;
        PropertyDefRNA *dparm;
        StructDefRNA *dsrna;
-       int first;
+       PropertyType type;
+       int flag, pout, cptr, first;
+       char *ptrstr;
 
        dsrna= rna_find_struct_def(srna);
        func= dfunc->func;
 
        /* return type */
        for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
-               if(dparm->prop==func->ret) {
-                       if(dparm->prop->arraylength && !(dparm->prop->flag & PROP_DYNAMIC_ARRAY))
-                               fprintf(f, "\"XXX array return types only allowed with PROP_DYNAMIC_ARRAY flag.\""); /* XXX not supported */
-                       else if(dparm->prop->type == PROP_POINTER || (dparm->prop->flag & PROP_DYNAMIC_ARRAY))
+               if(dparm->prop==func->c_ret) {
+                       if(dparm->prop->arraydimension)
+                               fprintf(f, "XXX no array return types yet"); /* XXX not supported */
+                       else if(dparm->prop->type == PROP_POINTER && !(dparm->prop->flag & PROP_RNAPTR))
                                fprintf(f, "%s%s *", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
                        else
                                fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
@@ -1514,6 +1810,9 @@ static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA
 
        /* self, context and reports parameters */
        if((func->flag & FUNC_NO_SELF)==0) {
+               if(func->flag & FUNC_USE_SELF_ID)
+                       fprintf(f, "struct ID *_selfid, ");
+
                if(dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname);
                else fprintf(f, "struct %s *_self", srna->identifier);
                first= 0;
@@ -1531,27 +1830,35 @@ static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA
                fprintf(f, "ReportList *reports");
        }
 
-       /* dynamic array length paramter */
-       if(func->ret && (func->ret->flag & PROP_DYNAMIC_ARRAY)) {
-               if(!first) fprintf(f, ", ");
-               first= 0;
-               fprintf(f, "int *array_length");
-       }
-
        /* defined parameters */
        for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
-               if(dparm->prop==func->ret)
+               type = dparm->prop->type;
+               flag = dparm->prop->flag;
+               pout = (flag & PROP_OUTPUT);
+               cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
+
+               if(dparm->prop==func->c_ret)
                        continue;
 
+               if (cptr || (flag & PROP_DYNAMIC))
+                       ptrstr= pout ? "**" : "*";
+               else if (type == PROP_POINTER || dparm->prop->arraydimension)
+                       ptrstr= "*";
+               else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
+                       ptrstr= "";
+               else
+                       ptrstr= pout ? "*" : "";
+
                if(!first) fprintf(f, ", ");
                first= 0;
 
-               if(dparm->prop->arraylength)
-                       fprintf(f, "%s%s %s[%d]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier, dparm->prop->arraylength);
-               else if(dparm->prop->type == PROP_POINTER)
-                       fprintf(f, "%s%s *%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier);
+               if(!(flag & PROP_DYNAMIC) && dparm->prop->arraydimension)
+                       fprintf(f, "%s%s %s[%d]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier, dparm->prop->totarraylength);
                else
-                       fprintf(f, "%s%s %s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier);
+                       fprintf(f, "%s%s %s%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier);
+
+               if (flag & PROP_DYNAMIC)
+                       fprintf(f, ", int %s%s_len", pout ? "*" : "", dparm->prop->identifier);
        }
 
        fprintf(f, ");\n");
@@ -1561,16 +1868,19 @@ static void rna_generate_static_function_prototypes(BlenderRNA *brna, StructRNA
 {
        FunctionRNA *func;
        FunctionDefRNA *dfunc;
-
-       fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
+       int first= 1;
 
        for(func= srna->functions.first; func; func= func->cont.next) {
-               if(func->flag & FUNC_REGISTER)
-                       continue;
-
                dfunc= rna_find_function_def(func);
-               if(dfunc->call)
+
+               if(dfunc->call) {
+                       if(first) {
+                               fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
+                               first= 0;
+                       }
+
                        rna_generate_static_parameter_prototypes(brna, srna, dfunc, f);
+               }
        }
 
        fprintf(f, "\n");
@@ -1599,21 +1909,21 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                                int i, defaultfound= 0;
 
                                if(eprop->item) {
-                                       fprintf(f, "static EnumPropertyItem rna_%s%s_%s_items[%d] = {", srna->identifier, strnest, prop->identifier, eprop->totitem+1);
+                                       fprintf(f, "static EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t", srna->identifier, strnest, prop->identifier, eprop->totitem+1);
 
                                        for(i=0; i<eprop->totitem; i++) {
                                                fprintf(f, "{%d, ", eprop->item[i].value);
                                                rna_print_c_string(f, eprop->item[i].identifier); fprintf(f, ", ");
                                                fprintf(f, "%d, ", eprop->item[i].icon);
                                                rna_print_c_string(f, eprop->item[i].name); fprintf(f, ", ");
-                                               rna_print_c_string(f, eprop->item[i].description); fprintf(f, "}, ");
+                                               rna_print_c_string(f, eprop->item[i].description); fprintf(f, "},\n\t");
 
                                                if(eprop->item[i].identifier[0])
                                                        if(eprop->defaultvalue == eprop->item[i].value)
                                                                defaultfound= 1;
                                        }
 
-                                       fprintf(f, "{0, NULL, 0, NULL, NULL}};\n\n");
+                                       fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
 
                                        if(!defaultfound) {
                                                fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default is not in items.\n", srna->identifier, errnest, prop->identifier);
@@ -1630,19 +1940,19 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                                BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
                                unsigned int i;
 
-                               if(prop->arraylength) {
-                                       fprintf(f, "static int rna_%s%s_%s_default[%d] = {", srna->identifier, strnest, prop->identifier, prop->arraylength);
+                               if(prop->arraydimension && prop->totarraylength) {
+                                       fprintf(f, "static int rna_%s%s_%s_default[%d] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
 
-                                       for(i=0; i<prop->arraylength; i++) {
+                                       for(i=0; i<prop->totarraylength; i++) {
                                                if(bprop->defaultarray)
                                                        fprintf(f, "%d", bprop->defaultarray[i]);
                                                else
                                                        fprintf(f, "%d", bprop->defaultvalue);
-                                               if(i != prop->arraylength-1)
-                                                       fprintf(f, ", ");
+                                               if(i != prop->totarraylength-1)
+                                                       fprintf(f, ",\n\t");
                                        }
 
-                                       fprintf(f, "};\n\n");
+                                       fprintf(f, "\n};\n\n");
                                }
                                break;
                        }
@@ -1650,19 +1960,19 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                                IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
                                unsigned int i;
 
-                               if(prop->arraylength) {
-                                       fprintf(f, "static int rna_%s%s_%s_default[%d] = {", srna->identifier, strnest, prop->identifier, prop->arraylength);
+                               if(prop->arraydimension && prop->totarraylength) {
+                                       fprintf(f, "static int rna_%s%s_%s_default[%d] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
 
-                                       for(i=0; i<prop->arraylength; i++) {
+                                       for(i=0; i<prop->totarraylength; i++) {
                                                if(iprop->defaultarray)
                                                        fprintf(f, "%d", iprop->defaultarray[i]);
                                                else
                                                        fprintf(f, "%d", iprop->defaultvalue);
-                                               if(i != prop->arraylength-1)
-                                                       fprintf(f, ", ");
+                                               if(i != prop->totarraylength-1)
+                                                       fprintf(f, ",\n\t");
                                        }
 
-                                       fprintf(f, "};\n\n");
+                                       fprintf(f, "\n};\n\n");
                                }
                                break;
                        }
@@ -1670,19 +1980,19 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                                FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
                                unsigned int i;
 
-                               if(prop->arraylength) {
-                                       fprintf(f, "static float rna_%s%s_%s_default[%d] = {", srna->identifier, strnest, prop->identifier, prop->arraylength);
+                               if(prop->arraydimension && prop->totarraylength) {
+                                       fprintf(f, "static float rna_%s%s_%s_default[%d] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
 
-                                       for(i=0; i<prop->arraylength; i++) {
+                                       for(i=0; i<prop->totarraylength; i++) {
                                                if(fprop->defaultarray)
                                                        rna_float_print(f, fprop->defaultarray[i]);
                                                else
                                                        rna_float_print(f, fprop->defaultvalue);
-                                               if(i != prop->arraylength-1)
-                                                       fprintf(f, ", ");
+                                               if(i != prop->totarraylength-1)
+                                                       fprintf(f, ",\n\t");
                                        }
 
-                                       fprintf(f, "};\n\n");
+                                       fprintf(f, "\n};\n\n");
                                }
                                break;
                        }
@@ -1702,18 +2012,23 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
        rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
        rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
        fprintf(f, "%d,\n", prop->icon);
-       fprintf(f, "\t%s, %s, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), prop->arraylength);
-       fprintf(f, "\t%s, %d, %s,\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable));
+       fprintf(f, "\t%s, %s|%s, %s, %d, {%d, %d, %d}, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), rna_property_subtype_unit(prop->subtype), rna_function_string(prop->getlength), prop->arraydimension, prop->arraylength[0], prop->arraylength[1], prop->arraylength[2], prop->totarraylength);
+       fprintf(f, "\t%s%s, %d, %s, %s,\n", (prop->flag & PROP_CONTEXT_UPDATE)? "(UpdateFunc)": "", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable), rna_function_string(prop->itemeditable));
 
        if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);
-       else fprintf(f, "\t0, 0");
+       else fprintf(f, "\t0, -1");
+
+       /* our own type - collections/arrays only */
+       if(prop->srna) fprintf(f, ", &RNA_%s", (char*)prop->srna);
+       else fprintf(f, ", NULL");
+
        fprintf(f, "},\n");
 
        switch(prop->type) {
                        case PROP_BOOLEAN: {
                                BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
                                fprintf(f, "\t%s, %s, %s, %s, %d, ", rna_function_string(bprop->get), rna_function_string(bprop->set), rna_function_string(bprop->getarray), rna_function_string(bprop->setarray), bprop->defaultvalue);
-                               if(prop->arraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
+                               if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
                                else fprintf(f, "NULL\n");
                                break;
                        }
@@ -1726,7 +2041,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                                rna_int_print(f, iprop->hardmax); fprintf(f, ", ");
                                rna_int_print(f, iprop->step); fprintf(f, ", ");
                                rna_int_print(f, iprop->defaultvalue); fprintf(f, ", ");
-                               if(prop->arraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
+                               if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
                                else fprintf(f, "NULL\n");
                                break;
                         }
@@ -1740,7 +2055,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                                rna_float_print(f, fprop->step); fprintf(f, ", ");
                                rna_int_print(f, (int)fprop->precision); fprintf(f, ", ");
                                rna_float_print(f, fprop->defaultvalue); fprintf(f, ", ");
-                               if(prop->arraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
+                               if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
                                else fprintf(f, "NULL\n");
                                break;
                         }
@@ -1770,11 +2085,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                        case PROP_COLLECTION: {
                                CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
                                fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, ", rna_function_string(cprop->begin), rna_function_string(cprop->next), rna_function_string(cprop->end), rna_function_string(cprop->get), rna_function_string(cprop->length), rna_function_string(cprop->lookupint), rna_function_string(cprop->lookupstring));
-                               if(cprop->add) fprintf(f, "&rna_%s_%s_func, ", srna->identifier, (char*)cprop->add);
-                               else fprintf(f, "NULL, ");
-                               if(cprop->remove) fprintf(f, "&rna_%s_%s_func, ", srna->identifier, (char*)cprop->remove);
-                               else fprintf(f, "NULL, ");
-                               if(cprop->type) fprintf(f, "&RNA_%s\n", (char*)cprop->type);
+                               if(cprop->item_type) fprintf(f, "&RNA_%s\n", (char*)cprop->item_type);
                                else fprintf(f, "NULL\n");
                                break;
                        }
@@ -1829,8 +2140,8 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
                dfunc= rna_find_function_def(func);
                if(dfunc->gencall) fprintf(f, "\t%s,\n", dfunc->gencall);
                else fprintf(f, "\tNULL,\n");
-       
-               if(func->ret) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->ret->identifier);
+
+               if(func->c_ret) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
                else fprintf(f, "\tNULL\n");
 
                fprintf(f, "};\n");
@@ -1862,7 +2173,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
        rna_print_c_string(f, srna->name);
        fprintf(f, ", ");
        rna_print_c_string(f, srna->description);
-       fprintf(f, ",\n %d,\n", srna->icon);
+       fprintf(f, ",\n\t%d,\n", srna->icon);
 
        prop= srna->nameproperty;
        if(prop) {
@@ -1921,9 +2232,10 @@ RNAProcessItem PROCESS_ITEMS[]= {
        {"rna_ID.c", NULL, RNA_def_ID},
        {"rna_texture.c", NULL, RNA_def_texture},
        {"rna_action.c", "rna_action_api.c", RNA_def_action},
-       {"rna_animation.c", NULL, RNA_def_animation},
+       {"rna_animation.c", "rna_animation_api.c", RNA_def_animation},
+       {"rna_animviz.c", NULL, RNA_def_animviz},
        {"rna_actuator.c", NULL, RNA_def_actuator},
-       {"rna_armature.c", NULL, RNA_def_armature},
+       {"rna_armature.c", "rna_armature_api.c", RNA_def_armature},
        {"rna_boid.c", NULL, RNA_def_boid},
        {"rna_brush.c", NULL, RNA_def_brush},
        {"rna_camera.c", NULL, RNA_def_camera},
@@ -1933,8 +2245,9 @@ RNAProcessItem PROCESS_ITEMS[]= {
        {"rna_context.c", NULL, RNA_def_context},
        {"rna_controller.c", NULL, RNA_def_controller},
        {"rna_curve.c", NULL, RNA_def_curve},
-       {"rna_fcurve.c", NULL, RNA_def_fcurve},
+       {"rna_fcurve.c", "rna_fcurve_api.c", RNA_def_fcurve},
        {"rna_fluidsim.c", NULL, RNA_def_fluidsim},
+       {"rna_gpencil.c", NULL, RNA_def_gpencil},
        {"rna_group.c", NULL, RNA_def_group},
        {"rna_image.c", "rna_image_api.c", RNA_def_image},
        {"rna_key.c", NULL, RNA_def_key},
@@ -1958,9 +2271,10 @@ RNAProcessItem PROCESS_ITEMS[]= {
        {"rna_screen.c", NULL, RNA_def_screen},
        {"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
        {"rna_sensor.c", NULL, RNA_def_sensor},
-       {"rna_sequence.c", NULL, RNA_def_sequence},
+       {"rna_sequencer.c", NULL, RNA_def_sequencer},
        {"rna_smoke.c", NULL, RNA_def_smoke},
        {"rna_space.c", NULL, RNA_def_space},
+       {"rna_test.c", NULL, RNA_def_test},
        {"rna_text.c", NULL, RNA_def_text},
        {"rna_timeline.c", NULL, RNA_def_timeline_marker},
        {"rna_sound.c", NULL, RNA_def_sound},
@@ -1978,8 +2292,8 @@ static void rna_generate(BlenderRNA *brna, FILE *f, char *filename, char *api_fi
        FunctionDefRNA *dfunc;
        
        fprintf(f, "\n/* Automatically generated struct definitions for the Data API.\n"
-                    "   Do not edit manually, changes will be overwritten.           */\n\n"
-                     "#define RNA_RUNTIME\n\n");
+                                "   Do not edit manually, changes will be overwritten.           */\n\n"
+                                 "#define RNA_RUNTIME\n\n");
 
        fprintf(f, "#include <float.h>\n");
        fprintf(f, "#include <limits.h>\n");
@@ -1987,11 +2301,13 @@ static void rna_generate(BlenderRNA *brna, FILE *f, char *filename, char *api_fi
        fprintf(f, "#include <stddef.h>\n\n");
 
        fprintf(f, "#include \"DNA_ID.h\"\n");
+       fprintf(f, "#include \"DNA_scene_types.h\"\n");
 
        fprintf(f, "#include \"BLI_blenlib.h\"\n\n");
 
        fprintf(f, "#include \"BKE_context.h\"\n");
        fprintf(f, "#include \"BKE_library.h\"\n");
+       fprintf(f, "#include \"BKE_main.h\"\n");
        fprintf(f, "#include \"BKE_report.h\"\n");
        fprintf(f, "#include \"BKE_utildefines.h\"\n\n");
 
@@ -2052,7 +2368,7 @@ static void rna_generate_header(BlenderRNA *brna, FILE *f)
        fprintf(f, "#define __RNA_BLENDER_H__\n\n");
 
        fprintf(f, "/* Automatically generated function declarations for the Data API.\n"
-                    "   Do not edit manually, changes will be overwritten.              */\n\n");
+                                "   Do not edit manually, changes will be overwritten.              */\n\n");
 
        fprintf(f, "#include \"RNA_types.h\"\n\n");
 
@@ -2207,12 +2523,12 @@ static void rna_generate_header_cpp(BlenderRNA *brna, FILE *f)
        fprintf(f, "#define __RNA_BLENDER_CPP_H__\n\n");
 
        fprintf(f, "/* Automatically generated classes for the Data API.\n"
-                    "   Do not edit manually, changes will be overwritten. */\n\n");
+                                "   Do not edit manually, changes will be overwritten. */\n\n");
 
        fprintf(f, "#include \"RNA_blender.h\"\n");
        fprintf(f, "#include \"RNA_types.h\"\n");
 
-       fprintf(f, cpp_classes);
+       fprintf(f, "%s", cpp_classes);
 
        fprintf(f, "/**************** Declarations ****************/\n\n");
 
@@ -2252,10 +2568,10 @@ static void rna_generate_header_cpp(BlenderRNA *brna, FILE *f)
        fprintf(f, "}\n\n#endif /* __RNA_BLENDER_CPP_H__ */\n\n");
 }
 
-static void make_bad_file(char *file)
+static void make_bad_file(char *file, int line)
 {
        FILE *fp= fopen(file, "w");
-       fprintf(fp, "ERROR! Cannot make correct RNA file, STUPID!\n");
+       fprintf(fp, "#error \"Error! can't make correct RNA file from %s:%d, STUPID!\"\n", __FILE__, line);
        fclose(fp);
 }
 
@@ -2285,12 +2601,12 @@ static int rna_preprocess(char *outfile)
 
        /* create RNA_blender_cpp.h */
        strcpy(deffile, outfile);
-       strcat(deffile, "RNA_blender_cpp.h");
+       strcat(deffile, "RNA_blender_cpp.h" TMP_EXT);
 
        status= (DefRNA.error != 0);
 
        if(status) {
-               make_bad_file(deffile);
+               make_bad_file(deffile, __LINE__);
        }
        else {
                file = fopen(deffile, "w");
@@ -2302,11 +2618,12 @@ static int rna_preprocess(char *outfile)
                else {
                        rna_generate_header_cpp(brna, file);
                        fclose(file);
-
                        status= (DefRNA.error != 0);
                }
        }
 
+       replace_if_different(deffile);
+
        rna_sort(brna);
 
        /* create rna_gen_*.c files */
@@ -2314,10 +2631,10 @@ static int rna_preprocess(char *outfile)
                strcpy(deffile, outfile);
                strcat(deffile, PROCESS_ITEMS[i].filename);
                deffile[strlen(deffile)-2] = '\0';
-               strcat(deffile, "_gen.c");
+               strcat(deffile, "_gen.c" TMP_EXT);
 
                if(status) {
-                       make_bad_file(deffile);
+                       make_bad_file(deffile, __LINE__);
                }
                else {
                        file = fopen(deffile, "w");
@@ -2329,18 +2646,19 @@ static int rna_preprocess(char *outfile)
                        else {
                                rna_generate(brna, file, PROCESS_ITEMS[i].filename, PROCESS_ITEMS[i].api_filename);
                                fclose(file);
-
                                status= (DefRNA.error != 0);
                        }
                }
+
+               replace_if_different(deffile);
        }
 
        /* create RNA_blender.h */
        strcpy(deffile, outfile);
-       strcat(deffile, "RNA_blender.h");
+       strcat(deffile, "RNA_blender.h" TMP_EXT);
 
        if(status) {
-               make_bad_file(deffile);
+               make_bad_file(deffile, __LINE__);
        }
        else {
                file = fopen(deffile, "w");
@@ -2352,11 +2670,12 @@ static int rna_preprocess(char *outfile)
                else {
                        rna_generate_header(brna, file);
                        fclose(file);
-
                        status= (DefRNA.error != 0);
                }
        }
 
+       replace_if_different(deffile);
+
        /* free RNA */
        RNA_define_free(brna);
        RNA_free(brna);
@@ -2364,7 +2683,7 @@ static int rna_preprocess(char *outfile)
        return status;
 }
 
-static void mem_error_cb(char *errorStr)
+static void mem_error_cb(const char *errorStr)
 {
        fprintf(stderr, "%s", errorStr);
        fflush(stderr);