From 8b0f82455ec0828cf4cb2449b95ed3f1146930cb Mon Sep 17 00:00:00 2001 From: Stefan Salewski Date: Wed, 13 Sep 2017 23:33:57 +0200 Subject: [PATCH] some bug fixes --- tests/gen.nim | 173 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 162 insertions(+), 11 deletions(-) diff --git a/tests/gen.nim b/tests/gen.nim index 9afbc24..c85f553 100644 --- a/tests/gen.nim +++ b/tests/gen.nim @@ -1,5 +1,5 @@ # High level gobject-introspection based GTK3 bindings for the Nim programming language -# v 0.2 2017-SEP-08 +# v 0.2 2017-SEP-13 # (c) S. Salewski 2017 # https://wiki.gnome.org/Projects/GObjectIntrospection @@ -200,6 +200,7 @@ gtk.TextIter pango.Weight gdk.Rectangle gtk.AccelKey +gtksource.RegionIter gtk.TextAttributes gobject.Value gobject.SignalQuery @@ -289,7 +290,6 @@ proc genRec(t: GITypeInfo; genProxy = false; fullQualified: bool = false): strin result = mangleType(result) if p and (not proxyResult):# or callerAlloc.contains(result)): result = "ptr " & result - var xxx = result result = mangleType(result) & rawmark proc isProxyCandidate(t: GITypeInfo): bool = @@ -368,6 +368,10 @@ proc genP(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil): (str if gArgInfoIsCallerAllocates(arg): callerAllocCollector.incl(genRec(t, true, true)) var str = genRec(t, genProxy and not gArgInfoIsCallerAllocates(arg)) + + if (sym.startsWith("gtk_widget_set_events") or sym.startsWith("gtk_widget_add_events")) and str == "int32": + str = "gdk.EventMask" + if isSignalInfo(info) and isProxyCandidate(t) and not genProxy: str.insert("ptr ") var userAlloc: bool @@ -567,6 +571,35 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) = methodBuffer.writeLine(" g_object_unref(result.impl)") methodBuffer.writeLine(" assert(g_object_get_qdata(result.impl, Quark) == nil)") methodBuffer.writeLine(" g_object_set_qdata(result.impl, Quark, addr(result[]))") + elif gCallableInfoGetCallerOwns(minfo) == GITransfer.EVERYTHING: + if sym == "g_closure_new_simple": + let nMethods = gStructInfoGetNMethods(info) + for j in 0 .. 0: swap(mseq[0], mseq[freePos]) + for mInfo in mseq: writeMethod(info, minfo) proc writeStruct(info: GIStructInfo) = if not suppressType: output.writeLine("type") if callerAlloc.contains(($gBaseInfoGetNamespace(info)).toLowerAscii & '.' & mangleName(gBaseInfoGetName(info))): - output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & EM & " {.pure, byCopy.} = object") + output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & EM & " {.pure, byRef.} = object") else: output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & "00" & EM & " {.pure.} = object") let n = info.gStructInfoGetNFields() @@ -702,22 +778,93 @@ proc writeStruct(info: GIStructInfo) = output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & EM & " = ref object") output.writeLine(" impl*: ptr " & mangleName(gBaseInfoGetName(info)) & "00") let nMethods = gStructInfoGetNMethods(info) + var mseq = newSeq[GIFunctionInfo]() + var freePos = -1 for j in 0 .. 0: swap(mseq[0], mseq[freePos]) + for mInfo in mseq: writeMethod(info, minfo) proc writeInterface(info: GIInterfaceInfo) = if not suppressType: output.writeLine("type") - output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & "00" & EM & " {.pure.} = object") - output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & EM & " = ref object") - output.writeLine(" impl*: ptr " & mangleName(gBaseInfoGetName(info)) & "00") + # we made interfaces a gobject now... + output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & "00" & EM & " = object of gobject.Object00") + output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & EM & " = ref object of gobject.Object") + #output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & "00" & EM & " {.pure.} = object") + #output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & EM & " = ref object") + #output.writeLine(" impl*: ptr " & mangleName(gBaseInfoGetName(info)) & "00") let nMethods = gInterfaceInfoGetNMethods(info) for j in 0 .. int: + result = cmp(x.v, y.v) + if result == 0: + result = cmp(x.n, y.n) + for j in 0 .. s.high: + if s[j].v < 0: flags = false + if j == 0 and s[j].v == 0: continue + #if bitops.popCount(s[j].v) != 1: flags = false + if s.len <= 1: flags = false + var tname = mangleName(gBaseInfoGetName(info)) + if flags: tname = tname[0 .. ^5] + if flags: + #output.writeLine(" ", tname & "Flag" & EM, " {.size: sizeof(cint), pure.} = enum") + output.writeLine(" ", tname & "Flag" & EM, " {.size: sizeof(cint), pure.} = enum") + if s[0].v != 1 and s[1].v != 1: + output.writeLine(" ignoreThisDummyValue = 0") + else: + output.writeLine(" ", tname & EM, " {.size: sizeof(cint), pure.} = enum") + var k: T + for j in 0 .. s.high: + let i = s[j] + var val = i.v + if flags and j == 0 and val == 0: continue + if j > 0 and i.v == k.v: + if i.n != k.n: + alias.add(" " & tname & i.n.capitalizeAscii & EM & " = " & tname & '.' & k.n) + continue + if flags: val = countTrailingZeroBits(val) # firstSetBit(val) + output.writeLine(" ", i.n, " = ", val) + k = i + if alias.len > 0: + output.writeLine("\nconst") + for i in alias: + output.writeLine(i) + if flags: + output.writeLine("\n ", tname & "Mask" & EM, " {.size: sizeof(cint).} = set[$1Flag]" % [tname]) + let nMethods = gEnumInfoGetNMethods(info) + ###assert(nMethods <= 0) + assert(flags) + for j in 0 ..