Giter Site home page Giter Site logo

Comments (8)

xlab avatar xlab commented on July 17, 2024

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.

juliandroid avatar juliandroid commented on July 17, 2024

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.

juliandroid avatar juliandroid commented on July 17, 2024

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.

dvlempljl avatar dvlempljl commented on July 17, 2024

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.

dvlempljl avatar dvlempljl commented on July 17, 2024

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.

dvlempljl avatar dvlempljl commented on July 17, 2024

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.

dvlempljl avatar dvlempljl commented on July 17, 2024

@xlab any chance to help with this one? Or any help to workaround it?

from c-for-go.

juliandroid avatar juliandroid commented on July 17, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.