[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41191] trunk/blender/source/blender: py api - added PyC_UnicodeFromByteAndSize() to match PyUnicode_FromStringAndSize()

Campbell Barton ideasman42 at gmail.com
Sat Oct 22 12:49:36 CEST 2011


Revision: 41191
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41191
Author:   campbellbarton
Date:     2011-10-22 10:49:35 +0000 (Sat, 22 Oct 2011)
Log Message:
-----------
py api - added PyC_UnicodeFromByteAndSize() to match PyUnicode_FromStringAndSize()
also made RNA_property_string_get_alloc() return the length of the new string to avoid having to run strlen on it after.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/anim_ipo_utils.c
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_layout.c
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/editors/space_buttons/buttons_context.c
    trunk/blender/source/blender/editors/space_buttons/buttons_ops.c
    trunk/blender/source/blender/editors/space_outliner/outliner_edit.c
    trunk/blender/source/blender/editors/space_outliner/outliner_tree.c
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/python/generic/IDProp.c
    trunk/blender/source/blender/python/generic/py_capi_utils.c
    trunk/blender/source/blender/python/generic/py_capi_utils.h
    trunk/blender/source/blender/python/intern/bpy_interface.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/editors/animation/anim_ipo_utils.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_ipo_utils.c	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/editors/animation/anim_ipo_utils.c	2011-10-22 10:49:35 UTC (rev 41191)
@@ -118,7 +118,7 @@
 				PropertyRNA *nameprop= RNA_struct_name_property(ptr.type);
 				if (nameprop) {
 					/* this gets a string which will need to be freed */
-					structname= RNA_property_string_get_alloc(&ptr, nameprop, NULL, 0);
+					structname= RNA_property_string_get_alloc(&ptr, nameprop, NULL, 0, NULL);
 					free_structname= 1;
 				}
 				else

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/editors/interface/interface.c	2011-10-22 10:49:35 UTC (rev 41191)
@@ -1593,17 +1593,18 @@
 	if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
 		PropertyType type;
 		char *buf= NULL;
+		int buf_len;
 
 		type= RNA_property_type(but->rnaprop);
 
 		if(type == PROP_STRING) {
 			/* RNA string */
-			buf= RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, maxlen);
+			buf= RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, maxlen, &buf_len);
 		}
 		else if(type == PROP_POINTER) {
 			/* RNA pointer */
 			PointerRNA ptr= RNA_property_pointer_get(&but->rnapoin, but->rnaprop);
-			buf= RNA_struct_name_get_alloc(&ptr, str, maxlen);
+			buf= RNA_struct_name_get_alloc(&ptr, str, maxlen, &buf_len);
 		}
 
 		if(!buf) {
@@ -1611,7 +1612,7 @@
 		}
 		else if(buf && buf != str) {
 			/* string was too long, we have to truncate */
-			BLI_strncpy(str, buf, maxlen);
+			memcpy(str, buf, MIN2(maxlen, buf_len+1));
 			MEM_freeN(buf);
 		}
 	}

Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_layout.c	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/editors/interface/interface_layout.c	2011-10-22 10:49:35 UTC (rev 41191)
@@ -1221,7 +1221,7 @@
 			iconid= ui_id_icon_get((bContext*)C, id, 1);
 		}
 		else {
-			name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
+			name= RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL); /* could use the string length here */
 			iconid = 0;
 		}
 

Modified: trunk/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_templates.c	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/editors/interface/interface_templates.c	2011-10-22 10:49:35 UTC (rev 41191)
@@ -2085,7 +2085,7 @@
 	if(icon == ICON_NONE || icon == ICON_DOT)
 		icon= 0;
 
-	namebuf= RNA_struct_name_get_alloc(itemptr, NULL, 0);
+	namebuf= RNA_struct_name_get_alloc(itemptr, NULL, 0, NULL);
 	name= (namebuf)? namebuf: "";
 
 	/* hardcoded types */
@@ -2270,7 +2270,7 @@
 
 				if(found) {
 					/* create button */
-					name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
+					name= RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL);
 					icon= list_item_icon_get(C, &itemptr, rnaicon, 0);
 					uiItemL(row, (name)? name: "", icon);
 

Modified: trunk/blender/source/blender/editors/space_buttons/buttons_context.c
===================================================================
--- trunk/blender/source/blender/editors/space_buttons/buttons_context.c	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/editors/space_buttons/buttons_context.c	2011-10-22 10:49:35 UTC (rev 41191)
@@ -925,7 +925,7 @@
 
 		if(ptr->data) {
 			icon= RNA_struct_ui_icon(ptr->type);
-			name= RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf));
+			name= RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf), NULL);
 
 			if(name) {
 				if(!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE) && ptr->type == &RNA_Scene)

Modified: trunk/blender/source/blender/editors/space_buttons/buttons_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_buttons/buttons_ops.c	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/editors/space_buttons/buttons_ops.c	2011-10-22 10:49:35 UTC (rev 41191)
@@ -169,7 +169,7 @@
 	if(!prop)
 		return OPERATOR_CANCELLED;
 
