Comments (5)
Hi @jakirkham !
Yes, sure, that is definitely something that we would consider.
What functionality are you expecting from autowrapping them? What can Cython do already internally?
from autowrap.
Thanks for your reply Julianus!
Maybe some kind of Python object that can easily move between Python/C with attribute access covered via property
s in Python and struct
field in C.
I guess C++ works with struct
s as if they were C++ class
es except by default things declared in them are public
as opposed to private
. Maybe this in some ways makes them closer to what is already done here for class
es with some tweaks?
AFAIK Cython doesn't do any wrapping on its own in this area. There was some discussion in issue ( cython/cython#3434 ) that seemed relevant.
A starting point might be extension types. For example something like this...
cdef class MyStruct:
cdef double d
cdef long i
...would get translated into something like this, which is pretty close.
struct __pyx_obj_<...>_MyStruct {
PyObject_HEAD
double d;
long i;
};
The one tricky thing with this kind of approach is this is effectively declaring a new struct
though wrapped code would already define a struct
. It is also adding in another member.
So maybe one could make an extension type that holds a struct
. Then one would need to generate some code to add property
access of the fields.
There are probably other options I'm not thinking of
from autowrap.
Do you have any thoughts on this @jpfeuffer?
from autowrap.
Hi! So I thought a bit more about this.
The problem is a bit, that we have no experience at all with wrapping C in autowrap (it might work to some extend).
Was your question about structs in C or C-style structs without member functions in C++?
For C++ I do not yet see any benefits over just using cdef cppclass
for a struct (based on the usecases we had so far) but you might have more experience.
The way autowrap wraps classes/structs is to create a Python class that has a member inst
which holds a shared pointer
to the actual C++ object. Attribute access and functions are just forwarded to the underlying object then.
The nice thing about this is, that if this Python object is passed to a function, there is no overhead in copying data (if the original C++ function was expecting references or pointers).
We are also using and forwarding whatever constructor is provided in C(++). So the special init methods that python generates for dataclasses does not add any advantage either.
from autowrap.
@jakirkham Does that help? We just recently adopted this project and we are still learning about the internals of Cython. So feel free to correct us or suggest something different.
from autowrap.
Related Issues (20)
- Support `using` like we support `typedef` HOT 3
- [Typing] Add code docs also to type stubs HOT 1
- CFuncDeclaratorNode AttributeError HOT 5
- Improve wrapping Special methods
- Differentiate between C and C++ mode and/or make clear that C++ is always required after autowrap HOT 1
- [Typing] Remaining mini issues
- 22.9 chokes on templated vector HOT 6
- Overloaded method docstrings don't indent properly HOT 1
- Use inheritance instead of assignment for "attached" classes
- Re-evaluate default docstrings HOT 1
- Typehint issues
- Evaluate if wrapping functions that accept std::function (callbacks) are easily possible
- named parameters possible? HOT 2
- Do not use list as pair replacement, since list cannot be heterogenously typed
- How to handle unnamed parameters in typestubs
- Remove all python2 special handling cases
- ConversionProviders for libcpp_container[libcpp_*_string, *] not picked up -> Careful with typing
- Autoapply reformating in CI?
- release-autowrap.yaml need updating
- Adapt docstring generation regarding inheritance
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autowrap.