aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Mercl <0xjnml@gmail.com>2017-07-14 19:20:46 +0200
committerJan Mercl <0xjnml@gmail.com>2017-07-14 19:20:46 +0200
commit4c91ab146ab47496fbde3e0381993ccd590f4427 (patch)
tree99cbcd8096a99c35d57884db9d3d7551a9255304
parent4becaacb9775939bdb8891d8c00e30d22b2ff447 (diff)
Update generator.go.
modified: generator.go modified: main.c
-rw-r--r--generator.go38
-rw-r--r--main.c7
2 files changed, 23 insertions, 22 deletions
diff --git a/generator.go b/generator.go
index 7401cee..41ae3eb 100644
--- a/generator.go
+++ b/generator.go
@@ -77,8 +77,6 @@ func ftrace(s string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "# %%s:%%d: %%v\n", path.Base(fn), fl, fmt.Sprintf(s, args...))
os.Stderr.Sync()
}
-
-func Xsqlite3PendingByte() int32 { return _sqlite3PendingByte }
`
prologueTest = `// Code generated by ccgo. DO NOT EDIT.
@@ -118,7 +116,6 @@ func main() {
#define SQLITE_WITHOUT_MSIZE 1
int sqlite3PendingByte;
-
`
)
@@ -170,7 +167,7 @@ func errStr(err error) string {
}
}
-func build(predef string, tus [][]string, qualifiers []string, opts ...cc.Opt) ([]*cc.TranslationUnit, []byte) {
+func build(predef string, tus [][]string, ccgoOpts []ccgo.Option, opts ...cc.Opt) ([]*cc.TranslationUnit, []byte) {
ndbg := ""
if *ndebug {
ndbg = "#define NDEBUG 1"
@@ -231,7 +228,7 @@ func build(predef string, tus [][]string, qualifiers []string, opts ...cc.Opt) (
}
var out buffer.Bytes
- if err := ccgo.New(build, &out, ccgo.Packages(qualifiers)); err != nil {
+ if err := ccgo.New(build, &out, ccgoOpts...); err != nil {
log.Fatal(err)
}
@@ -265,7 +262,7 @@ func macros(buf io.Writer, ast *cc.TranslationUnit) {
switch t := m.Type; t.Kind() {
case
cc.Int, cc.UInt, cc.Long, cc.ULong, cc.LongLong, cc.ULongLong,
- cc.Float, cc.LongDouble, cc.Bool:
+ cc.Float, cc.Double, cc.LongDouble, cc.Bool:
fmt.Fprintf(buf, "X%s = %v\n", v, m.Value)
case cc.Ptr:
switch t := t.Element(); t.Kind() {
@@ -406,14 +403,24 @@ func sqlite() {
}
pth := filepath.Join(repo, "sqlite-amalgamation-"+version)
- sqlite3 := filepath.Join(pth, "sqlite3.c")
- asta, src := build(
+ ast, _ := build(
defines,
[][]string{
+ {filepath.Join(pth, "sqlite3.h")},
{"main.c"},
+ },
+ []ccgo.Option{ccgo.Library()},
+ cc.EnableAnonymousStructFields(),
+ cc.IncludePaths([]string{pth}),
+ )
+ sqlite3 := filepath.Join(pth, "sqlite3.c")
+ _, src := build(
+ defines,
+ [][]string{
{sqlite3},
+ {"main.c"},
},
- nil,
+ []ccgo.Option{ccgo.Library()},
cc.EnableAnonymousStructFields(),
cc.IncludePaths([]string{pth}),
)
@@ -425,7 +432,7 @@ func sqlite() {
}
fmt.Fprintf(&b, prologueSqlite, lic, strings.TrimSpace(tidyComments(header(sqlite3))))
- macros(&b, asta[0])
+ macros(&b, ast[0])
b.Write(src)
b2, err := format.Source(b.Bytes())
if err != nil {
@@ -436,6 +443,7 @@ func sqlite() {
}
dst := fmt.Sprintf(filepath.Join("internal", "bin", "bin_%s_%s.go"), runtime.GOOS, runtime.GOARCH)
+ b2 = bytes.Replace(b2, []byte("var Xsqlite3PendingByte int32"), []byte("func Xsqlite3PendingByte() int32 { return _sqlite3PendingByte }"), 1)
if err := ioutil.WriteFile(dst, b2, 0664); err != nil {
log.Fatal(err)
}
@@ -460,7 +468,7 @@ func mpTest() {
{filepath.Join(sqlitePth, "sqlite3.c")},
{test},
},
- []string{"bin"},
+ []ccgo.Option{ccgo.Packages([]string{"bin"})},
cc.EnableAnonymousStructFields(),
cc.IncludePaths([]string{sqlitePth}),
)
@@ -506,7 +514,7 @@ func threadTest1() {
{filepath.Join(sqlitePth, "sqlite3.c")},
{test},
},
- []string{"bin"},
+ []ccgo.Option{ccgo.Packages([]string{"bin"})},
cc.EnableAnonymousStructFields(),
cc.IncludePaths([]string{".", sqlitePth, filepath.Join(repo, "sqlite-src-"+version, "src")}),
)
@@ -551,7 +559,7 @@ func threadTest2() {
{filepath.Join(sqlitePth, "sqlite3.c")},
{test},
},
- []string{"bin"},
+ []ccgo.Option{ccgo.Packages([]string{"bin"})},
cc.EnableAnonymousStructFields(),
cc.IncludePaths([]string{".", sqlitePth, filepath.Join(repo, "sqlite-src-"+version, "src")}),
)
@@ -598,7 +606,7 @@ func threadTest3() {
{filepath.Join(repo, "sqlite-src-"+version, "src", "test_multiplex.c")},
{test},
},
- []string{"bin"},
+ []ccgo.Option{ccgo.Packages([]string{"bin"})},
cc.EnableAnonymousStructFields(),
cc.IncludePaths([]string{".", sqlitePth, filepath.Join(repo, "sqlite-src-"+version, "src")}),
)
@@ -643,7 +651,7 @@ func threadTest4() {
{filepath.Join(sqlitePth, "sqlite3.c")},
{test},
},
- []string{"bin"},
+ []ccgo.Option{ccgo.Packages([]string{"bin"})},
cc.EnableAnonymousStructFields(),
cc.IncludePaths([]string{".", sqlitePth, filepath.Join(repo, "sqlite-src-"+version, "src")}),
)
diff --git a/main.c b/main.c
index f6f354f..369e126 100644
--- a/main.c
+++ b/main.c
@@ -4,13 +4,6 @@
// +build ignore
-#include <sqlite3.h>
-
-static void use(int, ...)
-{
-}
-
int main(int argc, char **argv)
{
- use(0, sqlite3_exec, sqlite3_enable_load_extension);
}