-
Notifications
You must be signed in to change notification settings - Fork 6
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
C++ unions #9
Comments
Union types are very, very, C/C++ specific. There is no such thing as unions in Python: object and base types will always occupy different memory locations. Solutions: 1/ Either you write a wrapper And use it in the API you want to publish. class MySignal
{
int as_int();
...
private:
signalValue_t xxx;
}; 2/ And/or you write a custom caster And give it appropriate methods. https://pybind11.readthedocs.io/en/stable/advanced/cast/custom.html |
Hi, I used the wrapper approach suggested above by ChatGPT. Now, I'm trying to add the original union type in the exclude options, but I don't find the proper option. I only found: the build process works, but then when I go to Python:
|
# Exclude certain functions and methods by a regex on any of their parameter type and/or return type
# (those should be decorated type)
# For example:
# options.fn_exclude_by_param_type__regex = "^char\s*$|^unsigned\s+char$|Callback$"
# would exclude all functions having params of type "char *", "unsigned char", "xxxCallback"
#
# Note: this is distinct from `fn_params_exclude_types__regex` which removes params
# from the function signature, but not the function itself.
fn_exclude_by_param_type__regex: str = "" |
ok, I was doing confusion before on what I really needed... I didn't need to exclude the "union" (also because it was already excluded by litgen by default, in fact I opened the issue exactly for this reason. So, now I found the way to expose union types, and I resume the procedure for eventual future users:
Now the bindings are correctly generaed and the wrapped union works s expected. Thanks a lot for your support, @pthom |
Hello,
I have code like this:
typedef union u_signalValue_t {
float flt;
int32_t i32;
double dbl;
int64_t i64;
} signalValue_t;
I already overcame the issue related to the usage of "typedef", by pre-processing the code, as suggested here:
#7
So, my pre-processed code is now:
union signalValue_t {
float flt;
int32_t i32;
double dbl;
int64_t i64;
};
however, it seems the the union type is not processed by litgen: I see all other types in the pybind11 C++ code, like enums, classes, structs, etc. except this union.
Any suggestion?
The text was updated successfully, but these errors were encountered: