Raise an exception when registering classes with ID names which are too long. (relate...
[blender-staging.git] / source / blender / python / intern / bpy_rna.c
index 8f745bc2756fc6faa3a4a779037795970a013745..e75d898d3aa151258369c1e076d83178b6061acb 100644 (file)
@@ -1071,17 +1071,19 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
                case PROP_STRING:
                {
                        const char *param;
+                       Py_ssize_t param_size= 0;
 #ifdef USE_STRING_COERCE
                        PyObject *value_coerce= NULL;
                        int subtype= RNA_property_subtype(prop);
                        if(ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
+                               /* TODO, get size */
                                param= PyC_UnicodeAsByte(value, &value_coerce);
                        }
                        else {
-                               param= _PyUnicode_AsString(value);
+                               param= _PyUnicode_AsStringAndSize(value, &param_size);
                        }
 #else // USE_STRING_COERCE
-                       param= _PyUnicode_AsString(value);
+                       param= _PyUnicode_AsStringAndSize(value, &param_size);
 #endif // USE_STRING_COERCE
 
                        if (param==NULL) {
@@ -1090,7 +1092,19 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
                        }
                        else {
                                if(data)        *((char**)data)= (char *)param; /*XXX, this is suspect but needed for function calls, need to see if theres a better way */
-                               else            RNA_property_string_set(ptr, prop, param);
+                               else {
+                                       if(RNA_property_flag(prop) & PROP_NEVER_CLAMP) {
+                                               int param_size_max= RNA_property_string_maxlength(prop);
+                                               if(param_size > param_size_max) {
+                                                       PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s only supports a string of length %d, found %d", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), param_size, param_size_max);
+                                                       return -1;
+                                               }
+#ifdef USE_STRING_COERCE
+                                               Py_XDECREF(value_coerce);
+#endif // USE_STRING_COERCE
+                                       }
+                                       RNA_property_string_set(ptr, prop, param);
+                               }
                        }
 #ifdef USE_STRING_COERCE
                        Py_XDECREF(value_coerce);