Page MenuHome

RNA: Use C++ for sequencer properties
Needs ReviewPublic

Authored by Richard Antalik (ISS) on Nov 18 2022, 10:43 PM.

Details

Summary

Files rna_sequencer.c and rna_sequencer_api.c were renamed to
corresponding .cc files. Only necessary changes were made such as type casts.

This required changes in RNA generator code. This generates macros to wrap
properties which are implicitly cast, to cast them explicitly in with C++
compliler.
Type casting in rna_def_property_set_func required adding header files
to some rna source files. I am not sure, whether this could have been
avoided by using macro.


Starting point was P3326, which has some useful debug points. It asumes rna_sound.c was being converted to C++ for simplicity.

Diff Detail

Repository
rB Blender
Branch
rna_cpp (branched from master)
Build Status
Buildable 24729
Build 24729: arc lint + arc unit

Event Timeline

Richard Antalik (ISS) requested review of this revision.Nov 18 2022, 10:43 PM
Richard Antalik (ISS) created this revision.
Richard Antalik (ISS) edited the summary of this revision. (Show Details)Nov 18 2022, 10:46 PM

Remove unintended changes

given rna_sequencer_api.c gets included in a xxxx_gen.cc file, probably a good idea to rename that one to .cc as well

Richard Antalik (ISS) edited the summary of this revision. (Show Details)Nov 18 2022, 10:53 PM

Looks incorrect that RNA_prototypes.h is a new file in this commit, since it's supposed to be generated automatically.

Do the casts in rna_sequencer.cc have to be C-style casts? I would think not, since they end up in a .cc file. It would be better to follow the style guide there then.

Remove debug printfs

  • Use C++ type casting style
  • Clang-format
  • Don't include RNA_prototypes.h file
  • Use C++ for RNA_sequencer_api.c file
  • Fix mistake - assumed, that (1 << 0) == 1, when cleaning up RNA_def_parameter_flags
  • Use C++ type cast style for missed casts
Campbell Barton (campbellbarton) requested changes to this revision.Dec 13 2022, 11:55 AM

GCC is emitting a lot of warnings with this patch applied (output P3388).

source/blender/makesrna/intern/makesrna.c
4630–4633

Not sure this is worth wrapping each cast with a define, couldn't C-style casts be used for both?

4635–4639

*picky*, use (x) instead of x, to avoid accidents.

source/blender/makesrna/intern/rna_sequencer_api.c
252

Can use function style cast eSeqImageFitMethod(fit_method)

This revision now requires changes to proceed.Dec 13 2022, 11:55 AM
Richard Antalik (ISS) marked 2 inline comments as done.
  • Address inlines, fix whitespace

Given i took the initial stab at this, the macro's are there to use the codestyle preferred casts for C++. If we're settling for all c style casts, the macro's seemingly bring very little to the party, (maybe code readability is a little better? but it be by a hair at best for me personally) and we could just cast directly at the call site.

check to hear back from campbell's thoughts on this before making any changes though.

If we do keep the macro's they can be identical for C and C++ no need to differentiate anymore with c style casts.

I am fine with C-style casts too.

As for warnings, I have looked into solutions and so far don't quite understand this completely. I get, that function without declaration should be static, but if I define these as such, it does not compile. I think that git ignores _gen files so these may be declared somewhere, will look further into that. I also may generate some noise here, so I can check things on buildbot.

After bit of reverse engineering, I have found a solution (diff for one case):

diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 75b4d11bfbe..47ed53749ce 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -1505,7 +1505,8 @@ static char *rna_def_property_begin_func(

   func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "begin");

-  fprintf(f, "void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
+  const char *is_static = ((prop->flag_internal & PROP_INTERN_BUILTIN) != 0) ? "static" : "";
+  fprintf(f, "%s void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", is_static, func);
   fprintf(f, "{\n");

   if (!manualfunc) {

Not sure if this is best way to resolve this issue, but should be functionally same as previous C code. Also there may be more untreated warnings, will check that tomorrow.

Update: Unfortunately, above approach does not work for all functions. Will check few things, but I think I will need to seek advice.

I updated this patch to master and spent a bit trying to solve the warnings about static. I didn't find anything better than the diff above though yet. Here's the current patch: