Comments (4)
Field that causes recursion is changed to pointer to CArray
only in the case when struct references itself struct node { struct node *next };
It happens in TypeTranslator
, but TypeTranslator
cannot handle more difficult cases as the one above because while translating struct a
it cannot know that struct a -> struct b -> struct c -> struct a
cycle exist (it may only detect cycle in struct c
when all types are known).
Cycles should be fixed after all types are generated. Before generating Scala code Structs and Unions should check whether their fields cause cycle, if so a field should be replace with a pointer to Byte
.
from scala-native-bindgen.
But on the other hand it is okay to break cycle in only one place, so there is no need to detect cycle in all 3 structures.
Original type of replaced type should be remembered to generate proper helper methods.
from scala-native-bindgen.
Following issues should be considered:
CycleDetection
adds dependency only for value types and pointer types.
Field may be of any type (for example function pointer), soCycleDetection
should "unroll" all types. I suppose it will be reasonable to modifyType::usesType
method such that it stops if cycle is found. Then the method may be used inStruct
andUnion
to detect cyclic fields.CycleDetection
then may be removed.- We should "brake" cycle on a pointer type filed because only pointer type field may be replaced with pointer to
Byte
.
So in this case:field ofstruct b; struct a { struct b *sb; }; struct b { struct a sa; };
struct a
should be replace bynative.Ptr[Byte]
.
Note: pointer type field always exists because otherwise structs will have never-ending recursion.
from scala-native-bindgen.
Case with function pointers is pretty complicated because there might not be a pointer where cycle should be broken:
struct a;
struct b {
int (*func)(struct a);
};
struct a {
struct b sb;
};
There are two possible solutions:
- Change type of function pointer to
native.CFunctionPtr1[native.CArray[...], native.CInt]
, so it usesCArray
instead of struct type. - Change type of field to
CArray
Seems like Scala Native supports casting function pointers and it should not break anything:
A pointer to a function of one type may be converted to a pointer to a function of another type and back again; the result shall compare equal to the original pointer.
from scala-native-bindgen.
Related Issues (20)
- Move transformations and code generation out of the intermediate representation HOT 9
- Skip functions that pass structs or arrays by value HOT 2
- Field offset in bits is not always divisible by 8 HOT 5
- Fix union helper methods for fields of value type
- Provide a default config to integrate standard bindings from Scala Native
- Create struct constructor helper HOT 2
- Add libuv binding
- Add sqlite binding HOT 11
- Add redis C library binding
- List of blocking Scala Native issues HOT 1
- RFC: What organization and name should be used for bindings
- Fix artifactId of bindings on bintray
- Anonymous union types in structs lead to invalid generated code
- Cannot use union members
- fatal error: 'stddef.h' file not found
- Align scala-native-bindgen with Scala Native 0.4.x API HOT 2
- Bindgen crashes on enums mixed with macros (#define)
- Incorrect translation of fixed size array to CArray HOT 3
- Can't fetch plugin [bintray error] (Maybe temporary?)
- fatal error: 'stddef.h' file not found
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 scala-native-bindgen.