From 08a882582760c8ef44aff8543c2fc3ed6ff35992 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 9 Aug 2023 22:40:39 +0200 Subject: [PATCH] Cleanup: use actual function type instead of void* in declaration This updates the signature of `RNA_def_property_update_runtime` which previously just has a `const void *` input. This made it difficult to know what function signature is expected and also does not result in compile errors when a wrong function is provided. There is one case which required a different signature, so now there is a separat function for that case. --- .../editors/gpencil_legacy/gpencil_bake_animation.cc | 2 +- source/blender/editors/gpencil_legacy/gpencil_convert.cc | 3 +-- source/blender/editors/gpencil_legacy/gpencil_mesh.cc | 2 +- source/blender/editors/io/io_obj.cc | 8 ++++---- source/blender/editors/io/io_ply_ops.cc | 8 ++++---- source/blender/editors/object/object_add.cc | 2 +- source/blender/editors/space_node/drawnode.cc | 2 +- source/blender/makesrna/RNA_define.h | 9 ++++++++- source/blender/makesrna/intern/rna_define.cc | 9 ++++++++- .../nodes/geometry/nodes/node_geo_curve_resample.cc | 2 +- .../nodes/geometry/nodes/node_geo_set_curve_normal.cc | 2 +- .../nodes/geometry/nodes/node_geo_subdivision_surface.cc | 4 ++-- source/blender/python/intern/bpy_props.cc | 4 +--- 13 files changed, 34 insertions(+), 23 deletions(-) diff --git a/source/blender/editors/gpencil_legacy/gpencil_bake_animation.cc b/source/blender/editors/gpencil_legacy/gpencil_bake_animation.cc index 18ec19a1c27..37b800d7332 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_bake_animation.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_bake_animation.cc @@ -416,7 +416,7 @@ void GPENCIL_OT_bake_grease_pencil_animation(wmOperatorType *ot) prop = RNA_def_int( ot->srna, "frame_end", 250, 1, 100000, "End Frame", "The end frame of animation", 1, 100000); - RNA_def_property_update_runtime(prop, (void *)gpencil_bake_set_frame_end); + RNA_def_property_update_runtime(prop, gpencil_bake_set_frame_end); prop = RNA_def_int(ot->srna, "step", 1, 1, 100, "Step", "Step between generated frames", 1, 100); diff --git a/source/blender/editors/gpencil_legacy/gpencil_convert.cc b/source/blender/editors/gpencil_legacy/gpencil_convert.cc index 7480ad52b19..cd7a8556167 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_convert.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_convert.cc @@ -1730,8 +1730,7 @@ void GPENCIL_OT_convert(wmOperatorType *ot) "The end frame of the path control curve (if Realtime is not set)", 1, 100000); - RNA_def_property_update_runtime(prop, - reinterpret_cast(gpencil_convert_set_end_frame)); + RNA_def_property_update_runtime(prop, gpencil_convert_set_end_frame); RNA_def_float(ot->srna, "gap_duration", diff --git a/source/blender/editors/gpencil_legacy/gpencil_mesh.cc b/source/blender/editors/gpencil_legacy/gpencil_mesh.cc index 6d68d754a97..32fc9fb7fd8 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_mesh.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_mesh.cc @@ -423,7 +423,7 @@ void GPENCIL_OT_bake_mesh_animation(wmOperatorType *ot) prop = RNA_def_int( ot->srna, "frame_end", 250, 1, 100000, "End Frame", "The end frame of animation", 1, 100000); - RNA_def_property_update_runtime(prop, (void *)gpencil_bake_set_frame_end); + RNA_def_property_update_runtime(prop, gpencil_bake_set_frame_end); prop = RNA_def_int(ot->srna, "step", 1, 1, 100, "Step", "Step between generated frames", 1, 100); diff --git a/source/blender/editors/io/io_obj.cc b/source/blender/editors/io/io_obj.cc index 26c0cb0f955..a09c0853e74 100644 --- a/source/blender/editors/io/io_obj.cc +++ b/source/blender/editors/io/io_obj.cc @@ -288,9 +288,9 @@ void WM_OT_obj_export(wmOperatorType *ot) /* Object transform options. */ prop = RNA_def_enum( ot->srna, "forward_axis", io_transform_axis, IO_AXIS_NEGATIVE_Z, "Forward Axis", ""); - RNA_def_property_update_runtime(prop, (void *)io_ui_forward_axis_update); + RNA_def_property_update_runtime(prop, io_ui_forward_axis_update); prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", ""); - RNA_def_property_update_runtime(prop, (void *)io_ui_up_axis_update); + RNA_def_property_update_runtime(prop, io_ui_up_axis_update); RNA_def_float( ot->srna, "global_scale", @@ -521,9 +521,9 @@ void WM_OT_obj_import(wmOperatorType *ot) 1000.0f); prop = RNA_def_enum( ot->srna, "forward_axis", io_transform_axis, IO_AXIS_NEGATIVE_Z, "Forward Axis", ""); - RNA_def_property_update_runtime(prop, (void *)io_ui_forward_axis_update); + RNA_def_property_update_runtime(prop, io_ui_forward_axis_update); prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", ""); - RNA_def_property_update_runtime(prop, (void *)io_ui_up_axis_update); + RNA_def_property_update_runtime(prop, io_ui_up_axis_update); RNA_def_boolean(ot->srna, "use_split_objects", true, diff --git a/source/blender/editors/io/io_ply_ops.cc b/source/blender/editors/io/io_ply_ops.cc index 7ab221a73b3..7362043edca 100644 --- a/source/blender/editors/io/io_ply_ops.cc +++ b/source/blender/editors/io/io_ply_ops.cc @@ -178,9 +178,9 @@ void WM_OT_ply_export(wmOperatorType *ot) /* Object transform options. */ prop = RNA_def_enum(ot->srna, "forward_axis", io_transform_axis, IO_AXIS_Y, "Forward Axis", ""); - RNA_def_property_update_runtime(prop, (void *)io_ui_forward_axis_update); + RNA_def_property_update_runtime(prop, io_ui_forward_axis_update); prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Z, "Up Axis", ""); - RNA_def_property_update_runtime(prop, (void *)io_ui_up_axis_update); + RNA_def_property_update_runtime(prop, io_ui_up_axis_update); RNA_def_float( ot->srna, "global_scale", @@ -309,9 +309,9 @@ void WM_OT_ply_import(wmOperatorType *ot) "Scene Unit", "Apply current scene's unit (as defined by unit scale) to imported data"); prop = RNA_def_enum(ot->srna, "forward_axis", io_transform_axis, IO_AXIS_Y, "Forward Axis", ""); - RNA_def_property_update_runtime(prop, (void *)io_ui_forward_axis_update); + RNA_def_property_update_runtime(prop, io_ui_forward_axis_update); prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Z, "Up Axis", ""); - RNA_def_property_update_runtime(prop, (void *)io_ui_up_axis_update); + RNA_def_property_update_runtime(prop, io_ui_up_axis_update); RNA_def_boolean(ot->srna, "merge_verts", false, "Merge Vertices", "Merges vertices by distance"); RNA_def_enum(ot->srna, "import_colors", diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc index 0e779a56b36..dc4a686c131 100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@ -416,7 +416,7 @@ void ED_object_add_generic_props(wmOperatorType *ot, bool do_editmode) /* NOTE: this property gets hidden for add-camera operator. */ prop = RNA_def_enum( ot->srna, "align", align_options, ALIGN_WORLD, "Align", "The alignment of the new object"); - RNA_def_property_update_runtime(prop, (void *)view_align_update); + RNA_def_property_update_runtime(prop, view_align_update); prop = RNA_def_float_vector_xyz(ot->srna, "location", diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index 5215f78837a..0a83c8285e3 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -1084,7 +1084,7 @@ static void node_socket_template_properties_update(bNodeType *ntype, bNodeSocket PropertyRNA *prop = RNA_struct_type_find_property(srna, stemp->identifier); if (prop) { - RNA_def_property_update_runtime(prop, (const void *)node_property_update_default); + RNA_def_property_update_runtime(prop, node_property_update_default); } } diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index 4a48873dc6f..cabd975b65d 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -453,7 +453,14 @@ void RNA_def_property_override_funcs(PropertyRNA *prop, const char *store, const char *apply); -void RNA_def_property_update_runtime(PropertyRNA *prop, const void *func); +typedef void (*RNAPropertyUpdateFunc)(struct Main *, struct Scene *, struct PointerRNA *); +typedef void (*RNAPropertyUpdateFuncWithContextAndProperty)(struct bContext *C, + struct PointerRNA *ptr, + struct PropertyRNA *prop); + +void RNA_def_property_update_runtime(PropertyRNA *prop, RNAPropertyUpdateFunc func); +void RNA_def_property_update_runtime_with_context_and_property( + PropertyRNA *prop, RNAPropertyUpdateFuncWithContextAndProperty func); void RNA_def_property_update_notifier(PropertyRNA *prop, int noteflag); void RNA_def_property_poll_runtime(PropertyRNA *prop, const void *func); diff --git a/source/blender/makesrna/intern/rna_define.cc b/source/blender/makesrna/intern/rna_define.cc index 873909e2b9c..29795ebd7c3 100644 --- a/source/blender/makesrna/intern/rna_define.cc +++ b/source/blender/makesrna/intern/rna_define.cc @@ -2920,11 +2920,18 @@ void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func) prop->update = (UpdateFunc)func; } -void RNA_def_property_update_runtime(PropertyRNA *prop, const void *func) +void RNA_def_property_update_runtime(PropertyRNA *prop, RNAPropertyUpdateFunc func) { prop->update = (UpdateFunc)func; } +void RNA_def_property_update_runtime_with_context_and_property( + PropertyRNA *prop, RNAPropertyUpdateFuncWithContextAndProperty func) +{ + prop->update = (UpdateFunc)func; + RNA_def_property_flag(prop, PROP_CONTEXT_PROPERTY_UPDATE); +} + void RNA_def_property_update_notifier(PropertyRNA *prop, const int noteflag) { prop->noteflag = noteflag; diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc index 66090d74bd4..631148d8b4a 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc @@ -137,7 +137,7 @@ static void node_rna(StructRNA *srna) RNA_def_property_enum_node_storage(prop, mode); RNA_def_property_enum_items(prop, mode_items); RNA_def_property_ui_text(prop, "Mode", "How to specify the amount of samples"); - RNA_def_property_update_runtime(prop, (void *)rna_Node_socket_update); + RNA_def_property_update_runtime(prop, rna_Node_socket_update); RNA_def_property_update_notifier(prop, NC_NODE | NA_EDITED); } diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc index 5a57c5e0e52..6d7fb927f4e 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc @@ -70,7 +70,7 @@ static void node_rna(StructRNA *srna) RNA_def_property_enum_node(prop, custom1); RNA_def_property_enum_items(prop, rna_enum_curve_normal_modes); RNA_def_property_ui_text(prop, "Mode", "Mode for curve normal evaluation"); - RNA_def_property_update_runtime(prop, (void *)rna_Node_update); + RNA_def_property_update_runtime(prop, rna_Node_update); RNA_def_property_update_notifier(prop, NC_NODE | NA_EDITED); } diff --git a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc index 4924cf8d531..d7b9d50d576 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc @@ -203,7 +203,7 @@ static void node_rna(StructRNA *srna) RNA_def_property_enum_items(prop, rna_enum_subdivision_uv_smooth_items); RNA_def_property_enum_default(prop, SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES); RNA_def_property_ui_text(prop, "UV Smooth", "Controls how smoothing is applied to UVs"); - RNA_def_property_update_runtime(prop, (void *)rna_Node_update); + RNA_def_property_update_runtime(prop, rna_Node_update); RNA_def_property_update_notifier(prop, NC_NODE | NA_EDITED); prop = RNA_def_property(srna, "boundary_smooth", PROP_ENUM, PROP_NONE); @@ -211,7 +211,7 @@ static void node_rna(StructRNA *srna) RNA_def_property_enum_items(prop, rna_enum_subdivision_boundary_smooth_items); RNA_def_property_enum_default(prop, SUBSURF_BOUNDARY_SMOOTH_ALL); RNA_def_property_ui_text(prop, "Boundary Smooth", "Controls how open boundaries are smoothed"); - RNA_def_property_update_runtime(prop, (void *)rna_Node_update); + RNA_def_property_update_runtime(prop, rna_Node_update); RNA_def_property_update_notifier(prop, NC_NODE | NA_EDITED); } diff --git a/source/blender/python/intern/bpy_props.cc b/source/blender/python/intern/bpy_props.cc index c00c999fc5a..c74d2bee516 100644 --- a/source/blender/python/intern/bpy_props.cc +++ b/source/blender/python/intern/bpy_props.cc @@ -2267,10 +2267,8 @@ static void bpy_prop_callback_assign_update(PropertyRNA *prop, PyObject *update_ if (update_fn && update_fn != Py_None) { BPyPropStore *prop_store = bpy_prop_py_data_ensure(prop); - RNA_def_property_update_runtime(prop, reinterpret_cast(bpy_prop_update_fn)); + RNA_def_property_update_runtime_with_context_and_property(prop, bpy_prop_update_fn); ASSIGN_PYOBJECT_INCREF(prop_store->py_data.update_fn, update_fn); - - RNA_def_property_flag(prop, PROP_CONTEXT_PROPERTY_UPDATE); } }