diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-09-01 09:50:48 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-09-01 09:50:48 +0300 |
commit | 89fa9aada56bae1505d2c803a1b127d2c0c15970 (patch) | |
tree | 6d46134c15474c4d5cc5d99e4245decb6d01846b | |
parent | 1730829592478f584d15f7874fa7e9cade1eb169 (diff) |
Cleanup: use "pyrna_enum_*" prefix for RNA utility functions
-rw-r--r-- | source/blender/python/generic/py_capi_rna.c | 32 | ||||
-rw-r--r-- | source/blender/python/generic/py_capi_rna.h | 24 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_msgbus.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 8 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 4 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_anim.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_id_collection.c | 4 |
7 files changed, 40 insertions, 36 deletions
diff --git a/source/blender/python/generic/py_capi_rna.c b/source/blender/python/generic/py_capi_rna.c index c4ec0be088d..f6a556a3fff 100644 --- a/source/blender/python/generic/py_capi_rna.c +++ b/source/blender/python/generic/py_capi_rna.c @@ -37,7 +37,11 @@ #include "MEM_guardedalloc.h" -char *BPy_enum_as_string(const EnumPropertyItem *item) +/** + * Convert all items into a single comma separated string. + * Use for creating useful error messages. + */ +char *pyrna_enum_repr(const EnumPropertyItem *item) { DynStr *dynstr = BLI_dynstr_new(); @@ -64,7 +68,7 @@ int pyrna_enum_value_from_id(const EnumPropertyItem *item, const char *error_prefix) { if (RNA_enum_value_from_id(item, identifier, r_value) == 0) { - const char *enum_str = BPy_enum_as_string(item); + const char *enum_str = pyrna_enum_repr(item); PyErr_Format( PyExc_ValueError, "%s: '%.200s' not found in (%s)", error_prefix, identifier, enum_str); MEM_freeN((void *)enum_str); @@ -106,7 +110,7 @@ int pyrna_enum_bitfield_parse_set(PyObject *o, void *p) } struct BPy_EnumProperty_Parse *parse_data = p; - if (pyrna_set_to_enum_bitfield( + if (pyrna_enum_bitfield_from_set( parse_data->items, o, &parse_data->value, "enum identifier set") == -1) { return 0; } @@ -123,12 +127,12 @@ int pyrna_enum_bitfield_parse_set(PyObject *o, void *p) * \param type_convert_sign: Maps signed to unsigned range, * needed when we want to use the full range of a signed short/char. */ -BLI_bitmap *pyrna_set_to_enum_bitmap(const EnumPropertyItem *items, - PyObject *value, - int type_size, - bool type_convert_sign, - int bitmap_size, - const char *error_prefix) +BLI_bitmap *pyrna_enum_bitmap_from_set(const EnumPropertyItem *items, + PyObject *value, + int type_size, + bool type_convert_sign, + int bitmap_size, + const char *error_prefix) { /* Set looping. */ Py_ssize_t pos = 0; @@ -189,10 +193,10 @@ error: /** * 'value' _must_ be a set type, error check before calling. */ -int pyrna_set_to_enum_bitfield(const EnumPropertyItem *items, - PyObject *value, - int *r_value, - const char *error_prefix) +int pyrna_enum_bitfield_from_set(const EnumPropertyItem *items, + PyObject *value, + int *r_value, + const char *error_prefix) { /* Set of enum items, concatenate all values with OR. */ int ret, flag = 0; @@ -226,7 +230,7 @@ int pyrna_set_to_enum_bitfield(const EnumPropertyItem *items, return 0; } -PyObject *pyrna_enum_bitfield_to_py(const EnumPropertyItem *items, int value) +PyObject *pyrna_enum_bitfield_as_set(const EnumPropertyItem *items, int value) { PyObject *ret = PySet_New(NULL); const char *identifier[RNA_ENUM_BITFLAG_SIZE + 1]; diff --git a/source/blender/python/generic/py_capi_rna.h b/source/blender/python/generic/py_capi_rna.h index 3328f94b8ae..d1a30e2177a 100644 --- a/source/blender/python/generic/py_capi_rna.h +++ b/source/blender/python/generic/py_capi_rna.h @@ -25,7 +25,7 @@ struct EnumPropertyItem; -char *BPy_enum_as_string(const struct EnumPropertyItem *item); +char *pyrna_enum_repr(const struct EnumPropertyItem *item); int pyrna_enum_value_from_id(const struct EnumPropertyItem *item, const char *identifier, @@ -51,16 +51,16 @@ struct BPy_EnumProperty_Parse { int pyrna_enum_value_parse_string(PyObject *o, void *p); int pyrna_enum_bitfield_parse_set(PyObject *o, void *p); -unsigned int *pyrna_set_to_enum_bitmap(const struct EnumPropertyItem *items, - PyObject *value, - int type_size, - bool type_convert_sign, - int bitmap_size, - const char *error_prefix); +unsigned int *pyrna_enum_bitmap_from_set(const struct EnumPropertyItem *items, + PyObject *value, + int type_size, + bool type_convert_sign, + int bitmap_size, + const char *error_prefix); -int pyrna_set_to_enum_bitfield(const struct EnumPropertyItem *items, - PyObject *value, - int *r_value, - const char *error_prefix); +int pyrna_enum_bitfield_from_set(const struct EnumPropertyItem *items, + PyObject *value, + int *r_value, + const char *error_prefix); -PyObject *pyrna_enum_bitfield_to_py(const struct EnumPropertyItem *items, int value); +PyObject *pyrna_enum_bitfield_as_set(const struct EnumPropertyItem *items, int value); diff --git a/source/blender/python/intern/bpy_msgbus.c b/source/blender/python/intern/bpy_msgbus.c index 0aff1249923..75a5f6f72ae 100644 --- a/source/blender/python/intern/bpy_msgbus.c +++ b/source/blender/python/intern/bpy_msgbus.c @@ -261,7 +261,7 @@ static PyObject *bpy_msgbus_subscribe_rna(PyObject *UNUSED(self), PyObject *args } if (py_options && - (pyrna_set_to_enum_bitfield(py_options_enum, py_options, &options, error_prefix)) == -1) { + (pyrna_enum_bitfield_from_set(py_options_enum, py_options, &options, error_prefix)) == -1) { return NULL; } diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index a08b375ee61..5ae123f3254 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -108,7 +108,7 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args) if (context_str) { if (RNA_enum_value_from_id(rna_enum_operator_context_items, context_str, &context) == 0) { - char *enum_str = BPy_enum_as_string(rna_enum_operator_context_items); + char *enum_str = pyrna_enum_repr(rna_enum_operator_context_items); PyErr_Format(PyExc_TypeError, "Calling operator \"bpy.ops.%s.poll\" error, " "expected a string enum in (%s)", @@ -210,7 +210,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) if (context_str) { if (RNA_enum_value_from_id(rna_enum_operator_context_items, context_str, &context) == 0) { - char *enum_str = BPy_enum_as_string(rna_enum_operator_context_items); + char *enum_str = pyrna_enum_repr(rna_enum_operator_context_items); PyErr_Format(PyExc_TypeError, "Calling operator \"bpy.ops.%s\" error, " "expected a string enum in (%s)", @@ -347,7 +347,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args) BPY_modules_update(); /* return operator_ret as a bpy enum */ - return pyrna_enum_bitfield_to_py(rna_enum_operator_return_items, operator_ret); + return pyrna_enum_bitfield_as_set(rna_enum_operator_return_items, operator_ret); } static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args) @@ -460,7 +460,7 @@ static PyObject *pyop_get_bl_options(PyObject *UNUSED(self), PyObject *value) if ((ot = ot_lookup_from_py_string(value, "get_bl_options")) == NULL) { return NULL; } - return pyrna_enum_bitfield_to_py(rna_enum_operator_type_flag_items, ot->flag); + return pyrna_enum_bitfield_as_set(rna_enum_operator_type_flag_items, ot->flag); } static struct PyMethodDef bpy_ops_methods[] = { diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 42db49b7688..9d0755a865d 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1213,7 +1213,7 @@ static const char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop) RNA_property_enum_items(BPY_context_get(), ptr, prop, &item, NULL, &free); if (item) { - result = BPy_enum_as_string(item); + result = pyrna_enum_repr(item); } else { result = ""; @@ -1275,7 +1275,7 @@ static int pyrna_prop_to_enum_bitfield( RNA_property_enum_items(BPY_context_get(), ptr, prop, &item, NULL, &free); if (item) { - ret = pyrna_set_to_enum_bitfield(item, value, r_value, error_prefix); + ret = pyrna_enum_bitfield_from_set(item, value, r_value, error_prefix); } else { if (PySet_GET_SIZE(value)) { diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c index 4063bb702bb..f4fe5838c6e 100644 --- a/source/blender/python/intern/bpy_rna_anim.c +++ b/source/blender/python/intern/bpy_rna_anim.c @@ -266,7 +266,7 @@ static int pyrna_struct_keyframe_parse(PointerRNA *ptr, /* flag may be null (no option currently for remove keyframes e.g.). */ if (r_options) { if (pyoptions && - (pyrna_set_to_enum_bitfield( + (pyrna_enum_bitfield_from_set( rna_enum_keying_flag_items_api, pyoptions, r_options, error_prefix) == -1)) { return -1; } diff --git a/source/blender/python/intern/bpy_rna_id_collection.c b/source/blender/python/intern/bpy_rna_id_collection.c index 4f3480ddc13..2e684faf61b 100644 --- a/source/blender/python/intern/bpy_rna_id_collection.c +++ b/source/blender/python/intern/bpy_rna_id_collection.c @@ -179,7 +179,7 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject * } if (key_types) { - key_types_bitmap = pyrna_set_to_enum_bitmap( + key_types_bitmap = pyrna_enum_bitmap_from_set( rna_enum_id_type_items, key_types, sizeof(short), true, USHRT_MAX, "key types"); if (key_types_bitmap == NULL) { goto error; @@ -187,7 +187,7 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject * } if (val_types) { - val_types_bitmap = pyrna_set_to_enum_bitmap( + val_types_bitmap = pyrna_enum_bitmap_from_set( rna_enum_id_type_items, val_types, sizeof(short), true, USHRT_MAX, "value types"); if (val_types_bitmap == NULL) { goto error; |