Skip to content

Commit

Permalink
gogensig:fix unexpect receiver reinit goplus#67
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed Dec 25, 2024
1 parent 63cdaab commit a0e793a
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/conf/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "comment",
"include": ["temp.h","use.h"],
"cplusplus":false
}
7 changes: 7 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/conf/llcppg.symb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"mangle": "ares_dns_addr_to_ptr",
"c++": "ares_dns_addr_to_ptr(const struct ares_addr *)",
"go": "(*aresAddr).AresDnsAddrToPtr"
}
]
43 changes: 43 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/gogensig.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
===== temp.go =====
package receiver

import (
"github.com/goplus/llgo/c"
_ "unsafe"
)

type X__Uint32T c.Uint
type InAddrT X__Uint32T

type InAddr struct {
SAddr InAddrT
}

type AresIn6Addr struct {
X_S6Un struct {
X_S6U8 [16]int8
}
}

===== use.go =====
package receiver

import _ "unsafe"

type AresAddr struct {
Family c.Int
Addr struct {
Addr6 AresIn6Addr
}
}
// llgo:link (*aresAddr).AresDnsAddrToPtr C.ares_dns_addr_to_ptr
func (p *AresAddr) AresDnsAddrToPtr() *int8 {
return nil
}

===== llcppg.pub =====
__uint32_t X__Uint32T
ares_addr AresAddr
ares_in6_addr AresIn6Addr
in_addr InAddr
in_addr_t InAddrT
22 changes: 22 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/hfile/temp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
typedef unsigned int __uint32_t;
typedef __uint32_t in_addr_t;
struct in_addr {
in_addr_t s_addr;
};

struct ares_in6_addr {
union {
unsigned char _S6_u8[16];
} _S6_un;
};

struct ares_addr {
int family;

union {
struct in_addr addr4;
struct ares_in6_addr addr6;
} addr;
};

#include "use.h"
2 changes: 2 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/hfile/use.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

char *ares_dns_addr_to_ptr(const struct ares_addr *addr);
6 changes: 5 additions & 1 deletion cmd/gogensig/convert/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,13 @@ func (p *TypeConv) ToSignature(funcType *ast.FuncType, recv *types.Var) (*types.
ctx := p.ctx
p.ctx = Param
defer func() { p.ctx = ctx }()
params, variadic, err := p.fieldListToParams(funcType.Params)
var params *types.Tuple
var variadic bool
var err error
if recv != nil {
params, variadic, err = p.fieldListToParams(&ast.FieldList{List: funcType.Params.List[1:]})
} else {
params, variadic, err = p.fieldListToParams(funcType.Params)
}
if err != nil {
return nil, err
Expand Down

0 comments on commit a0e793a

Please sign in to comment.