more fixes for Nim 0.19

This commit is contained in:
Stefan Salewski 2018-08-20 08:09:56 +02:00
commit 32b3018a7b
4 changed files with 20 additions and 16 deletions

View file

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

View file

@ -732,7 +732,7 @@ proc copyClipRectangleList*(cr: Context): seq[Rectangle] =
var h: Rectangle
var r = cairo_copy_clip_rectangle_list(cr.impl)
defer: cairo_rectangle_list_destroy(r)
if r.status != Status.success or r.numRectangles == 0: return nil
if r.status != Status.success or r.numRectangles == 0: return @[]
result = newSeq[Rectangle]()
for i in 0 ..< r.numRectangles:
let k = cast[ptr array[99, Rectangle00]](r.rectangles)[i]

View file

@ -51,7 +51,7 @@ macro mconnect(widget: gobject.Object; signal: string; p: typed; arg: typed; ign
var # position and actual type of interface provider, if any
ipos = -1
ipro: string = nil
ipro: string #= nil
inc(ProcID)
let wt = getType(widget)
@ -112,7 +112,7 @@ proc $1$2 {.cdecl.} =
(names[i], types[i]) = largs[i].split(": ptr ")
types[i].setLen(types[i].len - 2)
else:
types[i] = nil # plain arg, no object
types[i] = ""#nil # plain arg, no object
var a1, a2: string
(a1, a2) = largs[i].split(": ")
let h = ct5nt(a2)
@ -124,7 +124,7 @@ proc $1$2 {.cdecl.} =
types[ipos - 1] = ipro
for i in 0 .. largs.high:
if types[i] == nil:
if types[i] == "":
resu.add(", " & names[i])
else:
resu.add(", " & names[i] & "1")

View file

@ -1,5 +1,5 @@
# High level gobject-introspection based GTK3 bindings for the Nim programming language
# v 0.4.4 2018-AUG-02
# v 0.4.5 2018-AUG-20
# (c) S. Salewski 2018
# https://wiki.gnome.org/Projects/GObjectIntrospection
@ -433,8 +433,8 @@ proc genP(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil): (str
let kk = if name[0] == '`': name[1 .. ^2] else: name
arglist.add(kk & "_00")
elif ct2nt.contains(str):
if str == "cstring":
arglist.add("safeStringToCString" & '(' & name & ')')
if str == "cstring" and mayBeNil:
arglist.add("safeStringToCString" & '(' & name & ')')################################################
else:
arglist.add(str & '(' & name & ')')
else:
@ -453,7 +453,8 @@ proc genP(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil): (str
if name == h1 and str == h2:
str.add(" = " & h3)
if genProxy and str == "string" and mayBeNil:
str.add(" = nil")
#str.add(" = nil")
str.add(" = \"\"")
if genProxy and isProxyCandidate(t) and mayBeNil:
#if not str.contains("|") and (gArgInfoGetDirection(arg) == GIDirection.OUT or gArgInfoGetDirection(arg) == GIDirection.INOUT):
# str.add(" = cast[" & str & "](nil)")
@ -462,6 +463,7 @@ proc genP(info: GICallableInfo; genProxy = false; binfo: GIBaseInfo = nil): (str
# discard
#else:
str.add(" = nil")
#str.add(" = \"\"")
if (genProxy or sym == "pango_extents_to_pixels") and isFunctionInfo(info) and (gFunctionInfoGetFlags(info).int and GIFunctionInfoFlags.WRAPS_VFUNC.ord) == 0:
if userAlloc and mayBeNil:
var h = str
@ -690,7 +692,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
freeMeName = $gBaseInfoGetName(freeMe)
if sym == "g_closure_new_simple" or sym == "g_closure_new_object": freeMeName = "unref" # TODO GI bug?
assert(gCallableInfoGetCallerOwns(minfo) in {GITransfer.EVERYTHING, GITransfer.NOTHING})
if freeMeName.isNil:
if freeMeName == "":
methodBuffer.writeLine(" new(result)")
else:
methodBuffer.writeLine(" new(result, $1)" % freeMeName)
@ -760,7 +762,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
elif h.endsWith("unref"):
freeMeName = "unref"
break
if freeMeName.isNil:
if freeMeName == "":
# assert false # TODO we have to fix this case manually
echo "Caution: No free/unref found for ", ' ', gBaseInfoGetName(iface), " (", sym, ')'
methodBuffer.writeLine(" new(result)")
@ -781,7 +783,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
methodBuffer.writeLine("\nproc " & asym & EM & plist & " =")
var freeMeName: string
for j in 0.cint ..< gCallableInfoGetNArgs(minfo):
freeMeName = nil
freeMeName = ""
let arg = gCallableInfoGetArg(minfo, j)
let t = gArgInfoGetType(arg)
if gArgInfoGetDirection(arg) == GIDirection.OUT and isProxyCandidate(t) and not callerAlloc.contains(genRec(t, true, true)) and not gArgInfoIsCallerAllocates(arg):
@ -815,7 +817,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
else:
freeMeName = $gBaseInfoGetName(freeMe)
let h2 = mangleName(gBaseInfoGetName(arg))
if freeMeName.isNil:
if freeMeName == "":
methodBuffer.writeLine(" new(" & h2 & ")")
else:
methodBuffer.writeLine(" new(" & h2 & ", " & freeMeName & ")")
@ -976,6 +978,7 @@ proc writeInterface(info: GIInterfaceInfo) =
(plist, arglist, replist) = genP(signalInfo, false, info)
memo.add(plist)
memo = memo.replace("\n ", "")
memo = memo.replace("\"", "\\\"")
supmod.writeLine(" \"" & ($gBaseInfoGetName(signalInfo)).replace("-", "_") & RecSep & $gBaseInfoGetName(info) & RecSep & memo & "\",")
if gCallableInfoGetNArgs(signalInfo) > 0:
var plist, arglist: string
@ -1248,6 +1251,7 @@ proc writeObj(info: GIObjectInfo) =
(plist, arglist, replist) = genP(signalInfo, false, info)
memo.add(plist)
memo = memo.replace("\n ", "")
memo = memo.replace("\"", "\\\"")
supmod.writeLine(" \"" & ($gBaseInfoGetName(signalInfo)).replace("-", "_") & RecSep & $gBaseInfoGetName(info) & RecSep & memo & "\",")
if gCallableInfoGetNArgs(signalInfo) > 0:
var plist, arglist: string
@ -1424,7 +1428,7 @@ proc gtk_file_chooser_dialog_new*(title: cstring; parent: ptr Window00; action:
firstButtonText: cstring = nil): ptr FileChooserDialog00 {.varargs,
importc: "gtk_file_chooser_dialog_new", libprag.}
proc newFileChooserDialog*(title: string = nil; parent: Window = nil; action: FileChooserAction): FileChooserDialog =
proc newFileChooserDialog*(title: string = ""; parent: Window = nil; action: FileChooserAction): FileChooserDialog =
let gobj = gtk_file_chooser_dialog_new(safeStringToCString(title), if parent.isNil: nil else: cast[ptr Window00](parent.impl), action)
if g_object_get_qdata(gobj, Quark) != nil:
result = cast[type(result)](g_object_get_qdata(gobj, Quark))
@ -1439,7 +1443,7 @@ proc newFileChooserDialog*(title: string = nil; parent: Window = nil; action: Fi
assert(g_object_get_qdata(result.impl, Quark) == nil)
g_object_set_qdata(result.impl, Quark, addr(result[]))
proc initFileChooserDialog*[T](result: var T; title: string = nil; parent: Window = nil; action: FileChooserAction) =
proc initFileChooserDialog*[T](result: var T; title: string = ""; parent: Window = nil; action: FileChooserAction) =
assert(result is FileChooserDialog)
let gobj = gtk_file_chooser_dialog_new(safeStringToCString(title), if parent.isNil: nil else: cast[ptr Window00](parent.impl), action)
if g_object_get_qdata(gobj, Quark) != nil:
@ -1569,7 +1573,7 @@ proc main(namespace: string) =
output.writeLine("const GTrue = gboolean(1)")
output.writeLine("proc cogfree*(mem: pointer) {.importc: \"g_free\", libprag.}")
output.writeLine("proc toBool*(g: gboolean): bool = g.int != 0")
output.writeLine("proc safeStringToCString*(s: string): cstring = (if s.isNil: nil else: cstring(s))")
output.writeLine("proc safeStringToCString*(s: string): cstring = (if s.len == 0: nil else: cstring(s))")
elif namespace == "Gdk":
output.writeLine("type\n AtomArray* = pointer")
output.writeLine("type\n KeymapKey00Array* = pointer")