Comments (8)
These are wrapping structures, when you want to have a viewer on Go side for a C struct instance. You can skip generating such wrappers by setting MemTips
to raw
, e.g.
MemTips:
- {target: TsifT, self: raw}
for the "type TsifT struct" I'm also having recursive pointer:
this is clearly a bug, could you please provide a minimal reproducible piece of code?
from c-for-go.
xlab, thanks for looking into that. Didn't you manage to reproduce the same results by using the same test.tar.gz (attached file)?
Can you please confirm that test.tar.gz doesn't help you to reproduce both issues?
Regarding to TsiftT structure (C type tsif_t) - I actually need to use that since it is part of the API (as it is marked with comment inside header file "/** interfaces within endpoint */").
Any help with that? It seems to me some sort of bug.
from c-for-go.
Regarding the other issue:
If I have the following C structure:
/** Report in the interface */
typedef struct
{
uint8_t rpt_cmd; /**< report command */
uint8_t rsvd1; /**< Padding to make sure the structure is 4-byte aligned */
uint16_t rsvd2; /**< Padding to make sure the structure is 4-byte aligned */
void *rpt_cb; /**< pointer to report callback function */
void *sm_rpt_cb; /**< pointer to state-machine report callback function */
} if_rpt_t;
and it is wrapped like this in go:
type IfRptT struct {
RptCmd byte
Rsvd1 byte
Rsvd2 uint16
RptCb unsafe.Pointer
SmRptCb unsafe.Pointer
ref6ea68005 *C.if_rpt_t
allocs6ea68005 interface{}
}
It means, that I cannot fill-in the go structure and pass it to respective C function that accept it and I have to use always C.structname instead? I left with impression that the idea of Go wrapper around C struct is to provide memory-compatible to C variant structure (or at least go-function wrapper to know how to decode the go-struct) , so you can generate it in Go and pass it to respective C method?
Can you please confirm or clarify?
from c-for-go.
Not sure whether test.tar.gz is good enough, but the .h file could be even more simplified to:
struct obj;
typedef struct obj *obj_p;
typedef struct obj
{
int ver;
}
obj_t;
this produces (assuming you have "- {action: accept, from: "^obj"}") code that looks like:
// ObjP as declared in include/test.h:2
type ObjP struct {
Ver int32
ref6c6df6cb *C.obj_p
allocs6c6df6cb interface{}
}
// ObjT as declared in include/test.h:8
type ObjT struct {
Ver int32
ref63649241 ****************************************************************************************************************************************************************************************************************************************************************C.obj_t
allocs63649241 interface{}
}
from c-for-go.
The problem looks like to be at: translator/translator.go:873
cgo.Pointers = spec.GetPointers() - decl.Spec.GetPointers()
The spec.GetPointers() is 0 while the decl.Spec.GetPointers() = 1 and thus the result is 255. Not sure though what should be the correct behavior here? Always evaluate to 0 when the difference is "negative"?
from c-for-go.
I've checked all the other libraries listed on the main page that are using c-for-go and I couldn't find a single place where someone have even double pointers ( **C. )
I have another type that is similar to above, but this time "only" twice:
type NetInitP struct {
// ... some fields
ref4e3a9a4 **C.net_init_p
allocs4e3a9a4 interface{}
}
which in C have a similar structure:
typedef struct
{
//...
}
net_init_t, *net_init_p;
P.S. For this concrete case with just two refs, I don't have a reproducible headers, but it is possible to spend some time building a show case, but if that is not related issue to the one described above.
from c-for-go.
@xlab any chance to help with this one? Or any help to workaround it?
from c-for-go.
@xlab @cznic I was wondering, is there any chance to point me in the right direction?
Not sure how to overcome issues like generated code, like:
refff3c8fce ****************************************************************************************************************************************************************************************************************************************************************C.tsif_t
from c-for-go.
Related Issues (20)
- type C.struct_ in strut and func HOT 1
- How to handle a function returning a struct as value
- Type translation does not respect systems data model HOT 1
- Verbose argument to print more logs
- Avoid lock / unlock for some function call
- Wiki need to be updated
- panic: unknown type _Float128 HOT 2
- Non int return function pointer not recognized
- Generator uses underlying type of typedef when used as a parameter
- Website down HOT 3
- It would be nice to at least have an example of the YML required in the readme since the website does not work HOT 1
- build HOT 5
- [OS X / Ubuntu ARM64] include file not found: <string> HOT 3
- Extracting SAL annotations from declarations HOT 2
- Example where C const get translated into Go typed const
- Callback generation HOT 2
- THIS IS NOT AN ISSUE!!!
- Avoid symbol lookup error
- Passing in an array to a C function and reading the data - incorrect autogenerated Go code
- Write rules against the location of the type/define rather than the name
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 c-for-go.