Cleanup: use const variables where possible in the Python API
This commit is contained in:
@@ -343,7 +343,7 @@ static PyObject *bpy_app_debug_value_get(PyObject *UNUSED(self), void *UNUSED(cl
|
||||
|
||||
static int bpy_app_debug_value_set(PyObject *UNUSED(self), PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
short param = PyC_Long_AsI16(value);
|
||||
const short param = PyC_Long_AsI16(value);
|
||||
|
||||
if (param == -1 && PyErr_Occurred()) {
|
||||
PyC_Err_SetString_Prefix(PyExc_TypeError,
|
||||
|
||||
@@ -318,7 +318,7 @@ void bpy_app_generic_callback(struct Main *UNUSED(main),
|
||||
{
|
||||
PyObject *cb_list = py_cb_array[POINTER_AS_INT(arg)];
|
||||
if (PyList_GET_SIZE(cb_list) > 0) {
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
|
||||
const int num_arguments = 2;
|
||||
PyObject *args_all = PyTuple_New(num_arguments); /* save python creating each call */
|
||||
|
||||
@@ -71,8 +71,8 @@ static PyObject *bpy_app_icons_new_triangles(PyObject *UNUSED(self), PyObject *a
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int coords_size = sizeof(uchar[2]) * tris_len * 3;
|
||||
int colors_size = sizeof(uchar[4]) * tris_len * 3;
|
||||
const int coords_size = sizeof(uchar[2]) * tris_len * 3;
|
||||
const int colors_size = sizeof(uchar[4]) * tris_len * 3;
|
||||
uchar(*coords)[2] = MEM_mallocN(coords_size, __func__);
|
||||
uchar(*colors)[4] = MEM_mallocN(colors_size, __func__);
|
||||
|
||||
@@ -86,7 +86,7 @@ static PyObject *bpy_app_icons_new_triangles(PyObject *UNUSED(self), PyObject *a
|
||||
geom->coords = coords;
|
||||
geom->colors = colors;
|
||||
geom->icon_id = 0;
|
||||
int icon_id = BKE_icon_geom_ensure(geom);
|
||||
const int icon_id = BKE_icon_geom_ensure(geom);
|
||||
return PyLong_FromLong(icon_id);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ static PyObject *bpy_app_icons_new_triangles_from_file(PyObject *UNUSED(self),
|
||||
PyErr_SetString(PyExc_ValueError, "Unable to load from file");
|
||||
return NULL;
|
||||
}
|
||||
int icon_id = BKE_icon_geom_ensure(geom);
|
||||
const int icon_id = BKE_icon_geom_ensure(geom);
|
||||
return PyLong_FromLong(icon_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ static PyObject *make_opensubdiv_info(void)
|
||||
#define SetObjItem(obj) PyStructSequence_SET_ITEM(opensubdiv_info, pos++, obj)
|
||||
|
||||
#ifdef WITH_OPENSUBDIV
|
||||
int curversion = openSubdiv_getVersionHex();
|
||||
const int curversion = openSubdiv_getVersionHex();
|
||||
SetObjItem(PyBool_FromLong(1));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(curversion / 10000, (curversion / 100) % 100, curversion % 100));
|
||||
SetObjItem(PyUnicode_FromFormat(
|
||||
|
||||
@@ -65,7 +65,7 @@ static double py_timer_execute(uintptr_t UNUSED(uuid), void *user_data)
|
||||
gilstate = PyGILState_Ensure();
|
||||
|
||||
PyObject *py_ret = PyObject_CallObject(function, NULL);
|
||||
double ret = handle_returned_value(function, py_ret);
|
||||
const double ret = handle_returned_value(function, py_ret);
|
||||
|
||||
PyGILState_Release(gilstate);
|
||||
|
||||
@@ -151,7 +151,7 @@ PyDoc_STRVAR(bpy_app_timers_is_registered_doc,
|
||||
" :rtype: bool\n");
|
||||
static PyObject *bpy_app_timers_is_registered(PyObject *UNUSED(self), PyObject *function)
|
||||
{
|
||||
bool ret = BLI_timer_is_registered((intptr_t)function);
|
||||
const bool ret = BLI_timer_is_registered((intptr_t)function);
|
||||
return PyBool_FromLong(ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ static GHashKey *_ghashutil_keyalloc(const void *msgctxt, const void *msgid)
|
||||
static uint _ghashutil_keyhash(const void *ptr)
|
||||
{
|
||||
const GHashKey *key = ptr;
|
||||
uint hash = BLI_ghashutil_strhash(key->msgctxt);
|
||||
const uint hash = BLI_ghashutil_strhash(key->msgctxt);
|
||||
return hash ^ BLI_ghashutil_strhash(key->msgid);
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ static void bpy_pydriver_namespace_clear_self(void)
|
||||
void BPY_driver_reset(void)
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
bool use_gil = true; /* !PyC_IsInterpreterActive(); */
|
||||
const bool use_gil = true; /* !PyC_IsInterpreterActive(); */
|
||||
|
||||
if (use_gil) {
|
||||
gilstate = PyGILState_Ensure();
|
||||
@@ -594,7 +594,7 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna,
|
||||
#endif
|
||||
{
|
||||
/* try to get variable value */
|
||||
float tval = driver_get_variable_value(driver, dvar);
|
||||
const float tval = driver_get_variable_value(driver, dvar);
|
||||
driver_arg = PyFloat_FromDouble((double)tval);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ void BPY_text_free_code(Text *text)
|
||||
{
|
||||
if (text->compiled) {
|
||||
PyGILState_STATE gilstate;
|
||||
bool use_gil = !PyC_IsInterpreterActive();
|
||||
const bool use_gil = !PyC_IsInterpreterActive();
|
||||
|
||||
if (use_gil) {
|
||||
gilstate = PyGILState_Ensure();
|
||||
@@ -446,14 +446,14 @@ void BPY_python_backtrace(FILE *fp)
|
||||
|
||||
void BPY_DECREF(void *pyob_ptr)
|
||||
{
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
Py_DECREF((PyObject *)pyob_ptr);
|
||||
PyGILState_Release(gilstate);
|
||||
}
|
||||
|
||||
void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr)
|
||||
{
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const int do_invalidate = (Py_REFCNT((PyObject *)pyob_ptr) > 1);
|
||||
Py_DECREF((PyObject *)pyob_ptr);
|
||||
if (do_invalidate) {
|
||||
@@ -509,7 +509,7 @@ void BPY_modules_load_user(bContext *C)
|
||||
int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *result)
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
bool use_gil = !PyC_IsInterpreterActive();
|
||||
const bool use_gil = !PyC_IsInterpreterActive();
|
||||
|
||||
PyObject *pyctx;
|
||||
PyObject *item;
|
||||
@@ -544,7 +544,7 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
|
||||
PyErr_Clear();
|
||||
}
|
||||
else {
|
||||
int len = PySequence_Fast_GET_SIZE(seq_fast);
|
||||
const int len = PySequence_Fast_GET_SIZE(seq_fast);
|
||||
PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
|
||||
int i;
|
||||
|
||||
|
||||
@@ -321,7 +321,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
||||
{
|
||||
Main *bmain = CTX_data_main(BPy_GetContext());
|
||||
Main *mainl = NULL;
|
||||
int err = 0;
|
||||
const int err = 0;
|
||||
const bool do_append = ((self->flag & FILE_LINK) == 0);
|
||||
|
||||
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
|
||||
@@ -338,7 +338,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
||||
// printf("lib: %s\n", name_plural);
|
||||
if (ls && PyList_Check(ls)) {
|
||||
/* loop */
|
||||
Py_ssize_t size = PyList_GET_SIZE(ls);
|
||||
const Py_ssize_t size = PyList_GET_SIZE(ls);
|
||||
Py_ssize_t i;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
@@ -423,7 +423,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
||||
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);
|
||||
const Py_ssize_t size = PyList_GET_SIZE(ls);
|
||||
Py_ssize_t i;
|
||||
PyObject *item;
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ static void bpy_msgbus_notify(bContext *C,
|
||||
static void bpy_msgbus_subscribe_value_free_data(struct wmMsgSubscribeKey *UNUSED(msg_key),
|
||||
struct wmMsgSubscribeValue *msg_val)
|
||||
{
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
Py_DECREF(msg_val->owner);
|
||||
Py_DECREF(msg_val->user_data);
|
||||
PyGILState_Release(gilstate);
|
||||
|
||||
@@ -351,7 +351,7 @@ static bool bpy_prop_boolean_get_cb(struct PointerRNA *ptr, struct PropertyRNA *
|
||||
value = false;
|
||||
}
|
||||
else {
|
||||
int value_i = PyC_Long_AsBool(ret);
|
||||
const int value_i = PyC_Long_AsBool(ret);
|
||||
|
||||
if (value_i == -1 && PyErr_Occurred()) {
|
||||
PyC_Err_PrintWithFunc(py_func);
|
||||
@@ -443,7 +443,7 @@ static bool bpy_prop_poll_cb(struct PointerRNA *self,
|
||||
PyObject *ret;
|
||||
bool result;
|
||||
const int is_write_ok = pyrna_write_check();
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
|
||||
BLI_assert(self != NULL);
|
||||
|
||||
@@ -560,7 +560,7 @@ static void bpy_prop_boolean_array_set_cb(struct PointerRNA *ptr,
|
||||
PyGILState_STATE gilstate;
|
||||
bool use_gil;
|
||||
const bool is_write_ok = pyrna_write_check();
|
||||
int len = RNA_property_array_length(ptr, prop);
|
||||
const int len = RNA_property_array_length(ptr, prop);
|
||||
|
||||
BLI_assert(py_data != NULL);
|
||||
|
||||
@@ -804,7 +804,7 @@ static void bpy_prop_int_array_set_cb(struct PointerRNA *ptr,
|
||||
PyGILState_STATE gilstate;
|
||||
bool use_gil;
|
||||
const bool is_write_ok = pyrna_write_check();
|
||||
int len = RNA_property_array_length(ptr, prop);
|
||||
const int len = RNA_property_array_length(ptr, prop);
|
||||
|
||||
BLI_assert(py_data != NULL);
|
||||
|
||||
@@ -1048,7 +1048,7 @@ static void bpy_prop_float_array_set_cb(struct PointerRNA *ptr,
|
||||
PyGILState_STATE gilstate;
|
||||
bool use_gil;
|
||||
const bool is_write_ok = pyrna_write_check();
|
||||
int len = RNA_property_array_length(ptr, prop);
|
||||
const int len = RNA_property_array_length(ptr, prop);
|
||||
|
||||
BLI_assert(py_data != NULL);
|
||||
|
||||
|
||||
@@ -464,7 +464,7 @@ static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype)
|
||||
if (subtype == MATHUTILS_CB_SUBTYPE_EUL) {
|
||||
EulerObject *eul = (EulerObject *)bmo;
|
||||
PropertyRNA *prop_eul_order = NULL;
|
||||
short order = pyrna_rotation_euler_order_get(&self->ptr, eul->order, &prop_eul_order);
|
||||
const short order = pyrna_rotation_euler_order_get(&self->ptr, eul->order, &prop_eul_order);
|
||||
if (order != eul->order) {
|
||||
RNA_property_enum_set(&self->ptr, prop_eul_order, eul->order);
|
||||
if (RNA_property_update_check(prop_eul_order)) {
|
||||
@@ -599,7 +599,7 @@ static short pyrna_rotation_euler_order_get(PointerRNA *ptr,
|
||||
}
|
||||
|
||||
if (*r_prop_eul_order) {
|
||||
short order = RNA_property_enum_get(ptr, *r_prop_eul_order);
|
||||
const short order = RNA_property_enum_get(ptr, *r_prop_eul_order);
|
||||
/* Could be quat or axisangle. */
|
||||
if (order >= EULER_ORDER_XYZ && order <= EULER_ORDER_ZYX) {
|
||||
return order;
|
||||
@@ -714,7 +714,8 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
|
||||
/* Attempt to get order,
|
||||
* only needed for thick types since wrapped with update via callbacks. */
|
||||
PropertyRNA *prop_eul_order = NULL;
|
||||
short order = pyrna_rotation_euler_order_get(ptr, EULER_ORDER_XYZ, &prop_eul_order);
|
||||
const short order = pyrna_rotation_euler_order_get(
|
||||
ptr, EULER_ORDER_XYZ, &prop_eul_order);
|
||||
|
||||
ret = Euler_CreatePyObject(NULL, order, NULL); /* TODO, get order from RNA. */
|
||||
RNA_property_float_get_array(ptr, prop, ((EulerObject *)ret)->eul);
|
||||
@@ -1725,7 +1726,7 @@ static int pyrna_py_to_prop(
|
||||
}
|
||||
case PROP_INT: {
|
||||
int overflow;
|
||||
long param = PyLong_AsLongAndOverflow(value, &overflow);
|
||||
const long param = PyLong_AsLongAndOverflow(value, &overflow);
|
||||
if (overflow || (param > INT_MAX) || (param < INT_MIN)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s %.200s.%.200s value not in 'int' range "
|
||||
@@ -1757,7 +1758,7 @@ static int pyrna_py_to_prop(
|
||||
break;
|
||||
}
|
||||
case PROP_FLOAT: {
|
||||
float param = PyFloat_AsDouble(value);
|
||||
const float param = PyFloat_AsDouble(value);
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s %.200s.%.200s expected a float type, not %.200s",
|
||||
@@ -1935,8 +1936,8 @@ static int pyrna_py_to_prop(
|
||||
PyObject *value_new = NULL;
|
||||
|
||||
StructRNA *ptr_type = RNA_property_pointer_type(ptr, prop);
|
||||
int flag = RNA_property_flag(prop);
|
||||
int flag_parameter = RNA_parameter_flag(prop);
|
||||
const int flag = RNA_property_flag(prop);
|
||||
const int flag_parameter = RNA_parameter_flag(prop);
|
||||
|
||||
/* This is really nasty! Done so we can fake the operator having direct properties, eg:
|
||||
* layout.prop(self, "filepath")
|
||||
@@ -2075,7 +2076,7 @@ static int pyrna_py_to_prop(
|
||||
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));
|
||||
const int err = (BPy_reports_to_error(&reports, PyExc_RuntimeError, true));
|
||||
if (err == -1) {
|
||||
Py_XDECREF(value_new);
|
||||
return -1;
|
||||
@@ -2233,7 +2234,7 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P
|
||||
/* See if we can coerce into a Python type - 'PropertyType'. */
|
||||
switch (RNA_property_type(prop)) {
|
||||
case PROP_BOOLEAN: {
|
||||
int param = PyC_Long_AsBool(value);
|
||||
const int param = PyC_Long_AsBool(value);
|
||||
|
||||
if (param == -1) {
|
||||
/* Error is set. */
|
||||
@@ -2698,7 +2699,7 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject
|
||||
return pyrna_prop_collection_subscript_str(self, _PyUnicode_AsString(key));
|
||||
}
|
||||
if (PyIndex_Check(key)) {
|
||||
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
|
||||
const Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
|
||||
if (i == -1 && PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -2732,7 +2733,7 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject
|
||||
|
||||
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);
|
||||
const Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop);
|
||||
if (start < 0) {
|
||||
start += len;
|
||||
}
|
||||
@@ -2827,7 +2828,7 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self,
|
||||
else
|
||||
#endif
|
||||
if (PyIndex_Check(key)) {
|
||||
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
|
||||
const Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
|
||||
if (i == -1 && PyErr_Occurred()) {
|
||||
return -1;
|
||||
}
|
||||
@@ -2899,7 +2900,7 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject
|
||||
else
|
||||
#endif
|
||||
if (PyIndex_Check(key)) {
|
||||
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
|
||||
const Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
|
||||
if (i == -1 && PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -2919,11 +2920,11 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject
|
||||
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);
|
||||
const 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);
|
||||
}
|
||||
|
||||
int len = pyrna_prop_array_length(self);
|
||||
const int len = pyrna_prop_array_length(self);
|
||||
Py_ssize_t start, stop, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -3055,7 +3056,7 @@ static int prop_subscript_ass_array_slice__bool_recursive(PyObject **value_items
|
||||
BLI_assert(totdim == 1);
|
||||
int i;
|
||||
for (i = 0; i != length; i++) {
|
||||
int v = PyLong_AsLong(value_items[i]);
|
||||
const int v = PyLong_AsLong(value_items[i]);
|
||||
value[i] = v;
|
||||
}
|
||||
return i;
|
||||
@@ -3097,7 +3098,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr,
|
||||
}
|
||||
|
||||
int dimsize[3];
|
||||
int totdim = RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
const int totdim = RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
if (totdim > 1) {
|
||||
BLI_assert(dimsize[arraydim] == length);
|
||||
}
|
||||
@@ -3247,7 +3248,7 @@ static int pyrna_prop_array_ass_subscript(BPy_PropertyArrayRNA *self,
|
||||
}
|
||||
|
||||
else if (PyIndex_Check(key)) {
|
||||
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
|
||||
const Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
|
||||
if (i == -1 && PyErr_Occurred()) {
|
||||
ret = -1;
|
||||
}
|
||||
@@ -3256,7 +3257,7 @@ static int pyrna_prop_array_ass_subscript(BPy_PropertyArrayRNA *self,
|
||||
}
|
||||
}
|
||||
else if (PySlice_Check(key)) {
|
||||
Py_ssize_t len = pyrna_prop_array_length(self);
|
||||
const Py_ssize_t len = pyrna_prop_array_length(self);
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -4249,7 +4250,7 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname)
|
||||
ListBase newlb;
|
||||
short newtype;
|
||||
|
||||
int done = CTX_data_get(C, name, &newptr, &newlb, &newtype);
|
||||
const int done = CTX_data_get(C, name, &newptr, &newlb, &newtype);
|
||||
|
||||
if (done == 1) { /* Found. */
|
||||
switch (newtype) {
|
||||
@@ -4401,7 +4402,7 @@ static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyOb
|
||||
if (value) {
|
||||
/* Check if the value is a property. */
|
||||
if (is_deferred_prop) {
|
||||
int ret = deferred_register_prop(srna, attr, value);
|
||||
const int ret = deferred_register_prop(srna, attr, value);
|
||||
if (ret == -1) {
|
||||
/* Error set. */
|
||||
return ret;
|
||||
@@ -4471,7 +4472,7 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject
|
||||
ListBase newlb;
|
||||
short newtype;
|
||||
|
||||
int done = CTX_data_get(C, name, &newptr, &newlb, &newtype);
|
||||
const int done = CTX_data_get(C, name, &newptr, &newlb, &newtype);
|
||||
|
||||
if (done == 1) {
|
||||
PyErr_Format(
|
||||
@@ -4646,7 +4647,7 @@ static PyObject *pyrna_prop_collection_idprop_add(BPy_PropertyRNA *self)
|
||||
|
||||
static PyObject *pyrna_prop_collection_idprop_remove(BPy_PropertyRNA *self, PyObject *value)
|
||||
{
|
||||
int key = PyLong_AsLong(value);
|
||||
const int key = PyLong_AsLong(value);
|
||||
|
||||
#ifdef USE_PEDANTIC_WRITE
|
||||
if (rna_disallow_writes && rna_id_write_error(&self->ptr, NULL)) {
|
||||
@@ -5172,7 +5173,7 @@ static int foreach_parse_args(BPy_PropertyRNA *self,
|
||||
|
||||
static bool foreach_compat_buffer(RawPropertyType raw_type, int attr_signed, const char *format)
|
||||
{
|
||||
char f = format ? *format : 'B'; /* B is assumed when not set */
|
||||
const char f = format ? *format : 'B'; /* B is assumed when not set */
|
||||
|
||||
switch (raw_type) {
|
||||
case PROP_RAW_CHAR:
|
||||
@@ -5400,7 +5401,7 @@ static PyObject *pyprop_array_foreach_getset(BPy_PropertyArrayRNA *self,
|
||||
PyObject *item = NULL;
|
||||
Py_ssize_t i, seq_size, size;
|
||||
void *array = NULL;
|
||||
PropertyType prop_type = RNA_property_type(self->prop);
|
||||
const PropertyType prop_type = RNA_property_type(self->prop);
|
||||
|
||||
/* Get/set both take the same args currently. */
|
||||
PyObject *seq;
|
||||
@@ -5498,7 +5499,7 @@ static PyObject *pyprop_array_foreach_getset(BPy_PropertyArrayRNA *self,
|
||||
}
|
||||
}
|
||||
else {
|
||||
char f = buf.format ? buf.format[0] : 0;
|
||||
const char f = buf.format ? buf.format[0] : 0;
|
||||
if ((prop_type == PROP_INT && (buf.itemsize != sizeof(int) || (f != 'l' && f != 'i'))) ||
|
||||
(prop_type == PROP_FLOAT && (buf.itemsize != sizeof(float) || f != 'f'))) {
|
||||
PyBuffer_Release(&buf);
|
||||
@@ -8030,7 +8031,7 @@ static int rna_function_arg_count(FunctionRNA *func, int *min_count)
|
||||
const ListBase *lb = RNA_function_defined_parameters(func);
|
||||
PropertyRNA *parm;
|
||||
Link *link;
|
||||
int flag = RNA_function_flag(func);
|
||||
const int flag = RNA_function_flag(func);
|
||||
const bool is_staticmethod = (flag & FUNC_NO_SELF) && !(flag & FUNC_USE_SELF_TYPE);
|
||||
int count = is_staticmethod ? 0 : 1;
|
||||
bool done_min_count = false;
|
||||
@@ -8273,7 +8274,7 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
|
||||
ParameterIterator iter;
|
||||
PointerRNA funcptr;
|
||||
int err = 0, i, ret_len = 0, arg_count;
|
||||
int flag = RNA_function_flag(func);
|
||||
const int flag = RNA_function_flag(func);
|
||||
const bool is_staticmethod = (flag & FUNC_NO_SELF) && !(flag & FUNC_USE_SELF_TYPE);
|
||||
const bool is_classmethod = (flag & FUNC_NO_SELF) && (flag & FUNC_USE_SELF_TYPE);
|
||||
|
||||
@@ -9015,7 +9016,7 @@ void pyrna_struct_type_extend_capi(struct StructRNA *srna,
|
||||
py_method = PyCFunction_New(method, NULL);
|
||||
}
|
||||
|
||||
int err = PyDict_SetItemString(dict, method->ml_name, py_method);
|
||||
const int err = PyDict_SetItemString(dict, method->ml_name, py_method);
|
||||
Py_DECREF(py_method);
|
||||
BLI_assert(!(err < 0));
|
||||
UNUSED_VARS_NDEBUG(err);
|
||||
|
||||
@@ -131,7 +131,7 @@ static int pyrna_struct_anim_args_parse_ex(PointerRNA *ptr,
|
||||
}
|
||||
}
|
||||
else {
|
||||
int array_len = RNA_property_array_length(&r_ptr, prop);
|
||||
const int array_len = RNA_property_array_length(&r_ptr, prop);
|
||||
if ((*r_index) < -1 || (*r_index) >= array_len) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s index out of range \"%s\", given %d, array length is %d",
|
||||
@@ -316,7 +316,7 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
int index = -1;
|
||||
float cfra = FLT_MAX;
|
||||
const char *group_name = NULL;
|
||||
char keytype = BEZT_KEYTYPE_KEYFRAME; /* XXX: Expose this as a one-off option... */
|
||||
const char keytype = BEZT_KEYTYPE_KEYFRAME; /* XXX: Expose this as a one-off option... */
|
||||
int options = 0;
|
||||
|
||||
PYRNA_STRUCT_CHECK_OBJ(self);
|
||||
|
||||
@@ -361,7 +361,7 @@ static int validate_array(PyObject *rvalue,
|
||||
const char *error_prefix)
|
||||
{
|
||||
int dimsize[MAX_ARRAY_DIMENSION];
|
||||
int totdim = RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
const int totdim = RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
|
||||
/* validate type first because length validation may modify property array length */
|
||||
|
||||
@@ -466,7 +466,7 @@ static char *copy_values(PyObject *seq,
|
||||
const ItemConvert_FuncArg *convert_item,
|
||||
RNA_SetIndexFunc rna_set_index)
|
||||
{
|
||||
int totdim = RNA_property_array_dimension(ptr, prop, NULL);
|
||||
const int totdim = RNA_property_array_dimension(ptr, prop, NULL);
|
||||
const Py_ssize_t seq_size = PySequence_Size(seq);
|
||||
Py_ssize_t i;
|
||||
|
||||
@@ -487,7 +487,7 @@ static char *copy_values(PyObject *seq,
|
||||
if (dim == 0) {
|
||||
if (MatrixObject_Check(seq)) {
|
||||
MatrixObject *pymat = (MatrixObject *)seq;
|
||||
size_t allocsize = pymat->num_col * pymat->num_row * sizeof(float);
|
||||
const size_t allocsize = pymat->num_col * pymat->num_row * sizeof(float);
|
||||
|
||||
/* read callback already done by validate */
|
||||
/* since this is the first iteration we can assume data is allocated */
|
||||
@@ -993,7 +993,7 @@ PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop)
|
||||
/* TODO, multi-dimensional arrays */
|
||||
int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
|
||||
{
|
||||
int len = RNA_property_array_length(ptr, prop);
|
||||
const int len = RNA_property_array_length(ptr, prop);
|
||||
int type;
|
||||
int i;
|
||||
|
||||
@@ -1011,7 +1011,7 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
|
||||
|
||||
switch (type) {
|
||||
case PROP_FLOAT: {
|
||||
float value_f = PyFloat_AsDouble(value);
|
||||
const float value_f = PyFloat_AsDouble(value);
|
||||
if (value_f == -1 && PyErr_Occurred()) {
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
@@ -1044,7 +1044,7 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
|
||||
break;
|
||||
}
|
||||
case PROP_INT: {
|
||||
int value_i = PyC_Long_AsI32(value);
|
||||
const int value_i = PyC_Long_AsI32(value);
|
||||
if (value_i == -1 && PyErr_Occurred()) {
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
@@ -1077,7 +1077,7 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
|
||||
break;
|
||||
}
|
||||
case PROP_BOOLEAN: {
|
||||
int value_i = PyC_Long_AsBool(value);
|
||||
const int value_i = PyC_Long_AsBool(value);
|
||||
if (value_i == -1 && PyErr_Occurred()) {
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
|
||||
@@ -84,7 +84,7 @@ static void cb_region_draw(const bContext *C, ARegion *UNUSED(region), void *cus
|
||||
static PyObject *PyC_Tuple_CopySized(PyObject *src, int len_dst)
|
||||
{
|
||||
PyObject *dst = PyTuple_New(len_dst);
|
||||
int len_src = PyTuple_GET_SIZE(src);
|
||||
const int len_src = PyTuple_GET_SIZE(src);
|
||||
BLI_assert(len_src <= len_dst);
|
||||
for (int i = 0; i < len_src; i++) {
|
||||
PyObject *item = PyTuple_GET_ITEM(src, i);
|
||||
|
||||
@@ -57,7 +57,7 @@ PyObject *pyrna_driver_get_variable_value(struct ChannelDriver *driver, struct D
|
||||
}
|
||||
else {
|
||||
/* object & property */
|
||||
PropertyType type = RNA_property_type(prop);
|
||||
const PropertyType type = RNA_property_type(prop);
|
||||
if (type == PROP_ENUM) {
|
||||
/* Note that enum's are converted to strings by default,
|
||||
* we want to avoid that, see: T52213 */
|
||||
|
||||
@@ -63,7 +63,7 @@ static void py_rna_gizmo_handler_get_cb(const wmGizmo *UNUSED(gz),
|
||||
wmGizmoProperty *gz_prop,
|
||||
void *value_p)
|
||||
{
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
|
||||
struct BPyGizmoHandlerUserData *data = gz_prop->custom_func.user_data;
|
||||
PyObject *ret = PyObject_CallObject(data->fn_slots[BPY_GIZMO_FN_SLOT_GET], NULL);
|
||||
@@ -110,7 +110,7 @@ static void py_rna_gizmo_handler_set_cb(const wmGizmo *UNUSED(gz),
|
||||
wmGizmoProperty *gz_prop,
|
||||
const void *value_p)
|
||||
{
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
|
||||
struct BPyGizmoHandlerUserData *data = gz_prop->custom_func.user_data;
|
||||
|
||||
@@ -159,7 +159,7 @@ static void py_rna_gizmo_handler_range_get_cb(const wmGizmo *UNUSED(gz),
|
||||
{
|
||||
struct BPyGizmoHandlerUserData *data = gz_prop->custom_func.user_data;
|
||||
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
|
||||
PyObject *ret = PyObject_CallObject(data->fn_slots[BPY_GIZMO_FN_SLOT_RANGE_GET], NULL);
|
||||
if (ret == NULL) {
|
||||
@@ -211,7 +211,7 @@ static void py_rna_gizmo_handler_free_cb(const wmGizmo *UNUSED(gz), wmGizmoPrope
|
||||
{
|
||||
struct BPyGizmoHandlerUserData *data = gz_prop->custom_func.user_data;
|
||||
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
for (int i = 0; i < BPY_GIZMO_FN_SLOT_LEN; i++) {
|
||||
Py_XDECREF(data->fn_slots[i]);
|
||||
}
|
||||
@@ -234,7 +234,7 @@ PyDoc_STRVAR(
|
||||
" :type range: callable\n");
|
||||
static PyObject *bpy_gizmo_target_set_handler(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||
{
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
const PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
|
||||
struct {
|
||||
PyObject *self;
|
||||
@@ -368,7 +368,7 @@ static PyObject *bpy_gizmo_target_get_value(PyObject *UNUSED(self), PyObject *ar
|
||||
return PyC_Tuple_PackArray_F32(value, array_len);
|
||||
}
|
||||
|
||||
float value = WM_gizmo_target_property_float_get(gz, gz_prop);
|
||||
const float value = WM_gizmo_target_property_float_get(gz, gz_prop);
|
||||
return PyFloat_FromDouble(value);
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user