Skip to content

Commit

Permalink
Work around Nim compiler bug nim-lang/Nim#5140, which breaks
Browse files Browse the repository at this point in the history
newQSqlDateTime().
  • Loading branch information
philip-wernersbach committed Jun 15, 2017
1 parent 69f8dc2 commit 8700f4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion qt5_qtsql.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Package]
name = "qt5_qtsql"
version = "1.0.2"
version = "1.0.3"
author = "Philip Wernersbach <philip.wernersbach@gmail.com>"
description = "Binding for Qt 5's Qt SQL library. Provides a single API for multiple database engines."
license = "MIT"
Expand Down
15 changes: 11 additions & 4 deletions qt5_qtsql/src/qdatetime.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ proc newQDateTimeObj*(): QDateTimeObj {.header: QDATETIME_H, importcpp: "QDateTi
proc setMSecsSinceEpoch*(dateTime: var QDateTimeObj, msecs: qint64) {.header: QDATETIME_H, importcpp: "setMSecsSinceEpoch".}
proc setTimeSpec*(dateTime: var QDateTimeObj, timeSpec: QtTimeSpec) {.header: QDATETIME_H, importcpp: "setTimeSpec".}

proc newQDateTimeObj*(msecs: qint64): QDateTimeObj =
result = newQDateTimeObj()
# The newQDateTimeObj procs need to be templates to workaround a bug in the Nim compiler.
# When they are procs, Nim zeros the memory of the "result" variable, which is invalid in
# C++. (nim-lang/Nim#5140)
template newQDateTimeObj*(msecs: qint64): QDateTimeObj =
var result = newQDateTimeObj()
result.setMSecsSinceEpoch(msecs)

proc newQDateTimeObj*(msecs: qint64, timeSpec: QtTimeSpec): QDateTimeObj =
result = newQDateTimeObj()
result

template newQDateTimeObj*(msecs: qint64, timeSpec: QtTimeSpec): QDateTimeObj =
var result = newQDateTimeObj()
result.setTimeSpec(timeSpec)
result.setMSecsSinceEpoch(msecs)

result

proc currentQDateTimeUtc*(): QDateTimeObj {.header: QDATETIME_H, importcpp: "QDateTime::currentDateTimeUtc".}

proc toQStringObj*(dateTime: QDateTimeObj, format: cstring): QStringObj {.header: QDATETIME_H, importcpp: "toString".}
Expand Down

0 comments on commit 8700f4d

Please sign in to comment.