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

how do you init your custom c module at app startup? #848

Closed
tcaduser opened this issue Aug 26, 2023 · 4 comments
Closed

how do you init your custom c module at app startup? #848

tcaduser opened this issue Aug 26, 2023 · 4 comments
Labels

Comments

@tcaduser
Copy link
Contributor

tcaduser commented Aug 26, 2023

Versions

  • Python : 3.9
  • MacOS version : Ventura
  • XCode Version :
  • Cython version : 0.29

Describe the bug

My custom recipe successfully builds an archive. In addition copying the archive file into the recipes of my environment gets it installed into the image. However, the only way to get the module loaded is for me to add it to the command table in main.m

    NSLog(@"Initializing python");
    PyImport_AppendInittab("devsim_py3", PyInit_devsim_py3);
    Py_Initialize();

where I forward declare my init outside of the main function:

PyObject *PyInit_devsim_py3(void);

To Reproduce

build your own custom recipe which compiles a static archive creating a new module

Expected behavior

Document or make it easy

Logs

// REPLACE ME: Paste the build output containing the error

Screenshots

Additional context
Add any other context about the problem here.

@tcaduser
Copy link
Contributor Author

tcaduser commented Sep 3, 2023

to clarify what I am asking for. I have a custom recipe which can build my python module. It has the entry point function:

PyInit_devsim_py3

I am trying to understand how to get this imported in my application. Should I explicitly be using PyImport_AppendInittab in main.m? Should I be using a different naming convention for my PyInit function?

@tcaduser
Copy link
Contributor Author

tcaduser commented Sep 3, 2023

It looks like that python is patched to override the dlopen on an external shared library with the internal dlsym on the python executable.
https://groups.google.com/g/kivy-users/c/poh12uJ5DCM
https://discord.com/channels/423249981340778496/713442856190083094/989210942581669929

@tcaduser
Copy link
Contributor Author

tcaduser commented Sep 5, 2023

I now understand the last piece of the puzzle. What is needed is to create an empty .so file with the same name as your module. Then, the CustomBuiltinImporter.find_module method defined in main.m will be able to see the module, and call the appropriate PyInit function using dlsym on the application.

@github-actions
Copy link

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.

If you're having trouble installing or using kivy-ios, maybe you could be interested to installation and requirements.

Let us know if this comment was made in error, and we'll be happy to reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants