Skip to content

Constify C constructors and flags tables - #12223

Merged
xavierleroy merged 1 commit into
ocaml:trunkfrom
MisterDA:const-cst-flags-tables
May 8, 2023
Merged

xavierleroy merged 1 commit into
ocaml:trunkfrom
MisterDA:const-cst-flags-tables

Conversation

@MisterDA

@MisterDA MisterDA commented May 5, 2023

Copy link
Copy Markdown
Contributor

There's little value to this considering the constructors tables are static, used very locally, but this serves nonetheless as an indication to the programmer that the tables are not to be modified.

@gasche gasche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me.

@xavierleroy xavierleroy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch. Now these tables will go in the readonly segment, where they belong.

@xavierleroy

Copy link
Copy Markdown
Contributor

Can you add a Changes entry? Then I'll merge.

@avsm

avsm commented May 8, 2023

Copy link
Copy Markdown
Member

There's also another opportunity for the same treatment for static int posix_signals[] in runtime/sys.c, in case you want to constify that too.

@MisterDA
MisterDA force-pushed the const-cst-flags-tables branch from 81354d0 to 649b70f Compare May 8, 2023 15:55
@MisterDA

MisterDA commented May 8, 2023

Copy link
Copy Markdown
Contributor Author

Done and done!
While grepping, I've also found this:

output_string outchan "static int caml_code[] = {\n";

maybe the generated caml_code could be made const too, if it's not self-modifying, or no changes are made to the array?

@xavierleroy

Copy link
Copy Markdown
Contributor

maybe the generated caml_code could be made const too, if it's not self-modifying, or no changes are made to the array?

If memory serves, the bytecode can be modified before execution to replace opcodes by code pointers into the interpreter (the so-called indirect threaded code technique).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants