-
Notifications
You must be signed in to change notification settings - Fork 65
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
[question] customization of a trampoline function definition #250
Comments
@kliegeois If i have to face this then i would keep option writing post-processing-scripts at the bottom of my option list. While it certainly easy to do it is also most likely will be a highest maintenance option in the long run. I think it should be really straightforward way to add this functionality to the Binder and that would be my recommendation if you are do not mind writing a bit of C++ code (i do not think anything fancy will be needed here). The way i see it we can add per-member-function Binder config option that will instruct Binder to alter trampoline function generation. Let me know if you open to this idea and would like to implement it and i will outline changes thats need to be done (should be ~one-afternoon task unless i am overlooking something big). Thanks, |
@lyskov I totally agree with your point of view and your proposition. I can probably work on this by the Christmas break. You can list here or send me an email with any recommendations for this. Thanks! |
I have given this more thoughts and it i see a two ways we can implement this. Neither is perfect so some extra discussion might be needed: [a] Simplest approach would probably be to add add config option that will allow user to request python-counterpart creation for pure-virtual-functions. Code to modify for this will be around this line: https://github.com/RosettaCommons/binder/blob/master/source/class.cpp#L740. I imagine the logic would be about the following: if member function we about to bind is pure-virtual (ie [b] another approach would be to allow user to fully customize how particular trampoline function is generated similar to options At the moment I am leaning more towards [a] since it is much easier both to write and use and see how it goes. Thoughts? |
Thanks @lyskov for your comment! I was thinking about something similar to [b], mostly because [a] does not provide enough customization. For example, if you use a custom holder type, pybind/pybind11#1049 (comment) is not exactly what you need: you need to update the code snippet to be consistent with your used holder type and its corresponding functions/constructor. I was thinking of something as follows: Given files:
Then, binder would generate something similar to this:
This would allow the user to customize |
I agree that approach [a] seems way to rigid. Ok, lets see if we can make [b] work. A few thoughts on proposed design:
-- no need to custom include directive, we can re-use include_for_class here: Generated code:
|
Binder generates automatically some trampoline classes when needed and generates their corresponding member functions.
I am currently facing a particular case where I need to modify one of the generated member function of one of the trampoline classes (I will provide more details bellow for the interested developers/users). It seems that there is currently no ways to do it using binder configuration options. @lyskov do you have recommendation on how to do so?
More detailed context:
pybind/pybind11#1774 (comment)
pybind/pybind11#1049 (comment)
Work around that requires modification of the binder generated trampoline member function:
pybind/pybind11#1049 (comment)
Other potential work around on the pybind11 side that might solves the issues without binder modifications:
https://github.com/pybind/pybind11/blob/smart_holder/README_smart_holder.rst I did not find an ETA for the merging of this branch into master.
pybind/pybind11#2839 this PR has no activities since a year ago
In the case that I faced, the solution of pybind/pybind11#1049 (comment) worked.
To do so, I generated the trampoline class using binder and then I modified the clone member function to be consistent with pybind/pybind11#1049 (comment) with the shared pointer class that I am using. I could write a script that post-process the binder generated files and replace the definition of the function with one that suites my need in this case but this is not the cleanest way to resolve this and I am curious to have your point of view @lyskov on this.
The text was updated successfully, but these errors were encountered: