Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interrogate(_module?) to allow specifying a user-defined init function #3

Open
CFSworks opened this issue Sep 3, 2018 · 4 comments
Labels
enhancement New feature or request

Comments

@CFSworks
Copy link
Member

CFSworks commented Sep 3, 2018

This is needed for e.g. making sure panda3d/core.so calls init_libpanda to ensure pnmimagetypes is initialized.

Currently it's only needed in non-metalib builds where the platform linker only links libraries where at least one symbol is used, such as with Travis CI's version of GCC. For now, I'm silencing test errors with -Wl,--no-as-needed (see 601a82d).

@CFSworks CFSworks added the enhancement New feature or request label Sep 3, 2018
@rdb
Copy link
Member

rdb commented Sep 4, 2018

I agree, I have found myself wishing for such a feature in the past as well. Could you remind me why exactly the static initializers don't work when making a non-metalib build, though?

I can think several ways to implement such a feature:

  1. We can permit a CPPExpression to be added as an init invocation in an .N file, using a line like (eg.) oninit call_my_func()
  2. We could extend C++ syntax to add a special keyword or attribute to any function to mark it as needing to be invoked at init time
  3. We could add a command-line flag to interrogate_module to specify a function to be called on init (probably my least favourite option)

@CFSworks
Copy link
Member Author

CFSworks commented Sep 4, 2018 via email

@rdb
Copy link
Member

rdb commented Sep 4, 2018

Another option, mirroring other parts of Panda, is to consider libp3pnmimagetypes a plug-in and have it loaded via a Config.prc variable (ie. we would have load-image-type similar to load-file-type, load-audio-type, load-video-type. See LoaderFileTypeRegistry and MovieTypeRegistry.) This would allow us to separate out plug-ins that use external libraries (such as OpenEXR) in the future and also make it possible for people to provide their own plug-ins.

Either way, I'd still be OK with having something like what you describe.

@CFSworks
Copy link
Member Author

CFSworks commented Sep 5, 2018

The modular approach gets a +1 from me.

I have only a slight concern that we might be patching up the example and ignoring the more general problem. For example, --as-needed still prevents linking against libpanda.so at all when doing a non-metalib build, and the only way to change that would be to force Interrogate to make a call to init_libpanda(). (The bigger question, of course, is "Do we care?" since this doesn't actually prevent anything from working. We might only want to address this if we're concerned with future-proofing, i.e. if we want the ABI to be consistent even when we split apart component libs and we want to make sure libpanda is dynamically linked so it can pull in the newly-formed component lib.)

@rdb rdb transferred this issue from panda3d/panda3d Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants