Cleanup: Python, Clang-Tidy else-after-return fixes

This addresses warnings from Clang-Tidy's `readability-else-after-return`
rule in the `source/blender/python` module.

No functional changes.
This commit is contained in:
Sybren A. Stüvel
2020-08-07 12:41:06 +02:00
parent 44b7354742
commit 3d48d99647
29 changed files with 1799 additions and 2051 deletions

View File

@@ -118,22 +118,20 @@ static PyObject *bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type),
"get the dictionary from the function passed");
return NULL;
}
else {
/* set id */
if (*dict_ptr == NULL) {
*dict_ptr = PyDict_New();
}
PyDict_SetItemString(*dict_ptr, PERMINENT_CB_ID, Py_None);
/* set id */
if (*dict_ptr == NULL) {
*dict_ptr = PyDict_New();
}
PyDict_SetItemString(*dict_ptr, PERMINENT_CB_ID, Py_None);
Py_INCREF(value);
return value;
}
else {
PyErr_SetString(PyExc_ValueError, "bpy.app.handlers.persistent expected a function");
return NULL;
}
PyErr_SetString(PyExc_ValueError, "bpy.app.handlers.persistent expected a function");
return NULL;
}
/* dummy type because decorators can't be PyCFunctions */

View File

@@ -83,9 +83,8 @@ int bpy_pydriver_create_dict(void)
if (d == NULL) {
return -1;
}
else {
bpy_pydriver_Dict = d;
}
bpy_pydriver_Dict = d;
/* import some modules: builtins, bpy, math, (Blender.noise)*/
PyDict_SetItemString(d, "__builtins__", PyEval_GetBuiltins());
@@ -680,11 +679,8 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna,
if (isfinite(result)) {
return (float)result;
}
else {
fprintf(stderr,
"\tBPY_driver_eval() - driver '%s' evaluates to '%f'\n",
driver->expression,
result);
return 0.0f;
}
fprintf(
stderr, "\tBPY_driver_eval() - driver '%s' evaluates to '%f'\n", driver->expression, result);
return 0.0f;
}

View File

@@ -244,21 +244,20 @@ static PyObject *bpy_lib_enter(BPy_Library *self)
}
return NULL;
}
else {
int i = 0, code;
while ((code = BKE_idtype_idcode_iter_step(&i))) {
if (BKE_idtype_idcode_is_linkable(code)) {
const char *name_plural = BKE_idtype_idcode_to_name_plural(code);
PyObject *str = PyUnicode_FromString(name_plural);
PyObject *item;
PyDict_SetItem(self->dict, str, item = PyList_New(0));
Py_DECREF(item);
PyDict_SetItem(from_dict, str, item = _bpy_names(self, code));
Py_DECREF(item);
int i = 0, code;
while ((code = BKE_idtype_idcode_iter_step(&i))) {
if (BKE_idtype_idcode_is_linkable(code)) {
const char *name_plural = BKE_idtype_idcode_to_name_plural(code);
PyObject *str = PyUnicode_FromString(name_plural);
PyObject *item;
Py_DECREF(str);
}
PyDict_SetItem(self->dict, str, item = PyList_New(0));
Py_DECREF(item);
PyDict_SetItem(from_dict, str, item = _bpy_names(self, code));
Py_DECREF(item);
Py_DECREF(str);
}
}
@@ -393,65 +392,64 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
return NULL;
}
else {
Library *lib = mainl->curlib; /* newly added lib, assign before append end */
BLO_library_link_end(mainl, &(self->blo_handle), self->flag, NULL, NULL, NULL, NULL);
BLO_blendhandle_close(self->blo_handle);
self->blo_handle = NULL;
GHash *old_to_new_ids = BLI_ghash_ptr_new(__func__);
Library *lib = mainl->curlib; /* newly added lib, assign before append end */
BLO_library_link_end(mainl, &(self->blo_handle), self->flag, NULL, NULL, NULL, NULL);
BLO_blendhandle_close(self->blo_handle);
self->blo_handle = NULL;
/* copied from wm_operator.c */
{
/* mark all library linked objects to be updated */
BKE_main_lib_objects_recalc_all(bmain);
GHash *old_to_new_ids = BLI_ghash_ptr_new(__func__);
/* append, rather than linking */
if (do_append) {
BKE_library_make_local(bmain, lib, old_to_new_ids, true, false);
}
/* copied from wm_operator.c */
{
/* mark all library linked objects to be updated */
BKE_main_lib_objects_recalc_all(bmain);
/* append, rather than linking */
if (do_append) {
BKE_library_make_local(bmain, lib, old_to_new_ids, true, false);
}
}
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
/* finally swap the capsules for real bpy objects
* important since BLO_library_append_end initializes NodeTree types used by srna->refine */
/* finally swap the capsules for real bpy objects
* important since BLO_library_append_end initializes NodeTree types used by srna->refine */
#ifdef USE_RNA_DATABLOCKS
{
int idcode_step = 0, idcode;
while ((idcode = BKE_idtype_idcode_iter_step(&idcode_step))) {
if (BKE_idtype_idcode_is_linkable(idcode) && (idcode != ID_WS || do_append)) {
const char *name_plural = BKE_idtype_idcode_to_name_plural(idcode);
PyObject *ls = PyDict_GetItemString(self->dict, name_plural);
if (ls && PyList_Check(ls)) {
Py_ssize_t size = PyList_GET_SIZE(ls);
Py_ssize_t i;
PyObject *item;
{
int idcode_step = 0, idcode;
while ((idcode = BKE_idtype_idcode_iter_step(&idcode_step))) {
if (BKE_idtype_idcode_is_linkable(idcode) && (idcode != ID_WS || do_append)) {
const char *name_plural = BKE_idtype_idcode_to_name_plural(idcode);
PyObject *ls = PyDict_GetItemString(self->dict, name_plural);
if (ls && PyList_Check(ls)) {
Py_ssize_t size = PyList_GET_SIZE(ls);
Py_ssize_t i;
PyObject *item;
for (i = 0; i < size; i++) {
item = PyList_GET_ITEM(ls, i);
if (PyCapsule_CheckExact(item)) {
PointerRNA id_ptr;
ID *id;
for (i = 0; i < size; i++) {
item = PyList_GET_ITEM(ls, i);
if (PyCapsule_CheckExact(item)) {
PointerRNA id_ptr;
ID *id;
id = PyCapsule_GetPointer(item, NULL);
id = BLI_ghash_lookup_default(old_to_new_ids, id, id);
Py_DECREF(item);
id = PyCapsule_GetPointer(item, NULL);
id = BLI_ghash_lookup_default(old_to_new_ids, id, id);
Py_DECREF(item);
RNA_id_pointer_create(id, &id_ptr);
item = pyrna_struct_CreatePyObject(&id_ptr);
PyList_SET_ITEM(ls, i, item);
}
RNA_id_pointer_create(id, &id_ptr);
item = pyrna_struct_CreatePyObject(&id_ptr);
PyList_SET_ITEM(ls, i, item);
}
}
}
}
}
}
#endif /* USE_RNA_DATABLOCKS */
BLI_ghash_free(old_to_new_ids, NULL, NULL);
Py_RETURN_NONE;
}
BLI_ghash_free(old_to_new_ids, NULL, NULL);
Py_RETURN_NONE;
}
static PyObject *bpy_lib_dir(BPy_Library *self)

View File

@@ -1408,9 +1408,8 @@ static bool py_long_as_int(PyObject *py_long, int *r_int)
*r_int = (int)PyLong_AS_LONG(py_long);
return true;
}
else {
return false;
}
return false;
}
#if 0
@@ -1716,16 +1715,15 @@ static int bpy_prop_callback_check(PyObject *py_func, const char *keyword, int a
Py_TYPE(py_func)->tp_name);
return -1;
}
else {
PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func);
if (f_code->co_argcount != argcount) {
PyErr_Format(PyExc_TypeError,
"%s keyword: expected a function taking %d arguments, not %d",
keyword,
argcount,
f_code->co_argcount);
return -1;
}
PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func);
if (f_code->co_argcount != argcount) {
PyErr_Format(PyExc_TypeError,
"%s keyword: expected a function taking %d arguments, not %d",
keyword,
argcount,
f_code->co_argcount);
return -1;
}
}
@@ -1981,7 +1979,7 @@ static void bpy_prop_callback_assign_enum(struct PropertyRNA *prop,
Py_DECREF(args); \
return ret; \
} \
else if (PyTuple_GET_SIZE(args) > 1) { \
if (PyTuple_GET_SIZE(args) > 1) { \
PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \
return NULL; \
} \
@@ -3537,7 +3535,7 @@ static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw
Py_DECREF(args);
return ret;
}
else if (PyTuple_GET_SIZE(args) > 1) {
if (PyTuple_GET_SIZE(args) > 1) {
PyErr_SetString(PyExc_ValueError, "expected one positional arg, one keyword arg");
return NULL;
}
@@ -3546,27 +3544,27 @@ static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw
if (srna == NULL && PyErr_Occurred()) {
return NULL; /* self's type was compatible but error getting the srna */
}
else if (srna == NULL) {
if (srna == NULL) {
PyErr_SetString(PyExc_TypeError, "RemoveProperty(): struct rna not available for this type");
return NULL;
}
else {
const char *id = NULL;
static const char *_keywords[] = {
"attr",
NULL,
};
static _PyArg_Parser _parser = {"s:RemoveProperty", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &id)) {
return NULL;
}
const char *id = NULL;
if (RNA_def_property_free_identifier(srna, id) != 1) {
PyErr_Format(PyExc_TypeError, "RemoveProperty(): '%s' not a defined dynamic property", id);
return NULL;
}
static const char *_keywords[] = {
"attr",
NULL,
};
static _PyArg_Parser _parser = {"s:RemoveProperty", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &id)) {
return NULL;
}
if (RNA_def_property_free_identifier(srna, id) != 1) {
PyErr_Format(PyExc_TypeError, "RemoveProperty(): '%s' not a defined dynamic property", id);
return NULL;
}
Py_RETURN_NONE;
}

View File

@@ -987,24 +987,23 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self)
PyErr_SetString(PyExc_RuntimeError, "could not use property type, internal error");
return NULL;
}
else {
/* This should never fail. */
int len = -1;
char *c = type_fmt;
while ((*c++ = tolower(*type_id++))) {
}
/* This should never fail. */
int len = -1;
char *c = type_fmt;
if (type == PROP_COLLECTION) {
len = pyrna_prop_collection_length(self);
}
else if (RNA_property_array_check(self->prop)) {
len = pyrna_prop_array_length((BPy_PropertyArrayRNA *)self);
}
while ((*c++ = tolower(*type_id++))) {
}
if (len != -1) {
sprintf(--c, "[%d]", len);
}
if (type == PROP_COLLECTION) {
len = pyrna_prop_collection_length(self);
}
else if (RNA_property_array_check(self->prop)) {
len = pyrna_prop_array_length((BPy_PropertyArrayRNA *)self);
}
if (len != -1) {
sprintf(--c, "[%d]", len);
}
/* If a pointer, try to print name of pointer target too. */
@@ -1246,17 +1245,16 @@ static int pyrna_string_to_enum(
Py_TYPE(item)->tp_name);
return -1;
}
else {
if (!RNA_property_enum_value(BPy_GetContext(), ptr, prop, param, r_value)) {
const char *enum_str = pyrna_enum_as_string(ptr, prop);
PyErr_Format(PyExc_TypeError,
"%.200s enum \"%.200s\" not found in (%s)",
error_prefix,
param,
enum_str);
MEM_freeN((void *)enum_str);
return -1;
}
if (!RNA_property_enum_value(BPy_GetContext(), ptr, prop, param, r_value)) {
const char *enum_str = pyrna_enum_as_string(ptr, prop);
PyErr_Format(PyExc_TypeError,
"%.200s enum \"%.200s\" not found in (%s)",
error_prefix,
param,
enum_str);
MEM_freeN((void *)enum_str);
return -1;
}
return 0;
@@ -1715,14 +1713,14 @@ static int pyrna_py_to_prop(
Py_TYPE(value)->tp_name);
return -1;
}
else {
if (data) {
*((bool *)data) = param;
}
else {
RNA_property_boolean_set(ptr, prop, param);
}
if (data) {
*((bool *)data) = param;
}
else {
RNA_property_boolean_set(ptr, prop, param);
}
break;
}
case PROP_INT: {
@@ -1737,7 +1735,7 @@ static int pyrna_py_to_prop(
RNA_property_identifier(prop));
return -1;
}
else if (param == -1 && PyErr_Occurred()) {
if (param == -1 && PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError,
"%.200s %.200s.%.200s expected an int type, not %.200s",
error_prefix,
@@ -1746,16 +1744,16 @@ static int pyrna_py_to_prop(
Py_TYPE(value)->tp_name);
return -1;
}
else {
int param_i = (int)param;
if (data) {
RNA_property_int_clamp(ptr, prop, &param_i);
*((int *)data) = param_i;
}
else {
RNA_property_int_set(ptr, prop, param_i);
}
int param_i = (int)param;
if (data) {
RNA_property_int_clamp(ptr, prop, &param_i);
*((int *)data) = param_i;
}
else {
RNA_property_int_set(ptr, prop, param_i);
}
break;
}
case PROP_FLOAT: {
@@ -1769,15 +1767,15 @@ static int pyrna_py_to_prop(
Py_TYPE(value)->tp_name);
return -1;
}
else {
if (data) {
RNA_property_float_clamp(ptr, prop, (float *)&param);
*((float *)data) = param;
}
else {
RNA_property_float_set(ptr, prop, param);
}
if (data) {
RNA_property_float_clamp(ptr, prop, (float *)&param);
*((float *)data) = param;
}
else {
RNA_property_float_set(ptr, prop, param);
}
break;
}
case PROP_STRING: {
@@ -1835,19 +1833,18 @@ static int pyrna_py_to_prop(
return -1;
}
else {
if (data) {
if (RNA_property_flag(prop) & PROP_THICK_WRAP) {
BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop));
}
else {
*((char **)data) = (char *)param;
}
if (data) {
if (RNA_property_flag(prop) & PROP_THICK_WRAP) {
BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop));
}
else {
RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value));
*((char **)data) = (char *)param;
}
}
else {
RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value));
}
}
else {
/* Unicode String. */
@@ -1886,22 +1883,22 @@ static int pyrna_py_to_prop(
return -1;
}
else {
/* Same as bytes. */
/* XXX, this is suspect, but needed for function calls,
* need to see if there's a better way. */
if (data) {
if (RNA_property_flag(prop) & PROP_THICK_WRAP) {
BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop));
}
else {
*((char **)data) = (char *)param;
}
/* Same as bytes. */
/* XXX, this is suspect, but needed for function calls,
* need to see if there's a better way. */
if (data) {
if (RNA_property_flag(prop) & PROP_THICK_WRAP) {
BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop));
}
else {
RNA_property_string_set(ptr, prop, param);
*((char **)data) = (char *)param;
}
}
else {
RNA_property_string_set(ptr, prop, param);
}
#ifdef USE_STRING_COERCE
Py_XDECREF(value_coerce);
#endif /* USE_STRING_COERCE */
@@ -1971,7 +1968,7 @@ static int pyrna_py_to_prop(
PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
return pyrna_pydict_to_props(&opptr, value, false, error_prefix);
}
else if (base_type == &RNA_GizmoProperties) {
if (base_type == &RNA_GizmoProperties) {
PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
return pyrna_pydict_to_props(&opptr, value, false, error_prefix);
}
@@ -2008,7 +2005,7 @@ static int pyrna_py_to_prop(
Py_XDECREF(value_new);
return -1;
}
else if ((flag & PROP_NEVER_NULL) && value == Py_None) {
if ((flag & PROP_NEVER_NULL) && value == Py_None) {
PyErr_Format(PyExc_TypeError,
"%.200s %.200s.%.200s does not support a 'None' assignment %.200s type",
error_prefix,
@@ -2018,8 +2015,8 @@ static int pyrna_py_to_prop(
Py_XDECREF(value_new);
return -1;
}
else if ((value != Py_None) && ((flag & PROP_ID_SELF_CHECK) &&
ptr->owner_id == ((BPy_StructRNA *)value)->ptr.owner_id)) {
if ((value != Py_None) && ((flag & PROP_ID_SELF_CHECK) &&
ptr->owner_id == ((BPy_StructRNA *)value)->ptr.owner_id)) {
PyErr_Format(PyExc_TypeError,
"%.200s %.200s.%.200s ID type does not support assignment to itself",
error_prefix,
@@ -2028,85 +2025,84 @@ static int pyrna_py_to_prop(
Py_XDECREF(value_new);
return -1;
}
else {
BPy_StructRNA *param = (BPy_StructRNA *)value;
bool raise_error = false;
if (data) {
if (flag_parameter & PARM_RNAPTR) {
if (flag & PROP_THICK_WRAP) {
if (value == Py_None) {
memset(data, 0, sizeof(PointerRNA));
}
else if (RNA_struct_is_a(param->ptr.type, ptr_type)) {
*((PointerRNA *)data) = param->ptr;
}
else {
raise_error = true;
}
BPy_StructRNA *param = (BPy_StructRNA *)value;
bool raise_error = false;
if (data) {
if (flag_parameter & PARM_RNAPTR) {
if (flag & PROP_THICK_WRAP) {
if (value == Py_None) {
memset(data, 0, sizeof(PointerRNA));
}
else if (RNA_struct_is_a(param->ptr.type, ptr_type)) {
*((PointerRNA *)data) = param->ptr;
}
else {
/* For function calls, we sometimes want to pass the 'ptr' directly,
* but watch out that it remains valid!
* We could possibly support this later if needed. */
BLI_assert(value_new == NULL);
if (value == Py_None) {
*((void **)data) = NULL;
}
else if (RNA_struct_is_a(param->ptr.type, ptr_type)) {
*((PointerRNA **)data) = &param->ptr;
}
else {
raise_error = true;
}
raise_error = true;
}
}
else if (value == Py_None) {
*((void **)data) = NULL;
}
else if (RNA_struct_is_a(param->ptr.type, ptr_type)) {
*((void **)data) = param->ptr.data;
}
else {
raise_error = true;
/* For function calls, we sometimes want to pass the 'ptr' directly,
* but watch out that it remains valid!
* We could possibly support this later if needed. */
BLI_assert(value_new == NULL);
if (value == Py_None) {
*((void **)data) = NULL;
}
else if (RNA_struct_is_a(param->ptr.type, ptr_type)) {
*((PointerRNA **)data) = &param->ptr;
}
else {
raise_error = true;
}
}
}
else if (value == Py_None) {
*((void **)data) = NULL;
}
else if (RNA_struct_is_a(param->ptr.type, ptr_type)) {
*((void **)data) = param->ptr.data;
}
else {
raise_error = true;
}
}
else {
/* Data == NULL, assign to RNA. */
if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type)) {
ReportList reports;
BKE_reports_init(&reports, RPT_STORE);
RNA_property_pointer_set(
ptr, prop, value == Py_None ? PointerRNA_NULL : param->ptr, &reports);
int err = (BPy_reports_to_error(&reports, PyExc_RuntimeError, true));
if (err == -1) {
Py_XDECREF(value_new);
return -1;
}
}
else {
/* Data == NULL, assign to RNA. */
if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type)) {
ReportList reports;
BKE_reports_init(&reports, RPT_STORE);
RNA_property_pointer_set(
ptr, prop, value == Py_None ? PointerRNA_NULL : param->ptr, &reports);
int err = (BPy_reports_to_error(&reports, PyExc_RuntimeError, true));
if (err == -1) {
Py_XDECREF(value_new);
return -1;
}
}
else {
raise_error = true;
}
raise_error = true;
}
}
if (raise_error) {
if (pyrna_struct_validity_check(param) == -1) {
/* Error set. */
}
else {
PointerRNA tmp;
RNA_pointer_create(NULL, ptr_type, NULL, &tmp);
PyErr_Format(PyExc_TypeError,
"%.200s %.200s.%.200s expected a %.200s type, not %.200s",
error_prefix,
RNA_struct_identifier(ptr->type),
RNA_property_identifier(prop),
RNA_struct_identifier(tmp.type),
RNA_struct_identifier(param->ptr.type));
}
Py_XDECREF(value_new);
return -1;
if (raise_error) {
if (pyrna_struct_validity_check(param) == -1) {
/* Error set. */
}
else {
PointerRNA tmp;
RNA_pointer_create(NULL, ptr_type, NULL, &tmp);
PyErr_Format(PyExc_TypeError,
"%.200s %.200s.%.200s expected a %.200s type, not %.200s",
error_prefix,
RNA_struct_identifier(ptr->type),
RNA_property_identifier(prop),
RNA_struct_identifier(tmp.type),
RNA_struct_identifier(param->ptr.type));
}
Py_XDECREF(value_new);
return -1;
}
Py_XDECREF(value_new);
@@ -2295,9 +2291,8 @@ static Py_ssize_t pyrna_prop_array_length(BPy_PropertyArrayRNA *self)
if (RNA_property_array_dimension(&self->ptr, self->prop, NULL) > 1) {
return RNA_property_multi_array_length(&self->ptr, self->prop, self->arraydim);
}
else {
return RNA_property_array_length(&self->ptr, self->prop);
}
return RNA_property_array_length(&self->ptr, self->prop);
}
static Py_ssize_t pyrna_prop_collection_length(BPy_PropertyRNA *self)
@@ -2356,25 +2351,24 @@ static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_s
if (RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum_abs, &newptr)) {
return pyrna_struct_CreatePyObject(&newptr);
}
else {
const int len = RNA_property_collection_length(&self->ptr, self->prop);
if (keynum_abs >= len) {
PyErr_Format(PyExc_IndexError,
"bpy_prop_collection[index]: "
"index %d out of range, size %d",
keynum,
len);
}
else {
PyErr_Format(PyExc_RuntimeError,
"bpy_prop_collection[index]: internal error, "
"valid index %d given in %d sized collection, but value not found",
keynum_abs,
len);
}
return NULL;
const int len = RNA_property_collection_length(&self->ptr, self->prop);
if (keynum_abs >= len) {
PyErr_Format(PyExc_IndexError,
"bpy_prop_collection[index]: "
"index %d out of range, size %d",
keynum,
len);
}
else {
PyErr_Format(PyExc_RuntimeError,
"bpy_prop_collection[index]: internal error, "
"valid index %d given in %d sized collection, but value not found",
keynum_abs,
len);
}
return NULL;
}
/* Values type must have been already checked. */
@@ -2473,79 +2467,76 @@ static int pyrna_prop_collection_subscript_str_lib_pair_ptr(BPy_PropertyRNA *sel
PyTuple_GET_SIZE(key));
return -1;
}
else if (self->ptr.type != &RNA_BlendData) {
if (self->ptr.type != &RNA_BlendData) {
PyErr_Format(PyExc_KeyError,
"%s: is only valid for bpy.data collections, not %.200s",
err_prefix,
RNA_struct_identifier(self->ptr.type));
return -1;
}
else if ((keyname = _PyUnicode_AsString(PyTuple_GET_ITEM(key, 0))) == NULL) {
if ((keyname = _PyUnicode_AsString(PyTuple_GET_ITEM(key, 0))) == NULL) {
PyErr_Format(PyExc_KeyError,
"%s: id must be a string, not %.200s",
err_prefix,
Py_TYPE(PyTuple_GET_ITEM(key, 0))->tp_name);
return -1;
}
else {
PyObject *keylib = PyTuple_GET_ITEM(key, 1);
Library *lib;
bool found = false;
if (keylib == Py_None) {
lib = NULL;
}
else if (PyUnicode_Check(keylib)) {
Main *bmain = self->ptr.data;
const char *keylib_str = _PyUnicode_AsString(keylib);
lib = BLI_findstring(&bmain->libraries, keylib_str, offsetof(Library, filepath));
if (lib == NULL) {
if (err_not_found) {
PyErr_Format(PyExc_KeyError,
"%s: lib name '%.240s' "
"does not reference a valid library",
err_prefix,
keylib_str);
return -1;
}
else {
return 0;
}
PyObject *keylib = PyTuple_GET_ITEM(key, 1);
Library *lib;
bool found = false;
if (keylib == Py_None) {
lib = NULL;
}
else if (PyUnicode_Check(keylib)) {
Main *bmain = self->ptr.data;
const char *keylib_str = _PyUnicode_AsString(keylib);
lib = BLI_findstring(&bmain->libraries, keylib_str, offsetof(Library, filepath));
if (lib == NULL) {
if (err_not_found) {
PyErr_Format(PyExc_KeyError,
"%s: lib name '%.240s' "
"does not reference a valid library",
err_prefix,
keylib_str);
return -1;
}
}
else {
PyErr_Format(PyExc_KeyError,
"%s: lib must be a string or None, not %.200s",
err_prefix,
Py_TYPE(keylib)->tp_name);
return -1;
}
/* lib is either a valid pointer or NULL,
* either way can do direct comparison with id.lib */
RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) {
ID *id = itemptr.data; /* Always an ID. */
if (id->lib == lib && (STREQLEN(keyname, id->name + 2, sizeof(id->name) - 2))) {
found = true;
if (r_ptr) {
*r_ptr = itemptr;
}
break;
}
}
RNA_PROP_END;
/* We may want to fail silently as with collection.get(). */
if ((found == false) && err_not_found) {
/* Only runs for getitem access so use fixed string. */
PyErr_SetString(PyExc_KeyError, "bpy_prop_collection[key, lib]: not found");
return -1;
}
else {
return found; /* 1 / 0, no exception. */
return 0;
}
}
else {
PyErr_Format(PyExc_KeyError,
"%s: lib must be a string or None, not %.200s",
err_prefix,
Py_TYPE(keylib)->tp_name);
return -1;
}
/* lib is either a valid pointer or NULL,
* either way can do direct comparison with id.lib */
RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) {
ID *id = itemptr.data; /* Always an ID. */
if (id->lib == lib && (STREQLEN(keyname, id->name + 2, sizeof(id->name) - 2))) {
found = true;
if (r_ptr) {
*r_ptr = itemptr;
}
break;
}
}
RNA_PROP_END;
/* We may want to fail silently as with collection.get(). */
if ((found == false) && err_not_found) {
/* Only runs for getitem access so use fixed string. */
PyErr_SetString(PyExc_KeyError, "bpy_prop_collection[key, lib]: not found");
return -1;
}
return found; /* 1 / 0, no exception. */
}
static PyObject *pyrna_prop_collection_subscript_str_lib_pair(BPy_PropertyRNA *self,
@@ -2560,9 +2551,8 @@ static PyObject *pyrna_prop_collection_subscript_str_lib_pair(BPy_PropertyRNA *s
if (contains == 1) {
return pyrna_struct_CreatePyObject(&ptr);
}
else {
return NULL;
}
return NULL;
}
static PyObject *pyrna_prop_collection_subscript_slice(BPy_PropertyRNA *self,
@@ -2707,7 +2697,7 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject
if (PyUnicode_Check(key)) {
return pyrna_prop_collection_subscript_str(self, _PyUnicode_AsString(key));
}
else if (PyIndex_Check(key)) {
if (PyIndex_Check(key)) {
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
if (i == -1 && PyErr_Occurred()) {
return NULL;
@@ -2715,62 +2705,59 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject
return pyrna_prop_collection_subscript_int(self, i);
}
else if (PySlice_Check(key)) {
if (PySlice_Check(key)) {
PySliceObject *key_slice = (PySliceObject *)key;
Py_ssize_t step = 1;
if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
return NULL;
}
else if (step != 1) {
if (step != 1) {
PyErr_SetString(PyExc_TypeError, "bpy_prop_collection[slice]: slice steps not supported");
return NULL;
}
else if (key_slice->start == Py_None && key_slice->stop == Py_None) {
if (key_slice->start == Py_None && key_slice->stop == Py_None) {
return pyrna_prop_collection_subscript_slice(self, 0, PY_SSIZE_T_MAX);
}
else {
Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
/* Avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
return NULL;
}
if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
return NULL;
}
Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
if (start < 0 || stop < 0) {
/* Only get the length for negative values. */
Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop);
if (start < 0) {
start += len;
}
if (stop < 0) {
stop += len;
}
}
/* Avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
return NULL;
}
if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
return NULL;
}
if (stop - start <= 0) {
return PyList_New(0);
if (start < 0 || stop < 0) {
/* Only get the length for negative values. */
Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop);
if (start < 0) {
start += len;
}
else {
return pyrna_prop_collection_subscript_slice(self, start, stop);
if (stop < 0) {
stop += len;
}
}
if (stop - start <= 0) {
return PyList_New(0);
}
return pyrna_prop_collection_subscript_slice(self, start, stop);
}
else if (PyTuple_Check(key)) {
if (PyTuple_Check(key)) {
/* Special case, for ID datablocks we. */
return pyrna_prop_collection_subscript_str_lib_pair(
self, key, "bpy_prop_collection[id, lib]", true);
}
else {
PyErr_Format(PyExc_TypeError,
"bpy_prop_collection[key]: invalid key, "
"must be a string or an int, not %.200s",
Py_TYPE(key)->tp_name);
return NULL;
}
PyErr_Format(PyExc_TypeError,
"bpy_prop_collection[key]: invalid key, "
"must be a string or an int, not %.200s",
Py_TYPE(key)->tp_name);
return NULL;
}
/* generic check to see if a PyObject is compatible with a collection
@@ -2786,18 +2773,17 @@ static int pyrna_prop_collection_type_check(BPy_PropertyRNA *self, PyObject *val
"this collection doesn't support None assignment");
return -1;
}
else {
return 0; /* None is OK. */
}
return 0; /* None is OK. */
}
else if (BPy_StructRNA_Check(value) == 0) {
if (BPy_StructRNA_Check(value) == 0) {
PyErr_Format(PyExc_TypeError,
"bpy_prop_collection[key] = value: invalid, "
"expected a StructRNA type or None, not a %.200s",
Py_TYPE(value)->tp_name);
return -1;
}
else if ((prop_srna = RNA_property_pointer_type(&self->ptr, self->prop))) {
if ((prop_srna = RNA_property_pointer_type(&self->ptr, self->prop))) {
StructRNA *value_srna = ((BPy_StructRNA *)value)->ptr.type;
if (RNA_struct_is_a(value_srna, prop_srna) == 0) {
PyErr_Format(PyExc_TypeError,
@@ -2807,9 +2793,8 @@ static int pyrna_prop_collection_type_check(BPy_PropertyRNA *self, PyObject *val
RNA_struct_identifier(value_srna));
return -1;
}
else {
return 0; /* OK, this is the correct type! */
}
return 0; /* OK, this is the correct type! */
}
PyErr_Format(PyExc_TypeError,
@@ -2831,7 +2816,7 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self,
PyErr_SetString(PyExc_TypeError, "del bpy_prop_collection[key]: not supported");
return -1;
}
else if (pyrna_prop_collection_type_check(self, value) == -1) {
if (pyrna_prop_collection_type_check(self, value) == -1) {
return -1; /* Exception is set. */
}
@@ -2895,13 +2880,12 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self,
}
}
#endif
else {
PyErr_Format(PyExc_TypeError,
"bpy_prop_collection[key]: invalid key, "
"must be a string or an int, not %.200s",
Py_TYPE(key)->tp_name);
return -1;
}
PyErr_Format(PyExc_TypeError,
"bpy_prop_collection[key]: invalid key, "
"must be a string or an int, not %.200s",
Py_TYPE(key)->tp_name);
return -1;
}
static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject *key)
@@ -2921,43 +2905,40 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject
}
return pyrna_prop_array_subscript_int(self, i);
}
else if (PySlice_Check(key)) {
if (PySlice_Check(key)) {
Py_ssize_t step = 1;
PySliceObject *key_slice = (PySliceObject *)key;
if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
return NULL;
}
else if (step != 1) {
if (step != 1) {
PyErr_SetString(PyExc_TypeError, "bpy_prop_array[slice]: slice steps not supported");
return NULL;
}
else if (key_slice->start == Py_None && key_slice->stop == Py_None) {
if (key_slice->start == Py_None && key_slice->stop == Py_None) {
/* Note: no significant advantage with optimizing [:] slice as with collections,
* but include here for consistency with collection slice func */
Py_ssize_t len = (Py_ssize_t)pyrna_prop_array_length(self);
return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, 0, len, len);
}
else {
int len = pyrna_prop_array_length(self);
Py_ssize_t start, stop, slicelength;
if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) {
return NULL;
}
int len = pyrna_prop_array_length(self);
Py_ssize_t start, stop, slicelength;
if (slicelength <= 0) {
return PyTuple_New(0);
}
else {
return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, start, stop, len);
}
if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) {
return NULL;
}
if (slicelength <= 0) {
return PyTuple_New(0);
}
return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, start, stop, len);
}
else {
PyErr_SetString(PyExc_AttributeError, "bpy_prop_array[key]: invalid key, key must be an int");
return NULL;
}
PyErr_SetString(PyExc_AttributeError, "bpy_prop_array[key]: invalid key, key must be an int");
return NULL;
}
/**
@@ -2972,7 +2953,7 @@ static PyObject *prop_subscript_ass_array_slice__as_seq_fast(PyObject *value, in
"element in assignment is not a sequence type"))) {
return NULL;
}
else if (PySequence_Fast_GET_SIZE(value_fast) != length) {
if (PySequence_Fast_GET_SIZE(value_fast) != length) {
Py_DECREF(value_fast);
PyErr_SetString(PyExc_ValueError,
"bpy_prop_array[slice] = value: "
@@ -2980,9 +2961,8 @@ static PyObject *prop_subscript_ass_array_slice__as_seq_fast(PyObject *value, in
return NULL;
}
else {
return value_fast;
}
return value_fast;
}
static int prop_subscript_ass_array_slice__float_recursive(
@@ -3005,17 +2985,16 @@ static int prop_subscript_ass_array_slice__float_recursive(
}
return index;
}
else {
BLI_assert(totdim == 1);
const float min = range[0], max = range[1];
int i;
for (i = 0; i != length; i++) {
float v = PyFloat_AsDouble(value_items[i]);
CLAMP(v, min, max);
value[i] = v;
}
return i;
BLI_assert(totdim == 1);
const float min = range[0], max = range[1];
int i;
for (i = 0; i != length; i++) {
float v = PyFloat_AsDouble(value_items[i]);
CLAMP(v, min, max);
value[i] = v;
}
return i;
}
static int prop_subscript_ass_array_slice__int_recursive(
@@ -3038,17 +3017,16 @@ static int prop_subscript_ass_array_slice__int_recursive(
}
return index;
}
else {
BLI_assert(totdim == 1);
const int min = range[0], max = range[1];
int i;
for (i = 0; i != length; i++) {
int v = PyLong_AsLong(value_items[i]);
CLAMP(v, min, max);
value[i] = v;
}
return i;
BLI_assert(totdim == 1);
const int min = range[0], max = range[1];
int i;
for (i = 0; i != length; i++) {
int v = PyLong_AsLong(value_items[i]);
CLAMP(v, min, max);
value[i] = v;
}
return i;
}
static int prop_subscript_ass_array_slice__bool_recursive(PyObject **value_items,
@@ -3073,15 +3051,14 @@ static int prop_subscript_ass_array_slice__bool_recursive(PyObject **value_items
}
return index;
}
else {
BLI_assert(totdim == 1);
int i;
for (i = 0; i != length; i++) {
int v = PyLong_AsLong(value_items[i]);
value[i] = v;
}
return i;
BLI_assert(totdim == 1);
int i;
for (i = 0; i != length; i++) {
int v = PyLong_AsLong(value_items[i]);
value[i] = v;
}
return i;
}
/* Could call `pyrna_py_to_prop_array_index(self, i, value)` in a loop, but it is slow. */
@@ -3364,23 +3341,21 @@ static int pyrna_prop_collection_contains(BPy_PropertyRNA *self, PyObject *key)
return pyrna_prop_collection_subscript_str_lib_pair_ptr(
self, key, "(id, lib) in bpy_prop_collection", false, NULL);
}
else {
/* Key in dict style check. */
const char *keyname = _PyUnicode_AsString(key);
/* Key in dict style check. */
const char *keyname = _PyUnicode_AsString(key);
if (keyname == NULL) {
PyErr_SetString(PyExc_TypeError,
"bpy_prop_collection.__contains__: expected a string or a tuple of strings");
return -1;
}
if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) {
return 1;
}
return 0;
if (keyname == NULL) {
PyErr_SetString(PyExc_TypeError,
"bpy_prop_collection.__contains__: expected a string or a tuple of strings");
return -1;
}
if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) {
return 1;
}
return 0;
}
static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value)
@@ -3821,30 +3796,25 @@ static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args)
path);
return NULL;
}
else {
return pyrna_array_index(&r_ptr, r_prop, index);
}
return pyrna_array_index(&r_ptr, r_prop, index);
}
else {
if (coerce == Py_False) {
return pyrna_prop_CreatePyObject(&r_ptr, r_prop);
}
else {
return pyrna_prop_to_py(&r_ptr, r_prop);
}
if (coerce == Py_False) {
return pyrna_prop_CreatePyObject(&r_ptr, r_prop);
}
return pyrna_prop_to_py(&r_ptr, r_prop);
}
else {
return pyrna_struct_CreatePyObject(&r_ptr);
}
}
else {
PyErr_Format(PyExc_ValueError,
"%.200s.path_resolve(\"%.200s\") could not be resolved",
RNA_struct_identifier(self->ptr.type),
path);
return NULL;
return pyrna_struct_CreatePyObject(&r_ptr);
}
PyErr_Format(PyExc_ValueError,
"%.200s.path_resolve(\"%.200s\") could not be resolved",
RNA_struct_identifier(self->ptr.type),
path);
return NULL;
}
PyDoc_STRVAR(pyrna_struct_path_from_id_doc,
@@ -3954,22 +3924,21 @@ static PyObject *pyrna_prop_as_bytes(BPy_PropertyRNA *self)
RNA_property_identifier(self->prop));
return NULL;
}
else {
PyObject *ret;
char buf_fixed[256], *buf;
int buf_len;
buf = RNA_property_string_get_alloc(
&self->ptr, self->prop, buf_fixed, sizeof(buf_fixed), &buf_len);
PyObject *ret;
char buf_fixed[256], *buf;
int buf_len;
ret = PyBytes_FromStringAndSize(buf, buf_len);
buf = RNA_property_string_get_alloc(
&self->ptr, self->prop, buf_fixed, sizeof(buf_fixed), &buf_len);
if (buf_fixed != buf) {
MEM_freeN(buf);
}
ret = PyBytes_FromStringAndSize(buf, buf_len);
return ret;
if (buf_fixed != buf) {
MEM_freeN(buf);
}
return ret;
}
PyDoc_STRVAR(pyrna_prop_update_doc,
@@ -4478,7 +4447,7 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject
PyErr_SetString(PyExc_AttributeError, "bpy_struct: __setattr__ must be a string");
return -1;
}
else if (name[0] != '_' && (prop = RNA_struct_find_property(&self->ptr, name))) {
if (name[0] != '_' && (prop = RNA_struct_find_property(&self->ptr, name))) {
if (!RNA_property_editable_flag(&self->ptr, prop)) {
PyErr_Format(PyExc_AttributeError,
"bpy_struct: attribute \"%.200s\" from \"%.200s\" is read-only",
@@ -4497,22 +4466,21 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject
name);
return -1;
}
else {
PointerRNA newptr;
ListBase newlb;
short newtype;
int done = CTX_data_get(C, name, &newptr, &newlb, &newtype);
PointerRNA newptr;
ListBase newlb;
short newtype;
if (done == 1) {
PyErr_Format(
PyExc_AttributeError, "bpy_struct: Context property \"%.200s\" is read-only", name);
BLI_freelistN(&newlb);
return -1;
}
int done = CTX_data_get(C, name, &newptr, &newlb, &newtype);
if (done == 1) {
PyErr_Format(
PyExc_AttributeError, "bpy_struct: Context property \"%.200s\" is read-only", name);
BLI_freelistN(&newlb);
return -1;
}
BLI_freelistN(&newlb);
}
/* pyrna_py_to_prop sets its own exceptions */
@@ -4523,9 +4491,8 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject
}
return pyrna_py_to_prop(&self->ptr, prop, NULL, value, "bpy_struct: item.attr = val:");
}
else {
return PyObject_GenericSetAttr((PyObject *)self, pyname, value);
}
return PyObject_GenericSetAttr((PyObject *)self, pyname, value);
}
static PyObject *pyrna_prop_dir(BPy_PropertyRNA *self)
@@ -4563,7 +4530,7 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject
PyErr_SetString(PyExc_AttributeError, "bpy_prop_collection: __getattr__ must be a string");
return NULL;
}
else if (name[0] != '_') {
if (name[0] != '_') {
PyObject *ret;
PropertyRNA *prop;
FunctionRNA *func;
@@ -4575,7 +4542,7 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject
return ret;
}
else if ((func = RNA_struct_find_function(r_ptr.type, name))) {
if ((func = RNA_struct_find_function(r_ptr.type, name))) {
PyObject *self_collection = pyrna_struct_CreatePyObject(&r_ptr);
ret = pyrna_func_to_py(&((BPy_DummyPointerRNA *)self_collection)->ptr, func);
Py_DECREF(self_collection);
@@ -4639,11 +4606,11 @@ static int pyrna_prop_collection_setattro(BPy_PropertyRNA *self, PyObject *pynam
PyErr_SetString(PyExc_AttributeError, "bpy_prop: __setattr__ must be a string");
return -1;
}
else if (value == NULL) {
if (value == NULL) {
PyErr_SetString(PyExc_AttributeError, "bpy_prop: del not supported");
return -1;
}
else if (RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) {
if (RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) {
if ((prop = RNA_struct_find_property(&r_ptr, name))) {
/* pyrna_py_to_prop sets its own exceptions. */
return pyrna_py_to_prop(&r_ptr, prop, NULL, value, "BPy_PropertyRNA - Attribute (setattr):");
@@ -4673,9 +4640,8 @@ static PyObject *pyrna_prop_collection_idprop_add(BPy_PropertyRNA *self)
"bpy_prop_collection.add(): not supported for this collection");
return NULL;
}
else {
return pyrna_struct_CreatePyObject(&r_ptr);
}
return pyrna_struct_CreatePyObject(&r_ptr);
}
static PyObject *pyrna_prop_collection_idprop_remove(BPy_PropertyRNA *self, PyObject *value)
@@ -5798,7 +5764,7 @@ static PyObject *pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject *
Py_INCREF(base);
return (PyObject *)base;
}
else if (PyType_IsSubtype(Py_TYPE(base), &pyrna_struct_Type)) {
if (PyType_IsSubtype(Py_TYPE(base), &pyrna_struct_Type)) {
/* this almost never runs, only when using user defined subclasses of built-in object.
* this isn't common since it's NOT related to registerable subclasses. eg:
*
@@ -5826,10 +5792,9 @@ static PyObject *pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject *
type->tp_name);
return NULL;
}
else {
PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): expected a single argument");
return NULL;
}
PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): expected a single argument");
return NULL;
}
/* only needed for subtyping, so a new class gets a valid BPy_StructRNA
@@ -5845,18 +5810,17 @@ static PyObject *pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *UN
if (type == Py_TYPE(base)) {
return Py_INCREF_RET((PyObject *)base);
}
else if (PyType_IsSubtype(type, &pyrna_prop_Type)) {
if (PyType_IsSubtype(type, &pyrna_prop_Type)) {
BPy_PropertyRNA *ret = (BPy_PropertyRNA *)type->tp_alloc(type, 0);
ret->ptr = base->ptr;
ret->prop = base->prop;
return (PyObject *)ret;
}
else {
PyErr_Format(PyExc_TypeError,
"bpy_prop.__new__(type): type '%.200s' is not a subtype of bpy_prop",
type->tp_name);
return NULL;
}
PyErr_Format(PyExc_TypeError,
"bpy_prop.__new__(type): type '%.200s' is not a subtype of bpy_prop",
type->tp_name);
return NULL;
}
static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data)
@@ -6192,9 +6156,8 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
err = -1;
break;
}
else { /* PyDict_GetItemString wont raise an error. */
continue;
}
/* PyDict_GetItemString wont raise an error. */
continue;
}
#ifdef DEBUG_STRING_FREE
@@ -7131,25 +7094,24 @@ static PyObject *pyrna_prop_collection_iter_next(BPy_PropertyCollectionIterRNA *
PyErr_SetNone(PyExc_StopIteration);
return NULL;
}
else {
BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&self->iter.ptr);
BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&self->iter.ptr);
# ifdef USE_PYRNA_STRUCT_REFERENCE
if (pyrna) { /* Unlikely, but may fail. */
if ((PyObject *)pyrna != Py_None) {
/* hold a reference to the iterator since it may have
* allocated memory 'pyrna' needs. eg: introspecting dynamic enum's */
/* TODO, we could have an api call to know if this is
* needed since most collections don't */
pyrna_struct_reference_set(pyrna, (PyObject *)self);
}
if (pyrna) { /* Unlikely, but may fail. */
if ((PyObject *)pyrna != Py_None) {
/* hold a reference to the iterator since it may have
* allocated memory 'pyrna' needs. eg: introspecting dynamic enum's */
/* TODO, we could have an api call to know if this is
* needed since most collections don't */
pyrna_struct_reference_set(pyrna, (PyObject *)self);
}
}
# endif /* !USE_PYRNA_STRUCT_REFERENCE */
RNA_property_collection_next(&self->iter);
RNA_property_collection_next(&self->iter);
return (PyObject *)pyrna;
}
return (PyObject *)pyrna;
}
static void pyrna_prop_collection_iter_dealloc(BPy_PropertyCollectionIterRNA *self)
@@ -7413,9 +7375,8 @@ static StructRNA *srna_from_ptr(PointerRNA *ptr)
if (ptr->type == &RNA_Struct) {
return ptr->data;
}
else {
return ptr->type;
}
return ptr->type;
}
/* Always returns a new ref, be sure to decref when done. */
@@ -7445,15 +7406,14 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr)
Py_INCREF(pyrna);
return (PyObject *)pyrna;
}
else {
/* Existing users will need to use 'type_recast' method. */
Py_DECREF(pyrna);
*instance = NULL;
/* Continue as if no instance was made. */
/* Existing users will need to use 'type_recast' method. */
Py_DECREF(pyrna);
*instance = NULL;
/* Continue as if no instance was made. */
#if 0 /* No need to assign, will be written to next... */
pyrna = NULL;
#endif
}
}
{
@@ -7560,9 +7520,8 @@ PyObject *pyrna_id_CreatePyObject(ID *id)
RNA_id_pointer_create(id, &ptr);
return pyrna_struct_CreatePyObject(&ptr);
}
else {
Py_RETURN_NONE;
}
Py_RETURN_NONE;
}
bool pyrna_id_FromPyObject(PyObject *obj, ID **id)
@@ -7571,10 +7530,9 @@ bool pyrna_id_FromPyObject(PyObject *obj, ID **id)
*id = ((BPy_StructRNA *)obj)->ptr.owner_id;
return true;
}
else {
*id = NULL;
return false;
}
*id = NULL;
return false;
}
bool pyrna_id_CheckPyObject(PyObject *obj)
@@ -7869,30 +7827,29 @@ StructRNA *srna_from_self(PyObject *self, const char *error_prefix)
if (self == NULL) {
return NULL;
}
else if (PyCapsule_CheckExact(self)) {
if (PyCapsule_CheckExact(self)) {
return PyCapsule_GetPointer(self, NULL);
}
else if (PyType_Check(self) == 0) {
if (PyType_Check(self) == 0) {
return NULL;
}
else {
/* These cases above not errors, they just mean the type was not compatible
* After this any errors will be raised in the script */
PyObject *error_type, *error_value, *error_traceback;
StructRNA *srna;
/* These cases above not errors, they just mean the type was not compatible
* After this any errors will be raised in the script */
PyErr_Fetch(&error_type, &error_value, &error_traceback);
PyErr_Clear();
PyObject *error_type, *error_value, *error_traceback;
StructRNA *srna;
srna = pyrna_struct_as_srna(self, false, error_prefix);
PyErr_Fetch(&error_type, &error_value, &error_traceback);
PyErr_Clear();
if (!PyErr_Occurred()) {
PyErr_Restore(error_type, error_value, error_traceback);
}
srna = pyrna_struct_as_srna(self, false, error_prefix);
return srna;
if (!PyErr_Occurred()) {
PyErr_Restore(error_type, error_value, error_traceback);
}
return srna;
}
static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item)

View File

@@ -181,24 +181,24 @@ static int pyrna_struct_anim_args_parse_no_resolve(PointerRNA *ptr,
*r_path_full = path;
return 0;
}
else {
char *path_prefix = RNA_path_from_ID_to_struct(ptr);
if (path_prefix == NULL) {
PyErr_Format(PyExc_TypeError,
"%.200s could not make path for type %s",
error_prefix,
RNA_struct_identifier(ptr->type));
return -1;
}
if (*path == '[') {
*r_path_full = BLI_string_joinN(path_prefix, path);
}
else {
*r_path_full = BLI_string_join_by_sep_charN('.', path_prefix, path);
}
MEM_freeN(path_prefix);
char *path_prefix = RNA_path_from_ID_to_struct(ptr);
if (path_prefix == NULL) {
PyErr_Format(PyExc_TypeError,
"%.200s could not make path for type %s",
error_prefix,
RNA_struct_identifier(ptr->type));
return -1;
}
if (*path == '[') {
*r_path_full = BLI_string_joinN(path_prefix, path);
}
else {
*r_path_full = BLI_string_join_by_sep_charN('.', path_prefix, path);
}
MEM_freeN(path_prefix);
return 0;
}
@@ -383,33 +383,32 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
return PyBool_FromLong(result);
}
else {
ID *id = self->ptr.owner_id;
ReportList reports;
bool result;
BKE_reports_init(&reports, RPT_STORE);
ID *id = self->ptr.owner_id;
ReportList reports;
bool result;
BLI_assert(BKE_id_is_in_global_main(id));
result = (insert_keyframe(G_MAIN,
&reports,
id,
NULL,
group_name,
path_full,
index,
&anim_eval_context,
keytype,
NULL,
options) != 0);
MEM_freeN((void *)path_full);
BKE_reports_init(&reports, RPT_STORE);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
}
BLI_assert(BKE_id_is_in_global_main(id));
result = (insert_keyframe(G_MAIN,
&reports,
id,
NULL,
group_name,
path_full,
index,
&anim_eval_context,
keytype,
NULL,
options) != 0);
MEM_freeN((void *)path_full);
return PyBool_FromLong(result);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
}
return PyBool_FromLong(result);
}
char pyrna_struct_keyframe_delete_doc[] =
@@ -453,7 +452,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
NULL) == -1) {
return NULL;
}
else if (self->ptr.type == &RNA_NlaStrip) {
if (self->ptr.type == &RNA_NlaStrip) {
/* Handle special properties for NLA Strips, whose F-Curves are stored on the
* strips themselves. These are stored separately or else the properties will
* not have any effect.
@@ -518,22 +517,21 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
return PyBool_FromLong(result);
}
else {
bool result;
ReportList reports;
BKE_reports_init(&reports, RPT_STORE);
bool result;
ReportList reports;
result = (delete_keyframe(
G.main, &reports, self->ptr.owner_id, NULL, path_full, index, cfra) != 0);
MEM_freeN((void *)path_full);
BKE_reports_init(&reports, RPT_STORE);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
}
result = (delete_keyframe(G.main, &reports, self->ptr.owner_id, NULL, path_full, index, cfra) !=
0);
MEM_freeN((void *)path_full);
return PyBool_FromLong(result);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
}
return PyBool_FromLong(result);
}
char pyrna_struct_driver_add_doc[] =
@@ -563,60 +561,59 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
&self->ptr, "bpy_struct.driver_add():", path, &path_full, &index) == -1) {
return NULL;
}
else {
PyObject *ret = NULL;
ReportList reports;
int result;
BKE_reports_init(&reports, RPT_STORE);
PyObject *ret = NULL;
ReportList reports;
int result;
result = ANIM_add_driver(&reports,
(ID *)self->ptr.owner_id,
path_full,
index,
CREATEDRIVER_WITH_FMODIFIER,
DRIVER_TYPE_PYTHON);
BKE_reports_init(&reports, RPT_STORE);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
}
result = ANIM_add_driver(&reports,
(ID *)self->ptr.owner_id,
path_full,
index,
CREATEDRIVER_WITH_FMODIFIER,
DRIVER_TYPE_PYTHON);
if (result) {
ID *id = self->ptr.owner_id;
AnimData *adt = BKE_animdata_from_id(id);
FCurve *fcu;
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
}
PointerRNA tptr;
if (result) {
ID *id = self->ptr.owner_id;
AnimData *adt = BKE_animdata_from_id(id);
FCurve *fcu;
if (index == -1) { /* all, use a list */
int i = 0;
ret = PyList_New(0);
while ((fcu = BKE_fcurve_find(&adt->drivers, path_full, i++))) {
RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr);
PyList_APPEND(ret, pyrna_struct_CreatePyObject(&tptr));
}
}
else {
fcu = BKE_fcurve_find(&adt->drivers, path_full, index);
PointerRNA tptr;
if (index == -1) { /* all, use a list */
int i = 0;
ret = PyList_New(0);
while ((fcu = BKE_fcurve_find(&adt->drivers, path_full, i++))) {
RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr);
ret = pyrna_struct_CreatePyObject(&tptr);
PyList_APPEND(ret, pyrna_struct_CreatePyObject(&tptr));
}
bContext *context = BPy_GetContext();
WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION | ND_FCURVES_ORDER, NULL);
DEG_relations_tag_update(CTX_data_main(context));
}
else {
/* XXX, should be handled by reports, */
PyErr_SetString(PyExc_TypeError,
"bpy_struct.driver_add(): failed because of an internal error");
return NULL;
fcu = BKE_fcurve_find(&adt->drivers, path_full, index);
RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr);
ret = pyrna_struct_CreatePyObject(&tptr);
}
MEM_freeN((void *)path_full);
return ret;
bContext *context = BPy_GetContext();
WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION | ND_FCURVES_ORDER, NULL);
DEG_relations_tag_update(CTX_data_main(context));
}
else {
/* XXX, should be handled by reports, */
PyErr_SetString(PyExc_TypeError,
"bpy_struct.driver_add(): failed because of an internal error");
return NULL;
}
MEM_freeN((void *)path_full);
return ret;
}
char pyrna_struct_driver_remove_doc[] =
@@ -646,26 +643,25 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
&self->ptr, "bpy_struct.driver_remove():", path, &path_full, &index) == -1) {
return NULL;
}
else {
short result;
ReportList reports;
BKE_reports_init(&reports, RPT_STORE);
short result;
ReportList reports;
result = ANIM_remove_driver(&reports, (ID *)self->ptr.owner_id, path_full, index, 0);
BKE_reports_init(&reports, RPT_STORE);
if (path != path_full) {
MEM_freeN((void *)path_full);
}
result = ANIM_remove_driver(&reports, (ID *)self->ptr.owner_id, path_full, index, 0);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
}
bContext *context = BPy_GetContext();
WM_event_add_notifier(context, NC_ANIMATION | ND_FCURVES_ORDER, NULL);
DEG_relations_tag_update(CTX_data_main(context));
return PyBool_FromLong(result);
if (path != path_full) {
MEM_freeN((void *)path_full);
}
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
}
bContext *context = BPy_GetContext();
WM_event_add_notifier(context, NC_ANIMATION | ND_FCURVES_ORDER, NULL);
DEG_relations_tag_update(CTX_data_main(context));
return PyBool_FromLong(result);
}

