summaryrefslogtreecommitdiff
path: root/experiments/windowsconstgen.go
diff options
context:
space:
mode:
Diffstat (limited to 'experiments/windowsconstgen.go')
-rw-r--r--experiments/windowsconstgen.go38
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")