-	str= RNA_property_string_get_alloc(&ptr, prop, NULL, 0);
+	str= RNA_property_string_get_alloc(&ptr, prop, NULL, 0, NULL);
 
 	/* useful yet irritating feature, Shift+Click to open the file
 	 * Alt+Click to browse a folder in the OS's browser */

Modified: trunk/blender/source/blender/editors/space_outliner/outliner_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_outliner/outliner_edit.c	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/editors/space_outliner/outliner_edit.c	2011-10-22 10:49:35 UTC (rev 41191)
@@ -1021,7 +1021,7 @@
 					/* tsenext= TREESTORE(temnext); */ /* UNUSED */
 					
 					nextptr= &temnext->rnaptr;
-					name= RNA_struct_name_get_alloc(nextptr, buf, sizeof(buf));
+					name= RNA_struct_name_get_alloc(nextptr, buf, sizeof(buf), NULL);
 					
 					if(name) {
 						/* if possible, use name as a key in the path */

Modified: trunk/blender/source/blender/editors/space_outliner/outliner_tree.c
===================================================================
--- trunk/blender/source/blender/editors/space_outliner/outliner_tree.c	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/editors/space_outliner/outliner_tree.c	2011-10-22 10:49:35 UTC (rev 41191)
@@ -972,7 +972,7 @@
 		}
 		else if(type == TSE_RNA_STRUCT) {
 			/* struct */
-			te->name= RNA_struct_name_get_alloc(ptr, NULL, 0);
+			te->name= RNA_struct_name_get_alloc(ptr, NULL, 0, NULL);
 
 			if(te->name)
 				te->flag |= TE_FREE_NAME;

Modified: trunk/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_access.h	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/makesrna/RNA_access.h	2011-10-22 10:49:35 UTC (rev 41191)
@@ -648,7 +648,7 @@
 FunctionRNA *RNA_struct_find_function(PointerRNA *ptr, const char *identifier);
 const struct ListBase *RNA_struct_type_functions(StructRNA *srna);
 
-char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen);
+char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len);
 
 /* Properties
  *
@@ -755,7 +755,7 @@
 float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index);
 
 void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value);
-char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen);
+char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len);
 void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value);
 int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop);
 void RNA_property_string_get_default(PointerRNA *ptr, PropertyRNA *prop, char *value);

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2011-10-22 10:49:35 UTC (rev 41191)
@@ -748,12 +748,12 @@
 	srna->blender_type= blender_type;
 }
 
-char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen)
+char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
 {
 	PropertyRNA *nameprop;
 
 	if(ptr->data && (nameprop = RNA_struct_name_property(ptr->type)))
-		return RNA_property_string_get_alloc(ptr, nameprop, fixedbuf, fixedlen);
+		return RNA_property_string_get_alloc(ptr, nameprop, fixedbuf, fixedlen, r_len);
 
 	return NULL;
 }
@@ -2276,7 +2276,8 @@
 		strcpy(value, sprop->defaultvalue);
 }
 
-char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen)
+char *RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop,
+                                    char *fixedbuf, int fixedlen, int *r_len)
 {
 	char *buf;
 	int length;
@@ -2301,6 +2302,10 @@
 	BLI_assert(buf[length] == '\0');
 #endif
 
+	if (r_len) {
+		*r_len= length;
+	}
+
 	return buf;
 }
 
@@ -2836,15 +2841,17 @@
 		PropertyRNA *nameprop;
 		char name[256], *nameptr;
 		int found= 0;
+		int keylen= strlen(key);
+		int namelen;
 
 		RNA_property_collection_begin(ptr, prop, &iter);
 		for(; iter.valid; RNA_property_collection_next(&iter)) {
 			if(iter.ptr.data && iter.ptr.type->nameproperty) {
 				nameprop= iter.ptr.type->nameproperty;
 
-				nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name));
+				nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name), &namelen);
 
-				if(strcmp(nameptr, key) == 0) {
+				if((keylen == namelen) && (strcmp(nameptr, key) == 0)) {
 					*r_ptr= iter.ptr;
 					found= 1;
 				}
@@ -4254,7 +4261,7 @@
 	PropertyRNA *prop= RNA_struct_find_property(ptr, name);
 
 	if(prop) {
-		return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen);
+		return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, NULL); /* TODO, pass length */
 	}
 	else {
 		printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
@@ -5442,7 +5449,7 @@
 		}
 		case PROP_STRING:
 		{
-			char *value= RNA_property_string_get_alloc(fromptr, prop, NULL, 0);
+			char *value= RNA_property_string_get_alloc(fromptr, prop, NULL, 0, NULL);
 			RNA_property_string_set(ptr, prop, value);
 			MEM_freeN(value);
 			return 1;

Modified: trunk/blender/source/blender/python/generic/IDProp.c
===================================================================
--- trunk/blender/source/blender/python/generic/IDProp.c	2011-10-22 09:28:10 UTC (rev 41190)
+++ trunk/blender/source/blender/python/generic/IDProp.c	2011-10-22 10:49:35 UTC (rev 41191)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list