Skip to content

Commit

Permalink
gogensig:block implict incomplete recreate goplus#67
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed Dec 25, 2024
1 parent a0e793a commit fd8a0a3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
5 changes: 5 additions & 0 deletions cmd/gogensig/convert/_testdata/receiver/conf/llcppg.symb.json
Original file line number Diff line number Diff line change
@@ -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 *)",
Expand Down
15 changes: 6 additions & 9 deletions cmd/gogensig/convert/_testdata/receiver/gogensig.expect
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,22 +19,22 @@ type AresIn6Addr struct {
===== use.go =====
package receiver

import _ "unsafe"
import "unsafe"

type AresAddr struct {
Family c.Int
Addr 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
in_addr1 InAddr1
10 changes: 4 additions & 6 deletions cmd/gogensig/convert/_testdata/receiver/hfile/temp.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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"
5 changes: 3 additions & 2 deletions cmd/gogensig/convert/_testdata/receiver/hfile/use.h
Original file line number Diff line number Diff line change
@@ -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);
3 changes: 3 additions & 0 deletions cmd/gogensig/convert/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd8a0a3

Please sign in to comment.