Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-12-19 02:34:19 +0300
committerCampbell Barton <ideasman42@gmail.com>2008-12-19 02:34:19 +0300
commit9178dc859638815ec38d9b95d2df723892c1af38 (patch)
treee8bbe634c47785fae6d74e67daaf9e88dd9eeb1f
parent1dcbafa4e449818c54af34c33d1b97c5c49d6336 (diff)
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)
-rw-r--r--source/blender/makesrna/intern/rna_define.c43
-rw-r--r--source/blender/makesrna/intern/rna_image.c6
-rw-r--r--source/blender/makesrna/intern/rna_key.c5
-rw-r--r--source/blender/makesrna/intern/rna_rna.c10
4 files changed, 48 insertions, 16 deletions
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 16acb73193a..849bc9a1447 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -166,17 +166,44 @@ static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *
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 @@ StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *
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 *RNA_def_property(StructRNA *srna, const char *identifier, int type,
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;
}
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index 2a41961ca00..07e0e2c2bd6 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -72,11 +72,13 @@ static void rna_def_imageuser(BlenderRNA *brna)
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.");
}
diff --git a/source/blender/makesrna/intern/rna_key.c b/source/blender/makesrna/intern/rna_key.c
index 5726ad93244..ee0308c3782 100644
--- a/source/blender/makesrna/intern/rna_key.c
+++ b/source/blender/makesrna/intern/rna_key.c
@@ -326,8 +326,9 @@ static void rna_def_key(BlenderRNA *brna)
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);
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index e287a523de3..7f5a78b9303 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -52,7 +52,7 @@ static int rna_Struct_name_length(PointerRNA *ptr)
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 @@ static void rna_def_struct(BlenderRNA *brna)
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 @@ static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna)
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);