Skip to content

feat:gen a named func type for anonymous func pointer in struct. #448

@luoliwoshang

Description

@luoliwoshang
typedef struct Hooks {
    void *(*malloc_fn)(size_t sz);
    void (*free_fn)(void *ptr);
} Hooks;
type Hooks struct {
	MallocFn c.Pointer
	FreeFn   c.Pointer
}

Due to the characteristics of LLGo, an anonymous function type cannot be directly declared as a Field Type. Currently, the Field Type for an anonymous function is only mapped to c.Pointer, but this causes the original type information to be lost. To solve this problem, we can additionally declare a function type annotated with llgo:type C and reference it.

 typedef struct Hooks {
     void *(*malloc_fn)(size_t sz);
     void (*free_fn)(void *ptr);
 } Hooks;
// llgo:type C
type LLGO_HOOKS_MallocFn func(c.SizeT) c.Pointer

// llgo:type C
type LLGO_HOOKS_FreeFn func(c.Pointer)

type Hooks struct {
	MallocFn LLGO_HOOKS_MallocFn
	FreeFn   LLGO_HOOKS_FreeFn
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions