Core: add type checks to ID property accessors

Since moving the C++ ID property access macros cast "const" away,
replace with get/set accessors and add asserts that correct types
are used.
This commit is contained in:
Campbell Barton
2025-09-12 06:29:42 +00:00
parent f29382bd7b
commit 84511b8509
36 changed files with 381 additions and 286 deletions

View File

@@ -293,39 +293,86 @@ void IDP_ClearProperty(IDProperty *prop);
void IDP_Reset(IDProperty *prop, const IDProperty *reference);
#define IDP_Int(prop) ((prop)->data.val)
#define IDP_Bool(prop) ((prop)->data.val)
#define IDP_Array(prop) ((prop)->data.pointer)
/* C11 const correctness for casts */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
# define IDP_Float(prop) \
_Generic((prop), \
IDProperty *: (*(float *)&(prop)->data.val), \
const IDProperty *: (*(const float *)&(prop)->data.val))
# define IDP_Double(prop) \
_Generic((prop), \
IDProperty *: (*(double *)&(prop)->data.val), \
const IDProperty *: (*(const double *)&(prop)->data.val))
# define IDP_String(prop) \
_Generic((prop), \
IDProperty *: ((char *)(prop)->data.pointer), \
const IDProperty *: ((const char *)(prop)->data.pointer))
# define IDP_IDPArray(prop) \
_Generic((prop), \
IDProperty *: ((IDProperty *)(prop)->data.pointer), \
const IDProperty *: ((const IDProperty *)(prop)->data.pointer))
# define IDP_Id(prop) \
_Generic((prop), \
IDProperty *: ((ID *)(prop)->data.pointer), \
const IDProperty *: ((const ID *)(prop)->data.pointer))
#ifndef NDEBUG
const IDProperty *_IDP_assert_type(const IDProperty *prop, char ty);
const IDProperty *_IDP_assert_type_and_subtype(const IDProperty *prop, char ty, char sub_ty);
const IDProperty *_IDP_assert_type_mask(const IDProperty *prop, int ty_mask);
#else
# define IDP_Float(prop) (*(float *)&(prop)->data.val)
# define IDP_Double(prop) (*(double *)&(prop)->data.val)
# define IDP_String(prop) ((char *)(prop)->data.pointer)
# define IDP_IDPArray(prop) ((IDProperty *)(prop)->data.pointer)
# define IDP_Id(prop) ((ID *)(prop)->data.pointer)
# define _IDP_assert_type(prop, ty) (prop)
# define _IDP_assert_type_and_subtype(prop, ty, sub_ty) (prop)
# define _IDP_assert_type_mask(prop, ty_mask) (prop)
#endif
#define IDP_int_get(prop) (_IDP_assert_type(prop, IDP_INT)->data.val)
#define IDP_int_set(prop, value) \
{ \
IDProperty *prop_ = (prop); \
BLI_assert(prop_->type == IDP_INT); \
prop_->data.val = value; \
} \
((void)0)
#define IDP_bool_get(prop) ((_IDP_assert_type(prop, IDP_BOOLEAN))->data.val)
#define IDP_bool_set(prop, value) \
{ \
IDProperty *prop_ = (prop); \
BLI_assert(prop_->type == IDP_BOOLEAN); \
prop_->data.val = value; \
} \
((void)0)
#define IDP_int_or_bool_get(prop) \
(_IDP_assert_type_mask(prop, (1 << IDP_INT) | (1 << IDP_BOOLEAN))->data.val)
#define IDP_int_or_bool_set(prop, value) \
{ \
IDProperty *prop_ = (prop); \
BLI_assert(ELEM(prop_->type, IDP_INT, IDP_BOOLEAN)); \
prop_->data.val = value; \
} \
((void)0)
#define IDP_float_get(prop) (*(const float *)&(_IDP_assert_type(prop, IDP_FLOAT)->data.val))
#define IDP_float_set(prop, value) \
{ \
IDProperty *prop_ = (prop); \
BLI_assert(prop_->type == IDP_FLOAT); \
(*(float *)&(prop_)->data.val) = value; \
} \
((void)0)
#define IDP_double_get(prop) (*(const double *)&(_IDP_assert_type(prop, IDP_DOUBLE)->data.val))
#define IDP_double_set(prop, value) \
{ \
IDProperty *prop_ = (prop); \
BLI_assert(prop_->type == IDP_DOUBLE); \
(*(double *)&(prop_)->data.val) = value; \
} \
((void)0)
/**
* Use when the type of the array is not known.
*
* Avoid using this where possible.
*/
#define IDP_array_voidp_get(prop) (_IDP_assert_type(prop, IDP_ARRAY)->data.pointer)
#define IDP_array_int_get(prop) \
static_cast<int *>(_IDP_assert_type_and_subtype(prop, IDP_ARRAY, IDP_INT)->data.pointer)
#define IDP_array_bool_get(prop) \
static_cast<int8_t *>(_IDP_assert_type_and_subtype(prop, IDP_ARRAY, IDP_BOOLEAN)->data.pointer)
#define IDP_array_float_get(prop) \
static_cast<float *>(_IDP_assert_type_and_subtype(prop, IDP_ARRAY, IDP_FLOAT)->data.pointer)
#define IDP_array_double_get(prop) \
static_cast<double *>(_IDP_assert_type_and_subtype(prop, IDP_ARRAY, IDP_DOUBLE)->data.pointer)
#define IDP_property_array_get(prop) \
static_cast<IDProperty *>(_IDP_assert_type(prop, IDP_IDPARRAY)->data.pointer)
#define IDP_string_get(prop) ((char *)_IDP_assert_type(prop, IDP_STRING)->data.pointer)
/* No `IDP_string_set` needed. */
#define IDP_ID_get(prop) ((void)0, ((ID *)_IDP_assert_type(prop, IDP_ID)->data.pointer))
/* No `IDP_ID_set` needed. */
/**
* Return an int from an #IDProperty with a compatible type. This should be avoided, but
* it's sometimes necessary, for example when legacy files have incorrect property types.

View File

@@ -150,7 +150,7 @@ static CameraCyclesCompatibilityData camera_write_cycles_compatibility_data_crea
auto cycles_property_int_set = [](IDProperty *idprop, const char *name, int value) {
if (IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_INT)) {
IDP_Int(prop) = value;
IDP_int_set(prop, value);
}
else {
IDP_AddToGroup(idprop, blender::bke::idprop::create(name, value).release());
@@ -159,7 +159,7 @@ static CameraCyclesCompatibilityData camera_write_cycles_compatibility_data_crea
auto cycles_property_float_set = [](IDProperty *idprop, const char *name, float value) {
if (IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_FLOAT)) {
IDP_Float(prop) = value;
IDP_float_set(prop, value);
}
else {
IDP_AddToGroup(idprop, blender::bke::idprop::create(name, value).release());

View File

@@ -62,7 +62,7 @@ static size_t idp_size_table[] = {
/** \name Array Functions (IDP Array API)
* \{ */
#define GETPROP(prop, i) &(IDP_IDPArray(prop)[i])
#define GETPROP(prop, i) &(IDP_property_array_get(prop)[i])
IDProperty *IDP_NewIDPArray(const blender::StringRef name)
{
@@ -362,7 +362,7 @@ IDProperty *IDP_NewStringMaxSize(const char *st,
if (st == nullptr) {
prop->data.pointer = MEM_malloc_arrayN<char>(DEFAULT_ALLOC_FOR_NULL_STRINGS,
"id property string 1");
*IDP_String(prop) = '\0';
*IDP_string_get(prop) = '\0';
prop->totallen = DEFAULT_ALLOC_FOR_NULL_STRINGS;
prop->len = 1; /* nullptr string, has len of 1 to account for null byte. */
}
@@ -378,7 +378,7 @@ IDProperty *IDP_NewStringMaxSize(const char *st,
if (stlen > 1) {
memcpy(prop->data.pointer, st, size_t(stlen));
}
IDP_String(prop)[stlen - 1] = '\0';
IDP_string_get(prop)[stlen - 1] = '\0';
}
prop->type = IDP_STRING;
@@ -423,7 +423,7 @@ void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, const size_t st_m
if (stlen > 0) {
memcpy(prop->data.pointer, st, size_t(stlen));
if (is_byte == false) {
IDP_String(prop)[stlen - 1] = '\0';
IDP_string_get(prop)[stlen - 1] = '\0';
}
}
}
@@ -466,7 +466,7 @@ const IDPropertyUIDataEnumItem *IDP_EnumItemFind(const IDProperty *prop)
const IDPropertyUIDataInt *ui_data = reinterpret_cast<const IDPropertyUIDataInt *>(
prop->ui_data);
const int value = IDP_Int(prop);
const int value = IDP_int_get(prop);
for (const IDPropertyUIDataEnumItem &item :
blender::Span(ui_data->enum_items, ui_data->enum_items_num))
{
@@ -529,7 +529,7 @@ static IDProperty *IDP_CopyID(const IDProperty *prop, const int flag)
newp->data.pointer = prop->data.pointer;
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
id_us_plus(IDP_Id(newp));
id_us_plus(IDP_ID_get(newp));
}
return newp;
@@ -541,14 +541,14 @@ void IDP_AssignID(IDProperty *prop, ID *id, const int flag)
/* Do not assign embedded IDs to IDProperties. */
BLI_assert(!id || (id->flag & ID_FLAG_EMBEDDED_DATA) == 0);
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0 && IDP_Id(prop) != nullptr) {
id_us_min(IDP_Id(prop));
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0 && IDP_ID_get(prop) != nullptr) {
id_us_min(IDP_ID_get(prop));
}
prop->data.pointer = id;
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
id_us_plus(IDP_Id(prop));
id_us_plus(IDP_ID_get(prop));
}
}
@@ -808,13 +808,13 @@ int IDP_coerce_to_int_or_zero(const IDProperty *prop)
{
switch (prop->type) {
case IDP_INT:
return IDP_Int(prop);
return IDP_int_get(prop);
case IDP_DOUBLE:
return int(IDP_Double(prop));
return int(IDP_double_get(prop));
case IDP_FLOAT:
return int(IDP_Float(prop));
return int(IDP_float_get(prop));
case IDP_BOOLEAN:
return int(IDP_Bool(prop));
return int(IDP_bool_get(prop));
default:
return 0;
}
@@ -824,13 +824,13 @@ double IDP_coerce_to_double_or_zero(const IDProperty *prop)
{
switch (prop->type) {
case IDP_DOUBLE:
return IDP_Double(prop);
return IDP_double_get(prop);
case IDP_FLOAT:
return double(IDP_Float(prop));
return double(IDP_float_get(prop));
case IDP_INT:
return double(IDP_Int(prop));
return double(IDP_int_get(prop));
case IDP_BOOLEAN:
return double(IDP_Bool(prop));
return double(IDP_bool_get(prop));
default:
return 0.0;
}
@@ -840,13 +840,13 @@ float IDP_coerce_to_float_or_zero(const IDProperty *prop)
{
switch (prop->type) {
case IDP_FLOAT:
return IDP_Float(prop);
return IDP_float_get(prop);
case IDP_DOUBLE:
return float(IDP_Double(prop));
return float(IDP_double_get(prop));
case IDP_INT:
return float(IDP_Int(prop));
return float(IDP_int_get(prop));
case IDP_BOOLEAN:
return float(IDP_Bool(prop));
return float(IDP_bool_get(prop));
default:
return 0.0f;
}
@@ -936,12 +936,12 @@ bool IDP_EqualsProperties_ex(const IDProperty *prop1,
switch (prop1->type) {
case IDP_INT:
return (IDP_Int(prop1) == IDP_Int(prop2));
return (IDP_int_get(prop1) == IDP_int_get(prop2));
case IDP_FLOAT:
#if !defined(NDEBUG) && defined(WITH_PYTHON)
{
float p1 = IDP_Float(prop1);
float p2 = IDP_Float(prop2);
float p1 = IDP_float_get(prop1);
float p2 = IDP_float_get(prop2);
if ((p1 != p2) && ((fabsf(p1 - p2) / max_ff(fabsf(p1), fabsf(p2))) < 0.001f)) {
printf(
"WARNING: Comparing two float properties that have nearly the same value (%f vs. "
@@ -955,19 +955,19 @@ bool IDP_EqualsProperties_ex(const IDProperty *prop1,
}
}
#endif
return (IDP_Float(prop1) == IDP_Float(prop2));
return (IDP_float_get(prop1) == IDP_float_get(prop2));
case IDP_DOUBLE:
return (IDP_Double(prop1) == IDP_Double(prop2));
return (IDP_double_get(prop1) == IDP_double_get(prop2));
case IDP_BOOLEAN:
return (IDP_Bool(prop1) == IDP_Bool(prop2));
return (IDP_bool_get(prop1) == IDP_bool_get(prop2));
case IDP_STRING: {
return ((prop1->len == prop2->len) &&
STREQLEN(IDP_String(prop1), IDP_String(prop2), size_t(prop1->len)));
STREQLEN(IDP_string_get(prop1), IDP_string_get(prop2), size_t(prop1->len)));
}
case IDP_ARRAY:
if (prop1->len == prop2->len && prop1->subtype == prop2->subtype) {
return (memcmp(IDP_Array(prop1),
IDP_Array(prop2),
return (memcmp(IDP_array_voidp_get(prop1),
IDP_array_voidp_get(prop2),
idp_size_table[int(prop1->subtype)] * size_t(prop1->len)) == 0);
}
return false;
@@ -987,8 +987,8 @@ bool IDP_EqualsProperties_ex(const IDProperty *prop1,
return true;
}
case IDP_IDPARRAY: {
const IDProperty *array1 = IDP_IDPArray(prop1);
const IDProperty *array2 = IDP_IDPArray(prop2);
const IDProperty *array1 = IDP_property_array_get(prop1);
const IDProperty *array2 = IDP_property_array_get(prop2);
if (prop1->len != prop2->len) {
return false;
@@ -1002,7 +1002,7 @@ bool IDP_EqualsProperties_ex(const IDProperty *prop1,
return true;
}
case IDP_ID:
return (IDP_Id(prop1) == IDP_Id(prop2));
return (IDP_ID_get(prop1) == IDP_ID_get(prop2));
default:
BLI_assert_unreachable();
break;
@@ -1066,7 +1066,7 @@ IDProperty *IDP_New(const char type,
if (st == nullptr) {
prop->data.pointer = MEM_malloc_arrayN<char>(DEFAULT_ALLOC_FOR_NULL_STRINGS,
"id property string 1");
*IDP_String(prop) = '\0';
*IDP_string_get(prop) = '\0';
prop->totallen = DEFAULT_ALLOC_FOR_NULL_STRINGS;
prop->len = 0;
}
@@ -1082,7 +1082,7 @@ IDProperty *IDP_New(const char type,
if (st == nullptr || val->string.len <= 1) {
prop->data.pointer = MEM_malloc_arrayN<char>(DEFAULT_ALLOC_FOR_NULL_STRINGS,
"id property string 1");
*IDP_String(prop) = '\0';
*IDP_string_get(prop) = '\0';
prop->totallen = DEFAULT_ALLOC_FOR_NULL_STRINGS;
/* nullptr string, has len of 1 to account for null byte. */
prop->len = 1;
@@ -1092,7 +1092,7 @@ IDProperty *IDP_New(const char type,
prop->data.pointer = MEM_malloc_arrayN<char>(size_t(val->string.len),
"id property string 3");
memcpy(prop->data.pointer, st, size_t(val->string.len) - 1);
IDP_String(prop)[val->string.len - 1] = '\0';
IDP_string_get(prop)[val->string.len - 1] = '\0';
prop->len = prop->totallen = val->string.len;
}
prop->subtype = IDP_STRING_SUB_UTF8;
@@ -1108,7 +1108,7 @@ IDProperty *IDP_New(const char type,
prop = MEM_callocN<IDProperty>("IDProperty datablock");
prop->data.pointer = (void *)val->id;
prop->type = IDP_ID;
id_us_plus(IDP_Id(prop));
id_us_plus(IDP_ID_get(prop));
break;
}
default: {
@@ -1237,7 +1237,7 @@ void IDP_FreePropertyContent_ex(IDProperty *prop, const bool do_id_user)
break;
case IDP_ID:
if (do_id_user) {
id_us_min(IDP_Id(prop));
id_us_min(IDP_ID_get(prop));
}
break;
}
@@ -1303,7 +1303,7 @@ void IDP_foreach_property(IDProperty *id_property_root,
break;
}
case IDP_IDPARRAY: {
IDProperty *loop = static_cast<IDProperty *>(IDP_Array(id_property_root));
IDProperty *loop = IDP_property_array_get(id_property_root);
for (int i = 0; i < id_property_root->len; i++) {
IDP_foreach_property(&loop[i], type_filter, callback);
}
@@ -1666,7 +1666,7 @@ static void IDP_DirectLinkProperty(IDProperty *prop, BlendDataReader *reader)
/* NOTE: we do not attempt to free unknown prop, we have no way to know how to do that! */
prop->type = IDP_INT;
prop->subtype = 0;
IDP_Int(prop) = 0;
IDP_int_set(prop, 0);
}
if (prop->ui_data != nullptr) {
@@ -1976,3 +1976,30 @@ IDPropertyUIData *IDP_TryConvertUIData(IDPropertyUIData *src,
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Debugging
* \{ */
#ifndef NDEBUG
const IDProperty *_IDP_assert_type(const IDProperty *prop, const char ty)
{
BLI_assert(prop->type == ty);
return prop;
}
const IDProperty *_IDP_assert_type_and_subtype(const IDProperty *prop,
const char ty,
const char sub_ty)
{
BLI_assert((prop->type == ty) && (prop->subtype == sub_ty));
return prop;
}
const IDProperty *_IDP_assert_type_mask(const IDProperty *prop, const int ty_mask)
{
BLI_assert(1 << int(prop->type) & ty_mask);
return prop;
}
#endif /* !NDEBUG */
/** \} */

View File

@@ -94,7 +94,7 @@ static void array_values_set(IDProperty *property,
{
BLI_assert(values);
BLI_assert(property->len == values_len);
memcpy(IDP_Array(property), values, values_len * value_size);
memcpy(IDP_array_voidp_get(property), values, values_len * value_size);
}
/**

View File

@@ -300,7 +300,7 @@ class IDPStringSerializer : public IDPropertySerializer {
const IDProperty *id_property) const override
{
std::shared_ptr<DictionaryValue> result = create_dictionary(id_property);
result->append_str(IDP_KEY_VALUE, IDP_String(id_property));
result->append_str(IDP_KEY_VALUE, IDP_string_get(id_property));
return result;
}
@@ -339,7 +339,7 @@ class IDPBoolSerializer : public IDPropertySerializer {
const IDProperty *id_property) const override
{
std::shared_ptr<DictionaryValue> result = create_dictionary(id_property);
result->append(IDP_KEY_VALUE, std::make_shared<BooleanValue>(IDP_Bool(id_property) != 0));
result->append(IDP_KEY_VALUE, std::make_shared<BooleanValue>(IDP_bool_get(id_property) != 0));
return result;
}
@@ -378,7 +378,7 @@ class IDPIntSerializer : public IDPropertySerializer {
const IDProperty *id_property) const override
{
std::shared_ptr<DictionaryValue> result = create_dictionary(id_property);
result->append_int(IDP_KEY_VALUE, IDP_Int(id_property));
result->append_int(IDP_KEY_VALUE, IDP_int_get(id_property));
return result;
}
@@ -417,7 +417,7 @@ class IDPFloatSerializer : public IDPropertySerializer {
const IDProperty *id_property) const override
{
std::shared_ptr<DictionaryValue> result = create_dictionary(id_property);
result->append_double(IDP_KEY_VALUE, IDP_Float(id_property));
result->append_double(IDP_KEY_VALUE, IDP_float_get(id_property));
return result;
}
@@ -456,7 +456,7 @@ class IDPDoubleSerializer : public IDPropertySerializer {
const IDProperty *id_property) const override
{
std::shared_ptr<DictionaryValue> result = create_dictionary(id_property);
result->append_double(IDP_KEY_VALUE, IDP_Double(id_property));
result->append_double(IDP_KEY_VALUE, IDP_double_get(id_property));
return result;
}
@@ -502,22 +502,22 @@ class IDPArraySerializer : public IDPropertySerializer {
ArrayValue &array = *result->append_array(IDP_KEY_VALUE);
switch (static_cast<eIDPropertyType>(id_property->subtype)) {
case IDP_INT: {
int32_t *values = static_cast<int32_t *>(IDP_Array(id_property));
int32_t *values = IDP_array_int_get(id_property);
add_values<int32_t, IntValue>(array, Span<int32_t>(values, id_property->len));
break;
}
case IDP_FLOAT: {
float *values = static_cast<float *>(IDP_Array(id_property));
float *values = IDP_array_float_get(id_property);
add_values<float, DoubleValue>(array, Span<float>(values, id_property->len));
break;
}
case IDP_DOUBLE: {
double *values = static_cast<double *>(IDP_Array(id_property));
double *values = IDP_array_double_get(id_property);
add_values<double, DoubleValue>(array, Span<double>(values, id_property->len));
break;
}
case IDP_GROUP: {
IDProperty *values = static_cast<IDProperty *>(IDP_Array(id_property));
IDProperty *values = static_cast<IDProperty *>(IDP_array_voidp_get(id_property));
add_values(array, Span<IDProperty>(values, id_property->len));
break;
}

View File

@@ -218,7 +218,7 @@ static void test_idprop(const IDProperty *id_property,
ASSERT_NE(id_property, nullptr);
EXPECT_EQ(id_property->type, IDP_STRING);
EXPECT_EQ(id_property->name, expected_name);
EXPECT_EQ(IDP_String(id_property), expected_value);
EXPECT_EQ(IDP_string_get(id_property), expected_value);
}
static void test_idprop(const IDProperty *id_property,
@@ -228,7 +228,7 @@ static void test_idprop(const IDProperty *id_property,
ASSERT_NE(id_property, nullptr);
EXPECT_EQ(id_property->type, IDP_INT);
EXPECT_EQ(id_property->name, expected_name);
EXPECT_EQ(IDP_Int(id_property), expected_value);
EXPECT_EQ(IDP_int_get(id_property), expected_value);
}
static void test_idprop(const IDProperty *id_property,
@@ -238,7 +238,7 @@ static void test_idprop(const IDProperty *id_property,
ASSERT_NE(id_property, nullptr);
EXPECT_EQ(id_property->type, IDP_FLOAT);
EXPECT_EQ(id_property->name, expected_name);
EXPECT_EQ(IDP_Float(id_property), expected_value);
EXPECT_EQ(IDP_float_get(id_property), expected_value);
}
static void test_idprop(const IDProperty *id_property,
@@ -248,7 +248,7 @@ static void test_idprop(const IDProperty *id_property,
ASSERT_NE(id_property, nullptr);
EXPECT_EQ(id_property->type, IDP_DOUBLE);
EXPECT_EQ(id_property->name, expected_name);
EXPECT_EQ(IDP_Double(id_property), expected_value);
EXPECT_EQ(IDP_double_get(id_property), expected_value);
}
static void test_idprop(const IDProperty *id_property,
@@ -260,7 +260,7 @@ static void test_idprop(const IDProperty *id_property,
EXPECT_EQ(id_property->subtype, IDP_INT);
EXPECT_EQ(id_property->len, values.size());
EXPECT_EQ(id_property->name, expected_name);
int32_t *idprop_values = static_cast<int32_t *>(IDP_Array(id_property));
int32_t *idprop_values = IDP_array_int_get(id_property);
for (int i = 0; i < values.size(); i++) {
EXPECT_EQ(idprop_values[i], values[i]);
}
@@ -275,7 +275,7 @@ static void test_idprop(const IDProperty *id_property,
EXPECT_EQ(id_property->subtype, IDP_FLOAT);
EXPECT_EQ(id_property->len, values.size());
EXPECT_EQ(id_property->name, expected_name);
float *idprop_values = static_cast<float *>(IDP_Array(id_property));
float *idprop_values = IDP_array_float_get(id_property);
for (int i = 0; i < values.size(); i++) {
EXPECT_EQ(idprop_values[i], values[i]);
}
@@ -290,7 +290,7 @@ static void test_idprop(const IDProperty *id_property,
EXPECT_EQ(id_property->subtype, IDP_DOUBLE);
EXPECT_EQ(id_property->len, values.size());
EXPECT_EQ(id_property->name, expected_name);
double *idprop_values = static_cast<double *>(IDP_Array(id_property));
double *idprop_values = IDP_array_double_get(id_property);
for (int i = 0; i < values.size(); i++) {
EXPECT_EQ(idprop_values[i], values[i]);
}

View File

@@ -96,26 +96,26 @@ static void idp_repr_fn_recursive(ReprState *state, const IDProperty *prop)
switch (prop->type) {
case IDP_STRING: {
STR_APPEND_STR_LEN_QUOTE(IDP_String(prop), uint(std::max(0, prop->len - 1)));
STR_APPEND_STR_LEN_QUOTE(IDP_string_get(prop), uint(std::max(0, prop->len - 1)));
break;
}
case IDP_INT: {
if (const IDPropertyUIDataEnumItem *item = IDP_EnumItemFind(prop)) {
STR_APPEND_FMT("%s", item->name);
}
STR_APPEND_FMT("%d", IDP_Int(prop));
STR_APPEND_FMT("%d", IDP_int_get(prop));
break;
}
case IDP_FLOAT: {
STR_APPEND_FMT("%g", double(IDP_Float(prop)));
STR_APPEND_FMT("%g", double(IDP_float_get(prop)));
break;
}
case IDP_DOUBLE: {
STR_APPEND_FMT("%g", IDP_Double(prop));
STR_APPEND_FMT("%g", IDP_double_get(prop));
break;
}
case IDP_BOOLEAN: {
STR_APPEND_FMT("%s", IDP_Bool(prop) ? "True" : "False");
STR_APPEND_FMT("%s", IDP_bool_get(prop) ? "True" : "False");
break;
}
case IDP_ARRAY: {
@@ -165,7 +165,7 @@ static void idp_repr_fn_recursive(ReprState *state, const IDProperty *prop)
if (v != prop->data.pointer) {
STR_APPEND_STR(", ");
}
STR_APPEND_FMT("%s", IDP_Bool(prop) ? "True" : "False");
STR_APPEND_FMT("%s", IDP_bool_get(prop) ? "True" : "False");
}
break;
}

View File

@@ -117,7 +117,7 @@ void BKE_keyconfig_pref_set_select_mouse(UserDef *userdef, int value, bool overr
IDP_AddToGroup(kpt->prop, blender::bke::idprop::create("select_mouse", value).release());
}
else if (override) {
IDP_Int(idprop) = value;
IDP_int_set(idprop, value);
}
}

View File

@@ -3462,7 +3462,7 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
{ \
IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
if (_idprop != nullptr) { \
const int _value = IDP_Int(_idprop); \
const int _value = IDP_int_get(_idprop); \
if (_value) { \
scene->eevee.flag |= _flag; \
} \
@@ -3477,7 +3477,7 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
{ \
IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
if (_idprop != nullptr) { \
scene->eevee._name = IDP_Int(_idprop); \
scene->eevee._name = IDP_int_get(_idprop); \
} \
} \
((void)0)
@@ -3486,7 +3486,7 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
{ \
IDProperty *_idprop = IDP_GetPropertyFromGroup(_props, #_name); \
if (_idprop != nullptr) { \
scene->eevee._name = IDP_Float(_idprop); \
scene->eevee._name = IDP_float_get(_idprop); \
} \
} \
((void)0)

View File

@@ -145,7 +145,9 @@ static void version_idproperty_move_data_int(IDPropertyUIDataInt *ui_data,
if (default_value->type == IDP_ARRAY) {
if (default_value->subtype == IDP_INT) {
ui_data->default_array = MEM_malloc_arrayN<int>(size_t(default_value->len), __func__);
memcpy(ui_data->default_array, IDP_Array(default_value), sizeof(int) * default_value->len);
memcpy(ui_data->default_array,
IDP_array_int_get(default_value),
sizeof(int) * default_value->len);
ui_data->default_array_len = default_value->len;
}
}
@@ -191,14 +193,16 @@ static void version_idproperty_move_data_float(IDPropertyUIDataFloat *ui_data,
ui_data->default_array_len = array_len;
if (default_value->subtype == IDP_FLOAT) {
ui_data->default_array = MEM_malloc_arrayN<double>(size_t(array_len), __func__);
const float *old_default_array = static_cast<const float *>(IDP_Array(default_value));
const float *old_default_array = IDP_array_float_get(default_value);
for (int i = 0; i < ui_data->default_array_len; i++) {
ui_data->default_array[i] = double(old_default_array[i]);
}
}
else if (default_value->subtype == IDP_DOUBLE) {
ui_data->default_array = MEM_malloc_arrayN<double>(size_t(array_len), __func__);
memcpy(ui_data->default_array, IDP_Array(default_value), sizeof(double) * array_len);
memcpy(ui_data->default_array,
IDP_array_double_get(default_value),
sizeof(double) * array_len);
}
}
else if (ELEM(default_value->type, IDP_DOUBLE, IDP_FLOAT)) {
@@ -212,7 +216,7 @@ static void version_idproperty_move_data_string(IDPropertyUIDataString *ui_data,
{
IDProperty *default_value = IDP_GetPropertyFromGroup(prop_ui_data, "default");
if (default_value != nullptr && default_value->type == IDP_STRING) {
ui_data->default_value = BLI_strdup(IDP_String(default_value));
ui_data->default_value = BLI_strdup(IDP_string_get(default_value));
}
}
@@ -242,7 +246,7 @@ static void version_idproperty_ui_data(IDProperty *idprop_group)
IDProperty *subtype = IDP_GetPropertyFromGroup(prop_ui_data, "subtype");
if (subtype != nullptr && subtype->type == IDP_STRING) {
const char *subtype_string = IDP_String(subtype);
const char *subtype_string = IDP_string_get(subtype);
int result = PROP_NONE;
RNA_enum_value_from_id(rna_enum_property_subtype_items, subtype_string, &result);
ui_data->rna_subtype = result;
@@ -250,7 +254,7 @@ static void version_idproperty_ui_data(IDProperty *idprop_group)
IDProperty *description = IDP_GetPropertyFromGroup(prop_ui_data, "description");
if (description != nullptr && description->type == IDP_STRING) {
ui_data->description = BLI_strdup(IDP_String(description));
ui_data->description = BLI_strdup(IDP_string_get(description));
}
/* Type specific data. */

View File

@@ -152,8 +152,8 @@ static void version_bonelayers_to_bonecollections(Main *bmain)
* for managing bone layers and giving them names. */
SNPRINTF_UTF8(custom_prop_name, "layer_name_%u", layer);
IDProperty *prop = IDP_GetPropertyFromGroup(arm_idprops, custom_prop_name);
if (prop != nullptr && prop->type == IDP_STRING && IDP_String(prop)[0] != '\0') {
SNPRINTF_UTF8(bcoll_name, "Layer %u - %s", layer + 1, IDP_String(prop));
if (prop != nullptr && prop->type == IDP_STRING && IDP_string_get(prop)[0] != '\0') {
SNPRINTF_UTF8(bcoll_name, "Layer %u - %s", layer + 1, IDP_string_get(prop));
}
}
if (bcoll_name[0] == '\0') {
@@ -535,7 +535,7 @@ static void version_mesh_crease_generic(Main &bmain)
if (IDProperty *settings = reinterpret_cast<NodesModifierData *>(md)->settings.properties) {
LISTBASE_FOREACH (IDProperty *, prop, &settings->data.group) {
if (blender::StringRef(prop->name).endswith("_attribute_name")) {
if (STREQ(IDP_String(prop), "crease")) {
if (STREQ(IDP_string_get(prop), "crease")) {
IDP_AssignString(prop, "crease_edge");
}
}

View File

@@ -521,19 +521,19 @@ IDProperty *version_cycles_properties_from_render_layer(SceneRenderLayer *render
float version_cycles_property_float(IDProperty *idprop, const char *name, float default_value)
{
IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_FLOAT);
return (prop) ? IDP_Float(prop) : default_value;
return (prop) ? IDP_float_get(prop) : default_value;
}
int version_cycles_property_int(IDProperty *idprop, const char *name, int default_value)
{
IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_INT);
return (prop) ? IDP_Int(prop) : default_value;
return (prop) ? IDP_int_get(prop) : default_value;
}
void version_cycles_property_int_set(IDProperty *idprop, const char *name, int value)
{
if (IDProperty *prop = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_INT)) {
IDP_Int(prop) = value;
IDP_int_set(prop, value);
}
else {
IDP_AddToGroup(idprop, blender::bke::idprop::create(name, value).release());

View File

@@ -516,7 +516,7 @@ static void keymap_update_brushes_handle_add_item(
if (STREQ(kmi->idname, "WM_OT_tool_set_by_id")) {
IDProperty *idprop = IDP_GetPropertyFromGroup(kmi->properties, "name");
if (idprop && (idprop->type == IDP_STRING)) {
const blender::StringRef prop_val = IDP_String(idprop);
const blender::StringRef prop_val = IDP_string_get(idprop);
if (!prop_val.startswith("builtin_brush.")) {
return;
}
@@ -531,7 +531,7 @@ static void keymap_update_brushes_handle_add_item(
else if (STREQ(kmi->idname, "PAINT_OT_brush_select")) {
IDProperty *idprop = IDP_GetPropertyFromGroup(kmi->properties, tool_property);
if (idprop && (idprop->type == IDP_INT)) {
const int prop_val = IDP_Int(idprop);
const int prop_val = IDP_int_get(idprop);
if (id_asset_map.contains(prop_val)) {
asset_id = id_asset_map.lookup(prop_val);
}
@@ -567,7 +567,7 @@ static void keymap_update_brushes_handle_remove_item(
if (STREQ(kmi->idname, "PAINT_OT_brush_select")) {
IDProperty *idprop = IDP_GetPropertyFromGroup(kmi->properties, tool_property);
if (idprop && (idprop->type == IDP_INT)) {
const int prop_val = IDP_Int(idprop);
const int prop_val = IDP_int_get(idprop);
if (id_asset_map.contains(prop_val)) {
asset_id = id_asset_map.lookup(prop_val);
}

View File

@@ -573,7 +573,7 @@ static Map<StringRef, ID *> gather_input_ids(const Main &bmain,
if (!id_type) {
return;
}
const char *id_name = IDP_String(prop);
const char *id_name = IDP_string_get(prop);
ID *id = BKE_libblock_find_name(&const_cast<Main &>(bmain), *id_type, id_name);
if (!id) {
return;
@@ -613,7 +613,7 @@ static void replace_inputs_evaluated_data_blocks(
IDProperty &properties, const nodes::GeoNodesOperatorDepsgraphs &depsgraphs)
{
IDP_foreach_property(&properties, IDP_TYPE_FILTER_ID, [&](IDProperty *property) {
if (ID *id = IDP_Id(property)) {
if (ID *id = IDP_ID_get(property)) {
if (ID_TYPE_USE_COPY_ON_EVAL(GS(id->name))) {
property->data.pointer = const_cast<ID *>(depsgraphs.get_evaluated_id(*id));
}
@@ -945,7 +945,7 @@ static bool run_node_group_depends_on_cursor(bContext &C, wmOperatorType & /*ot*
}
const IDProperty *traits_flag = BKE_asset_metadata_idprop_find(
&asset->get_metadata(), "geometry_node_asset_traits_flag");
if (traits_flag == nullptr || !(IDP_Int(traits_flag) & GEO_NODE_ASSET_WAIT_FOR_CURSOR)) {
if (traits_flag == nullptr || !(IDP_int_get(traits_flag) & GEO_NODE_ASSET_WAIT_FOR_CURSOR)) {
return false;
}
return true;
@@ -1223,12 +1223,12 @@ static asset::AssetItemTree build_catalog_tree(const bContext &C, const Object &
const GeometryNodeAssetTraitFlag flag = asset_flag_for_context(active_object);
auto meta_data_filter = [&](const AssetMetaData &meta_data) {
const IDProperty *tree_type = BKE_asset_metadata_idprop_find(&meta_data, "type");
if (tree_type == nullptr || IDP_Int(tree_type) != NTREE_GEOMETRY) {
if (tree_type == nullptr || IDP_int_get(tree_type) != NTREE_GEOMETRY) {
return false;
}
const IDProperty *traits_flag = BKE_asset_metadata_idprop_find(
&meta_data, "geometry_node_asset_traits_flag");
if (traits_flag == nullptr || (IDP_Int(traits_flag) & flag) != flag) {
if (traits_flag == nullptr || (IDP_int_get(traits_flag) & flag) != flag) {
return false;
}
return true;

View File

@@ -56,12 +56,12 @@ static asset::AssetItemTree build_catalog_tree(const bContext &C)
type_filter.id_types = FILTER_ID_NT;
auto meta_data_filter = [&](const AssetMetaData &meta_data) {
const IDProperty *tree_type = BKE_asset_metadata_idprop_find(&meta_data, "type");
if (tree_type == nullptr || IDP_Int(tree_type) != NTREE_GEOMETRY) {
if (tree_type == nullptr || IDP_int_get(tree_type) != NTREE_GEOMETRY) {
return false;
}
const IDProperty *traits_flag = BKE_asset_metadata_idprop_find(
&meta_data, "geometry_node_asset_traits_flag");
if (traits_flag == nullptr || !(IDP_Int(traits_flag) & GEO_NODE_ASSET_MODIFIER)) {
if (traits_flag == nullptr || !(IDP_int_get(traits_flag) & GEO_NODE_ASSET_MODIFIER)) {
return false;
}
return true;

View File

@@ -1898,10 +1898,10 @@ static wmOperatorStatus shade_auto_smooth_exec(bContext *C, wmOperator *op)
IDProperty *angle_prop = IDP_GetPropertyFromGroup(smooth_by_angle_nmd->settings.properties,
angle_identifier.c_str());
if (angle_prop->type == IDP_FLOAT) {
IDP_Float(angle_prop) = angle;
IDP_float_set(angle_prop, angle);
}
else if (angle_prop->type == IDP_DOUBLE) {
IDP_Double(angle_prop) = angle;
IDP_double_set(angle_prop, angle);
}
DEG_id_tag_update(&object->id, ID_RECALC_GEOMETRY);

View File

@@ -3510,10 +3510,10 @@ static wmOperatorStatus geometry_nodes_input_attribute_toggle_exec(bContext *C,
}
if (use_attribute->type == IDP_INT) {
IDP_Int(use_attribute) = !IDP_Int(use_attribute);
IDP_int_set(use_attribute, !IDP_int_get(use_attribute));
}
else if (use_attribute->type == IDP_BOOLEAN) {
IDP_Bool(use_attribute) = !IDP_Bool(use_attribute);
IDP_bool_set(use_attribute, !IDP_bool_get(use_attribute));
}
else {
return OPERATOR_CANCELLED;

View File

@@ -3759,7 +3759,7 @@ static void proj_paint_state_viewport_init(ProjPaintState *ps, const char symmet
IDProperty *idgroup = IDP_GetProperties(&ps->reproject_image->id);
IDProperty *view_data = IDP_GetPropertyFromGroup(idgroup, PROJ_VIEW_DATA_ID);
const float *array = (float *)IDP_Array(view_data);
const float *array = IDP_array_float_get(view_data);
/* use image array, written when creating image */
memcpy(winmat, array, sizeof(winmat));

View File

@@ -45,7 +45,7 @@ static asset::AssetItemTree build_catalog_tree(const bContext &C, const bNodeTre
type_filter.id_types = FILTER_ID_NT;
auto meta_data_filter = [&](const AssetMetaData &meta_data) {
const IDProperty *tree_type = BKE_asset_metadata_idprop_find(&meta_data, "type");
if (tree_type == nullptr || IDP_Int(tree_type) != node_tree.type) {
if (tree_type == nullptr || IDP_int_get(tree_type) != node_tree.type) {
return false;
}
return true;

View File

@@ -161,7 +161,7 @@ static void search_link_ops_for_asset_metadata(const bNodeTree &node_tree,
{
const AssetMetaData &asset_data = asset.get_metadata();
const IDProperty *tree_type = BKE_asset_metadata_idprop_find(&asset_data, "type");
if (tree_type == nullptr || IDP_Int(tree_type) != node_tree.type) {
if (tree_type == nullptr || IDP_int_get(tree_type) != node_tree.type) {
return;
}
@@ -177,7 +177,7 @@ static void search_link_ops_for_asset_metadata(const bNodeTree &node_tree,
if (socket_property->type != IDP_STRING) {
continue;
}
const char *socket_idname = IDP_String(socket_property);
const char *socket_idname = IDP_string_get(socket_property);
const bke::bNodeSocketType *socket_type = bke::node_socket_type_find(socket_idname);
if (socket_type == nullptr) {
continue;

View File

@@ -990,7 +990,7 @@ static bool node_group_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*ev
}
const AssetMetaData *metadata = &asset_data->asset->get_metadata();
const IDProperty *tree_type = BKE_asset_metadata_idprop_find(metadata, "type");
if (!tree_type || IDP_Int(tree_type) != snode->edittree->type) {
if (!tree_type || IDP_int_get(tree_type) != snode->edittree->type) {
return false;
}
}

View File

@@ -129,7 +129,7 @@ static void view3d_ob_drop_on_enter(wmDropBox *drop, wmDrag *drag)
AssetMetaData *meta_data = WM_drag_get_asset_meta_data(drag, ID_OB);
IDProperty *dimensions_prop = BKE_asset_metadata_idprop_find(meta_data, "dimensions");
if (dimensions_prop) {
copy_v3_v3(dimensions, static_cast<float *>(IDP_Array(dimensions_prop)));
copy_v3_v3(dimensions, IDP_array_float_get(dimensions_prop));
}
}
@@ -308,7 +308,7 @@ static bool view3d_geometry_nodes_drop_poll(bContext *C, wmDrag *drag, const wmE
}
const AssetMetaData *metadata = &asset_data->asset->get_metadata();
const IDProperty *tree_type = BKE_asset_metadata_idprop_find(metadata, "type");
if (!tree_type || IDP_Int(tree_type) != NTREE_GEOMETRY) {
if (!tree_type || IDP_int_get(tree_type) != NTREE_GEOMETRY) {
return false;
}
if (wmDropBox *drop_box = drag->drop_state.active_dropbox) {

View File

@@ -582,7 +582,7 @@ static void write_jpeg(jpeg_compress_struct *cinfo, ImBuf *ibuf)
if (prop->type == IDP_STRING) {
size_t text_len;
if (STREQ(prop->name, "None")) {
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)IDP_String(prop), prop->len);
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)IDP_string_get(prop), prop->len);
}
char *text = static_text;
@@ -590,8 +590,8 @@ static void write_jpeg(jpeg_compress_struct *cinfo, ImBuf *ibuf)
/* 7 is for Blender, 2 colon separators, length of property
* name and property value, followed by the nullptr-terminator
* which isn't needed by JPEG but #BLI_snprintf_rlen requires it. */
const size_t text_length_required = 7 + 2 + strlen(prop->name) + strlen(IDP_String(prop)) +
1;
const size_t text_length_required = 7 + 2 + strlen(prop->name) +
strlen(IDP_string_get(prop)) + 1;
if (text_length_required > static_text_size) {
text = MEM_malloc_arrayN<char>(text_length_required, "jpeg metadata field");
text_size = text_length_required;
@@ -607,7 +607,7 @@ static void write_jpeg(jpeg_compress_struct *cinfo, ImBuf *ibuf)
* in the read process.
*/
text_len = BLI_snprintf_utf8_rlen(
text, text_size, "Blender:%s:%s", prop->name, IDP_String(prop));
text, text_size, "Blender:%s:%s", prop->name, IDP_string_get(prop));
/* Don't write the null byte (not expected by the JPEG format). */
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)text, uint(text_len));

View File

@@ -50,7 +50,7 @@ bool IMB_metadata_get_field(const IDProperty *metadata,
IDProperty *prop = IDP_GetPropertyFromGroup(metadata, key);
if (prop && prop->type == IDP_STRING) {
BLI_strncpy(value, IDP_String(prop), value_maxncpy);
BLI_strncpy(value, IDP_string_get(prop), value_maxncpy);
return true;
}
return false;
@@ -90,6 +90,6 @@ void IMB_metadata_foreach(const ImBuf *ibuf, IMBMetadataForeachCb callback, void
return;
}
LISTBASE_FOREACH (IDProperty *, prop, &ibuf->metadata->data.group) {
callback(prop->name, IDP_String(prop), userdata);
callback(prop->name, IDP_string_get(prop), userdata);
}
}

View File

@@ -432,7 +432,7 @@ ImageSpec imb_create_write_spec(const WriteContext &ctx, int file_channels, Type
}
}
file_spec.attribute(prop->name, IDP_String(prop));
file_spec.attribute(prop->name, IDP_string_get(prop));
}
}
}

View File

@@ -515,7 +515,7 @@ static void openexr_header_metadata(Header *header, ImBuf *ibuf)
if (prop->type == IDP_STRING &&
!(STREQ(prop->name, "compression") || STREQ(prop->name, "colorInteropID")))
{
header->insert(prop->name, StringAttribute(IDP_String(prop)));
header->insert(prop->name, StringAttribute(IDP_string_get(prop)));
}
}
}

View File

@@ -52,23 +52,25 @@ void CustomPropertiesExporter::write(const IDProperty *id_property)
switch (id_property->type) {
case IDP_STRING: {
/* The Alembic library doesn't accept null-terminated character arrays. */
const std::string prop_value(IDP_String(id_property), id_property->len - 1);
const std::string prop_value(IDP_string_get(id_property), id_property->len - 1);
set_scalar_property<OStringArrayProperty, std::string>(id_property->name, prop_value);
break;
}
case IDP_INT:
static_assert(sizeof(int) == sizeof(int32_t), "Expecting 'int' to be 32-bit");
set_scalar_property<OInt32ArrayProperty, int32_t>(id_property->name, IDP_Int(id_property));
set_scalar_property<OInt32ArrayProperty, int32_t>(id_property->name,
IDP_int_get(id_property));
break;
case IDP_FLOAT:
set_scalar_property<OFloatArrayProperty, float>(id_property->name, IDP_Float(id_property));
set_scalar_property<OFloatArrayProperty, float>(id_property->name,
IDP_float_get(id_property));
break;
case IDP_DOUBLE:
set_scalar_property<ODoubleArrayProperty, double>(id_property->name,
IDP_Double(id_property));
IDP_double_get(id_property));
break;
case IDP_BOOLEAN:
set_scalar_property<OBoolArrayProperty, bool>(id_property->name, IDP_Bool(id_property));
set_scalar_property<OBoolArrayProperty, bool>(id_property->name, IDP_bool_get(id_property));
break;
case IDP_ARRAY:
write_array(id_property);
@@ -85,23 +87,23 @@ void CustomPropertiesExporter::write_array(const IDProperty *id_property)
switch (id_property->subtype) {
case IDP_INT: {
const int *array = (int *)IDP_Array(id_property);
const int *array = IDP_array_int_get(id_property);
static_assert(sizeof(int) == sizeof(int32_t), "Expecting 'int' to be 32-bit");
set_array_property<OInt32ArrayProperty, int32_t>(id_property->name, array, id_property->len);
break;
}
case IDP_FLOAT: {
const float *array = (float *)IDP_Array(id_property);
const float *array = IDP_array_float_get(id_property);
set_array_property<OFloatArrayProperty, float>(id_property->name, array, id_property->len);
break;
}
case IDP_DOUBLE: {
const double *array = (double *)IDP_Array(id_property);
const double *array = IDP_array_double_get(id_property);
set_array_property<ODoubleArrayProperty, double>(id_property->name, array, id_property->len);
break;
}
case IDP_BOOLEAN: {
const int8_t *array = static_cast<const int8_t *>(IDP_Array(id_property));
const int8_t *array = IDP_array_bool_get(id_property);
set_array_property<OBoolArrayProperty, int8_t>(id_property->name, array, id_property->len);
break;
}
@@ -117,7 +119,7 @@ void CustomPropertiesExporter::write_idparray(const IDProperty *idp_array)
return;
}
IDProperty *idp_elements = (IDProperty *)IDP_Array(idp_array);
IDProperty *idp_elements = IDP_property_array_get(idp_array);
#ifndef NDEBUG
/* Sanity check that all elements of the array have the same type.
@@ -147,11 +149,11 @@ void CustomPropertiesExporter::write_idparray_of_strings(const IDProperty *idp_a
BLI_assert(idp_array->len > 0);
/* Convert to an array of std::strings, because Alembic doesn't like zero-delimited strings. */
IDProperty *idp_elements = (IDProperty *)IDP_Array(idp_array);
IDProperty *idp_elements = IDP_property_array_get(idp_array);
std::vector<std::string> strings(idp_array->len);
for (int i = 0; i < idp_array->len; i++) {
BLI_assert(idp_elements[i].type == IDP_STRING);
strings[i] = IDP_String(&idp_elements[i]);
strings[i] = IDP_string_get(&idp_elements[i]);
}
/* Alembic needs a pointer to the first value of the array. */
@@ -166,7 +168,7 @@ void CustomPropertiesExporter::write_idparray_of_numbers(const IDProperty *idp_a
BLI_assert(idp_array->len > 0);
/* This must be an array of arrays. */
IDProperty *idp_rows = (IDProperty *)IDP_Array(idp_array);
IDProperty *idp_rows = IDP_property_array_get(idp_array);
BLI_assert(idp_rows[0].type == IDP_ARRAY);
const int subtype = idp_rows[0].subtype;
@@ -198,14 +200,14 @@ void CustomPropertiesExporter::write_idparray_flattened_typed(const IDProperty *
BLI_assert(idp_array->type == IDP_IDPARRAY);
BLI_assert(idp_array->len > 0);
const IDProperty *idp_rows = (IDProperty *)IDP_Array(idp_array);
const IDProperty *idp_rows = IDP_property_array_get(idp_array);
BLI_assert(idp_rows[0].type == IDP_ARRAY);
BLI_assert(ELEM(idp_rows[0].subtype, IDP_INT, IDP_FLOAT, IDP_DOUBLE, IDP_BOOLEAN));
const uint64_t num_rows = idp_array->len;
std::vector<BlenderValueType> matrix_values;
for (size_t row_idx = 0; row_idx < num_rows; ++row_idx) {
const BlenderValueType *row = (BlenderValueType *)IDP_Array(&idp_rows[row_idx]);
const BlenderValueType *row = (BlenderValueType *)IDP_array_voidp_get(&idp_rows[row_idx]);
for (size_t col_idx = 0; col_idx < idp_rows[row_idx].len; col_idx++) {
matrix_values.push_back(row[col_idx]);
}

View File

@@ -18,13 +18,13 @@ static pxr::VtValue vt_value(const IDProperty *prop)
{
switch (prop->type) {
case IDP_INT:
return pxr::VtValue{IDP_Int(prop)};
return pxr::VtValue{IDP_int_get(prop)};
case IDP_FLOAT:
return pxr::VtValue{IDP_Float(prop)};
return pxr::VtValue{IDP_float_get(prop)};
case IDP_DOUBLE:
return pxr::VtValue{IDP_Double(prop)};
return pxr::VtValue{IDP_double_get(prop)};
case IDP_BOOLEAN:
return pxr::VtValue{bool(IDP_Bool(prop))};
return pxr::VtValue{bool(IDP_bool_get(prop))};
}
return pxr::VtValue{};
}

View File

@@ -1152,7 +1152,7 @@ static void rna_IDPArray_begin(CollectionPropertyIterator *iter, PointerRNA *ptr
{
IDProperty *prop = (IDProperty *)ptr->data;
rna_iterator_array_begin(
iter, ptr, IDP_IDPArray(prop), sizeof(IDProperty), prop->len, 0, nullptr);
iter, ptr, IDP_property_array_get(prop), sizeof(IDProperty), prop->len, 0, nullptr);
}
static int rna_IDPArray_length(PointerRNA *ptr)

View File

@@ -73,6 +73,13 @@
static CLG_LogRef LOG = {"rna.access"};
/**
* The boolean IDProperty type isn't supported in old versions. In order to keep forward
* compatibility for a period of time (until 4.0), save boolean RNA properties as integer
* IDProperties.
*/
#define USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
/* Init/Exit */
/* NOTE: Initializing this object here is fine for now, as it should not allocate any memory. */
@@ -2542,7 +2549,11 @@ void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, Proper
static bool property_boolean_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
{
if (prop_rna_or_id.idprop) {
return IDP_Bool(prop_rna_or_id.idprop);
#ifdef USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
return IDP_int_or_bool_get(prop_rna_or_id.idprop);
#else
return IDP_bool_get(prop_rna_or_id.idprop);
#endif
}
BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(prop_rna_or_id.rnaprop);
if (bprop->get) {
@@ -2573,13 +2584,6 @@ bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
return value;
}
/**
* The boolean IDProperty type isn't supported in old versions. In order to keep forward
* compatibility for a period of time (until 4.0), save boolean RNA properties as integer
* IDProperties.
*/
#define USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
{
BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN);
@@ -2599,7 +2603,11 @@ void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
}
if (idprop) {
IDP_Bool(idprop) = value;
#ifdef USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
IDP_int_or_bool_set(idprop, value);
#else
IDP_bool_set(idprop, value);
#endif
rna_idproperty_touch(idprop);
}
else if (bprop->set) {
@@ -2691,13 +2699,13 @@ static void property_boolean_get_array(PointerRNA *ptr,
else if (idprop->subtype == IDP_INT) {
/* Some boolean IDProperty arrays might be saved in files as an integer
* array property, since the boolean IDProperty type was added later. */
const int *values_src = static_cast<const int *>(IDP_Array(idprop));
const int *values_src = IDP_array_int_get(idprop);
for (int i = 0; i < idprop->len; i++) {
r_values[i] = bool(values_src[i]);
}
}
else if (idprop->subtype == IDP_BOOLEAN) {
bool *values_src = static_cast<bool *>(IDP_Array(idprop));
int8_t *values_src = IDP_array_bool_get(idprop);
for (int i = 0; i < idprop->len; i++) {
r_values[i] = values_src[i];
}
@@ -2827,24 +2835,24 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bo
* RNA properties used to be stored with integer IDProperties. */
if (rna_prop->arraydimension == 0) {
if (idprop->subtype == IDP_BOOLEAN) {
IDP_Bool(idprop) = final_values[0];
IDP_bool_set(idprop, final_values[0]);
}
else {
BLI_assert(idprop->subtype == IDP_INT);
IDP_Int(idprop) = final_values[0];
IDP_int_set(idprop, final_values[0]);
}
}
else {
BLI_assert(idprop->type = IDP_ARRAY);
BLI_assert(idprop->len == values_num);
if (idprop->subtype == IDP_BOOLEAN) {
memcpy(IDP_Array(idprop),
memcpy(IDP_array_bool_get(idprop),
final_values.data(),
sizeof(decltype(final_values)::value_type) * idprop->len);
}
else {
BLI_assert(idprop->subtype == IDP_INT);
int *values_dst = static_cast<int *>(IDP_Array(idprop));
int *values_dst = IDP_array_int_get(idprop);
for (int i = 0; i < idprop->len; i++) {
values_dst[i] = int(final_values[i]);
}
@@ -2874,12 +2882,12 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bo
idprop = IDP_New(IDP_ARRAY, &val, prop_rna_or_id.identifier, IDP_FLAG_STATIC_TYPE);
IDP_AddToGroup(group, idprop);
#ifdef USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
int *values_dst = static_cast<int *>(IDP_Array(idprop));
int *values_dst = IDP_array_int_get(idprop);
for (int i = 0; i < idprop->len; i++) {
values_dst[i] = int(final_values[i]);
}
#else
bool *values_dst = static_cast<bool *>(IDP_Array(idprop));
int8_t *values_dst = IDP_array_bool_get(idprop);
for (int i = 0; i < idprop->len; i++) {
values_dst[i] = final_values[i];
}
@@ -3050,7 +3058,7 @@ bool RNA_property_boolean_get_default_index(PointerRNA *ptr, PropertyRNA *prop,
static int property_int_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
{
if (prop_rna_or_id.idprop) {
return IDP_Int(prop_rna_or_id.idprop);
return IDP_int_get(prop_rna_or_id.idprop);
}
IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop_rna_or_id.rnaprop);
if (iprop->get) {
@@ -3100,7 +3108,7 @@ void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
}
if (idprop) {
IDP_Int(idprop) = value;
IDP_int_set(idprop, value);
rna_idproperty_touch(idprop);
}
else if (iprop->set) {
@@ -3166,7 +3174,7 @@ static void property_int_get_array(PointerRNA *ptr,
}
else {
memcpy(r_values.data(),
IDP_Array(idprop),
IDP_array_int_get(idprop),
sizeof(decltype(r_values)::value_type) * idprop->len);
}
}
@@ -3324,10 +3332,10 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v
if (idprop) {
BLI_assert(idprop->len == values_num);
if (rna_prop->arraydimension == 0) {
IDP_Int(idprop) = final_values[0];
IDP_int_set(idprop, final_values[0]);
}
else {
memcpy(IDP_Array(idprop),
memcpy(IDP_array_int_get(idprop),
final_values.data(),
sizeof(decltype(final_values)::value_type) * idprop->len);
}
@@ -3495,9 +3503,9 @@ static float property_float_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id
if (prop_rna_or_id.idprop) {
IDProperty *idprop = prop_rna_or_id.idprop;
if (idprop->type == IDP_FLOAT) {
return IDP_Float(idprop);
return IDP_float_get(idprop);
}
return float(IDP_Double(idprop));
return float(IDP_double_get(idprop));
}
FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop_rna_or_id.rnaprop);
if (fprop->get) {
@@ -3548,10 +3556,10 @@ void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
if (idprop) {
if (idprop->type == IDP_FLOAT) {
IDP_Float(idprop) = value;
IDP_float_set(idprop, value);
}
else {
IDP_Double(idprop) = double(value);
IDP_double_set(idprop, double(value));
}
rna_idproperty_touch(idprop);
}
@@ -3641,11 +3649,11 @@ static void property_float_get_array(PointerRNA *ptr,
}
else if (idprop->subtype == IDP_FLOAT) {
memcpy(r_values.data(),
IDP_Array(idprop),
IDP_array_float_get(idprop),
sizeof(decltype(r_values)::value_type) * idprop->len);
}
else {
double *src_values = static_cast<double *>(IDP_Array(idprop));
double *src_values = IDP_array_double_get(idprop);
for (int i = 0; i < idprop->len; i++) {
r_values[i] = float(src_values[i]);
}
@@ -3807,19 +3815,19 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa
BLI_assert(idprop->len == values_num);
if (rna_prop->arraydimension == 0) {
if (idprop->type == IDP_FLOAT) {
IDP_Float(idprop) = final_values[0];
IDP_float_set(idprop, final_values[0]);
}
else {
IDP_Double(idprop) = double(final_values[0]);
IDP_double_set(idprop, double(final_values[0]));
}
}
else if (idprop->subtype == IDP_FLOAT) {
memcpy(IDP_Array(idprop),
memcpy(IDP_array_float_get(idprop),
final_values.data(),
sizeof(decltype(final_values)::value_type) * idprop->len);
}
else {
double *dst_values = static_cast<double *>(IDP_Array(idprop));
double *dst_values = IDP_array_double_get(idprop);
for (int i = 0; i < idprop->len; i++) {
dst_values[i] = double(final_values[i]);
}
@@ -3989,10 +3997,10 @@ static size_t property_string_length_storage(PointerRNA *ptr, PropertyRNAOrID &p
return size_t(idprop->len);
}
/* these _must_ stay in sync */
if (strlen(IDP_String(idprop)) != idprop->len - 1) {
printf("%zu vs. %d\n", strlen(IDP_String(idprop)), idprop->len - 1);
if (strlen(IDP_string_get(idprop)) != idprop->len - 1) {
printf("%zu vs. %d\n", strlen(IDP_string_get(idprop)), idprop->len - 1);
}
BLI_assert(strlen(IDP_String(idprop)) == idprop->len - 1);
BLI_assert(strlen(IDP_string_get(idprop)) == idprop->len - 1);
return size_t(idprop->len - 1);
}
@@ -4010,7 +4018,7 @@ static std::string property_string_get(PointerRNA *ptr, PropertyRNAOrID &prop_rn
{
if (prop_rna_or_id.idprop) {
const size_t length = property_string_length_storage(ptr, prop_rna_or_id);
return std::string{IDP_String(prop_rna_or_id.idprop), length};
return std::string{IDP_string_get(prop_rna_or_id.idprop), length};
}
StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop_rna_or_id.rnaprop);
if (sprop->get) {
@@ -4302,7 +4310,7 @@ std::optional<std::string> RNA_property_string_path_filter(const bContext *C,
static int property_enum_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
{
if (prop_rna_or_id.idprop) {
return IDP_Int(prop_rna_or_id.idprop);
return IDP_int_get(prop_rna_or_id.idprop);
}
EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(prop_rna_or_id.rnaprop);
if (eprop->get) {
@@ -4352,7 +4360,7 @@ void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
}
if (idprop) {
IDP_Int(idprop) = value;
IDP_int_set(idprop, value);
rna_idproperty_touch(idprop);
}
else if (eprop->set) {
@@ -4439,7 +4447,7 @@ PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
if (RNA_struct_is_ID(pprop->type)) {
/* ID PointerRNA should not have ancestors currently. */
return RNA_id_pointer_create(IDP_Id(idprop));
return RNA_id_pointer_create(idprop->type == IDP_GROUP ? nullptr : IDP_ID_get(idprop));
}
/* for groups, data is idprop itself */
@@ -4704,8 +4712,13 @@ void RNA_property_collection_begin(PointerRNA *ptr,
iter->prop = prop;
if (idprop) {
rna_iterator_array_begin(
iter, ptr, IDP_IDPArray(idprop), sizeof(IDProperty), idprop->len, false, nullptr);
rna_iterator_array_begin(iter,
ptr,
IDP_property_array_get(idprop),
sizeof(IDProperty),
idprop->len,
false,
nullptr);
}
else {
rna_iterator_array_begin(iter, ptr, nullptr, sizeof(IDProperty), 0, false, nullptr);
@@ -4926,7 +4939,7 @@ bool RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
int len;
len = idprop->len;
array = IDP_IDPArray(idprop);
array = IDP_property_array_get(idprop);
if (key >= 0 && key < len) {
if (is_liboverride && (array[key].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) == 0) {
@@ -4969,7 +4982,7 @@ bool RNA_property_collection_move(PointerRNA *ptr, PropertyRNA *prop, int key, i
int len;
len = idprop->len;
array = IDP_IDPArray(idprop);
array = IDP_property_array_get(idprop);
if (key >= 0 && key < len && pos >= 0 && pos < len && key != pos) {
if (is_liboverride && (array[key].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) == 0) {
@@ -5011,7 +5024,7 @@ void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop)
if (is_liboverride) {
/* We can only move items that we actually inserted in the local override. */
int len = idprop->len;
IDProperty tmp, *array = IDP_IDPArray(idprop);
IDProperty tmp, *array = IDP_property_array_get(idprop);
for (int i = 0; i < len; i++) {
if ((array[i].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) != 0) {
memcpy(&tmp, &array[i], sizeof(IDProperty));

View File

@@ -564,7 +564,7 @@ static const char *rna_CollectionExport_filepath_value_from_idprop(CollectionExp
if (IDProperty *group = data->export_properties) {
IDProperty *filepath_prop = IDP_GetPropertyFromGroup(group, "filepath");
if (filepath_prop && filepath_prop->type == IDP_STRING) {
return IDP_String(filepath_prop);
return IDP_string_get(filepath_prop);
}
}
return nullptr;

View File

@@ -884,7 +884,7 @@ static char *rna_idp_path(PointerRNA *ptr,
}
else if (iter->type == IDP_IDPARRAY) {
if (prop->type == PROP_COLLECTION) {
const IDProperty *array = IDP_IDPArray(iter);
const IDProperty *array = IDP_property_array_get(iter);
if (needle >= array && needle < (iter->len + array)) { /* found! */
link.name = iter->name;
link.index = int(needle - array);

View File

@@ -114,7 +114,7 @@ static void find_dependencies_from_settings(const NodesModifierSettings &setting
nodes::GeometryNodesEvalDependencies &deps)
{
IDP_foreach_property(settings.properties, IDP_TYPE_FILTER_ID, [&](IDProperty *property) {
if (ID *id = IDP_Id(property)) {
if (ID *id = IDP_ID_get(property)) {
deps.add_generic_id_full(id);
}
});

View File

@@ -277,7 +277,7 @@ static bool old_id_property_type_matches_socket_convert_to_new_int(const IDPrope
}
if (new_property) {
BLI_assert(new_property->type == IDP_INT);
IDP_Int(new_property) = IDP_Int(&old_property);
IDP_int_set(new_property, IDP_int_get(&old_property));
}
return true;
}
@@ -296,7 +296,7 @@ static bool old_id_property_type_matches_socket_convert_to_new_float_vec(
switch (old_property.subtype) {
case IDP_DOUBLE: {
double *const old_value = static_cast<double *const>(IDP_Array(&old_property));
double *const old_value = IDP_array_double_get(&old_property);
float *new_value = static_cast<float *>(new_property->data.pointer);
for (int i = 0; i < len; i++) {
if (i < old_property.len) {
@@ -309,7 +309,7 @@ static bool old_id_property_type_matches_socket_convert_to_new_float_vec(
break;
}
case IDP_INT: {
int *const old_value = static_cast<int *const>(IDP_Array(&old_property));
int *const old_value = IDP_array_int_get(&old_property);
float *new_value = static_cast<float *>(new_property->data.pointer);
for (int i = 0; i < len; i++) {
if (i < old_property.len) {
@@ -322,7 +322,7 @@ static bool old_id_property_type_matches_socket_convert_to_new_float_vec(
break;
}
case IDP_FLOAT: {
float *const old_value = static_cast<float *const>(IDP_Array(&old_property));
float *const old_value = IDP_array_float_get(&old_property);
float *new_value = static_cast<float *>(new_property->data.pointer);
for (int i = 0; i < len; i++) {
if (i < old_property.len) {
@@ -347,7 +347,7 @@ static bool old_id_property_type_matches_socket_convert_to_new_string(
}
if (new_property) {
BLI_assert(new_property->type == IDP_STRING && new_property->subtype == IDP_STRING_SUB_UTF8);
IDP_AssignString(new_property, IDP_String(&old_property));
IDP_AssignString(new_property, IDP_string_get(&old_property));
}
return true;
}
@@ -377,13 +377,13 @@ static bool old_id_property_type_matches_socket_convert_to_new(
BLI_assert(new_property->type == IDP_FLOAT);
switch (old_property.type) {
case IDP_DOUBLE:
IDP_Float(new_property) = float(IDP_Double(&old_property));
IDP_float_set(new_property, float(IDP_double_get(&old_property)));
break;
case IDP_INT:
IDP_Float(new_property) = float(IDP_Int(&old_property));
IDP_float_set(new_property, float(IDP_int_get(&old_property)));
break;
case IDP_FLOAT:
IDP_Float(new_property) = IDP_Float(&old_property);
IDP_float_set(new_property, IDP_float_get(&old_property));
break;
}
}
@@ -416,10 +416,10 @@ static bool old_id_property_type_matches_socket_convert_to_new(
BLI_assert(new_property->type == IDP_BOOLEAN);
switch (old_property.type) {
case IDP_INT:
IDP_Bool(new_property) = bool(IDP_Int(&old_property));
IDP_bool_set(new_property, bool(IDP_int_get(&old_property)));
break;
case IDP_BOOLEAN:
IDP_Bool(new_property) = IDP_Bool(&old_property);
IDP_bool_set(new_property, IDP_bool_get(&old_property));
break;
}
}
@@ -442,7 +442,7 @@ static bool old_id_property_type_matches_socket_convert_to_new(
}
if (new_property) {
BLI_assert(new_property->type == IDP_ID);
ID *id = IDP_Id(&old_property);
ID *id = IDP_ID_get(&old_property);
new_property->data.pointer = id;
id_us_plus(id);
}
@@ -487,19 +487,19 @@ static bke::SocketValueVariant init_socket_cpp_value_from_property(
case SOCK_FLOAT: {
float value = 0.0f;
if (property.type == IDP_FLOAT) {
value = IDP_Float(&property);
value = IDP_float_get(&property);
}
else if (property.type == IDP_DOUBLE) {
value = float(IDP_Double(&property));
value = float(IDP_double_get(&property));
}
return bke::SocketValueVariant(value);
}
case SOCK_INT: {
int value = IDP_Int(&property);
int value = IDP_int_get(&property);
return bke::SocketValueVariant(value);
}
case SOCK_VECTOR: {
const void *property_array = IDP_Array(&property);
const void *property_array = IDP_array_voidp_get(&property);
BLI_assert(property.len >= 2 && property.len <= 4);
float4 values = float4(0.0f);
@@ -526,7 +526,7 @@ static bke::SocketValueVariant init_socket_cpp_value_from_property(
return bke::SocketValueVariant(float3(values));
}
case SOCK_RGBA: {
const void *property_array = IDP_Array(&property);
const void *property_array = IDP_array_voidp_get(&property);
float4 vec;
if (property.subtype == IDP_FLOAT) {
vec = float4(static_cast<const float *>(property_array));
@@ -542,11 +542,11 @@ static bke::SocketValueVariant init_socket_cpp_value_from_property(
return bke::SocketValueVariant(value);
}
case SOCK_BOOLEAN: {
const bool value = IDP_Bool(&property);
const bool value = IDP_bool_get(&property);
return bke::SocketValueVariant(value);
}
case SOCK_ROTATION: {
const void *property_array = IDP_Array(&property);
const void *property_array = IDP_array_voidp_get(&property);
float3 vec;
if (property.subtype == IDP_FLOAT) {
vec = float3(static_cast<const float *>(property_array));
@@ -562,35 +562,35 @@ static bke::SocketValueVariant init_socket_cpp_value_from_property(
return bke::SocketValueVariant(math::to_quaternion(euler_value));
}
case SOCK_STRING: {
std::string value = IDP_String(&property);
std::string value = IDP_string_get(&property);
return bke::SocketValueVariant::From(std::move(value));
}
case SOCK_MENU: {
int value = IDP_Int(&property);
int value = IDP_int_get(&property);
return bke::SocketValueVariant::From(MenuValue(value));
}
case SOCK_OBJECT: {
ID *id = IDP_Id(&property);
ID *id = IDP_ID_get(&property);
Object *object = (id && GS(id->name) == ID_OB) ? (Object *)id : nullptr;
return bke::SocketValueVariant::From(object);
}
case SOCK_COLLECTION: {
ID *id = IDP_Id(&property);
ID *id = IDP_ID_get(&property);
Collection *collection = (id && GS(id->name) == ID_GR) ? (Collection *)id : nullptr;
return bke::SocketValueVariant::From(collection);
}
case SOCK_TEXTURE: {
ID *id = IDP_Id(&property);
ID *id = IDP_ID_get(&property);
Tex *texture = (id && GS(id->name) == ID_TE) ? (Tex *)id : nullptr;
return bke::SocketValueVariant::From(texture);
}
case SOCK_IMAGE: {
ID *id = IDP_Id(&property);
ID *id = IDP_ID_get(&property);
Image *image = (id && GS(id->name) == ID_IM) ? (Image *)id : nullptr;
return bke::SocketValueVariant::From(image);
}
case SOCK_MATERIAL: {
ID *id = IDP_Id(&property);
ID *id = IDP_ID_get(&property);
Material *material = (id && GS(id->name) == ID_MA) ? (Material *)id : nullptr;
return bke::SocketValueVariant::From(material);
}
@@ -610,12 +610,12 @@ std::optional<StringRef> input_attribute_name_get(const PropertiesVectorSet &pro
return std::nullopt;
}
if (use_attribute->type == IDP_INT) {
if (IDP_Int(use_attribute) == 0) {
if (IDP_int_get(use_attribute) == 0) {
return std::nullopt;
}
}
if (use_attribute->type == IDP_BOOLEAN) {
if (!IDP_Bool(use_attribute)) {
if (!IDP_bool_get(use_attribute)) {
return std::nullopt;
}
}
@@ -623,7 +623,7 @@ std::optional<StringRef> input_attribute_name_get(const PropertiesVectorSet &pro
const IDProperty *property_attribute_name = properties.lookup_key_default_as(
io_input.identifier + input_attribute_name_suffix, nullptr);
return IDP_String(property_attribute_name);
return IDP_string_get(property_attribute_name);
}
static bke::SocketValueVariant initialize_group_input(const bNodeTree &tree,
@@ -653,7 +653,7 @@ static bke::SocketValueVariant initialize_group_input(const bNodeTree &tree,
}
if (is_layer_selection_field(io_input)) {
const IDProperty *property_layer_name = properties.lookup_key_as(io_input.identifier);
StringRef layer_name = IDP_String(property_layer_name);
StringRef layer_name = IDP_string_get(property_layer_name);
fn::GField selection_field(std::make_shared<bke::NamedLayerSelectionFieldInput>(layer_name),
0);
return bke::SocketValueVariant::From(std::move(selection_field));
@@ -694,7 +694,7 @@ static MultiValueMap<bke::AttrDomain, OutputAttributeInfo> find_output_attribute
if (prop == nullptr) {
continue;
}
const StringRefNull attribute_name = IDP_String(prop);
const StringRefNull attribute_name = IDP_string_get(prop);
if (attribute_name.is_empty()) {
continue;
}
@@ -1002,7 +1002,7 @@ void update_input_properties_from_node_tree(const bNodeTree &tree,
if (old_properties == nullptr) {
if (socket.default_attribute_name && socket.default_attribute_name[0] != '\0') {
IDP_AssignStringMaxSize(attribute_prop, socket.default_attribute_name, MAX_NAME);
IDP_Int(use_attribute_prop) = 1;
IDP_int_set(use_attribute_prop, 1);
}
}
else {

View File

@@ -56,34 +56,34 @@ static int BPy_IDGroup_Contains(BPy_IDProperty *self, PyObject *value);
static PyObject *idprop_py_from_idp_string(const IDProperty *prop)
{
if (prop->subtype == IDP_STRING_SUB_BYTE) {
return PyBytes_FromStringAndSize(IDP_String(prop), prop->len);
return PyBytes_FromStringAndSize(IDP_string_get(prop), prop->len);
}
#ifdef USE_STRING_COERCE
return PyC_UnicodeFromBytesAndSize(static_cast<const char *>(IDP_Array(prop)), prop->len - 1);
return PyC_UnicodeFromBytesAndSize(IDP_string_get(prop), prop->len - 1);
#else
return PyUnicode_FromStringAndSize(IDP_String(prop), prop->len - 1);
return PyUnicode_FromStringAndSize(IDP_string_get(prop), prop->len - 1);
#endif
}
static PyObject *idprop_py_from_idp_int(const IDProperty *prop)
{
return PyLong_FromLong(long(IDP_Int(prop)));
return PyLong_FromLong(long(IDP_int_get(prop)));
}
static PyObject *idprop_py_from_idp_float(const IDProperty *prop)
{
return PyFloat_FromDouble(double(IDP_Float(prop)));
return PyFloat_FromDouble(double(IDP_float_get(prop)));
}
static PyObject *idprop_py_from_idp_double(const IDProperty *prop)
{
return PyFloat_FromDouble(IDP_Double(prop));
return PyFloat_FromDouble(IDP_double_get(prop));
}
static PyObject *idprop_py_from_idp_bool(const IDProperty *prop)
{
return PyBool_FromLong(IDP_Bool(prop));
return PyBool_FromLong(IDP_bool_get(prop));
}
static PyObject *idprop_py_from_idp_group(ID *id, IDProperty *prop, IDProperty *parent)
@@ -111,7 +111,7 @@ static PyObject *idprop_py_from_idp_array(ID *id, IDProperty *prop)
static PyObject *idprop_py_from_idp_idparray(ID *id, IDProperty *prop)
{
PyObject *seq = PyList_New(prop->len);
IDProperty *array = IDP_IDPArray(prop);
IDProperty *array = IDP_property_array_get(prop);
int i;
if (!seq) {
@@ -203,14 +203,14 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
st = PyUnicode_AsUTF8(value);
IDP_ResizeArray(prop, alloc_len);
memcpy(IDP_Array(prop), st, alloc_len);
memcpy(IDP_string_get(prop), st, alloc_len);
Py_XDECREF(value_coerce);
}
# else
length_ssize_t st_len;
st = PyUnicode_AsUTF8AndSize(value, &st_len);
IDP_ResizeArray(prop, st_len + 1);
memcpy(IDP_Array(prop), st, st_len + 1);
memcpy(IDP_string_get(prop), st, st_len + 1);
# endif
return 0;
@@ -222,7 +222,7 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
PyErr_SetString(PyExc_TypeError, "expected an int type");
return -1;
}
IDP_Int(prop) = ivalue;
IDP_int_set(prop, ivalue);
break;
}
case IDP_FLOAT: {
@@ -231,7 +231,7 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
PyErr_SetString(PyExc_TypeError, "expected a float");
return -1;
}
IDP_Float(self->prop) = fvalue;
IDP_float_set(self->prop, fvalue);
break;
}
case IDP_DOUBLE: {
@@ -240,7 +240,7 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
PyErr_SetString(PyExc_TypeError, "expected a float");
return -1;
}
IDP_Double(self->prop) = dvalue;
IDP_double_set(self->prop, value);
break;
}
default:
@@ -440,13 +440,13 @@ static IDProperty *idp_from_PyFloat(IDProperty *prop_exist,
const double value = PyFloat_AsDouble(ob);
if (prop_exist) {
if (prop_exist->type == IDP_DOUBLE) {
IDP_Double(prop_exist) = value;
IDP_double_set(prop_exist, value);
prop = prop_exist;
}
else if (do_conversion) {
switch (prop_exist->type) {
case IDP_FLOAT:
IDP_Float(prop_exist) = float(value);
IDP_float_set(prop_exist, float(value));
prop = prop_exist;
break;
case IDP_STRING:
@@ -477,13 +477,13 @@ static IDProperty *idp_from_PyBool(IDProperty *prop_exist,
const bool value = PyC_Long_AsBool(ob);
if (prop_exist) {
if (prop_exist->type == IDP_BOOLEAN) {
IDP_Bool(prop_exist) = value;
IDP_bool_set(prop_exist, value);
prop = prop_exist;
}
else if (do_conversion) {
switch (prop_exist->type) {
case IDP_INT:
IDP_Int(prop_exist) = int(value);
IDP_int_set(prop_exist, int(value));
prop = prop_exist;
break;
case IDP_STRING:
@@ -517,7 +517,7 @@ static IDProperty *idp_from_PyLong(IDProperty *prop_exist,
if (value == -1 && PyErr_Occurred()) {
return prop;
}
IDP_Int(prop_exist) = value;
IDP_int_set(prop_exist, value);
prop = prop_exist;
}
else if (do_conversion) {
@@ -527,11 +527,11 @@ static IDProperty *idp_from_PyLong(IDProperty *prop_exist,
}
switch (prop_exist->type) {
case IDP_FLOAT:
IDP_Float(prop_exist) = float(value);
IDP_float_set(prop_exist, float(value));
prop = prop_exist;
break;
case IDP_DOUBLE:
IDP_Double(prop_exist) = double(value);
IDP_double_set(prop_exist, double(value));
prop = prop_exist;
break;
case IDP_STRING:
@@ -676,7 +676,7 @@ static IDProperty *idp_from_PySequence_Buffer(IDProperty *prop_exist,
if (prop_exist) {
if (prop_exist->type == IDP_ARRAY && prop_exist->subtype == idp_type) {
BLI_assert(buffer.len == prop_exist->len);
memcpy(IDP_Array(prop_exist), buffer.buf, buffer.len);
memcpy(IDP_array_voidp_get(prop_exist), buffer.buf, buffer.len);
prop = prop_exist;
}
/* No conversion. */
@@ -686,7 +686,7 @@ static IDProperty *idp_from_PySequence_Buffer(IDProperty *prop_exist,
val.array.type = idp_type;
val.array.len = buffer.len / buffer.itemsize;
prop = IDP_New(IDP_ARRAY, &val, name);
memcpy(IDP_Array(prop), buffer.buf, buffer.len);
memcpy(IDP_array_voidp_get(prop), buffer.buf, buffer.len);
}
return prop;
}
@@ -738,7 +738,7 @@ static IDProperty *idp_from_PySequence_Fast(IDProperty *prop_exist,
break;
}
prop = prop_exist;
void *prop_data = IDP_Array(prop);
void *prop_data = IDP_array_voidp_get(prop);
for (i = 0; i < val.array.len; i++) {
item = ob_seq_fast_items[i];
const double value = PyFloat_AsDouble(item);
@@ -763,7 +763,7 @@ static IDProperty *idp_from_PySequence_Fast(IDProperty *prop_exist,
break;
}
prop = prop_exist;
void *prop_data = IDP_Array(prop);
void *prop_data = IDP_array_voidp_get(prop);
for (i = 0; i < val.array.len; i++) {
item = ob_seq_fast_items[i];
if (to_float || to_double) {
@@ -796,7 +796,7 @@ static IDProperty *idp_from_PySequence_Fast(IDProperty *prop_exist,
break;
}
prop = prop_exist;
void *prop_data = IDP_Array(prop);
void *prop_data = IDP_array_voidp_get(prop);
for (i = 0; i < val.array.len; i++) {
item = ob_seq_fast_items[i];
const int value = PyC_Long_AsBool(item);
@@ -827,7 +827,7 @@ static IDProperty *idp_from_PySequence_Fast(IDProperty *prop_exist,
case IDP_DOUBLE: {
double *prop_data;
prop = IDP_New(IDP_ARRAY, &val, name);
prop_data = static_cast<double *>(IDP_Array(prop));
prop_data = IDP_array_double_get(prop);
for (i = 0; i < val.array.len; i++) {
item = ob_seq_fast_items[i];
if (((prop_data[i] = PyFloat_AsDouble(item)) == -1.0) && PyErr_Occurred()) {
@@ -840,7 +840,7 @@ static IDProperty *idp_from_PySequence_Fast(IDProperty *prop_exist,
case IDP_INT: {
int *prop_data;
prop = IDP_New(IDP_ARRAY, &val, name);
prop_data = static_cast<int *>(IDP_Array(prop));
prop_data = IDP_array_int_get(prop);
for (i = 0; i < val.array.len; i++) {
item = ob_seq_fast_items[i];
if (((prop_data[i] = PyC_Long_AsI32(item)) == -1) && PyErr_Occurred()) {
@@ -863,7 +863,7 @@ static IDProperty *idp_from_PySequence_Fast(IDProperty *prop_exist,
}
case IDP_BOOLEAN: {
prop = IDP_New(IDP_ARRAY, &val, name);
bool *prop_data = static_cast<bool *>(IDP_Array(prop));
int8_t *prop_data = IDP_array_bool_get(prop);
for (i = 0; i < val.array.len; i++) {
item = ob_seq_fast_items[i];
const int value = PyC_Long_AsBool(item);
@@ -1200,28 +1200,28 @@ PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
switch (prop->subtype) {
case IDP_FLOAT: {
const float *array = (float *)IDP_Array(prop);
const float *array = IDP_array_float_get(prop);
for (i = 0; i < prop->len; i++) {
PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i]));
}
break;
}
case IDP_DOUBLE: {
const double *array = (double *)IDP_Array(prop);
const double *array = IDP_array_double_get(prop);
for (i = 0; i < prop->len; i++) {
PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i]));
}
break;
}
case IDP_INT: {
const int *array = (int *)IDP_Array(prop);
const int *array = IDP_array_int_get(prop);
for (i = 0; i < prop->len; i++) {
PyList_SET_ITEM(seq, i, PyLong_FromLong(array[i]));
}
break;
}
case IDP_BOOLEAN: {
const int8_t *array = (const int8_t *)IDP_Array(prop);
const int8_t *array = IDP_array_bool_get(prop);
for (i = 0; i < prop->len; i++) {
PyList_SET_ITEM(seq, i, PyBool_FromLong(array[i]));
}
@@ -1238,7 +1238,7 @@ PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
}
case IDP_IDPARRAY: {
PyObject *seq = PyList_New(prop->len);
IDProperty *array = IDP_IDPArray(prop);
IDProperty *array = IDP_property_array_get(prop);
int i;
if (!seq) {
@@ -2201,13 +2201,13 @@ static PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, Py_ssize_t index)
switch (self->prop->subtype) {
case IDP_FLOAT:
return PyFloat_FromDouble(((float *)IDP_Array(self->prop))[index]);
return PyFloat_FromDouble(IDP_array_float_get(self->prop)[index]);
case IDP_DOUBLE:
return PyFloat_FromDouble(((double *)IDP_Array(self->prop))[index]);
return PyFloat_FromDouble(IDP_array_double_get(self->prop)[index]);
case IDP_INT:
return PyLong_FromLong(long(((int *)IDP_Array(self->prop))[index]));
return PyLong_FromLong(long(IDP_array_int_get(self->prop)[index]));
case IDP_BOOLEAN:
return PyBool_FromLong(long(((int8_t *)IDP_Array(self->prop))[index]));
return PyBool_FromLong(long(IDP_array_bool_get(self->prop)[index]));
}
PyErr_Format(
@@ -2229,7 +2229,7 @@ static int BPy_IDArray_SetItem(BPy_IDArray *self, Py_ssize_t index, PyObject *va
if (f == -1 && PyErr_Occurred()) {
return -1;
}
((float *)IDP_Array(self->prop))[index] = f;
IDP_array_float_get(self->prop)[index] = f;
break;
}
case IDP_DOUBLE: {
@@ -2237,7 +2237,7 @@ static int BPy_IDArray_SetItem(BPy_IDArray *self, Py_ssize_t index, PyObject *va
if (d == -1 && PyErr_Occurred()) {
return -1;
}
((double *)IDP_Array(self->prop))[index] = d;
IDP_array_double_get(self->prop)[index] = d;
break;
}
case IDP_INT: {
@@ -2246,7 +2246,7 @@ static int BPy_IDArray_SetItem(BPy_IDArray *self, Py_ssize_t index, PyObject *va
return -1;
}
((int *)IDP_Array(self->prop))[index] = i;
IDP_array_int_get(self->prop)[index] = i;
break;
}
case IDP_BOOLEAN: {
@@ -2255,7 +2255,7 @@ static int BPy_IDArray_SetItem(BPy_IDArray *self, Py_ssize_t index, PyObject *va
return -1;
}
((int8_t *)IDP_Array(self->prop))[index] = i;
IDP_array_bool_get(self->prop)[index] = i;
break;
}
}
@@ -2293,28 +2293,28 @@ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
switch (prop->subtype) {
case IDP_FLOAT: {
const float *array = (float *)IDP_Array(prop);
const float *array = IDP_array_float_get(prop);
for (count = begin; count < end; count++) {
PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(array[count]));
}
break;
}
case IDP_DOUBLE: {
const double *array = (double *)IDP_Array(prop);
const double *array = IDP_array_double_get(prop);
for (count = begin; count < end; count++) {
PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(array[count]));
}
break;
}
case IDP_INT: {
const int *array = (int *)IDP_Array(prop);
const int *array = IDP_array_int_get(prop);
for (count = begin; count < end; count++) {
PyTuple_SET_ITEM(tuple, count - begin, PyLong_FromLong(array[count]));
}
break;
}
case IDP_BOOLEAN: {
const int8_t *array = (const int8_t *)IDP_Array(prop);
const int8_t *array = IDP_array_bool_get(prop);
for (count = begin; count < end; count++) {
PyTuple_SET_ITEM(tuple, count - begin, PyBool_FromLong(long(array[count])));
}
@@ -2349,7 +2349,7 @@ static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject
return -1;
}
memcpy((void *)(((char *)IDP_Array(prop)) + (begin * elem_size)), vec, alloc_len);
memcpy((void *)(((char *)IDP_array_voidp_get(prop)) + (begin * elem_size)), vec, alloc_len);
MEM_freeN(vec);
return 0;
@@ -2454,7 +2454,9 @@ static int BPy_IDArray_getbuffer(BPy_IDArray *self, Py_buffer *view, int flags)
const int itemsize = itemsize_by_idarray_type(prop->subtype);
const int length = itemsize * prop->len;
if (PyBuffer_FillInfo(view, (PyObject *)self, IDP_Array(prop), length, false, flags) == -1) {
if (PyBuffer_FillInfo(view, (PyObject *)self, IDP_array_voidp_get(prop), length, false, flags) ==
-1)
{
return -1;
}

View File

@@ -821,7 +821,7 @@ static void idprop_ui_data_to_dict_id(IDProperty *property, PyObject *dict)
/* While UI exposed custom properties do not allow the 'all ID types' `0` value, in
* py-defined IDProperties it is accepted. So force defining a valid id_type value when this
* function is called. */
ID *id = IDP_Id(property);
ID *id = IDP_ID_get(property);
id_type_value = id ? GS(id->name) : ID_OB;
}