Revision: 17932
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17932
Author:   campbellbarton
Date:     2008-12-19 00:34:19 +0100 (Fri, 19 Dec 2008)

Log Message:
-----------
Small RNA changes
* rna_validate_identifier now checks identifiers are not python keywords such 
as if, and, from (builtins like max, object and sort are ok)
* rna_validate_identifier prints an error explaining why it fails
* renamed Struct's "from" to "base" - to point to the struct inherited from.
* renamed ImageUsers's "pass" and "layer" to "renderPass" and "renderLayer"
* use the identifier as the key for ENUM's (matching structs and properties)

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_image.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_key.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c

Modified: 
branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c     
2008-12-18 23:23:09 UTC (rev 17931)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c     
2008-12-18 23:34:19 UTC (rev 17932)
@@ -166,19 +166,46 @@
        return 0;
 }
 
-static int rna_validate_identifier(const char *identifier)
+static int rna_validate_identifier(const char *identifier, char *error)
 {
        int a=0;
        
+       /*  list from 
http://docs.python.org/reference/lexical_analysis.html#id5 */
+       static char *kwlist[] = {
+               "and", "as", "assert", "break",
+               "class", "continue", "def", "del",
+               "elif", "else", "except", "exec",
+               "finally", "for", "from", "global",
+               "if", "import", "in", "is",
+               "lambda", "not", "or", "pass",
+               "print", "raise", "return", "try",
+               "while", "with", "yield", NULL
+       };
+       
+       
        if (!isalpha(identifier[0])) {
+               strcpy(error, "first character failed isalpha() check");
                return 0;
        }
        
        for(a=1; identifier[a] != '\0'; a++) {
-               if (identifier[a]=='_')                 continue;
-               if (isalnum(identifier[a])==0)  return 0;
+               if (identifier[a]=='_') {
+                       continue;
+               }
+               
+               if (isalnum(identifier[a])==0) {
+                       strcpy(error, "one of the characters failed an 
isalnum() check and is not an underscore");
+                       return 0;
+               }
        }
        
+       for(a=0; kwlist[a]; a++) {
+               if (strcmp(identifier, kwlist[a]) == 0) {
+                       strcpy(error, "this keyword is reserved by python");
+                       return 0;
+               }
+       }
+       
        return 1;
 }
 
@@ -299,8 +326,9 @@
        PropertyRNA *prop, *propfrom;
        
        if(DefRNA.preprocess) {
-               if (rna_validate_identifier(identifier) == 0) {
-                       fprintf(stderr, "RNA_def_struct: struct identifier 
\"%s\" is an invalid name\n", identifier);
+               char error[512];
+               if (rna_validate_identifier(identifier, error) == 0) {
+                       fprintf(stderr, "RNA_def_struct: struct identifier 
\"%s\" error - %s\n", identifier, error);
                        DefRNA.error= 1;
                }
        }
@@ -524,9 +552,10 @@
        PropertyRNA *prop;
 
        if(DefRNA.preprocess) {
+               char error[512];
                
-               if (rna_validate_identifier(identifier) == 0) {
-                       fprintf(stderr, "RNA_def_property: property identifier 
\"%s\" is an invalid name\n", identifier);
+               if (rna_validate_identifier(identifier, error) == 0) {
+                       fprintf(stderr, "RNA_def_property: property identifier 
\"%s\" - %s\n", identifier, error);
                        DefRNA.error= 1;
                        return NULL;
                }

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_image.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_image.c      
2008-12-18 23:23:09 UTC (rev 17931)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_image.c      
2008-12-18 23:34:19 UTC (rev 17932)
@@ -72,11 +72,13 @@
        RNA_def_property_range(prop, -MAXFRAMEF, MAXFRAMEF);
        RNA_def_property_ui_text(prop, "Fields per Frame", "The number of 
fields per rendered frame (2 fields is 1 image).");
 
-       prop= RNA_def_property(srna, "layer", PROP_INT, PROP_UNSIGNED);
+       prop= RNA_def_property(srna, "renderLayer", PROP_INT, PROP_UNSIGNED);
+       RNA_def_property_int_sdna(prop, NULL, "layer");
        RNA_def_property_flag(prop, PROP_NOT_EDITABLE); /* image_multi_cb */
        RNA_def_property_ui_text(prop, "Layer", "Layer in multilayer image.");
 
-       prop= RNA_def_property(srna, "pass", PROP_INT, PROP_UNSIGNED);
+       prop= RNA_def_property(srna, "renderPass", PROP_INT, PROP_UNSIGNED);
+       RNA_def_property_int_sdna(prop, NULL, "pass");
        RNA_def_property_flag(prop, PROP_NOT_EDITABLE); /* image_multi_cb */
        RNA_def_property_ui_text(prop, "Pass", "Pass in multilayer image.");
 }

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_key.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_key.c        
2008-12-18 23:23:09 UTC (rev 17931)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_key.c        
2008-12-18 23:34:19 UTC (rev 17932)
@@ -326,8 +326,9 @@
 
        rna_def_ipo_common(srna);
 
-       prop= RNA_def_property(srna, "from", PROP_POINTER, PROP_NONE);
-       RNA_def_property_ui_text(prop, "From", "Datablock using these shape 
keys.");
+       prop= RNA_def_property(srna, "user", PROP_POINTER, PROP_NONE);
+       RNA_def_property_pointer_sdna(prop, NULL, "from");
+       RNA_def_property_ui_text(prop, "User", "Datablock using these shape 
keys.");
 
        prop= RNA_def_property(srna, "relative", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "type", KEY_RELATIVE);

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c        
2008-12-18 23:23:09 UTC (rev 17931)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c        
2008-12-18 23:34:19 UTC (rev 17932)
@@ -52,7 +52,7 @@
        return strlen(((StructRNA*)ptr->data)->name);
 }
 
-static void *rna_Struct_from_get(PointerRNA *ptr)
+static void *rna_Struct_base_get(PointerRNA *ptr)
 {
        return ((StructRNA*)ptr->data)->from;
 }
@@ -400,11 +400,11 @@
        RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the 
code and scripting.");
        RNA_def_struct_name_property(srna, prop);
        
-       prop= RNA_def_property(srna, "from", PROP_POINTER, PROP_NONE);
+       prop= RNA_def_property(srna, "base", PROP_POINTER, PROP_NONE);
        RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
        RNA_def_property_struct_type(prop, "Struct");
-       RNA_def_property_pointer_funcs(prop, "rna_Struct_from_get", NULL, NULL);
-       RNA_def_property_ui_text(prop, "From", "Struct definition this is 
derived from.");
+       RNA_def_property_pointer_funcs(prop, "rna_Struct_base_get", NULL, NULL);
+       RNA_def_property_ui_text(prop, "base", "Struct definition this is 
derived from.");
 
        prop= RNA_def_property(srna, "name_property", PROP_POINTER, PROP_NONE);
        RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
@@ -551,12 +551,12 @@
        RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
        RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_name_get", 
"rna_EnumPropertyItem_name_length", NULL);
        RNA_def_property_ui_text(prop, "Name", "Human readable name.");
-       RNA_def_struct_name_property(srna, prop);
 
        prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
        RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
        RNA_def_property_string_funcs(prop, 
"rna_EnumPropertyItem_identifier_get", 
"rna_EnumPropertyItem_identifier_length", NULL);
        RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the 
code and scripting.");
+       RNA_def_struct_name_property(srna, prop);
 
        prop= RNA_def_property(srna, "value", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_flag(prop, PROP_NOT_EDITABLE);


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to