diff options
| author | Pietro Gagliardi <[email protected]> | 2014-05-25 14:04:03 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-05-25 14:04:03 -0400 |
| commit | 1f94a68432dce90a1780ca2be44f12dc5514c622 (patch) | |
| tree | d32a48c0a00d73982912159ed4882a6595027a54 /experiments | |
| parent | d2746b7d2ca606f2212a9bd31e793d0778dad64d (diff) | |
Fixed issues handling INVALID_HANDLE_VALUE in the Windows constant generator, and built the first build with generated constants!
Diffstat (limited to 'experiments')
| -rw-r--r-- | experiments/windowsconstgen.go | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/experiments/windowsconstgen.go b/experiments/windowsconstgen.go index d9fd3bb..4671111 100644 --- a/experiments/windowsconstgen.go +++ b/experiments/windowsconstgen.go @@ -72,6 +72,31 @@ func gatherNames(pkg *ast.Package) { } } +// some constants confuse cgo into thinking they're external symbols for some reason +// TODO debug cgo +var hacknames = map[string]string{ + "_INVALID_HANDLE_VALUE": "x_INVALID_HANDLE_VALUE", +} + +func hacknamesPreamble() string { + if len(hacknames) == 0 { + return "" + } + // keep sorted for git + hn := make([]string, 0, len(hacknames)) + for origname, _ := range hacknames { + hn = append(hn, origname) + } + sort.Strings(hn) + s := "// /* because cgo has issues with these */\n" + s += "// #include <stdint.h>\n" + for _, origname := range hn { + s += "// uintptr_t " + hacknames[origname] + " = (uintptr_t) (" + + origname[1:] + ");\n" // strip leading _ + } + return s +} + func preamble(pkg string) string { return "// autogenerated by windowsconstgen; do not edit\n" + "package " + pkg + "\n" @@ -104,6 +129,10 @@ func main() { // keep sorted for git consts := make([]string, 0, len(unknown)) for ident, _ := range unknown { + if hackname, ok := hacknames[ident]; ok { + consts = append(consts, hackname) + continue + } consts = append(consts, ident) } sort.Strings(consts) @@ -122,11 +151,18 @@ func main() { "import \"fmt\"\n" + "// #include <windows.h>\n" + "// #include <commctrl.h>\n" + + "%s" + "import \"C\"\n" + "func main() {\n" + " fmt.Println(%q)\n", - preamble("main"), preamble("ui")) + preamble("main"), hacknamesPreamble(), preamble("ui")) for _, ident := range consts { + if ident[0] == 'x' { + // hack name; strip the leading x (but not the _ after it) from the constant name but keep the value name unchanged + fmt.Fprintf(f, " fmt.Println(\"const %s =\", C.%s)\n", ident[1:], ident) + continue + } + // not a hack name; strip the leading _ from the value name but keep the constant name unchanged fmt.Fprintf(f, " fmt.Println(\"const %s =\", C.%s)\n", ident, ident[1:]) } fmt.Fprintf(f, "}\n") |
