make implicit cstring conversions explicit (#19488)
The Nim manual says that an implicit conversion to cstring will
eventually not be allowed [1]:
A Nim `string` is implicitly convertible to `cstring` for convenience.
[...]
Even though the conversion is implicit, it is not *safe*: The garbage collector
does not consider a `cstring` to be a root and may collect the underlying
memory. For this reason, the implicit conversion will be removed in future
releases of the Nim compiler. Certain idioms like conversion of a `const` string
to `cstring` are safe and will remain to be allowed.
And from Nim 1.6.0, such a conversion triggers a warning [2]:
A dangerous implicit conversion to `cstring` now triggers a `[CStringConv]` warning.
This warning will become an error in future versions! Use an explicit conversion
like `cstring(x)` in order to silence the warning.
However, some files in this repo produced such a warning. For example,
before this commit, compiling `parsejson.nim` would produce:
/foo/Nim/lib/pure/parsejson.nim(221, 37) Warning: implicit conversion to 'cstring' from a non-const location: my.buf; this will become a compile time error in the future [CStringConv]
/foo/Nim/lib/pure/parsejson.nim(231, 39) Warning: implicit conversion to 'cstring' from a non-const location: my.buf; this will become a compile time error in the future [CStringConv]
This commit resolves the most visible `CStringConv` warnings, making the
cstring conversions explicit.
[1] d2318d9ccf/doc/manual.md (cstring-type)
[2] d2318d9ccf/changelogs/changelog_1_6_0.md (type-system)
This commit is contained in:
parent
7fe6dedb62
commit
e8657c7107
14 changed files with 63 additions and 63 deletions
|
|
@ -65,16 +65,16 @@ proc importcSymbol*(conf: ConfigRef, sym: PSym): PNode =
|
||||||
if (lib.isNil or lib.kind == libHeader) and not gExeHandle.isNil:
|
if (lib.isNil or lib.kind == libHeader) and not gExeHandle.isNil:
|
||||||
libPathMsg = "current exe: " & getAppFilename() & " nor libc: " & libcDll
|
libPathMsg = "current exe: " & getAppFilename() & " nor libc: " & libcDll
|
||||||
# first try this exe itself:
|
# first try this exe itself:
|
||||||
theAddr = gExeHandle.symAddr(name)
|
theAddr = gExeHandle.symAddr(name.cstring)
|
||||||
# then try libc:
|
# then try libc:
|
||||||
if theAddr.isNil:
|
if theAddr.isNil:
|
||||||
let dllhandle = getDll(conf, gDllCache, libcDll, sym.info)
|
let dllhandle = getDll(conf, gDllCache, libcDll, sym.info)
|
||||||
theAddr = dllhandle.symAddr(name)
|
theAddr = dllhandle.symAddr(name.cstring)
|
||||||
elif not lib.isNil:
|
elif not lib.isNil:
|
||||||
let dll = if lib.kind == libHeader: libcDll else: lib.path.strVal
|
let dll = if lib.kind == libHeader: libcDll else: lib.path.strVal
|
||||||
libPathMsg = dll
|
libPathMsg = dll
|
||||||
let dllhandle = getDll(conf, gDllCache, dll, sym.info)
|
let dllhandle = getDll(conf, gDllCache, dll, sym.info)
|
||||||
theAddr = dllhandle.symAddr(name)
|
theAddr = dllhandle.symAddr(name.cstring)
|
||||||
if theAddr.isNil: globalError(conf, sym.info,
|
if theAddr.isNil: globalError(conf, sym.info,
|
||||||
"cannot import symbol: " & name & " from " & libPathMsg)
|
"cannot import symbol: " & name & " from " & libPathMsg)
|
||||||
result.intVal = cast[ByteAddress](theAddr)
|
result.intVal = cast[ByteAddress](theAddr)
|
||||||
|
|
|
||||||
|
|
@ -48,15 +48,15 @@ proc setupEnvironment =
|
||||||
var tinycRoot = nimDir / tinyPrefix
|
var tinycRoot = nimDir / tinyPrefix
|
||||||
let libpath = nimDir / "lib"
|
let libpath = nimDir / "lib"
|
||||||
|
|
||||||
addIncludePath(gTinyC, libpath)
|
addIncludePath(gTinyC, cstring(libpath))
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
addSysincludePath(gTinyC, tinycRoot / "tinyc/win32/include")
|
addSysincludePath(gTinyC, cstring(tinycRoot / "tinyc/win32/include"))
|
||||||
addSysincludePath(gTinyC, tinycRoot / "tinyc/include")
|
addSysincludePath(gTinyC, cstring(tinycRoot / "tinyc/include"))
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
defineSymbol(gTinyC, "_WIN32", nil)
|
defineSymbol(gTinyC, "_WIN32", nil)
|
||||||
# we need Mingw's headers too:
|
# we need Mingw's headers too:
|
||||||
var gccbin = getConfigVar("gcc.path") % ["nim", tinycRoot]
|
var gccbin = getConfigVar("gcc.path") % ["nim", tinycRoot]
|
||||||
addSysincludePath(gTinyC, gccbin /../ "include")
|
addSysincludePath(gTinyC, cstring(gccbin /../ "include"))
|
||||||
#addFile(tinycRoot / r"tinyc\win32\wincrt1.o")
|
#addFile(tinycRoot / r"tinyc\win32\wincrt1.o")
|
||||||
addFile(tinycRoot / r"tinyc\win32\alloca86.o")
|
addFile(tinycRoot / r"tinyc\win32\alloca86.o")
|
||||||
addFile(tinycRoot / r"tinyc\win32\chkstk.o")
|
addFile(tinycRoot / r"tinyc\win32\chkstk.o")
|
||||||
|
|
|
||||||
|
|
@ -149,17 +149,17 @@ proc tryExec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]): bool {.
|
||||||
tags: [ReadDbEffect, WriteDbEffect].} =
|
tags: [ReadDbEffect, WriteDbEffect].} =
|
||||||
## tries to execute the query and returns true if successful, false otherwise.
|
## tries to execute the query and returns true if successful, false otherwise.
|
||||||
var q = dbFormat(query, args)
|
var q = dbFormat(query, args)
|
||||||
return mysql.real_query(PMySQL db, q, q.len) == 0'i32
|
return mysql.real_query(PMySQL db, q.cstring, q.len) == 0'i32
|
||||||
|
|
||||||
proc rawExec(db: DbConn, query: SqlQuery, args: varargs[string, `$`]) =
|
proc rawExec(db: DbConn, query: SqlQuery, args: varargs[string, `$`]) =
|
||||||
var q = dbFormat(query, args)
|
var q = dbFormat(query, args)
|
||||||
if mysql.real_query(PMySQL db, q, q.len) != 0'i32: dbError(db)
|
if mysql.real_query(PMySQL db, q.cstring, q.len) != 0'i32: dbError(db)
|
||||||
|
|
||||||
proc exec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]) {.
|
proc exec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]) {.
|
||||||
tags: [ReadDbEffect, WriteDbEffect].} =
|
tags: [ReadDbEffect, WriteDbEffect].} =
|
||||||
## executes the query and raises EDB if not successful.
|
## executes the query and raises EDB if not successful.
|
||||||
var q = dbFormat(query, args)
|
var q = dbFormat(query, args)
|
||||||
if mysql.real_query(PMySQL db, q, q.len) != 0'i32: dbError(db)
|
if mysql.real_query(PMySQL db, q.cstring, q.len) != 0'i32: dbError(db)
|
||||||
|
|
||||||
proc newRow(L: int): Row =
|
proc newRow(L: int): Row =
|
||||||
newSeq(result, L)
|
newSeq(result, L)
|
||||||
|
|
@ -360,7 +360,7 @@ proc tryInsertId*(db: DbConn, query: SqlQuery,
|
||||||
## executes the query (typically "INSERT") and returns the
|
## executes the query (typically "INSERT") and returns the
|
||||||
## generated ID for the row or -1 in case of an error.
|
## generated ID for the row or -1 in case of an error.
|
||||||
var q = dbFormat(query, args)
|
var q = dbFormat(query, args)
|
||||||
if mysql.real_query(PMySQL db, q, q.len) != 0'i32:
|
if mysql.real_query(PMySQL db, q.cstring, q.len) != 0'i32:
|
||||||
result = -1'i64
|
result = -1'i64
|
||||||
else:
|
else:
|
||||||
result = mysql.insertId(PMySQL db)
|
result = mysql.insertId(PMySQL db)
|
||||||
|
|
@ -409,7 +409,7 @@ proc open*(connection, user, password, database: string): DbConn {.
|
||||||
else: substr(connection, 0, colonPos-1)
|
else: substr(connection, 0, colonPos-1)
|
||||||
port: int32 = if colonPos < 0: 0'i32
|
port: int32 = if colonPos < 0: 0'i32
|
||||||
else: substr(connection, colonPos+1).parseInt.int32
|
else: substr(connection, colonPos+1).parseInt.int32
|
||||||
if mysql.realConnect(res, host, user, password, database,
|
if mysql.realConnect(res, host.cstring, user, password, database,
|
||||||
port, nil, 0) == nil:
|
port, nil, 0) == nil:
|
||||||
var errmsg = $mysql.error(res)
|
var errmsg = $mysql.error(res)
|
||||||
mysql.close(res)
|
mysql.close(res)
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,7 @@ proc `[]`*(row: InstantRow, col: int): string {.inline.} =
|
||||||
|
|
||||||
proc unsafeColumnAt*(row: InstantRow, index: int): cstring {.inline.} =
|
proc unsafeColumnAt*(row: InstantRow, index: int): cstring {.inline.} =
|
||||||
## Return cstring of given column of the row
|
## Return cstring of given column of the row
|
||||||
row.row[index]
|
row.row[index].cstring
|
||||||
|
|
||||||
proc len*(row: InstantRow): int {.inline.} =
|
proc len*(row: InstantRow): int {.inline.} =
|
||||||
## Returns number of columns in the row
|
## Returns number of columns in the row
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ proc dbFormat(formatstr: SqlQuery, args: varargs[string]): string =
|
||||||
proc tryExec*(db: DbConn, query: SqlQuery,
|
proc tryExec*(db: DbConn, query: SqlQuery,
|
||||||
args: varargs[string, `$`]): bool {.tags: [ReadDbEffect, WriteDbEffect].} =
|
args: varargs[string, `$`]): bool {.tags: [ReadDbEffect, WriteDbEffect].} =
|
||||||
## tries to execute the query and returns true if successful, false otherwise.
|
## tries to execute the query and returns true if successful, false otherwise.
|
||||||
var res = pqexecParams(db, dbFormat(query, args), 0, nil, nil,
|
var res = pqexecParams(db, dbFormat(query, args).cstring, 0, nil, nil,
|
||||||
nil, nil, 0)
|
nil, nil, 0)
|
||||||
result = pqresultStatus(res) == PGRES_COMMAND_OK
|
result = pqresultStatus(res) == PGRES_COMMAND_OK
|
||||||
pqclear(res)
|
pqclear(res)
|
||||||
|
|
@ -143,7 +143,7 @@ proc tryExec*(db: DbConn, stmtName: SqlPrepared,
|
||||||
ReadDbEffect, WriteDbEffect].} =
|
ReadDbEffect, WriteDbEffect].} =
|
||||||
## tries to execute the query and returns true if successful, false otherwise.
|
## tries to execute the query and returns true if successful, false otherwise.
|
||||||
var arr = allocCStringArray(args)
|
var arr = allocCStringArray(args)
|
||||||
var res = pqexecPrepared(db, stmtName.string, int32(args.len), arr,
|
var res = pqexecPrepared(db, stmtName.cstring, int32(args.len), arr,
|
||||||
nil, nil, 0)
|
nil, nil, 0)
|
||||||
deallocCStringArray(arr)
|
deallocCStringArray(arr)
|
||||||
result = pqresultStatus(res) == PGRES_COMMAND_OK
|
result = pqresultStatus(res) == PGRES_COMMAND_OK
|
||||||
|
|
@ -152,7 +152,7 @@ proc tryExec*(db: DbConn, stmtName: SqlPrepared,
|
||||||
proc exec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]) {.
|
proc exec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]) {.
|
||||||
tags: [ReadDbEffect, WriteDbEffect].} =
|
tags: [ReadDbEffect, WriteDbEffect].} =
|
||||||
## executes the query and raises EDB if not successful.
|
## executes the query and raises EDB if not successful.
|
||||||
var res = pqexecParams(db, dbFormat(query, args), 0, nil, nil,
|
var res = pqexecParams(db, dbFormat(query, args).cstring, 0, nil, nil,
|
||||||
nil, nil, 0)
|
nil, nil, 0)
|
||||||
if pqresultStatus(res) != PGRES_COMMAND_OK: dbError(db)
|
if pqresultStatus(res) != PGRES_COMMAND_OK: dbError(db)
|
||||||
pqclear(res)
|
pqclear(res)
|
||||||
|
|
@ -160,7 +160,7 @@ proc exec*(db: DbConn, query: SqlQuery, args: varargs[string, `$`]) {.
|
||||||
proc exec*(db: DbConn, stmtName: SqlPrepared,
|
proc exec*(db: DbConn, stmtName: SqlPrepared,
|
||||||
args: varargs[string]) {.tags: [ReadDbEffect, WriteDbEffect].} =
|
args: varargs[string]) {.tags: [ReadDbEffect, WriteDbEffect].} =
|
||||||
var arr = allocCStringArray(args)
|
var arr = allocCStringArray(args)
|
||||||
var res = pqexecPrepared(db, stmtName.string, int32(args.len), arr,
|
var res = pqexecPrepared(db, stmtName.cstring, int32(args.len), arr,
|
||||||
nil, nil, 0)
|
nil, nil, 0)
|
||||||
deallocCStringArray(arr)
|
deallocCStringArray(arr)
|
||||||
if pqResultStatus(res) != PGRES_COMMAND_OK: dbError(db)
|
if pqResultStatus(res) != PGRES_COMMAND_OK: dbError(db)
|
||||||
|
|
@ -172,20 +172,20 @@ proc newRow(L: int): Row =
|
||||||
|
|
||||||
proc setupQuery(db: DbConn, query: SqlQuery,
|
proc setupQuery(db: DbConn, query: SqlQuery,
|
||||||
args: varargs[string]): PPGresult =
|
args: varargs[string]): PPGresult =
|
||||||
result = pqexec(db, dbFormat(query, args))
|
result = pqexec(db, dbFormat(query, args).cstring)
|
||||||
if pqResultStatus(result) != PGRES_TUPLES_OK: dbError(db)
|
if pqResultStatus(result) != PGRES_TUPLES_OK: dbError(db)
|
||||||
|
|
||||||
proc setupQuery(db: DbConn, stmtName: SqlPrepared,
|
proc setupQuery(db: DbConn, stmtName: SqlPrepared,
|
||||||
args: varargs[string]): PPGresult =
|
args: varargs[string]): PPGresult =
|
||||||
var arr = allocCStringArray(args)
|
var arr = allocCStringArray(args)
|
||||||
result = pqexecPrepared(db, stmtName.string, int32(args.len), arr,
|
result = pqexecPrepared(db, stmtName.cstring, int32(args.len), arr,
|
||||||
nil, nil, 0)
|
nil, nil, 0)
|
||||||
deallocCStringArray(arr)
|
deallocCStringArray(arr)
|
||||||
if pqResultStatus(result) != PGRES_TUPLES_OK: dbError(db)
|
if pqResultStatus(result) != PGRES_TUPLES_OK: dbError(db)
|
||||||
|
|
||||||
proc setupSingeRowQuery(db: DbConn, query: SqlQuery,
|
proc setupSingeRowQuery(db: DbConn, query: SqlQuery,
|
||||||
args: varargs[string]) =
|
args: varargs[string]) =
|
||||||
if pqsendquery(db, dbFormat(query, args)) != 1:
|
if pqsendquery(db, dbFormat(query, args).cstring) != 1:
|
||||||
dbError(db)
|
dbError(db)
|
||||||
if pqSetSingleRowMode(db) != 1:
|
if pqSetSingleRowMode(db) != 1:
|
||||||
dbError(db)
|
dbError(db)
|
||||||
|
|
@ -193,7 +193,7 @@ proc setupSingeRowQuery(db: DbConn, query: SqlQuery,
|
||||||
proc setupSingeRowQuery(db: DbConn, stmtName: SqlPrepared,
|
proc setupSingeRowQuery(db: DbConn, stmtName: SqlPrepared,
|
||||||
args: varargs[string]) =
|
args: varargs[string]) =
|
||||||
var arr = allocCStringArray(args)
|
var arr = allocCStringArray(args)
|
||||||
if pqsendqueryprepared(db, stmtName.string, int32(args.len), arr, nil, nil, 0) != 1:
|
if pqsendqueryprepared(db, stmtName.cstring, int32(args.len), arr, nil, nil, 0) != 1:
|
||||||
dbError(db)
|
dbError(db)
|
||||||
if pqSetSingleRowMode(db) != 1:
|
if pqSetSingleRowMode(db) != 1:
|
||||||
dbError(db)
|
dbError(db)
|
||||||
|
|
@ -205,7 +205,7 @@ proc prepare*(db: DbConn; stmtName: string, query: SqlQuery;
|
||||||
## via `$1`, `$2`, `$3`, etc.
|
## via `$1`, `$2`, `$3`, etc.
|
||||||
if nParams > 0 and not string(query).contains("$1"):
|
if nParams > 0 and not string(query).contains("$1"):
|
||||||
dbError("parameter substitution expects \"$1\"")
|
dbError("parameter substitution expects \"$1\"")
|
||||||
var res = pqprepare(db, stmtName, query.string, int32(nParams), nil)
|
var res = pqprepare(db, stmtName, query.cstring, int32(nParams), nil)
|
||||||
if pqResultStatus(res) != PGRES_COMMAND_OK: dbError(db)
|
if pqResultStatus(res) != PGRES_COMMAND_OK: dbError(db)
|
||||||
return SqlPrepared(stmtName)
|
return SqlPrepared(stmtName)
|
||||||
|
|
||||||
|
|
@ -590,7 +590,7 @@ proc execAffectedRows*(db: DbConn, query: SqlQuery,
|
||||||
## executes the query (typically "UPDATE") and returns the
|
## executes the query (typically "UPDATE") and returns the
|
||||||
## number of affected rows.
|
## number of affected rows.
|
||||||
var q = dbFormat(query, args)
|
var q = dbFormat(query, args)
|
||||||
var res = pqExec(db, q)
|
var res = pqExec(db, q.cstring)
|
||||||
if pqresultStatus(res) != PGRES_COMMAND_OK: dbError(db)
|
if pqresultStatus(res) != PGRES_COMMAND_OK: dbError(db)
|
||||||
result = parseBiggestInt($pqcmdTuples(res))
|
result = parseBiggestInt($pqcmdTuples(res))
|
||||||
pqclear(res)
|
pqclear(res)
|
||||||
|
|
@ -601,7 +601,7 @@ proc execAffectedRows*(db: DbConn, stmtName: SqlPrepared,
|
||||||
## executes the query (typically "UPDATE") and returns the
|
## executes the query (typically "UPDATE") and returns the
|
||||||
## number of affected rows.
|
## number of affected rows.
|
||||||
var arr = allocCStringArray(args)
|
var arr = allocCStringArray(args)
|
||||||
var res = pqexecPrepared(db, stmtName.string, int32(args.len), arr,
|
var res = pqexecPrepared(db, stmtName.cstring, int32(args.len), arr,
|
||||||
nil, nil, 0)
|
nil, nil, 0)
|
||||||
deallocCStringArray(arr)
|
deallocCStringArray(arr)
|
||||||
if pqresultStatus(res) != PGRES_COMMAND_OK: dbError(db)
|
if pqresultStatus(res) != PGRES_COMMAND_OK: dbError(db)
|
||||||
|
|
@ -634,7 +634,7 @@ proc open*(connection, user, password, database: string): DbConn {.
|
||||||
else: substr(connection, 0, colonPos-1)
|
else: substr(connection, 0, colonPos-1)
|
||||||
port = if colonPos < 0: ""
|
port = if colonPos < 0: ""
|
||||||
else: substr(connection, colonPos+1)
|
else: substr(connection, colonPos+1)
|
||||||
result = pqsetdbLogin(host, port, nil, nil, database, user, password)
|
result = pqsetdbLogin(host.cstring, port.cstring, nil, nil, database, user, password)
|
||||||
if pqStatus(result) != CONNECTION_OK: dbError(result) # result = nil
|
if pqStatus(result) != CONNECTION_OK: dbError(result) # result = nil
|
||||||
|
|
||||||
proc setEncoding*(connection: DbConn, encoding: string): bool {.
|
proc setEncoding*(connection: DbConn, encoding: string): bool {.
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ proc tryExec*(db: DbConn, query: SqlQuery,
|
||||||
assert(not db.isNil, "Database not connected.")
|
assert(not db.isNil, "Database not connected.")
|
||||||
var q = dbFormat(query, args)
|
var q = dbFormat(query, args)
|
||||||
var stmt: sqlite3.PStmt
|
var stmt: sqlite3.PStmt
|
||||||
if prepare_v2(db, q, q.len.cint, stmt, nil) == SQLITE_OK:
|
if prepare_v2(db, q.cstring, q.len.cint, stmt, nil) == SQLITE_OK:
|
||||||
let x = step(stmt)
|
let x = step(stmt)
|
||||||
if x in {SQLITE_DONE, SQLITE_ROW}:
|
if x in {SQLITE_DONE, SQLITE_ROW}:
|
||||||
result = finalize(stmt) == SQLITE_OK
|
result = finalize(stmt) == SQLITE_OK
|
||||||
|
|
@ -278,7 +278,7 @@ proc setupQuery(db: DbConn, query: SqlQuery,
|
||||||
args: varargs[string]): PStmt =
|
args: varargs[string]): PStmt =
|
||||||
assert(not db.isNil, "Database not connected.")
|
assert(not db.isNil, "Database not connected.")
|
||||||
var q = dbFormat(query, args)
|
var q = dbFormat(query, args)
|
||||||
if prepare_v2(db, q, q.len.cint, result, nil) != SQLITE_OK: dbError(db)
|
if prepare_v2(db, q.cstring, q.len.cint, result, nil) != SQLITE_OK: dbError(db)
|
||||||
|
|
||||||
proc setupQuery(db: DbConn, stmtName: SqlPrepared): SqlPrepared {.since: (1, 3).} =
|
proc setupQuery(db: DbConn, stmtName: SqlPrepared): SqlPrepared {.since: (1, 3).} =
|
||||||
assert(not db.isNil, "Database not connected.")
|
assert(not db.isNil, "Database not connected.")
|
||||||
|
|
@ -653,7 +653,7 @@ proc tryInsertID*(db: DbConn, query: SqlQuery,
|
||||||
var q = dbFormat(query, args)
|
var q = dbFormat(query, args)
|
||||||
var stmt: sqlite3.PStmt
|
var stmt: sqlite3.PStmt
|
||||||
result = -1
|
result = -1
|
||||||
if prepare_v2(db, q, q.len.cint, stmt, nil) == SQLITE_OK:
|
if prepare_v2(db, q.cstring, q.len.cint, stmt, nil) == SQLITE_OK:
|
||||||
if step(stmt) == SQLITE_DONE:
|
if step(stmt) == SQLITE_DONE:
|
||||||
result = last_insert_rowid(db)
|
result = last_insert_rowid(db)
|
||||||
if finalize(stmt) != SQLITE_OK:
|
if finalize(stmt) != SQLITE_OK:
|
||||||
|
|
|
||||||
|
|
@ -487,7 +487,7 @@ when defined(createNimHcr):
|
||||||
recursiveDiscovery(modules[curr].imports)
|
recursiveDiscovery(modules[curr].imports)
|
||||||
allModulesOrderedByDFS.add(curr)
|
allModulesOrderedByDFS.add(curr)
|
||||||
continue
|
continue
|
||||||
loadDll(curr)
|
loadDll(curr.cstring)
|
||||||
# first load all dependencies of the current module and init it after that
|
# first load all dependencies of the current module and init it after that
|
||||||
recursiveDiscovery(modules[curr].imports)
|
recursiveDiscovery(modules[curr].imports)
|
||||||
|
|
||||||
|
|
@ -497,20 +497,20 @@ when defined(createNimHcr):
|
||||||
proc initModules() =
|
proc initModules() =
|
||||||
# first init the pointers to hcr functions and also do the registering of typeinfo globals
|
# first init the pointers to hcr functions and also do the registering of typeinfo globals
|
||||||
for curr in modulesToInit:
|
for curr in modulesToInit:
|
||||||
initHcrData(curr)
|
initHcrData(curr.cstring)
|
||||||
initTypeInfoGlobals(curr)
|
initTypeInfoGlobals(curr.cstring)
|
||||||
# for now system always gets fully inited before any other module (including when reloading)
|
# for now system always gets fully inited before any other module (including when reloading)
|
||||||
initPointerData(system)
|
initPointerData(system.cstring)
|
||||||
initGlobalScope(system)
|
initGlobalScope(system.cstring)
|
||||||
# proceed with the DatInit calls - for all modules - including the main one!
|
# proceed with the DatInit calls - for all modules - including the main one!
|
||||||
for curr in allModulesOrderedByDFS:
|
for curr in allModulesOrderedByDFS:
|
||||||
if curr != system:
|
if curr != system:
|
||||||
initPointerData(curr)
|
initPointerData(curr.cstring)
|
||||||
mainDatInit()
|
mainDatInit()
|
||||||
# execute top-level code (in global scope)
|
# execute top-level code (in global scope)
|
||||||
for curr in modulesToInit:
|
for curr in modulesToInit:
|
||||||
if curr != system:
|
if curr != system:
|
||||||
initGlobalScope(curr)
|
initGlobalScope(curr.cstring)
|
||||||
# cleanup old symbols which are gone now
|
# cleanup old symbols which are gone now
|
||||||
for curr in modulesToInit:
|
for curr in modulesToInit:
|
||||||
cleanupSymbols(curr)
|
cleanupSymbols(curr)
|
||||||
|
|
|
||||||
|
|
@ -367,7 +367,7 @@ method log*(logger: ConsoleLogger, level: Level, args: varargs[string, `$`]) =
|
||||||
if level >= logging.level and level >= logger.levelThreshold:
|
if level >= logging.level and level >= logger.levelThreshold:
|
||||||
let ln = substituteLog(logger.fmtStr, level, args)
|
let ln = substituteLog(logger.fmtStr, level, args)
|
||||||
when defined(js):
|
when defined(js):
|
||||||
let cln: cstring = ln
|
let cln = ln.cstring
|
||||||
case level
|
case level
|
||||||
of lvlDebug: {.emit: "console.debug(`cln`);".}
|
of lvlDebug: {.emit: "console.debug(`cln`);".}
|
||||||
of lvlInfo: {.emit: "console.info(`cln`);".}
|
of lvlInfo: {.emit: "console.info(`cln`);".}
|
||||||
|
|
|
||||||
|
|
@ -300,7 +300,7 @@ proc getAddrInfo*(address: string, port: Port, domain: Domain = AF_INET,
|
||||||
if domain == AF_INET6:
|
if domain == AF_INET6:
|
||||||
hints.ai_flags = AI_V4MAPPED
|
hints.ai_flags = AI_V4MAPPED
|
||||||
let socketPort = if sockType == SOCK_RAW: "" else: $port
|
let socketPort = if sockType == SOCK_RAW: "" else: $port
|
||||||
var gaiResult = getaddrinfo(address, socketPort, addr(hints), result)
|
var gaiResult = getaddrinfo(address, socketPort.cstring, addr(hints), result)
|
||||||
if gaiResult != 0'i32:
|
if gaiResult != 0'i32:
|
||||||
when useWinVersion or defined(freertos):
|
when useWinVersion or defined(freertos):
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
@ -460,10 +460,10 @@ when not useNimNetLite:
|
||||||
const size = 256
|
const size = 256
|
||||||
result = newString(size)
|
result = newString(size)
|
||||||
when useWinVersion:
|
when useWinVersion:
|
||||||
let success = winlean.gethostname(result, size)
|
let success = winlean.gethostname(result.cstring, size)
|
||||||
else:
|
else:
|
||||||
# Posix
|
# Posix
|
||||||
let success = posix.gethostname(result, size)
|
let success = posix.gethostname(result.cstring, size)
|
||||||
if success != 0.cint:
|
if success != 0.cint:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
let x = len(cstring(result))
|
let x = len(cstring(result))
|
||||||
|
|
|
||||||
|
|
@ -682,7 +682,7 @@ when defineSsl:
|
||||||
var found = false
|
var found = false
|
||||||
let useEnvVars = (if verifyMode == CVerifyPeerUseEnvVars: true else: false)
|
let useEnvVars = (if verifyMode == CVerifyPeerUseEnvVars: true else: false)
|
||||||
for fn in scanSSLCertificates(useEnvVars = useEnvVars):
|
for fn in scanSSLCertificates(useEnvVars = useEnvVars):
|
||||||
if newCTX.SSL_CTX_load_verify_locations(fn, nil) == VerifySuccess:
|
if newCTX.SSL_CTX_load_verify_locations(fn.cstring, nil) == VerifySuccess:
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
if not found:
|
if not found:
|
||||||
|
|
|
||||||
|
|
@ -1259,12 +1259,12 @@ proc findExe*(exe: string, followSymlinks: bool = true;
|
||||||
while followSymlinks: # doubles as if here
|
while followSymlinks: # doubles as if here
|
||||||
if x.symlinkExists:
|
if x.symlinkExists:
|
||||||
var r = newString(maxSymlinkLen)
|
var r = newString(maxSymlinkLen)
|
||||||
var len = readlink(x, r, maxSymlinkLen)
|
var len = readlink(x.cstring, r.cstring, maxSymlinkLen)
|
||||||
if len < 0:
|
if len < 0:
|
||||||
raiseOSError(osLastError(), exe)
|
raiseOSError(osLastError(), exe)
|
||||||
if len > maxSymlinkLen:
|
if len > maxSymlinkLen:
|
||||||
r = newString(len+1)
|
r = newString(len+1)
|
||||||
len = readlink(x, r, len)
|
len = readlink(x.cstring, r.cstring, len)
|
||||||
setLen(r, len)
|
setLen(r, len)
|
||||||
if isAbsolute(r):
|
if isAbsolute(r):
|
||||||
x = r
|
x = r
|
||||||
|
|
@ -1404,8 +1404,8 @@ when not defined(nimscript):
|
||||||
var bufsize = 1024 # should be enough
|
var bufsize = 1024 # should be enough
|
||||||
result = newString(bufsize)
|
result = newString(bufsize)
|
||||||
while true:
|
while true:
|
||||||
if getcwd(result, bufsize) != nil:
|
if getcwd(result.cstring, bufsize) != nil:
|
||||||
setLen(result, c_strlen(result))
|
setLen(result, c_strlen(result.cstring))
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
let err = osLastError()
|
let err = osLastError()
|
||||||
|
|
@ -1774,12 +1774,12 @@ proc expandSymlink*(symlinkPath: string): string {.noWeirdTarget.} =
|
||||||
result = symlinkPath
|
result = symlinkPath
|
||||||
else:
|
else:
|
||||||
result = newString(maxSymlinkLen)
|
result = newString(maxSymlinkLen)
|
||||||
var len = readlink(symlinkPath, result, maxSymlinkLen)
|
var len = readlink(symlinkPath, result.cstring, maxSymlinkLen)
|
||||||
if len < 0:
|
if len < 0:
|
||||||
raiseOSError(osLastError(), symlinkPath)
|
raiseOSError(osLastError(), symlinkPath)
|
||||||
if len > maxSymlinkLen:
|
if len > maxSymlinkLen:
|
||||||
result = newString(len+1)
|
result = newString(len+1)
|
||||||
len = readlink(symlinkPath, result, len)
|
len = readlink(symlinkPath, result.cstring, len)
|
||||||
setLen(result, len)
|
setLen(result, len)
|
||||||
|
|
||||||
const hasCCopyfile = defined(osx) and not defined(nimLegacyCopyFile)
|
const hasCCopyfile = defined(osx) and not defined(nimLegacyCopyFile)
|
||||||
|
|
@ -2344,7 +2344,7 @@ iterator walkDir*(dir: string; relative = false, checkDir = false):
|
||||||
var k = pcFile
|
var k = pcFile
|
||||||
|
|
||||||
template kSetGeneric() = # pure Posix component `k` resolution
|
template kSetGeneric() = # pure Posix component `k` resolution
|
||||||
if lstat(path, s) < 0'i32: continue # don't yield
|
if lstat(path.cstring, s) < 0'i32: continue # don't yield
|
||||||
elif S_ISDIR(s.st_mode):
|
elif S_ISDIR(s.st_mode):
|
||||||
k = pcDir
|
k = pcDir
|
||||||
elif S_ISLNK(s.st_mode):
|
elif S_ISLNK(s.st_mode):
|
||||||
|
|
@ -3041,10 +3041,10 @@ when not weirdTarget and (defined(freebsd) or defined(dragonfly) or defined(netb
|
||||||
when not weirdTarget and (defined(linux) or defined(solaris) or defined(bsd) or defined(aix)):
|
when not weirdTarget and (defined(linux) or defined(solaris) or defined(bsd) or defined(aix)):
|
||||||
proc getApplAux(procPath: string): string =
|
proc getApplAux(procPath: string): string =
|
||||||
result = newString(maxSymlinkLen)
|
result = newString(maxSymlinkLen)
|
||||||
var len = readlink(procPath, result, maxSymlinkLen)
|
var len = readlink(procPath, result.cstring, maxSymlinkLen)
|
||||||
if len > maxSymlinkLen:
|
if len > maxSymlinkLen:
|
||||||
result = newString(len+1)
|
result = newString(len+1)
|
||||||
len = readlink(procPath, result, len)
|
len = readlink(procPath, result.cstring, len)
|
||||||
setLen(result, len)
|
setLen(result, len)
|
||||||
|
|
||||||
when not weirdTarget and defined(openbsd):
|
when not weirdTarget and defined(openbsd):
|
||||||
|
|
@ -3169,7 +3169,7 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect], noW
|
||||||
var size = cuint32(0)
|
var size = cuint32(0)
|
||||||
getExecPath1(nil, size)
|
getExecPath1(nil, size)
|
||||||
result = newString(int(size))
|
result = newString(int(size))
|
||||||
if getExecPath2(result, size):
|
if getExecPath2(result.cstring, size):
|
||||||
result = "" # error!
|
result = "" # error!
|
||||||
if result.len > 0:
|
if result.len > 0:
|
||||||
result = result.expandFilename
|
result = result.expandFilename
|
||||||
|
|
|
||||||
|
|
@ -1086,9 +1086,9 @@ elif not defined(useNimRtl):
|
||||||
var pid: Pid
|
var pid: Pid
|
||||||
|
|
||||||
if (poUsePath in data.options):
|
if (poUsePath in data.options):
|
||||||
res = posix_spawnp(pid, data.sysCommand, fops, attr, data.sysArgs, data.sysEnv)
|
res = posix_spawnp(pid, data.sysCommand.cstring, fops, attr, data.sysArgs, data.sysEnv)
|
||||||
else:
|
else:
|
||||||
res = posix_spawn(pid, data.sysCommand, fops, attr, data.sysArgs, data.sysEnv)
|
res = posix_spawn(pid, data.sysCommand.cstring, fops, attr, data.sysArgs, data.sysEnv)
|
||||||
|
|
||||||
discard posix_spawn_file_actions_destroy(fops)
|
discard posix_spawn_file_actions_destroy(fops)
|
||||||
discard posix_spawnattr_destroy(attr)
|
discard posix_spawnattr_destroy(attr)
|
||||||
|
|
@ -1174,14 +1174,14 @@ elif not defined(useNimRtl):
|
||||||
when defined(uClibc) or defined(linux) or defined(haiku):
|
when defined(uClibc) or defined(linux) or defined(haiku):
|
||||||
# uClibc environment (OpenWrt included) doesn't have the full execvpe
|
# uClibc environment (OpenWrt included) doesn't have the full execvpe
|
||||||
let exe = findExe(data.sysCommand)
|
let exe = findExe(data.sysCommand)
|
||||||
discard execve(exe, data.sysArgs, data.sysEnv)
|
discard execve(exe.cstring, data.sysArgs, data.sysEnv)
|
||||||
else:
|
else:
|
||||||
# MacOSX doesn't have execvpe, so we need workaround.
|
# MacOSX doesn't have execvpe, so we need workaround.
|
||||||
# On MacOSX we can arrive here only from fork, so this is safe:
|
# On MacOSX we can arrive here only from fork, so this is safe:
|
||||||
environ = data.sysEnv
|
environ = data.sysEnv
|
||||||
discard execvp(data.sysCommand, data.sysArgs)
|
discard execvp(data.sysCommand.cstring, data.sysArgs)
|
||||||
else:
|
else:
|
||||||
discard execve(data.sysCommand, data.sysArgs, data.sysEnv)
|
discard execve(data.sysCommand.cstring, data.sysArgs, data.sysEnv)
|
||||||
|
|
||||||
startProcessFail(data)
|
startProcessFail(data)
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ proc parseString(my: var JsonParser): TokKind =
|
||||||
add(my.a, 'u')
|
add(my.a, 'u')
|
||||||
inc(pos, 2)
|
inc(pos, 2)
|
||||||
var pos2 = pos
|
var pos2 = pos
|
||||||
var r = parseEscapedUTF16(my.buf, pos)
|
var r = parseEscapedUTF16(cstring(my.buf), pos)
|
||||||
if r < 0:
|
if r < 0:
|
||||||
my.err = errInvalidToken
|
my.err = errInvalidToken
|
||||||
break
|
break
|
||||||
|
|
@ -231,7 +231,7 @@ proc parseString(my: var JsonParser): TokKind =
|
||||||
my.err = errInvalidToken
|
my.err = errInvalidToken
|
||||||
break
|
break
|
||||||
inc(pos, 2)
|
inc(pos, 2)
|
||||||
var s = parseEscapedUTF16(my.buf, pos)
|
var s = parseEscapedUTF16(cstring(my.buf), pos)
|
||||||
if (s and 0xfc00) == 0xdc00 and s > 0:
|
if (s and 0xfc00) == 0xdc00 and s > 0:
|
||||||
r = 0x10000 + (((r - 0xd800) shl 10) or (s - 0xdc00))
|
r = 0x10000 + (((r - 0xd800) shl 10) or (s - 0xdc00))
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -56,16 +56,16 @@ proc processContent(content: string) =
|
||||||
var officialPkgListDiv = document.getElementById("officialPkgList")
|
var officialPkgListDiv = document.getElementById("officialPkgList")
|
||||||
|
|
||||||
officialPkgListDiv.innerHTML =
|
officialPkgListDiv.innerHTML =
|
||||||
p("There are currently " & $officialCount &
|
(p("There are currently " & $officialCount &
|
||||||
" official packages in the Nimble package repository.") &
|
" official packages in the Nimble package repository.") &
|
||||||
ul(officialList)
|
ul(officialList)).cstring
|
||||||
|
|
||||||
var unofficialPkgListDiv = document.getElementById("unofficialPkgList")
|
var unofficialPkgListDiv = document.getElementById("unofficialPkgList")
|
||||||
|
|
||||||
unofficialPkgListDiv.innerHTML =
|
unofficialPkgListDiv.innerHTML =
|
||||||
p("There are currently " & $unofficialCount &
|
(p("There are currently " & $unofficialCount &
|
||||||
" unofficial packages in the Nimble package repository.") &
|
" unofficial packages in the Nimble package repository.") &
|
||||||
ul(unofficialList)
|
ul(unofficialList)).cstring
|
||||||
|
|
||||||
proc gotPackageList(apiReply: TData) {.exportc.} =
|
proc gotPackageList(apiReply: TData) {.exportc.} =
|
||||||
let decoded = decodeContent($apiReply.content)
|
let decoded = decodeContent($apiReply.content)
|
||||||
|
|
@ -76,5 +76,5 @@ proc gotPackageList(apiReply: TData) {.exportc.} =
|
||||||
var unofficialPkgListDiv = document.getElementById("unofficialPkgList")
|
var unofficialPkgListDiv = document.getElementById("unofficialPkgList")
|
||||||
let msg = p("Unable to retrieve package list: ",
|
let msg = p("Unable to retrieve package list: ",
|
||||||
code(getCurrentExceptionMsg()))
|
code(getCurrentExceptionMsg()))
|
||||||
officialPkgListDiv.innerHTML = msg
|
officialPkgListDiv.innerHTML = msg.cstring
|
||||||
unofficialPkgListDiv.innerHTML = msg
|
unofficialPkgListDiv.innerHTML = msg.cstring
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue