Skip to content

Commit

Permalink
bind fix UnmarshalString bug in RecordLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkwork committed Jun 19, 2024
1 parent be54d98 commit 7d2810e
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 5 deletions.
Empty file added gengo/bind/demo/Stderr.log
Empty file.
264 changes: 264 additions & 0 deletions gengo/bind/demo/Stdout.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
{
"id": "0x1f6d25f9380",
"kind": "TranslationUnitDecl",
"loc": {},
"range": {
"begin": {},
"end": {}
},
"inner": [
{
"id": "0x1f6d25f9bd8",
"kind": "CXXRecordDecl",
"loc": {},
"range": {
"begin": {},
"end": {}
},
"isImplicit": true,
"name": "_GUID",
"tagUsed": "struct",
"inner": [
{
"id": "0x1f6d25f9c90",
"kind": "TypeVisibilityAttr",
"range": {
"begin": {},
"end": {}
},
"implicit": true
}
]
},
{
"id": "0x1f6d25f9d08",
"kind": "TypedefDecl",
"loc": {},
"range": {
"begin": {},
"end": {}
},
"isImplicit": true,
"name": "__int128_t",
"type": {
"qualType": "__int128"
},
"inner": [
{
"id": "0x1f6d25f9950",
"kind": "BuiltinType",
"type": {
"qualType": "__int128"
}
}
]
},
{
"id": "0x1f6d25f9d78",
"kind": "TypedefDecl",
"loc": {},
"range": {
"begin": {},
"end": {}
},
"isImplicit": true,
"name": "__uint128_t",
"type": {
"qualType": "unsigned __int128"
},
"inner": [
{
"id": "0x1f6d25f9970",
"kind": "BuiltinType",
"type": {
"qualType": "unsigned __int128"
}
}
]
},
{
"id": "0x1f6d25fa118",
"kind": "TypedefDecl",
"loc": {},
"range": {
"begin": {},
"end": {}
},
"isImplicit": true,
"name": "__NSConstantString",
"type": {
"qualType": "__NSConstantString_tag"
},
"inner": [
{
"id": "0x1f6d25f9e60",
"kind": "RecordType",
"type": {
"qualType": "__NSConstantString_tag"
},
"decl": {
"id": "0x1f6d25f9dd0",
"kind": "CXXRecordDecl",
"name": "__NSConstantString_tag"
}
}
]
},
{
"id": "0x1f6d25fa170",
"kind": "CXXRecordDecl",
"loc": {},
"range": {
"begin": {},
"end": {}
},
"isImplicit": true,
"name": "type_info",
"tagUsed": "class",
"inner": [
{
"id": "0x1f6d25fa220",
"kind": "TypeVisibilityAttr",
"range": {
"begin": {},
"end": {}
},
"implicit": true
}
]
},
{
"id": "0x1f6d25fa298",
"kind": "TypedefDecl",
"loc": {},
"range": {
"begin": {},
"end": {}
},
"isImplicit": true,
"name": "size_t",
"type": {
"qualType": "unsigned long long"
},
"inner": [
{
"id": "0x1f6d25f9570",
"kind": "BuiltinType",
"type": {
"qualType": "unsigned long long"
}
}
]
},
{
"id": "0x1f6d3fd2238",
"kind": "TypedefDecl",
"loc": {},
"range": {
"begin": {},
"end": {}
},
"isImplicit": true,
"name": "__builtin_ms_va_list",
"type": {
"qualType": "char *"
},
"inner": [
{
"id": "0x1f6d25fa2f0",
"kind": "PointerType",
"type": {
"qualType": "char *"
},
"inner": [
{
"id": "0x1f6d25f9430",
"kind": "BuiltinType",
"type": {
"qualType": "char"
}
}
]
}
]
},
{
"id": "0x1f6d3fd22a8",
"kind": "TypedefDecl",
"loc": {},
"range": {
"begin": {},
"end": {}
},
"isImplicit": true,
"name": "__builtin_va_list",
"type": {
"qualType": "char *"
},
"inner": [
{
"id": "0x1f6d25fa2f0",
"kind": "PointerType",
"type": {
"qualType": "char *"
},
"inner": [
{
"id": "0x1f6d25f9430",
"kind": "BuiltinType",
"type": {
"qualType": "char"
}
}
]
}
]
},
{
"id": "0x1f6d3fd2348",
"kind": "FunctionDecl",
"loc": {
"offset": 82,
"file": "cpp\\library.hpp",
"line": 4,
"col": 28,
"tokLen": 5
},
"range": {
"begin": {
"offset": 55,
"col": 1,
"tokLen": 10
},
"end": {
"offset": 88,
"col": 34,
"tokLen": 1
}
},
"name": "hello",
"mangledName": "?hello@@YAXXZ",
"type": {
"qualType": "void ()"
},
"inner": [
{
"id": "0x1f6d3fd23f0",
"kind": "DLLExportAttr",
"range": {
"begin": {
"offset": 66,
"col": 12,
"tokLen": 9
},
"end": {
"offset": 66,
"col": 12,
"tokLen": 9
}
}
}
]
}
]
}
Binary file modified gengo/bind/demo/demo.dll
Binary file not shown.
11 changes: 8 additions & 3 deletions gengo/bind/demo/demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ func TestHello(t *testing.T) {
}

func TestDemoDll(t *testing.T) {
pkg := gengo.NewPackage("demo")
pkg := gengo.NewPackage("demo",
gengo.WithForcedSynthetic(
"ZydisShortString_",
"struct ZydisShortString_",
))
path := "cpp\\library.hpp"
mylog.Check(pkg.Transform("demo", &clang.Options{
Sources: []string{path},
AdditionalParams: []string{},
}))
mylog.Check(pkg.WriteToDir("demo"))
}),
)
mylog.Check(pkg.WriteToDir("."))
}
4 changes: 2 additions & 2 deletions gengo/clang/layout_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (r *RecordLayout) UnmarshalString(data string) error {
before = strings.TrimSpace(before)
if before == "" {
after = strings.TrimSpace(after)
_ = mylog.Check2(fmt.Sscanf(after, "[sizeof=%d, align=%d]", &r.Size, &r.Align))

//mylog.Check2(fmt.Sscanf(after, "[sizeof=%d, align=%d]", &r.Size, &r.Align))
mylog.Check2(fmt.Sscanf(after, "[sizeof=%d, align=%d", &r.Size, &r.Align))
break
}

Expand Down
15 changes: 15 additions & 0 deletions gengo/clang/layout_parse_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package clang

import (
"fmt"
"testing"

"github.com/ddkwork/golibrary/mylog"
)

func TestRecordLayout_UnmarshalString(t *testing.T) {
after := "[sizeof=32, align=8]"
Size := 0
Align := 0
mylog.Check2(fmt.Sscanf(after, "[sizeof=%d, align=%d]", &Size, &Align))
}

0 comments on commit 7d2810e

Please sign in to comment.