RNA generated code: Move extern'ed PropertyRNA from pointers to references.

Clang (at least on OSX) has optimization issues with the pointer
version, which seem to be 'fixed' by using references.

Note that using references here is not a bad thing anyway (none of these
pointers would ever be expected to be NULL).

Pull Request: https://projects.blender.org/blender/blender/pulls/124883
This commit is contained in:
Bastien Montagne
2024-07-17 14:46:50 +02:00
committed by Gitea
parent c7a26cf5c2
commit faf56cc3bf
16 changed files with 85 additions and 85 deletions

View File

@@ -96,7 +96,7 @@ static bool eyedropper_colorband_init(bContext *C, wmOperator *op)
/* Set this to a sub-member of the property to trigger an update. */
rna_update_ptr = ptr;
rna_update_prop = rna_ColorRamp_color_mode;
rna_update_prop = &rna_ColorRamp_color_mode;
is_undo = RNA_struct_undo_check(ptr.type);
}
}

View File

@@ -965,7 +965,7 @@ static void ui_apply_but_undo(uiBut *but)
* because undo systems track data by their ID, see: #67002. */
/* Exception for active shape-key, since changing this in edit-mode updates
* the shape key from object mode data. */
if (ELEM(but->rnaprop, rna_ID_name, rna_Object_active_shape_key_index)) {
if (ELEM(but->rnaprop, &rna_ID_name, &rna_Object_active_shape_key_index)) {
/* pass */
}
else {

View File

@@ -492,10 +492,10 @@ static void saction_main_region_message_subscribe(const wmRegionMessageSubscribe
{
bool use_preview = (scene->r.flag & SCER_PRV_RANGE);
const PropertyRNA *props[] = {
use_preview ? rna_Scene_frame_preview_start : rna_Scene_frame_start,
use_preview ? rna_Scene_frame_preview_end : rna_Scene_frame_end,
rna_Scene_use_preview_range,
rna_Scene_frame_current,
use_preview ? &rna_Scene_frame_preview_start : &rna_Scene_frame_start,
use_preview ? &rna_Scene_frame_preview_end : &rna_Scene_frame_end,
&rna_Scene_use_preview_range,
&rna_Scene_frame_current,
};
PointerRNA idptr = RNA_id_pointer_create(&scene->id);

View File

@@ -518,10 +518,10 @@ static void graph_region_message_subscribe(const wmRegionMessageSubscribeParams
{
bool use_preview = (scene->r.flag & SCER_PRV_RANGE);
const PropertyRNA *props[] = {
use_preview ? rna_Scene_frame_preview_start : rna_Scene_frame_start,
use_preview ? rna_Scene_frame_preview_end : rna_Scene_frame_end,
rna_Scene_use_preview_range,
rna_Scene_frame_current,
use_preview ? &rna_Scene_frame_preview_start : &rna_Scene_frame_start,
use_preview ? &rna_Scene_frame_preview_end : &rna_Scene_frame_end,
&rna_Scene_use_preview_range,
&rna_Scene_frame_current,
};
PointerRNA idptr = RNA_id_pointer_create(&scene->id);

View File

@@ -435,10 +435,10 @@ static void nla_main_region_message_subscribe(const wmRegionMessageSubscribePara
{
bool use_preview = (scene->r.flag & SCER_PRV_RANGE);
const PropertyRNA *props[] = {
use_preview ? rna_Scene_frame_preview_start : rna_Scene_frame_start,
use_preview ? rna_Scene_frame_preview_end : rna_Scene_frame_end,
rna_Scene_use_preview_range,
rna_Scene_frame_current,
use_preview ? &rna_Scene_frame_preview_start : &rna_Scene_frame_start,
use_preview ? &rna_Scene_frame_preview_end : &rna_Scene_frame_end,
&rna_Scene_use_preview_range,
&rna_Scene_frame_current,
};
PointerRNA idptr = RNA_id_pointer_create(&scene->id);

View File

@@ -604,10 +604,10 @@ static void sequencer_main_region_message_subscribe(const wmRegionMessageSubscri
{
bool use_preview = (scene->r.flag & SCER_PRV_RANGE);
const PropertyRNA *props[] = {
use_preview ? rna_Scene_frame_preview_start : rna_Scene_frame_start,
use_preview ? rna_Scene_frame_preview_end : rna_Scene_frame_end,
rna_Scene_use_preview_range,
rna_Scene_frame_current,
use_preview ? &rna_Scene_frame_preview_start : &rna_Scene_frame_start,
use_preview ? &rna_Scene_frame_preview_end : &rna_Scene_frame_end,
&rna_Scene_use_preview_range,
&rna_Scene_frame_current,
};
PointerRNA idptr = RNA_id_pointer_create(&scene->id);

View File

@@ -260,16 +260,16 @@ static void WIDGETGROUP_camera_message_subscribe(const bContext *C,
{
const PropertyRNA *props[] = {
rna_CameraDOFSettings_focus_distance,
rna_Camera_display_size,
rna_Camera_ortho_scale,
rna_Camera_sensor_fit,
rna_Camera_sensor_width,
rna_Camera_sensor_height,
rna_Camera_shift_x,
rna_Camera_shift_y,
rna_Camera_type,
rna_Camera_lens,
&rna_CameraDOFSettings_focus_distance,
&rna_Camera_display_size,
&rna_Camera_ortho_scale,
&rna_Camera_sensor_fit,
&rna_Camera_sensor_width,
&rna_Camera_sensor_height,
&rna_Camera_shift_x,
&rna_Camera_shift_y,
&rna_Camera_type,
&rna_Camera_lens,
};
PointerRNA idptr = RNA_id_pointer_create(&ca->id);

View File

@@ -174,7 +174,7 @@ static void WIDGETGROUP_gizmo_message_subscribe(const bContext *C,
{
const PropertyRNA *props[] = {
rna_ToolSettings_workspace_tool_type,
&rna_ToolSettings_workspace_tool_type,
};
Scene *scene = CTX_data_scene(C);

View File

@@ -1784,19 +1784,19 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
if (t->spacetype == SPACE_NODE) {
snap_flag_ptr = &ts->snap_flag_node;
msg_key_params.prop = rna_ToolSettings_use_snap_node;
msg_key_params.prop = &rna_ToolSettings_use_snap_node;
}
else if (t->spacetype == SPACE_IMAGE) {
snap_flag_ptr = &ts->snap_uv_flag;
msg_key_params.prop = rna_ToolSettings_use_snap_uv;
msg_key_params.prop = &rna_ToolSettings_use_snap_uv;
}
else if (t->spacetype == SPACE_SEQ) {
snap_flag_ptr = &ts->snap_flag_seq;
msg_key_params.prop = rna_ToolSettings_use_snap_sequencer;
msg_key_params.prop = &rna_ToolSettings_use_snap_sequencer;
}
else {
snap_flag_ptr = &ts->snap_flag;
msg_key_params.prop = rna_ToolSettings_use_snap;
msg_key_params.prop = &rna_ToolSettings_use_snap;
}
if (t->modifiers & MOD_SNAP) {

View File

@@ -123,8 +123,8 @@ static void gizmo2d_pivot_point_message_subscribe(wmGizmoGroup *gzgroup,
PointerRNA ptr = RNA_pointer_create(&screen->id, &RNA_SpaceImageEditor, sima);
{
const PropertyRNA *props[] = {
rna_SpaceImageEditor_pivot_point,
(sima->around == V3D_AROUND_CURSOR) ? rna_SpaceImageEditor_cursor_location : nullptr,
&rna_SpaceImageEditor_pivot_point,
(sima->around == V3D_AROUND_CURSOR) ? &rna_SpaceImageEditor_cursor_location : nullptr,
};
for (int i = 0; i < ARRAY_SIZE(props); i++) {
if (props[i] == nullptr) {

View File

@@ -1225,7 +1225,7 @@ void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup,
PointerRNA scene_ptr = RNA_id_pointer_create(&scene->id);
{
const PropertyRNA *props[] = {
rna_Scene_transform_orientation_slots,
&rna_Scene_transform_orientation_slots,
};
for (int i = 0; i < ARRAY_SIZE(props); i++) {
WM_msg_subscribe_rna(mbus, &scene_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);
@@ -1241,8 +1241,8 @@ void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup,
{
const PropertyRNA *props[] = {
rna_TransformOrientationSlot_type,
rna_TransformOrientationSlot_use,
&rna_TransformOrientationSlot_type,
&rna_TransformOrientationSlot_use,
};
for (int i = 0; i < ARRAY_SIZE(props); i++) {
if (props[i]) {
@@ -1257,7 +1257,7 @@ void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup,
if (ELEM(type_fn, VIEW3D_GGT_xform_gizmo, VIEW3D_GGT_xform_shear)) {
const PropertyRNA *props[] = {
rna_ToolSettings_transform_pivot_point,
&rna_ToolSettings_transform_pivot_point,
};
for (int i = 0; i < ARRAY_SIZE(props); i++) {
WM_msg_subscribe_rna(
@@ -1267,7 +1267,7 @@ void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup,
{
const PropertyRNA *props[] = {
rna_ToolSettings_workspace_tool_type,
&rna_ToolSettings_workspace_tool_type,
};
for (int i = 0; i < ARRAY_SIZE(props); i++) {
WM_msg_subscribe_rna(
@@ -1281,9 +1281,9 @@ void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup,
GizmoGroup *ggd = static_cast<GizmoGroup *>(gzgroup->customdata);
if (ggd->use_twtype_refresh) {
const PropertyRNA *props[] = {
rna_SpaceView3D_show_gizmo_object_translate,
rna_SpaceView3D_show_gizmo_object_rotate,
rna_SpaceView3D_show_gizmo_object_scale,
&rna_SpaceView3D_show_gizmo_object_translate,
&rna_SpaceView3D_show_gizmo_object_rotate,
&rna_SpaceView3D_show_gizmo_object_scale,
};
for (int i = 0; i < ARRAY_SIZE(props); i++) {
WM_msg_subscribe_rna(mbus, &view3d_ptr, props[i], &msg_sub_value_gz_tag_refresh, __func__);

View File

@@ -480,7 +480,7 @@ static void gizmo_mesh_extrude_message_subscribe(const bContext *C,
PointerRNA toolsettings_ptr = RNA_pointer_create(
&scene->id, &RNA_ToolSettings, scene->toolsettings);
const PropertyRNA *props[] = {
rna_ToolSettings_workspace_tool_type,
&rna_ToolSettings_workspace_tool_type,
};
for (int i = 0; i < ARRAY_SIZE(props); i++) {
WM_msg_subscribe_rna(

View File

@@ -1621,7 +1621,7 @@ static char *rna_def_property_begin_func(
fprintf(f, "\n memset(iter, 0, sizeof(*iter));\n");
fprintf(f, " iter->parent = *ptr;\n");
fprintf(f, " iter->prop = rna_%s_%s;\n", srna->identifier, prop->identifier);
fprintf(f, " iter->prop = &rna_%s_%s;\n", srna->identifier, prop->identifier);
if (dp->dnalengthname || dp->dnalengthfixed) {
if (manualfunc) {
@@ -3725,14 +3725,14 @@ static void rna_generate_external_property_prototypes(BlenderRNA *brna, FILE *f)
rna_generate_struct_rna_prototypes(brna, f);
/* NOTE: Generate generic `PropertyRNA *` pointers. The actual, type-refined properties data are
* static variables in their translation units (the `_gen.cc` files), which addresses are
* assigned to these public generic `PointerRNA *` pointers. */
/* NOTE: Generate generic `PropertyRNA &` references. The actual, type-refined properties data
* are static variables in their translation units (the `_gen.cc` files), which are assigned to
* these public generic `PointerRNA &` references. */
for (StructRNA *srna = static_cast<StructRNA *>(brna->structs.first); srna;
srna = static_cast<StructRNA *>(srna->cont.next))
{
LISTBASE_FOREACH (PropertyRNA *, prop, &srna->cont.properties) {
fprintf(f, "extern PropertyRNA *rna_%s_%s;\n", srna->identifier, prop->identifier);
fprintf(f, "extern PropertyRNA &rna_%s_%s;\n", srna->identifier, prop->identifier);
}
fprintf(f, "\n");
}
@@ -3744,13 +3744,13 @@ static void rna_generate_internal_property_prototypes(BlenderRNA * /*brna*/,
{
StructRNA *base;
/* NOTE: Generic `PropertyRNA *` pointers, see #rna_generate_external_property_prototypes
/* NOTE: Generic `PropertyRNA &` references, see #rna_generate_external_property_prototypes
* comments for details. */
base = srna->base;
while (base) {
fprintf(f, "\n");
LISTBASE_FOREACH (PropertyRNA *, prop, &base->cont.properties) {
fprintf(f, "extern PropertyRNA *rna_%s_%s;\n", base->identifier, prop->identifier);
fprintf(f, "extern PropertyRNA &rna_%s_%s;\n", base->identifier, prop->identifier);
}
base = base->base;
}
@@ -3760,7 +3760,7 @@ static void rna_generate_internal_property_prototypes(BlenderRNA * /*brna*/,
}
LISTBASE_FOREACH (PropertyRNA *, prop, &srna->cont.properties) {
fprintf(f, "extern PropertyRNA *rna_%s_%s;\n", srna->identifier, prop->identifier);
fprintf(f, "extern PropertyRNA &rna_%s_%s;\n", srna->identifier, prop->identifier);
}
fprintf(f, "\n");
}
@@ -3770,11 +3770,11 @@ static void rna_generate_parameter_prototypes(BlenderRNA * /*brna*/,
FunctionRNA *func,
FILE *f)
{
/* NOTE: Generic `PropertyRNA *` pointers, see #rna_generate_external_property_prototypes
/* NOTE: Generic `PropertyRNA &` references, see #rna_generate_external_property_prototypes
* comments for details. */
LISTBASE_FOREACH (PropertyRNA *, parm, &func->cont.properties) {
fprintf(f,
"extern PropertyRNA *rna_%s_%s_%s;\n",
"extern PropertyRNA &rna_%s_%s_%s;\n",
srna->identifier,
func->identifier,
parm->identifier);
@@ -4305,13 +4305,13 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
prop->identifier);
if (prop->next) {
fprintf(f, "\t{rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
fprintf(f, "\t{&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
}
else {
fprintf(f, "\t{nullptr, ");
}
if (prop->prev) {
fprintf(f, "rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
fprintf(f, "&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
}
else {
fprintf(f, "nullptr,\n");
@@ -4560,12 +4560,12 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
fprintf(f, "};\n");
/* Assign the RNA-private, type-refined static (local) property data address to the public
* matching generic `PropertyRNA *` pointer.
/* Assign the RNA-private, type-refined static (local) property data to the public matching
* generic `PropertyRNA &` reference.
*
* See #rna_generate_external_property_prototypes comments for details. */
fprintf(f,
"PropertyRNA *rna_%s%s_%s = reinterpret_cast<PropertyRNA *>(&rna_%s%s_%s_);\n\n",
"PropertyRNA &rna_%s%s_%s = reinterpret_cast<PropertyRNA &>(rna_%s%s_%s_);\n\n",
srna->identifier,
strnest,
prop->identifier,
@@ -4624,7 +4624,7 @@ static void rna_generate_struct(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f)
parm = static_cast<PropertyRNA *>(func->cont.properties.first);
if (parm) {
fprintf(f, "\t{rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
fprintf(f, "\t{&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
}
else {
fprintf(f, "\t{nullptr, ");
@@ -4632,7 +4632,7 @@ static void rna_generate_struct(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f)
parm = static_cast<PropertyRNA *>(func->cont.properties.last);
if (parm) {
fprintf(f, "rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
fprintf(f, "&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
}
else {
fprintf(f, "nullptr}},\n");
@@ -4653,7 +4653,7 @@ static void rna_generate_struct(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f)
}
if (func->c_ret) {
fprintf(f, "\trna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
fprintf(f, "\t&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
}
else {
fprintf(f, "\tnullptr\n");
@@ -4682,7 +4682,7 @@ static void rna_generate_struct(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f)
prop = static_cast<PropertyRNA *>(srna->cont.properties.first);
if (prop) {
fprintf(f, "\t{rna_%s_%s, ", srna->identifier, prop->identifier);
fprintf(f, "\t{&rna_%s_%s, ", srna->identifier, prop->identifier);
}
else {
fprintf(f, "\t{nullptr, ");
@@ -4690,7 +4690,7 @@ static void rna_generate_struct(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f)
prop = static_cast<PropertyRNA *>(srna->cont.properties.last);
if (prop) {
fprintf(f, "rna_%s_%s}},\n", srna->identifier, prop->identifier);
fprintf(f, "&rna_%s_%s}},\n", srna->identifier, prop->identifier);
}
else {
fprintf(f, "nullptr}},\n");
@@ -4713,7 +4713,7 @@ static void rna_generate_struct(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f)
base = base->base;
}
fprintf(f, "\trna_%s_%s, ", base->identifier, prop->identifier);
fprintf(f, "\t&rna_%s_%s, ", base->identifier, prop->identifier);
}
else {
fprintf(f, "\tnullptr, ");
@@ -4724,7 +4724,7 @@ static void rna_generate_struct(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f)
while (base->base && base->base->iteratorproperty == prop) {
base = base->base;
}
fprintf(f, "rna_%s_rna_properties,\n", base->identifier);
fprintf(f, "&rna_%s_rna_properties,\n", base->identifier);
if (srna->base) {
fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);

View File

@@ -434,31 +434,31 @@ static bool rna_idproperty_verify_valid(PointerRNA *ptr, PropertyRNA *prop, IDPr
}
static PropertyRNA *typemap[IDP_NUMTYPES] = {
rna_PropertyGroupItem_string,
rna_PropertyGroupItem_int,
rna_PropertyGroupItem_float,
&rna_PropertyGroupItem_string,
&rna_PropertyGroupItem_int,
&rna_PropertyGroupItem_float,
nullptr,
nullptr,
nullptr,
rna_PropertyGroupItem_group,
rna_PropertyGroupItem_id,
rna_PropertyGroupItem_double,
rna_PropertyGroupItem_idp_array,
rna_PropertyGroupItem_bool,
&rna_PropertyGroupItem_group,
&rna_PropertyGroupItem_id,
&rna_PropertyGroupItem_double,
&rna_PropertyGroupItem_idp_array,
&rna_PropertyGroupItem_bool,
};
static PropertyRNA *arraytypemap[IDP_NUMTYPES] = {
nullptr,
rna_PropertyGroupItem_int_array,
rna_PropertyGroupItem_float_array,
&rna_PropertyGroupItem_int_array,
&rna_PropertyGroupItem_float_array,
nullptr,
nullptr,
nullptr,
rna_PropertyGroupItem_collection,
&rna_PropertyGroupItem_collection,
nullptr,
rna_PropertyGroupItem_double_array,
&rna_PropertyGroupItem_double_array,
nullptr,
rna_PropertyGroupItem_bool_array,
&rna_PropertyGroupItem_bool_array,
};
void rna_property_rna_or_id_get(PropertyRNA *prop,
@@ -533,7 +533,7 @@ void rna_property_rna_or_id_get(PropertyRNA *prop,
const IDPropertyUIDataInt *ui_data_int = reinterpret_cast<IDPropertyUIDataInt *>(
idprop->ui_data);
if (ui_data_int && ui_data_int->enum_items_num > 0) {
r_prop_rna_or_id->rnaprop = rna_PropertyGroupItem_enum;
r_prop_rna_or_id->rnaprop = &rna_PropertyGroupItem_enum;
return;
}
}
@@ -571,7 +571,7 @@ PropertyRNA *rna_ensure_property(PropertyRNA *prop)
const IDPropertyUIDataInt *ui_data_int = reinterpret_cast<IDPropertyUIDataInt *>(
idprop->ui_data);
if (ui_data_int && ui_data_int->enum_items_num > 0) {
return rna_PropertyGroupItem_enum;
return &rna_PropertyGroupItem_enum;
}
}
return typemap[int(idprop->type)];

View File

@@ -2627,7 +2627,7 @@ static void radial_control_set_initial_mouse(bContext *C, RadialControl *rc, con
d[1] *= zoom[1];
}
rc->scale_fac = 1.0f;
if (rc->ptr.owner_id && GS(rc->ptr.owner_id->name) == ID_BR && rc->prop == rna_Brush_size) {
if (rc->ptr.owner_id && GS(rc->ptr.owner_id->name) == ID_BR && rc->prop == &rna_Brush_size) {
Brush *brush = reinterpret_cast<Brush *>(rc->ptr.owner_id);
if ((brush && brush->gpencil_settings) && (brush->ob_mode == OB_MODE_PAINT_GPENCIL_LEGACY) &&
(brush->gpencil_tool == GPAINT_TOOL_DRAW) && (brush->flag & BRUSH_LOCK_SIZE) != 0)

View File

@@ -218,7 +218,7 @@ void WM_msg_publish_ID(wmMsgBus *mbus, ID *id);
{ \
wmMsgParams_RNA msg_key_params_ = {{0}}; \
msg_key_params_.ptr = RNA_pointer_create(id_, &RNA_##type_, data_); \
msg_key_params_.prop = rna_##type_##_##prop_; \
msg_key_params_.prop = &rna_##type_##_##prop_; \
WM_msg_publish_rna_params(mbus, &msg_key_params_); \
} \
((void)0)
@@ -226,7 +226,7 @@ void WM_msg_publish_ID(wmMsgBus *mbus, ID *id);
{ \
wmMsgParams_RNA msg_key_params_ = {{0}}; \
msg_key_params_.ptr = RNA_pointer_create(id_, &RNA_##type_, data_); \
msg_key_params_.prop = rna_##type_##_##prop_; \
msg_key_params_.prop = &rna_##type_##_##prop_; \
WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
} \
((void)0)
@@ -246,7 +246,7 @@ void WM_msg_publish_ID(wmMsgBus *mbus, ID *id);
PointerRNA msg_ptr_ = {0, &RNA_##type_}; \
wmMsgParams_RNA msg_key_params_ = {{0}}; \
msg_key_params_.ptr = msg_ptr_; \
msg_key_params_.prop = rna_##type_##_##prop_; \
msg_key_params_.prop = &rna_##type_##_##prop_; \
\
WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
} \