diff options
Diffstat (limited to 'lib/impure')
-rwxr-xr-x | lib/impure/db_postgres.nim | 6 | ||||
-rwxr-xr-x | lib/impure/db_sqlite.nim | 10 | ||||
-rwxr-xr-x | lib/impure/graphics.nim | 9 | ||||
-rwxr-xr-x | lib/impure/re.nim | 16 |
4 files changed, 21 insertions, 20 deletions
diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index 506da9c84..19701f896 100755 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -84,7 +84,7 @@ proc setupQuery(db: TDbConn, query: TSqlQuery, result = PQExec(db, q) if PQresultStatus(result) != PGRES_TUPLES_OK: dbError(db) -proc setRow(res: PPGresult, r: var TRow, line, cols: int) = +proc setRow(res: PPGresult, r: var TRow, line, cols: int32) = for col in 0..cols-1: setLen(r[col], 0) var x = PQgetvalue(res, line, col) @@ -96,7 +96,7 @@ iterator FastRows*(db: TDbConn, query: TSqlQuery, ## fast, but potenially dangerous: If the for-loop-body executes another ## query, the results can be undefined. For Postgres it is safe though. var res = setupQuery(db, query, args) - var L = int(PQnfields(res)) + var L = PQnfields(res) var result = newRow(L) for i in 0..PQntuples(res)-1: setRow(res, result, i, L) @@ -107,7 +107,7 @@ proc getRow*(db: TDbConn, query: TSqlQuery, args: openarray[string]): TRow = ## retrieves a single row. var res = setupQuery(db, query, args) - var L = int(PQnfields(res)) + var L = PQnfields(res) result = newRow(L) setRow(res, result, 0, L) PQclear(res) diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index b6c8003b9..dbeb1e594 100755 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -64,7 +64,7 @@ proc TryExec*(db: TDbConn, query: TSqlQuery, ## tries to execute the query and returns true if successful, false otherwise. var q = dbFormat(query, args) var stmt: sqlite3.PStmt - if prepare_v2(db, q, q.len, stmt, nil) == SQLITE_OK: + if prepare_v2(db, q, q.len.cint, stmt, nil) == SQLITE_OK: if step(stmt) == SQLITE_DONE: result = finalize(stmt) == SQLITE_OK @@ -79,9 +79,9 @@ proc newRow(L: int): TRow = proc setupQuery(db: TDbConn, query: TSqlQuery, args: openarray[string]): PStmt = var q = dbFormat(query, args) - if prepare_v2(db, q, q.len, result, nil) != SQLITE_OK: dbError(db) + if prepare_v2(db, q, q.len.cint, result, nil) != SQLITE_OK: dbError(db) -proc setRow(stmt: PStmt, r: var TRow, cols: int) = +proc setRow(stmt: PStmt, r: var TRow, cols: cint) = for col in 0..cols-1: setLen(r[col], column_bytes(stmt, col)) # set capacity setLen(r[col], 0) @@ -94,7 +94,7 @@ iterator FastRows*(db: TDbConn, query: TSqlQuery, ## fast, but potenially dangerous: If the for-loop-body executes another ## query, the results can be undefined. For Sqlite it is safe though. var stmt = setupQuery(db, query, args) - var L = int(columnCount(stmt)) + var L = (columnCount(stmt)) var result = newRow(L) while step(stmt) == SQLITE_ROW: setRow(stmt, result, L) @@ -105,7 +105,7 @@ proc getRow*(db: TDbConn, query: TSqlQuery, args: openarray[string]): TRow = ## retrieves a single row. var stmt = setupQuery(db, query, args) - var L = int(columnCount(stmt)) + var L = (columnCount(stmt)) result = newRow(L) if step(stmt) == SQLITE_ROW: setRow(stmt, result, L) diff --git a/lib/impure/graphics.nim b/lib/impure/graphics.nim index 348907f9a..1392fd903 100755 --- a/lib/impure/graphics.nim +++ b/lib/impure/graphics.nim @@ -35,14 +35,15 @@ type proc toSdlColor*(c: TColor): Sdl.TColor = ## Convert colors.TColor to SDL.TColor var x = c.extractRGB - result.r = toU8(x.r) - result.g = toU8(x.g) - result.b = toU8(x.b) + result.r = x.r and 0xff + result.g = x.g and 0xff + result.b = x.b and 0xff proc createSdlColor*(sur: PSurface, c: TColor, alpha: int = 0): int32 = ## Creates a color using ``sdl.MapRGBA``. var x = c.extractRGB - return sdl.MapRGBA(sur.s.format, toU8(x.r), toU8(x.g), toU8(x.b), toU8(alpha)) + return sdl.MapRGBA(sur.s.format, x.r and 0xff, x.g and 0xff, + x.b and 0xff, alpha and 0xff) proc toSdlRect*(r: TRect): sdl.TRect = ## Convert ``graphics.TRect`` to ``sdl.TRect``. diff --git a/lib/impure/re.nim b/lib/impure/re.nim index 1fe1582bd..f3a6e5a44 100755 --- a/lib/impure/re.nim +++ b/lib/impure/re.nim @@ -82,7 +82,7 @@ proc matchOrFind(s: string, pattern: TRegEx, matches: var openarray[string], start, flags: cint): cint = var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] - res = pcre.Exec(pattern.h, pattern.e, s, len(s), start, flags, + res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, flags, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: return res for i in 1..int(res)-1: @@ -100,7 +100,7 @@ proc findBounds*(s: string, pattern: TRegEx, matches: var openarray[string], ## is written into `matches` and ``(-1,0)`` is returned. var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] - res = pcre.Exec(pattern.h, pattern.e, s, len(s), start, 0'i32, + res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: return (-1, 0) for i in 1..int(res)-1: @@ -119,7 +119,7 @@ proc findBounds*(s: string, pattern: TRegEx, ## ``(-1,0)`` is returned. var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] - res = pcre.Exec(pattern.h, pattern.e, s, len(s), start, 0'i32, + res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: return (-1, 0) for i in 1..int(res)-1: @@ -135,14 +135,14 @@ proc findBounds*(s: string, pattern: TRegEx, ## match, ``(-1,0)`` is returned. var rawMatches: array[0..3 - 1, cint] - res = pcre.Exec(pattern.h, nil, s, len(s), start, 0'i32, + res = pcre.Exec(pattern.h, nil, s, len(s).cint, start, 0'i32, cast[ptr cint](addr(rawMatches)), 3) if res < 0'i32: return (int(res), 0) return (int(rawMatches[0]), int(rawMatches[1]-1)) proc matchOrFind(s: string, pattern: TRegEx, start, flags: cint): cint = var rawMatches: array [0..maxSubpatterns * 3 - 1, cint] - result = pcre.Exec(pattern.h, pattern.e, s, len(s), start, flags, + result = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, flags, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if result >= 0'i32: result = rawMatches[1] - rawMatches[0] @@ -180,7 +180,7 @@ proc find*(s: string, pattern: TRegEx, matches: var openarray[string], ## is written into ``matches`` and -1 is returned. var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] - res = pcre.Exec(pattern.h, pattern.e, s, len(s), start, 0'i32, + res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: return res for i in 1..int(res)-1: @@ -195,7 +195,7 @@ proc find*(s: string, pattern: TRegEx, start = 0): int = ## match, -1 is returned. var rawMatches: array[0..3 - 1, cint] - res = pcre.Exec(pattern.h, nil, s, len(s), start, 0'i32, + res = pcre.Exec(pattern.h, nil, s, len(s).cint, start, 0'i32, cast[ptr cint](addr(rawMatches)), 3) if res < 0'i32: return res return rawMatches[0] @@ -205,7 +205,7 @@ iterator findAll*(s: string, pattern: TRegEx, start = 0): string = var i = int32(start) var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] while true: - let res = pcre.Exec(pattern.h, pattern.e, s, len(s), i, 0'i32, + let res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, i, 0'i32, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: break let a = rawMatches[0] |