diff --git a/cmd/gogensig/convert/_testdata/receiver/conf/llcppg.symb.json b/cmd/gogensig/convert/_testdata/receiver/conf/llcppg.symb.json index afd2c42..5fb5f44 100644 --- a/cmd/gogensig/convert/_testdata/receiver/conf/llcppg.symb.json +++ b/cmd/gogensig/convert/_testdata/receiver/conf/llcppg.symb.json @@ -1,4 +1,9 @@ [ + { + "mangle": "ares_dns_pton", + "c++": "ares_dns_pton(const char *, struct ares_addr *, int *)", + "go": "AresDnsPton" + }, { "mangle": "ares_dns_addr_to_ptr", "c++": "ares_dns_addr_to_ptr(const struct ares_addr *)", diff --git a/cmd/gogensig/convert/_testdata/receiver/gogensig.expect b/cmd/gogensig/convert/_testdata/receiver/gogensig.expect index 58333ea..e10ad2a 100644 --- a/cmd/gogensig/convert/_testdata/receiver/gogensig.expect +++ b/cmd/gogensig/convert/_testdata/receiver/gogensig.expect @@ -6,11 +6,8 @@ import ( _ "unsafe" ) -type X__Uint32T c.Uint -type InAddrT X__Uint32T - -type InAddr struct { - SAddr InAddrT +type InAddr1 struct { + SAddr c.Uint } type AresIn6Addr struct { @@ -22,7 +19,7 @@ type AresIn6Addr struct { ===== use.go ===== package receiver -import _ "unsafe" +import "unsafe" type AresAddr struct { Family c.Int @@ -30,14 +27,14 @@ type AresAddr struct { Addr6 AresIn6Addr } } +//go:linkname AresDnsPton C.ares_dns_pton +func AresDnsPton(ipaddr *int8, addr *AresAddr) unsafe.Pointer // 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 \ No newline at end of file +in_addr1 InAddr1 \ No newline at end of file diff --git a/cmd/gogensig/convert/_testdata/receiver/hfile/temp.h b/cmd/gogensig/convert/_testdata/receiver/hfile/temp.h index d265b65..46c6245 100644 --- a/cmd/gogensig/convert/_testdata/receiver/hfile/temp.h +++ b/cmd/gogensig/convert/_testdata/receiver/hfile/temp.h @@ -1,7 +1,5 @@ -typedef unsigned int __uint32_t; -typedef __uint32_t in_addr_t; -struct in_addr { - in_addr_t s_addr; +struct in_addr1 { + unsigned int s_addr; }; struct ares_in6_addr { @@ -14,9 +12,9 @@ struct ares_addr { int family; union { - struct in_addr addr4; + struct in_addr1 addr4; struct ares_in6_addr addr6; } addr; }; -#include "use.h" +#include "use.h" \ No newline at end of file diff --git a/cmd/gogensig/convert/_testdata/receiver/hfile/use.h b/cmd/gogensig/convert/_testdata/receiver/hfile/use.h index 6fb852a..3042c95 100644 --- a/cmd/gogensig/convert/_testdata/receiver/hfile/use.h +++ b/cmd/gogensig/convert/_testdata/receiver/hfile/use.h @@ -1,2 +1,3 @@ - -char *ares_dns_addr_to_ptr(const struct ares_addr *addr); +// todo(zzy): ares_addr need generate in the temp.go +const void *ares_dns_pton(const char *ipaddr, struct ares_addr *addr); +char *ares_dns_addr_to_ptr(const struct ares_addr *addr); \ No newline at end of file diff --git a/cmd/gogensig/convert/package.go b/cmd/gogensig/convert/package.go index 67271d9..e784d84 100644 --- a/cmd/gogensig/convert/package.go +++ b/cmd/gogensig/convert/package.go @@ -297,6 +297,9 @@ func (p *Package) handleCompleteType(decl *gogen.TypeDecl, typ *ast.RecordType, // For such declarations, create a empty type decl and store it in the // incomplete map, but not in the public symbol table. func (p *Package) handleImplicitForwardDecl(name string) *gogen.TypeDecl { + if decl, ok := p.incomplete[name]; ok { + return decl + } pubName := p.nameMapper.GetGoName(name, p.trimPrefixes()) decl := p.emptyTypeDecl(pubName, nil) p.incomplete[name] = decl