View File

@@ -180,7 +180,7 @@ static int validate_array_type(PyObject *seq,
Py_TYPE(seq)->tp_name);
return -1;
}
else if ((seq_size != dimsize[dim]) && (is_dynamic == false)) {
if ((seq_size != dimsize[dim]) && (is_dynamic == false)) {
PyErr_Format(PyExc_ValueError,
"%s sequences of dimension %d should contain %d items, not %d",
error_prefix,
@@ -201,7 +201,7 @@ static int validate_array_type(PyObject *seq,
i);
return -1;
}
else if (!check_item_type(item)) {
if (!check_item_type(item)) {
Py_DECREF(item);
#if 0
@@ -279,7 +279,7 @@ static int validate_array_length(PyObject *rvalue,
RNA_property_identifier(prop));
return -1;
}
else if ((RNA_property_flag(prop) & PROP_DYNAMIC) && lvalue_dim == 0) {
if ((RNA_property_flag(prop) & PROP_DYNAMIC) && lvalue_dim == 0) {
if (RNA_property_array_length(ptr, prop) != tot) {
#if 0
/* length is flexible */
@@ -382,7 +382,7 @@ static int validate_array(PyObject *rvalue,
RNA_property_identifier(prop));
return -1;
}
else if (totdim != 2) {
if (totdim != 2) {
PyErr_Format(PyExc_ValueError,
"%s %.200s.%.200s, matrix assign array with %d dimensions",
error_prefix,
@@ -391,7 +391,7 @@ static int validate_array(PyObject *rvalue,
totdim);
return -1;
}
else if (pymat->num_col != dimsize[0] || pymat->num_row != dimsize[1]) {
if (pymat->num_col != dimsize[0] || pymat->num_row != dimsize[1]) {
PyErr_Format(PyExc_ValueError,
"%s %.200s.%.200s, matrix assign dimension size mismatch, "
"is %dx%d, expected be %dx%d",
@@ -404,10 +404,9 @@ static int validate_array(PyObject *rvalue,
dimsize[1]);
return -1;
}
else {
*r_totitem = dimsize[0] * dimsize[1];
return 0;
}
*r_totitem = dimsize[0] * dimsize[1];
return 0;
}
}
#endif /* USE_MATHUTILS */
@@ -1017,31 +1016,31 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
PyErr_Clear();
return 0;
}
else {
float tmp[32];
float *tmp_arr;
if (len * sizeof(float) > sizeof(tmp)) {
tmp_arr = PyMem_MALLOC(len * sizeof(float));
}
else {
tmp_arr = tmp;
}
float tmp[32];
float *tmp_arr;
RNA_property_float_get_array(ptr, prop, tmp_arr);
for (i = 0; i < len; i++) {
if (tmp_arr[i] == value_f) {
break;
}
}
if (tmp_arr != tmp) {
PyMem_FREE(tmp_arr);
}
return i < len ? 1 : 0;
if (len * sizeof(float) > sizeof(tmp)) {
tmp_arr = PyMem_MALLOC(len * sizeof(float));
}
else {
tmp_arr = tmp;
}
RNA_property_float_get_array(ptr, prop, tmp_arr);
for (i = 0; i < len; i++) {
if (tmp_arr[i] == value_f) {
break;
}
}
if (tmp_arr != tmp) {
PyMem_FREE(tmp_arr);
}
return i < len ? 1 : 0;
break;
}
case PROP_INT: {
@@ -1050,31 +1049,31 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
PyErr_Clear();
return 0;
}
else {
int tmp[32];
int *tmp_arr;
if (len * sizeof(int) > sizeof(tmp)) {
tmp_arr = PyMem_MALLOC(len * sizeof(int));
}
else {
tmp_arr = tmp;
}
int tmp[32];
int *tmp_arr;
RNA_property_int_get_array(ptr, prop, tmp_arr);
for (i = 0; i < len; i++) {
if (tmp_arr[i] == value_i) {
break;
}
}
if (tmp_arr != tmp) {
PyMem_FREE(tmp_arr);
}
return i < len ? 1 : 0;
if (len * sizeof(int) > sizeof(tmp)) {
tmp_arr = PyMem_MALLOC(len * sizeof(int));
}
else {
tmp_arr = tmp;
}
RNA_property_int_get_array(ptr, prop, tmp_arr);
for (i = 0; i < len; i++) {
if (tmp_arr[i] == value_i) {
break;
}
}
if (tmp_arr != tmp) {
PyMem_FREE(tmp_arr);
}
return i < len ? 1 : 0;
break;
}
case PROP_BOOLEAN: {
@@ -1083,31 +1082,31 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
PyErr_Clear();
return 0;
}
else {
bool tmp[32];
bool *tmp_arr;
if (len * sizeof(bool) > sizeof(tmp)) {
tmp_arr = PyMem_MALLOC(len * sizeof(bool));
}
else {
tmp_arr = tmp;
}
bool tmp[32];
bool *tmp_arr;
RNA_property_boolean_get_array(ptr, prop, tmp_arr);
for (i = 0; i < len; i++) {
if (tmp_arr[i] == value_i) {
break;
}
}
if (tmp_arr != tmp) {
PyMem_FREE(tmp_arr);
}
return i < len ? 1 : 0;
if (len * sizeof(bool) > sizeof(tmp)) {
tmp_arr = PyMem_MALLOC(len * sizeof(bool));
}
else {
tmp_arr = tmp;
}
RNA_property_boolean_get_array(ptr, prop, tmp_arr);
for (i = 0; i < len; i++) {
if (tmp_arr[i] == value_i) {
break;
}
}
if (tmp_arr != tmp) {
PyMem_FREE(tmp_arr);
}
return i < len ? 1 : 0;
break;
}
}

View File

@@ -317,10 +317,10 @@ PyObject *pyrna_callback_classmethod_add(PyObject *UNUSED(self), PyObject *args)
error_prefix) == -1) {
return NULL;
}
else if (params.region_type_str && pyrna_enum_value_from_id(rna_enum_region_type_items,
params.region_type_str,
&params.region_type,
error_prefix) == -1) {
if (params.region_type_str && pyrna_enum_value_from_id(rna_enum_region_type_items,
params.region_type_str,
&params.region_type,
error_prefix) == -1) {
return NULL;
}
@@ -352,29 +352,26 @@ PyObject *pyrna_callback_classmethod_add(PyObject *UNUSED(self), PyObject *args)
region_draw_mode_items, params.event_str, &params.event, error_prefix) == -1) {
return NULL;
}
else if (pyrna_enum_value_from_id(rna_enum_region_type_items,
params.region_type_str,
&params.region_type,
error_prefix) == -1) {
if (pyrna_enum_value_from_id(rna_enum_region_type_items,
params.region_type_str,
&params.region_type,
error_prefix) == -1) {
return NULL;
}
else {
const eSpace_Type spaceid = rna_Space_refine_reverse(srna);
if (spaceid == SPACE_EMPTY) {
PyErr_Format(PyExc_TypeError, "unknown space type '%.200s'", RNA_struct_identifier(srna));
return NULL;
}
else {
SpaceType *st = BKE_spacetype_from_id(spaceid);
ARegionType *art = BKE_regiontype_from_id(st, params.region_type);
if (art == NULL) {
PyErr_Format(
PyExc_TypeError, "region type '%.200s' not in space", params.region_type_str);
return NULL;
}
handle = ED_region_draw_cb_activate(art, cb_region_draw, (void *)args, params.event);
}
const eSpace_Type spaceid = rna_Space_refine_reverse(srna);
if (spaceid == SPACE_EMPTY) {
PyErr_Format(PyExc_TypeError, "unknown space type '%.200s'", RNA_struct_identifier(srna));
return NULL;
}
SpaceType *st = BKE_spacetype_from_id(spaceid);
ARegionType *art = BKE_regiontype_from_id(st, params.region_type);
if (art == NULL) {
PyErr_Format(PyExc_TypeError, "region type '%.200s' not in space", params.region_type_str);
return NULL;
}
handle = ED_region_draw_cb_activate(art, cb_region_draw, (void *)args, params.event);
}
else {
PyErr_SetString(PyExc_TypeError, "callback_add(): type does not support callbacks");
@@ -448,24 +445,21 @@ PyObject *pyrna_callback_classmethod_remove(PyObject *UNUSED(self), PyObject *ar
error_prefix) == -1) {
return NULL;
}
else {
const eSpace_Type spaceid = rna_Space_refine_reverse(srna);
if (spaceid == SPACE_EMPTY) {
PyErr_Format(PyExc_TypeError, "unknown space type '%.200s'", RNA_struct_identifier(srna));
return NULL;
}
else {
SpaceType *st = BKE_spacetype_from_id(spaceid);
ARegionType *art = BKE_regiontype_from_id(st, params.region_type);
if (art == NULL) {
PyErr_Format(
PyExc_TypeError, "region type '%.200s' not in space", params.region_type_str);
return NULL;
}
ED_region_draw_cb_exit(art, handle);
capsule_clear = true;
}
const eSpace_Type spaceid = rna_Space_refine_reverse(srna);
if (spaceid == SPACE_EMPTY) {
PyErr_Format(PyExc_TypeError, "unknown space type '%.200s'", RNA_struct_identifier(srna));
return NULL;
}
SpaceType *st = BKE_spacetype_from_id(spaceid);
ARegionType *art = BKE_regiontype_from_id(st, params.region_type);
if (art == NULL) {
PyErr_Format(PyExc_TypeError, "region type '%.200s' not in space", params.region_type_str);
return NULL;
}
ED_region_draw_cb_exit(art, handle);
capsule_clear = true;
}
else {
PyErr_SetString(PyExc_TypeError, "callback_remove(): type does not support callbacks");

View File

@@ -367,10 +367,10 @@ static PyObject *bpy_gizmo_target_get_value(PyObject *UNUSED(self), PyObject *ar
WM_gizmo_target_property_float_get_array(gz, gz_prop, value);
return PyC_Tuple_PackArray_F32(value, array_len);
}
else {
float value = WM_gizmo_target_property_float_get(gz, gz_prop);
return PyFloat_FromDouble(value);
}
float value = WM_gizmo_target_property_float_get(gz, gz_prop);
return PyFloat_FromDouble(value);
break;
}
default: {