Skip to content
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

How to handle a function returning a struct as value #137

Open
bearsh opened this issue Nov 16, 2022 · 0 comments
Open

How to handle a function returning a struct as value #137

bearsh opened this issue Nov 16, 2022 · 0 comments

Comments

@bearsh
Copy link
Contributor

bearsh commented Nov 16, 2022

I have following situation:

typedef struct {
    int A;
} member;

typedef struct {
    size_t size;    // size of array defined below
    type1* members; // pointer to an array of members
} members;

// function returning members as value
members get_members(void);

I've instructed c-for-go to generates MemTips if kind bind for member and members. the wrapper for get_members() looks ruffly like this:

func GetMembers() Memebrs {
    __ret := C.get_members()
    __v := *(*Members)(unsafe.Pointer(&__ret))
    return __v
}

now I have the following problems:

  1. GetMembers seems to return a wrongly initialized struct as it simply uses the c-structs pointer and casts it. changing it to:

    func GetMembers() Memebrs {
        __ret := C.get_members()
        return *NewMembersRef(unsafe.Pointer(&__ret)
    }

    seems to fix that...

  2. with the above fix, I can call .Deref() which sets the .Size member to value of the underlying c-struct but the .Members ([]Member) does not get filled in

do I miss an important instruction in the yaml file or is this simply a limitation on c-to-go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant