This commit is contained in:
Stefan Salewski 2021-03-05 17:15:45 +01:00
commit 8f737dcee3
3 changed files with 559 additions and 414 deletions

View file

@ -1,6 +1,6 @@
= High level GTK4 and GTK3 bindings for the Nim programming language = High level GTK4 and GTK3 bindings for the Nim programming language
//(c) Stefan Salewski //(c) Stefan Salewski
//Version 0.8.7 //Version 0.8.8
:experimental: :experimental:
:imagesdir: http://ssalewski.de/tmp :imagesdir: http://ssalewski.de/tmp
//:source-highlighter: pygments //:source-highlighter: pygments
@ -29,13 +29,17 @@ with code inserted from files directly.
NOTE: This work is partly based on earlier works of J. Mansour and has been supported by A. Rumpf, E. Bassi and other _Nim_ and _GTK/Gnome_ developers. NOTE: This work is partly based on earlier works of J. Mansour and has been supported by A. Rumpf, E. Bassi and other _Nim_ and _GTK/Gnome_ developers.
The `combinatorics` module was kindly provided by R. Behrends. The `combinatorics` module was kindly provided by R. Behrends.
NOTE: This is version 0.8.7 of the gintro Nim GTK bindings. NOTE: This is version 0.8.8 of the gintro Nim GTK bindings.
We did a larger internal cleanup for the gen.nim generator script but tried to For procs like getStartIter() without a result but with a var out
parameter an overloaded version is created where the var out
parameter is returned as result. So we can write "let startIter = buffer.getStartIter()" now.
And we tried to fix the issues with out gobject parameters as in g_file_new_tmp().
NOTE: For version 0.8.7 of the gintro Nim GTK bindings
we did a larger internal cleanup for the gen.nim generator script but tried to
generate output modules identical to v.0.8.6 still. For next release v0.8.8 generate output modules identical to v.0.8.6 still. For next release v0.8.8
there will be some changes in the generated modules then. there will be some changes in the generated modules then.
Also for this version 0.8.7 we do support webkit2 for GTK4, and we have Also for this version 0.8.7 we do support webkit2 for GTK4.
fixed the newGFileTmp() issue, see https://github.com/StefanSalewski/gintro/issues/112.
NOTE: Version 0.8.6 of the gintro Nim GTK bindings NOTE: Version 0.8.6 of the gintro Nim GTK bindings
contains now all the standard gst modules, and due to a recent contains now all the standard gst modules, and due to a recent

View file

@ -1,6 +1,6 @@
# Package # Package
version = "0.8.7" version = "0.8.8"
author = "Stefan Salewski" author = "Stefan Salewski"
description = "High level GObject-Introspection based GTK3/GTK4 bindings" description = "High level GObject-Introspection based GTK3/GTK4 bindings"
license = "MIT" license = "MIT"

View file

@ -1,6 +1,6 @@
# High level gobject-introspection based GTK3/GTK4 bindings for the Nim programming language # High level gobject-introspection based GTK3/GTK4 bindings for the Nim programming language
# nimpretty --maxLineLen:130 gen.nim # nimpretty --maxLineLen:130 gen.nim
# v 0.8.7 2021-FEB-16 # v 0.8.8 2021-MAR-05
# (c) S. Salewski 2018 # (c) S. Salewski 2018
# usefull for finding death code: # usefull for finding death code:
@ -737,8 +737,12 @@ type
blex: string blex: string
tempRes: string tempRes: string
tempResFree: string tempResFree: string
tmpoutgobjectarg: string
outgobjectargname: string
outgobjectargisoptional: bool
outgobjectargmaybenull: bool
proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; genArrayMark = false): GPars proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; genArrayMark = false; tryOut2Ret: bool = false): GPars
# recursive investigate that type -- resolve Arrays and Interfaces # recursive investigate that type -- resolve Arrays and Interfaces
proc newGenRec(t: GITypeInfo; genProxy = false): RecRes = proc newGenRec(t: GITypeInfo; genProxy = false): RecRes =
@ -973,7 +977,7 @@ proc fixedName2(s: string): string =
else: else:
return s return s
proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; genArrayMark = false): GPars = proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; genArrayMark = false; tryOut2Ret: bool = false): GPars =
proc makePList(s: seq[(string, string)]; self, r: string): string = proc makePList(s: seq[(string, string)]; self, r: string): string =
result = self result = self
@ -1021,6 +1025,25 @@ proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; ge
var num = "" var num = ""
for j in 0 .. m: for j in 0 .. m:
let arg = gCallableInfoGetArg(info, j) let arg = gCallableInfoGetArg(info, j)
var argName = mangleName(gBaseInfoGetName(arg))
var isGObject = false
let tt = gArgInfoGetType(arg)
let tag = gTypeInfoGetTag(tt)
if tag == GITypeTag.INTERFACE:
let iface = gTypeInfoGetInterface(tt)
if gBaseInfoGetType(iface) == GIInfoType.Object and gObjectInfoGetFundamental(iface) == GFalse:
if gArgInfoGetDirection(arg) == GIDirection.OUT:
isGObject = true
var out2Ret = false
if tryOut2Ret:
let match = if gCallableInfoIsMethod(info): 1 else: 0
out2ret = (gCallableInfoGetNArgs(info) + match) == 2 and (j + match) == 1 and gTypeInfoGetTag(gCallableInfoGetReturnType(info)) == GITypeTag.VOID and gArgInfoGetDirection(arg) == GIDirection.OUT
if out2ret:# and genProxy:
argName = "result"
let t = gArgInfoGetType(arg) let t = gArgInfoGetType(arg)
let mayBeNil = gArgInfoMayBeNull(arg) let mayBeNil = gArgInfoMayBeNull(arg)
var ngr = newGenRec(t, true) var ngr = newGenRec(t, true)
@ -1030,7 +1053,7 @@ proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; ge
else: else:
str = ngr.name00 str = ngr.name00
if genProxy and ngr.res == glist: if genProxy and ngr.res == glist:
result.tempRes = " var tempResGL = seq2GList($1)\n" % [mangleName(gBaseInfoGetName(arg))] result.tempRes = " var tempResGL = seq2GList($1)\n" % [argname]
if gArgInfoGetOwnershipTransfer(arg) == GITransfer.NOTHING: if gArgInfoGetOwnershipTransfer(arg) == GITransfer.NOTHING:
result.tempResFree = " g_list_free(tempResGL)\n" result.tempResFree = " g_list_free(tempResGL)\n"
if str.startsWith("var "): if str.startsWith("var "):
@ -1039,7 +1062,7 @@ proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; ge
str = "seq[$1]" % [ngr.childname] str = "seq[$1]" % [ngr.childname]
if genProxy and ngr.res == gslist: if genProxy and ngr.res == gslist:
result.tempRes = " var tempResGL = seq2GSList($1)\n" % [mangleName(gBaseInfoGetName(arg))] result.tempRes = " var tempResGL = seq2GSList($1)\n" % [argName]
if gArgInfoGetOwnershipTransfer(arg) == GITransfer.NOTHING: if gArgInfoGetOwnershipTransfer(arg) == GITransfer.NOTHING:
result.tempResFree = " g_slist_free(tempResGL)\n" result.tempResFree = " g_slist_free(tempResGL)\n"
if str.startsWith("var "): if str.startsWith("var "):
@ -1053,7 +1076,7 @@ proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; ge
resusLen = gTypeInfoGetArrayLength(t) resusLen = gTypeInfoGetArrayLength(t)
if resusLen >= 0: if resusLen >= 0:
resusIn = gArgInfoGetDirection(gCallableInfoGetArg(info, resusLen.cint)) == GIDirection.IN resusIn = gArgInfoGetDirection(gCallableInfoGetArg(info, resusLen.cint)) == GIDirection.IN
lastName = gBaseInfoGetName(arg) lastName = argName
if (sym.startsWith("gtk_widget_set_events", "gtk_widget_add_events")) and str == "int32": if (sym.startsWith("gtk_widget_set_events", "gtk_widget_add_events")) and str == "int32":
str = fixedModName("gdk") & ".EventMask" str = fixedModName("gdk") & ".EventMask"
if isSignalInfo(info) and isProxyCandidate(t) and not genProxy: if isSignalInfo(info) and isProxyCandidate(t) and not genProxy:
@ -1082,12 +1105,23 @@ proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; ge
discard #echo str, " xxxxxxxxxxxxxxxxx" discard #echo str, " xxxxxxxxxxxxxxxxx"
#str = "cstringArray" #str = "cstringArray"
let name = mangleName(gBaseInfoGetName(arg)) var name = argName#mangleName(gBaseInfoGetName(arg))
if isProxyCandidate(t) and not gArgInfoIsCallerAllocates(arg) and not userAlloc: if isProxyCandidate(t) and not gArgInfoIsCallerAllocates(arg) and not userAlloc:
if mayBeNil and gArgInfoGetDirection(arg) != GIDirection.OUT: if mayBeNil and gArgInfoGetDirection(arg) != GIDirection.OUT:
result.arglist.add("if " & name & ".isNil: nil else: cast[" & ngr.name00 & "](" & name & ".impl)") result.arglist.add("if " & name & ".isNil: nil else: cast[" & ngr.name00 & "](" & name & ".impl)")
else: else:
if gArgInfoGetDirection(arg) == GIDirection.OUT or gArgInfoGetDirection(arg) == GIDirection.INOUT: if isGobject:
if gArgInfoIsOptional(arg):
result.arglist.add("cast[var " & ngr.name00 & "](if addr(" & name & ") == nil: nil else: tmpoutgobjectarg)")
else:
result.arglist.add("tmpoutgobjectarg")
result.tmpoutgobjectarg = " var tmpoutgobjectarg: " & ngr.name00 & "\n"
result.outgobjectargname = argName
result.outgobjectargisoptional = gArgInfoIsOptional(arg)
result.outgobjectargmaybenull = gArgInfoMayBeNull(arg)
elif gArgInfoGetDirection(arg) == GIDirection.OUT or gArgInfoGetDirection(arg) == GIDirection.INOUT:
if gArgInfoIsOptional(arg): # INOUT i.e. for gst_gl_ensure_element_data if gArgInfoIsOptional(arg): # INOUT i.e. for gst_gl_ensure_element_data
result.arglist.add("cast[var " & ngr.name00 & "](if addr(" & name & ") == nil: nil else: addr " & name & ".impl)") result.arglist.add("cast[var " & ngr.name00 & "](if addr(" & name & ") == nil: nil else: addr " & name & ".impl)")
else: else:
@ -1126,6 +1160,10 @@ proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; ge
if gArgInfoGetDirection(arg) in {GIDirection.OUT, INOUT} and not (ngr.flags.contains(RecResFlag.unamedA) and if gArgInfoGetDirection(arg) in {GIDirection.OUT, INOUT} and not (ngr.flags.contains(RecResFlag.unamedA) and
gArgInfoIsCallerAllocates(arg)): gArgInfoIsCallerAllocates(arg)):
needVar = true needVar = true
if sym in ["nice_agent_recv", "nice_agent_recv_nonblocking"] and name == "bufLen": # https://discourse.gnome.org/t/nice-agent-recv/5747/2
needVar = false
if genProxy and needTypeConv(str, ngr): if genProxy and needTypeConv(str, ngr):
if gArgInfoGetDirection(arg) in {GIDirection.OUT, INOUT} and (not gArgInfoIsCallerAllocates(arg) or (str in ["int32", if gArgInfoGetDirection(arg) in {GIDirection.OUT, INOUT} and (not gArgInfoIsCallerAllocates(arg) or (str in ["int32",
"uint32", "ptr cstring", "cstring"])): "uint32", "ptr cstring", "cstring"])):
@ -1191,7 +1229,15 @@ proc genPars(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil; ge
if genArrayMark and ngr.flags.contains(RecResFlag.array) and str.startsWith("ptr "): if genArrayMark and ngr.flags.contains(RecResFlag.array) and str.startsWith("ptr "):
str.removePrefix("ptr ") str.removePrefix("ptr ")
str.add("Array") str.add("Array")
if not out2Ret:#(out2ret and genProxy):
resus.add((name, str)) resus.add((name, str))
else:
var h = str
let i = h.find('=')
if i > 0:
h.setLen(i) # well i - 1 , try find(" =")
h.removePrefix("var ")
resusres = ": " & h#str.dup(removePrefix("var "))
if j < m: if j < m:
result.arglist.add(", ") result.arglist.add(", ")
if not genProxy and gCallableInfoCanThrowGerror(info): if not genProxy and gCallableInfoCanThrowGerror(info):
@ -1274,6 +1320,51 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
methodBuffer.writeLine(" g_error_free(gerror[])") methodBuffer.writeLine(" g_error_free(gerror[])")
methodBuffer.writeLine(" raise newException(GException, msg)") methodBuffer.writeLine(" raise newException(GException, msg)")
# new for v0.8.8
template dothegobjectargmagic(): untyped =
if pars.outgobjectargisoptional:
methodBuffer.writeLine("""
if addr($1) != nil:
$1 = nil
""" % [pars.outgobjectargname])
elif pars.outgobjectargmaybenull:
methodBuffer.writeLine(" $1 = nil" % [pars.outgobjectargname])
if pars.outgobjectargisoptional or pars.outgobjectargmaybenull:
methodBuffer.writeLine("""
if tmpoutgobjectarg != nil:
let argqdata = g_object_get_qdata(tmpoutgobjectarg, Quark)
if argqdata != nil:
$1 = cast[type($1)](argqdata)
assert($1.impl == tmpoutgobjectarg)
else:
fnew($1, $2.finalizeGObject)
$1.impl = tmpoutgobjectarg
GC_ref($1)
if g_object_is_floating($1.impl).int != 0:
discard g_object_ref_sink($1.impl)
g_object_add_toggle_ref($1.impl, toggleNotify, addr($1[]))
g_object_unref($1.impl)
assert(g_object_get_qdata($1.impl, Quark) == nil)
g_object_set_qdata($1.impl, Quark, addr($1[]))
""" % [pars.outgobjectargname, moduleNamespace])
else:
methodBuffer.writeLine("""
let argqdata = g_object_get_qdata(tmpoutgobjectarg, Quark)
if argqdata != nil:
$1 = cast[type($1)](argqdata)
assert($1.impl == tmpoutgobjectarg)
else:
fnew($1, $2.finalizeGObject)
$1.impl = tmpoutgobjectarg
GC_ref($1)
if g_object_is_floating($1.impl).int != 0:
discard g_object_ref_sink($1.impl)
g_object_add_toggle_ref($1.impl, toggleNotify, addr($1[]))
g_object_unref($1.impl)
assert(g_object_get_qdata($1.impl, Quark) == nil)
g_object_set_qdata($1.impl, Quark, addr($1[]))
""" % [pars.outgobjectargname, moduleNamespace])
# new for v0.7.8: we ref all gobjects now, even if transfer is none. So result.ignoreFinalizer = false always for gobjects! # new for v0.7.8: we ref all gobjects now, even if transfer is none. So result.ignoreFinalizer = false always for gobjects!
template gobjectTemp(): untyped = template gobjectTemp(): untyped =
assert sym notin ["g_object_ref_sink", "g_object_ref"] assert sym notin ["g_object_ref_sink", "g_object_ref"]
@ -1363,7 +1454,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
freeMeName = "generic_" & $g_object_info_get_unref_function(parent) freeMeName = "generic_" & $g_object_info_get_unref_function(parent)
assert(freeMeName != "") assert(freeMeName != "")
template block8(prochead: string; errorcheckadd: bool): untyped = template block8(prochead: string; errorcheckadd: bool; tryOut2Ret: bool): untyped =
if isProxyCandidateret2: if isProxyCandidateret2:
assert (gCallableInfoGetCallerOwns(minfo) in {GITransfer.NOTHING, GITransfer.EVERYTHING}) # both occur assert (gCallableInfoGetCallerOwns(minfo) in {GITransfer.NOTHING, GITransfer.EVERYTHING}) # both occur
if asym == "newFromStreamAsync" and sym.startsWith("gdk_pixbuf_animation_new"): if asym == "newFromStreamAsync" and sym.startsWith("gdk_pixbuf_animation_new"):
@ -1384,6 +1475,16 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
let arg = gCallableInfoGetArg(minfo, j) let arg = gCallableInfoGetArg(minfo, j)
let t = gArgInfoGetType(arg) let t = gArgInfoGetType(arg)
var ngrt = newGenRec(t) var ngrt = newGenRec(t)
var isGObject = false
let tt = gArgInfoGetType(arg)
let tag = gTypeInfoGetTag(tt)
if tag == GITypeTag.INTERFACE:
let iface = gTypeInfoGetInterface(tt)
if gBaseInfoGetType(iface) == GIInfoType.Object and gObjectInfoGetFundamental(iface) == GFalse:
if gArgInfoGetDirection(arg) == GIDirection.OUT:
isGObject = true
if ((gFunctionInfoGetFlags(mInfo).int and GIFunctionInfoFlags.IS_CONSTRUCTOR.int) == 0): if ((gFunctionInfoGetFlags(mInfo).int and GIFunctionInfoFlags.IS_CONSTRUCTOR.int) == 0):
if gArgInfoGetDirection(arg) == GIDirection.IN and gArgInfoGetOwnershipTransfer(arg) == GITransfer.EVERYTHING and if gArgInfoGetDirection(arg) == GIDirection.IN and gArgInfoGetOwnershipTransfer(arg) == GITransfer.EVERYTHING and
isProxyCandidate(t) and not callerAlloc.contains(ngrt.namePlainNS): isProxyCandidate(t) and not callerAlloc.contains(ngrt.namePlainNS):
@ -1394,7 +1495,11 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
methodBuffer.writeLine(" " & n & ".ignoreFinalizer = true") methodBuffer.writeLine(" " & n & ".ignoreFinalizer = true")
else: else:
methodBuffer.writeLine(" " & n & ".ignoreFinalizer = true") methodBuffer.writeLine(" " & n & ".ignoreFinalizer = true")
if gArgInfoGetDirection(arg) == GIDirection.OUT and isProxyCandidate(t) and
if isGobject:
discard
elif gArgInfoGetDirection(arg) == GIDirection.OUT and isProxyCandidate(t) and
not callerAlloc.contains(ngrt.namePlainNS) and not gArgInfoIsCallerAllocates(arg): not callerAlloc.contains(ngrt.namePlainNS) and not gArgInfoIsCallerAllocates(arg):
let tag = gTypeInfoGetTag(t) let tag = gTypeInfoGetTag(t)
assert(tag == GITypeTag.INTERFACE) assert(tag == GITypeTag.INTERFACE)
@ -1409,7 +1514,14 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
let info = iface let info = iface
var freeMe{.inject.}: GIFunctionInfo var freeMe{.inject.}: GIFunctionInfo
findFreeProc(info, gArgInfoGetOwnershipTransfer(arg) == GITransfer.NOTHING) findFreeProc(info, gArgInfoGetOwnershipTransfer(arg) == GITransfer.NOTHING)
let h2 = mangleName(gBaseInfoGetName(arg)) var h2 = mangleName(gBaseInfoGetName(arg))
if tryOut2Ret:
let match = if gCallableInfoIsMethod(minfo): 1 else: 0
let out2ret = (gCallableInfoGetNArgs(minfo) + match) == 2 and (j + match) == 1 and gTypeInfoGetTag(gCallableInfoGetReturnType(minfo)) == GITypeTag.VOID and gArgInfoGetDirection(arg) == GIDirection.OUT
if out2ret:# and genProxy:
h2 = "result"
if gArgInfoIsOptional(arg): if gArgInfoIsOptional(arg):
methodBuffer.writeLine(" if addr($2) != nil:" % [ngrt.namePlain, h2]) methodBuffer.writeLine(" if addr($2) != nil:" % [ngrt.namePlain, h2])
if boxedFreeMeName != "": if boxedFreeMeName != "":
@ -1457,6 +1569,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
# assert(info != nil) # why can it be nil? # assert(info != nil) # why can it be nil?
# if Lib.len == 0: # xlib, fontconfig, freetype2 # but Lib is local to main(), so let it crash # if Lib.len == 0: # xlib, fontconfig, freetype2 # but Lib is local to main(), so let it crash
# return # return
assert(isCallableInfo(mInfo)) assert(isCallableInfo(mInfo))
assert(isFunctionInfo(mInfo)) assert(isFunctionInfo(mInfo))
@ -1537,7 +1650,18 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
if sym == "g_hash_table_destroy": return if sym == "g_hash_table_destroy": return
try: try:
pars = genPars(mInfo, false, info)
for tryOut2Ret in [false, true]:
if tryOut2Ret:
var ret2 = gCallableInfoGetReturnType(minfo)
let match = if gCallableInfoIsMethod(minfo): 1 else: 0
let arg = gCallableInfoGetArg(minfo, (1 - match).cint)
let out2ret = (gCallableInfoGetNArgs(minfo) + match) == 2 and gTypeInfoGetTag(ret2) == GITypeTag.VOID and gArgInfoGetDirection(arg) == GIDirection.OUT
if not out2Ret:
break
pars = genPars(mInfo, false, info)#, tryOut2Ret = tryOut2Ret)
processedFunctions.incl(sym) processedFunctions.incl(sym)
if not sym.startsWith("g_param_spec_uref"): if not sym.startsWith("g_param_spec_uref"):
if sym.startsWith("g_param_spec_", "g_type_interface_", "g_object_interface_"): return if sym.startsWith("g_param_spec_", "g_type_interface_", "g_object_interface_"): return
@ -1602,7 +1726,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
let b7 = needProxyProc(mInfo) or isString(ret2) or pars.replist.len > 0 or needTypeConv(ngrRet.name00, ngrRet) or let b7 = needProxyProc(mInfo) or isString(ret2) or pars.replist.len > 0 or needTypeConv(ngrRet.name00, ngrRet) or
gTypeInfoGetTag(ret2) == GITypeTag.GLIST gTypeInfoGetTag(ret2) == GITypeTag.GLIST
# export only low level symbols that are needed internally -- maybe we should export only a private name for them # export only low level symbols that are needed internally -- maybe we should export only a private name for them
if run == 0: if run == 0 and not tryOut2Ret:
if sym in ["g_quark_from_static_string", "g_error_free", "g_object_get_qdata", "g_object_ref_sink", "g_object_unref", if sym in ["g_quark_from_static_string", "g_error_free", "g_object_get_qdata", "g_object_ref_sink", "g_object_unref",
"g_timeout_add_full", "g_object_is_floating", "gst_bus_add_watch_full", "g_timeout_add_full", "g_object_is_floating", "gst_bus_add_watch_full",
"g_type_from_name", "g_type_check_instance_is_a", "g_idle_add_full", "g_quark_try_string", "vte_regex_unref", "g_type_from_name", "g_type_check_instance_is_a", "g_idle_add_full", "g_quark_try_string", "vte_regex_unref",
@ -1618,6 +1742,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
methodBuffer.writeLine(" {.\n importc, ", libprag, ".}") methodBuffer.writeLine(" {.\n importc, ", libprag, ".}")
if sym in ["g_object_ref_sink", "g_object_ref"]: if sym in ["g_object_ref_sink", "g_object_ref"]:
return return
if b7: if b7:
var isGObject = false var isGObject = false
let tag = gTypeInfoGetTag(ret2) let tag = gTypeInfoGetTag(ret2)
@ -1625,8 +1750,12 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
let iface = gTypeInfoGetInterface(ret2) let iface = gTypeInfoGetInterface(ret2)
if gBaseInfoGetType(iface) == GIInfoType.Object and gObjectInfoGetFundamental(iface) == GFalse: if gBaseInfoGetType(iface) == GIInfoType.Object and gObjectInfoGetFundamental(iface) == GFalse:
isGObject = true isGObject = true
pars = genPars(mInfo, true, info) pars = genPars(mInfo, true, info, tryOut2Ret = tryOut2Ret)
var sss = "" var sss = ""
sss = pars.tmpoutgobjectarg
let num = max([pars.arglist.count("seq2CstringArray"), pars.arglist.count("seq2TargetEntryArray"), pars.arglist.count( let num = max([pars.arglist.count("seq2CstringArray"), pars.arglist.count("seq2TargetEntryArray"), pars.arglist.count(
"seq2PageRangeArray"), pars.arglist.count("seq2KeymapKeyArray")]) "seq2PageRangeArray"), pars.arglist.count("seq2KeymapKeyArray")])
for i in 1 .. num: for i in 1 .. num:
@ -1651,7 +1780,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
#else: # BLOCKMARK8 assert gerror #else: # BLOCKMARK8 assert gerror
if not (isProxyCandidateret2 or isGObject): if not (isProxyCandidateret2 or isGObject):
block8("", true) block8("", true, tryOut2Ret)
if isProxyCandidateret2 or isGObject: # BLOCKMARK8 if isProxyCandidateret2 or isGObject: # BLOCKMARK8
for itt in 0 .. 2: # generate the new(), the new(typedesc) and the init() proc for itt in 0 .. 2: # generate the new(), the new(typedesc) and the init() proc
var hhh = "\nproc " & asym & EM & pars.plist var hhh = "\nproc " & asym & EM & pars.plist
@ -1674,7 +1803,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
hhh = hhh & depStr & " =" hhh = hhh & depStr & " ="
else: else:
hhh = hhh & " =" hhh = hhh & " ="
block8(hhh, itt == 0) block8(hhh, itt == 0, tryOut2Ret)
if not isGObject: if not isGObject:
methodBuffer.write(pars.tempRes) # caution, gobjectTemp() may write tempRes too. methodBuffer.write(pars.tempRes) # caution, gobjectTemp() may write tempRes too.
if itt == 1 or itt == 2: if itt == 1 or itt == 2:
@ -1835,7 +1964,8 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
assert(gCallableInfoGetCallerOwns(minfo) in {GITransfer.EVERYTHING, GITransfer.NOTHING}) assert(gCallableInfoGetCallerOwns(minfo) in {GITransfer.EVERYTHING, GITransfer.NOTHING})
if gCallableInfoGetCallerOwns(minfo) == GITransfer.EVERYTHING: if gCallableInfoGetCallerOwns(minfo) == GITransfer.EVERYTHING:
methodBuffer.writeLine(" cogfree(resul0)") methodBuffer.writeLine(" cogfree(resul0)")
elif (pars.replist.len > 0 or gCallableInfoCanThrowGerror(minfo)) and ngrRet.name != "void": #elif (pars.replist.len > 0 or gCallableInfoCanThrowGerror(minfo)) and ngrRet.name != "void" or pars.tmpoutgobjectarg.len != 0:
elif (pars.replist.len > 0 or gCallableInfoCanThrowGerror(minfo) or pars.tmpoutgobjectarg.len != 0) and ngrRet.name != "void":
# caution dragons like g_key_file_get_locale_string_list() # caution dragons like g_key_file_get_locale_string_list()
if gCallableInfoGetCallerOwns(minfo) == GITransfer.EVERYTHING: if gCallableInfoGetCallerOwns(minfo) == GITransfer.EVERYTHING:
discard # echo "Untamed dragon: ", sym discard # echo "Untamed dragon: ", sym
@ -1906,10 +2036,15 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
# BLOCKMARK8 # BLOCKMARK8
else: # } end of large proxy block BLOCK7 else: # } end of large proxy block BLOCK7
asym = fixedProcNames.getOrDefault(sym, asym) asym = fixedProcNames.getOrDefault(sym, asym)
pars = genPars(mInfo, false, info) pars = genPars(mInfo, false, info, tryOut2Ret = tryOut2Ret)
if asym != "errorQuark" and asym != "getPlugin" and asym != "quark": if asym != "errorQuark" and asym != "getPlugin" and asym != "quark":
methodBuffer.write("\nproc " & asym & EM & pars.plist) methodBuffer.write("\nproc " & asym & EM & pars.plist)
methodBuffer.writeLine(" {.\n importc: \"", sym, "\", ", libprag, ".}") methodBuffer.writeLine(" {.\n importc: \"", sym, "\", ", libprag, ".}")
if pars.tmpoutgobjectarg.len != 0:
methodBuffer.writeLine("# dothemagic(" & pars.outgobjectargname)
dothegobjectargmagic()
if info != nil and (gBaseInfoGetType(info) == GIInfoType.UNION or gBaseInfoGetType(info) == GIInfoType.STRUCT) and if info != nil and (gBaseInfoGetType(info) == GIInfoType.UNION or gBaseInfoGetType(info) == GIInfoType.STRUCT) and
gCallableInfoGetNArgs(minfo) == (if gCallableInfoIsMethod(minfo): 0 else: 1): gCallableInfoGetNArgs(minfo) == (if gCallableInfoIsMethod(minfo): 0 else: 1):
#if not callerAlloc.contains(modulenamespace & '.' & $gBaseInfoGetName(info)) and (asym == "free" or asym == "unref"): #if not callerAlloc.contains(modulenamespace & '.' & $gBaseInfoGetName(info)) and (asym == "free" or asym == "unref"):
@ -1948,12 +2083,18 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
if useTempProcessedFunctions: if useTempProcessedFunctions:
tempProcessedFunctions.add(sym) tempProcessedFunctions.add(sym)
except UndefEx: except UndefEx:
processedFunctions.excl(sym) processedFunctions.excl(sym)
delayedMethods.add((info, minfo)) delayedMethods.add((info, minfo))
methodBuffer.cut(p) methodBuffer.cut(p)
#proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo) =
#
# writeMethodImpl(info, minfo)
# #writeMethodImpl(info, minfo, false)
template genBoxedFree = template genBoxedFree =
if not callerAlloc.contains(($gBaseInfoGetNamespace(info)).toLowerAscii & '.' & mangleName(gBaseInfoGetName(info))): if not callerAlloc.contains(($gBaseInfoGetNamespace(info)).toLowerAscii & '.' & mangleName(gBaseInfoGetName(info))):
if gRegisteredTypeInfoGetGType(info) != G_TYPE_NONE and gTypeFundamental(gRegisteredTypeInfoGetGType(info)) == if gRegisteredTypeInfoGetGType(info) != G_TYPE_NONE and gTypeFundamental(gRegisteredTypeInfoGetGType(info)) ==
@ -3948,7 +4089,7 @@ launch()
# if not xcallerAlloc.contains(el): # if not xcallerAlloc.contains(el):
# echo el # echo el
# 3951 lines # 4092 lines
# gtk_icon_view_get_tooltip_context bug Candidate # gtk_icon_view_get_tooltip_context bug Candidate
# gtk_tree_view_get_cursor bug # gtk_tree_view_get_cursor bug
# #