Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/intern/bpy_rna.c
| Show First 20 Lines • Show All 1,416 Lines • ▼ Show 20 Lines | else { | ||||
| RNA_property_enum_items(NULL, ptr, prop, &enum_item, NULL, &free); | RNA_property_enum_items(NULL, ptr, prop, &enum_item, NULL, &free); | ||||
| /* Do not print warning in case of DummyRNA_NULL_items, this one will never match any value... */ | /* Do not print warning in case of DummyRNA_NULL_items, this one will never match any value... */ | ||||
| if (enum_item != DummyRNA_NULL_items) { | if (enum_item != DummyRNA_NULL_items) { | ||||
| const char *ptr_name = RNA_struct_name_get_alloc(ptr, NULL, 0, NULL); | const char *ptr_name = RNA_struct_name_get_alloc(ptr, NULL, 0, NULL); | ||||
| /* prefer not fail silently in case of api errors, maybe disable it later */ | /* prefer not fail silently in case of api errors, maybe disable it later */ | ||||
| CLOG_WARN(BPY_LOG_RNA, | CLOG_WARN(BPY_LOG_RNA, | ||||
| "Current value \"%d\" " | "current value '%d' " | ||||
| "matches no enum in '%s', '%s', '%s'\n", | "matches no enum in '%s', '%s', '%s'", | ||||
| val, RNA_struct_identifier(ptr->type), | val, RNA_struct_identifier(ptr->type), | ||||
| ptr_name, RNA_property_identifier(prop)); | ptr_name, RNA_property_identifier(prop)); | ||||
| #if 0 /* gives python decoding errors while generating docs :( */ | #if 0 /* gives python decoding errors while generating docs :( */ | ||||
| char error_str[256]; | char error_str[256]; | ||||
| BLI_snprintf(error_str, sizeof(error_str), | BLI_snprintf(error_str, sizeof(error_str), | ||||
| "RNA Warning: Current value \"%d\" " | "RNA Warning: Current value \"%d\" " | ||||
| "matches no enum in '%s', '%s', '%s'", | "matches no enum in '%s', '%s', '%s'", | ||||
| ▲ Show 20 Lines • Show All 5,169 Lines • ▼ Show 20 Lines | static PyObject *pyrna_srna_ExternalType(StructRNA *srna) | ||||
| PyObject *newclass; | PyObject *newclass; | ||||
| if (bpy_types_dict == NULL) { | if (bpy_types_dict == NULL) { | ||||
| PyObject *bpy_types = PyImport_ImportModuleLevel("bpy_types", NULL, NULL, NULL, 0); | PyObject *bpy_types = PyImport_ImportModuleLevel("bpy_types", NULL, NULL, NULL, 0); | ||||
| if (bpy_types == NULL) { | if (bpy_types == NULL) { | ||||
| PyErr_Print(); | PyErr_Print(); | ||||
| PyErr_Clear(); | PyErr_Clear(); | ||||
| CLOG_ERROR(BPY_LOG_RNA, "failed to find 'bpy_types' module\n"); | CLOG_ERROR(BPY_LOG_RNA, "failed to find 'bpy_types' module"); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| bpy_types_dict = PyModule_GetDict(bpy_types); /* borrow */ | bpy_types_dict = PyModule_GetDict(bpy_types); /* borrow */ | ||||
| Py_DECREF(bpy_types); /* fairly safe to assume the dict is kept */ | Py_DECREF(bpy_types); /* fairly safe to assume the dict is kept */ | ||||
| } | } | ||||
| newclass = PyDict_GetItemString(bpy_types_dict, idname); | newclass = PyDict_GetItemString(bpy_types_dict, idname); | ||||
| /* sanity check, could skip this unless in debug mode */ | /* sanity check, could skip this unless in debug mode */ | ||||
| if (newclass) { | if (newclass) { | ||||
| PyObject *base_compare = pyrna_srna_PyBase(srna); | PyObject *base_compare = pyrna_srna_PyBase(srna); | ||||
| //PyObject *slots = PyObject_GetAttrString(newclass, "__slots__"); // cant do this because it gets superclasses values! | //PyObject *slots = PyObject_GetAttrString(newclass, "__slots__"); // cant do this because it gets superclasses values! | ||||
| //PyObject *bases = PyObject_GetAttrString(newclass, "__bases__"); // can do this but faster not to. | //PyObject *bases = PyObject_GetAttrString(newclass, "__bases__"); // can do this but faster not to. | ||||
| PyObject *tp_bases = ((PyTypeObject *)newclass)->tp_bases; | PyObject *tp_bases = ((PyTypeObject *)newclass)->tp_bases; | ||||
| PyObject *tp_slots = PyDict_GetItem(((PyTypeObject *)newclass)->tp_dict, bpy_intern_str___slots__); | PyObject *tp_slots = PyDict_GetItem(((PyTypeObject *)newclass)->tp_dict, bpy_intern_str___slots__); | ||||
| if (tp_slots == NULL) { | if (tp_slots == NULL) { | ||||
| CLOG_ERROR(BPY_LOG_RNA, "expected class '%s' to have __slots__ defined, see bpy_types.py\n", idname); | CLOG_ERROR(BPY_LOG_RNA, "expected class '%s' to have __slots__ defined, see bpy_types.py", idname); | ||||
| newclass = NULL; | newclass = NULL; | ||||
| } | } | ||||
| else if (PyTuple_GET_SIZE(tp_bases)) { | else if (PyTuple_GET_SIZE(tp_bases)) { | ||||
| PyObject *base = PyTuple_GET_ITEM(tp_bases, 0); | PyObject *base = PyTuple_GET_ITEM(tp_bases, 0); | ||||
| if (base_compare != base) { | if (base_compare != base) { | ||||
| char pyob_info[256]; | char pyob_info[256]; | ||||
| PyC_ObSpitStr(pyob_info, sizeof(pyob_info), base_compare); | PyC_ObSpitStr(pyob_info, sizeof(pyob_info), base_compare); | ||||
| CLOG_ERROR(BPY_LOG_RNA, | CLOG_ERROR(BPY_LOG_RNA, | ||||
| "incorrect subclassing of SRNA '%s', expected '%s', see bpy_types.py\n", | "incorrect subclassing of SRNA '%s', expected '%s', see bpy_types.py", | ||||
| idname, pyob_info); | idname, pyob_info); | ||||
| newclass = NULL; | newclass = NULL; | ||||
| } | } | ||||
| else { | else { | ||||
| CLOG_INFO(BPY_LOG_RNA, 2, "SRNA sub-classed: '%s'\n", idname); | CLOG_INFO(BPY_LOG_RNA, 2, "SRNA sub-classed: '%s'", idname); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return newclass; | return newclass; | ||||
| } | } | ||||
| static PyObject *pyrna_srna_Subtype(StructRNA *srna) | static PyObject *pyrna_srna_Subtype(StructRNA *srna) | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | if (newclass) { | ||||
| /* srna owns one, and the other is owned by the caller */ | /* srna owns one, and the other is owned by the caller */ | ||||
| pyrna_subtype_set_rna(newclass, srna); | pyrna_subtype_set_rna(newclass, srna); | ||||
| /* XXX, adding this back segfaults blender on load. */ | /* XXX, adding this back segfaults blender on load. */ | ||||
| // Py_DECREF(newclass); /* let srna own */ | // Py_DECREF(newclass); /* let srna own */ | ||||
| } | } | ||||
| else { | else { | ||||
| /* this should not happen */ | /* this should not happen */ | ||||
| CLOG_ERROR(BPY_LOG_RNA, "error registering '%s'", idname); | CLOG_ERROR(BPY_LOG_RNA, "failed to register '%s'", idname); | ||||
| PyErr_Print(); | PyErr_Print(); | ||||
| PyErr_Clear(); | PyErr_Clear(); | ||||
| } | } | ||||
| } | } | ||||
| return newclass; | return newclass; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 856 Lines • ▼ Show 20 Lines | #ifdef USE_PEDANTIC_WRITE | ||||
| // const char *func_id = RNA_function_identifier(func); /* UNUSED */ | // const char *func_id = RNA_function_identifier(func); /* UNUSED */ | ||||
| /* testing, for correctness, not operator and not draw function */ | /* testing, for correctness, not operator and not draw function */ | ||||
| const bool is_readonly = !(RNA_function_flag(func) & FUNC_ALLOW_WRITE); | const bool is_readonly = !(RNA_function_flag(func) & FUNC_ALLOW_WRITE); | ||||
| #endif | #endif | ||||
| py_class = RNA_struct_py_type_get(ptr->type); | py_class = RNA_struct_py_type_get(ptr->type); | ||||
| /* rare case. can happen when registering subclasses */ | /* rare case. can happen when registering subclasses */ | ||||
| if (py_class == NULL) { | if (py_class == NULL) { | ||||
| CLOG_WARN(BPY_LOG_RNA, "unable to get Python class for rna struct '%.200s'\n", RNA_struct_identifier(ptr->type)); | CLOG_WARN(BPY_LOG_RNA, "unable to get Python class for rna struct '%.200s'", RNA_struct_identifier(ptr->type)); | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| /* XXX, this is needed because render engine calls without a context | /* XXX, this is needed because render engine calls without a context | ||||
| * this should be supported at some point but at the moment its not! */ | * this should be supported at some point but at the moment its not! */ | ||||
| if (C == NULL) | if (C == NULL) | ||||
| C = BPy_GetContext(); | C = BPy_GetContext(); | ||||
| ▲ Show 20 Lines • Show All 712 Lines • Show Last 20 Lines | |||||