summary refs log tree commit diff stats
path: root/lib/impure/db_odbc.nim
diff options
context:
space:
mode:
authoree7 <45465154+ee7@users.noreply.github.com>2022-08-19 21:40:53 +0200
committerGitHub <noreply@github.com>2022-08-19 15:40:53 -0400
commite8657c7107761fae7a8b5559df3b88165c238a12 (patch)
treeba65f39bf4fd3dd14fb9f695d4d6c01aa9c37ae2 /lib/impure/db_odbc.nim
parent7fe6dedb623b9bc781df9e68b53e354c73034090 (diff)
downloadNim-e8657c7107761fae7a8b5559df3b88165c238a12.tar.gz
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] https://github.com/nim-lang/Nim/blob/d2318d9ccfe6/doc/manual.md#cstring-type
[2] https://github.com/nim-lang/Nim/blob/d2318d9ccfe6/changelogs/changelog_1_6_0.md#type-system
Diffstat (limited to 'lib/impure/db_odbc.nim')
-rw-r--r--lib/impure/db_odbc.nim2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/impure/db_odbc.nim b/lib/impure/db_odbc.nim
index 1e4032b34..0ecd8129f 100644
--- a/lib/impure/db_odbc.nim
+++ b/lib/impure/db_odbc.nim
@@ -334,7 +334,7 @@ proc `[]`*(row: InstantRow, col: int): string {.inline.} =
 
 proc unsafeColumnAt*(row: InstantRow, index: int): cstring {.inline.} =
   ## Return cstring of given column of the row
-  row.row[index]
+  row.row[index].cstring
 
 proc len*(row: InstantRow): int {.inline.} =
   ## Returns number of columns in the row
#4485; package handling works better; docgen works with --project on Nimble package level' href='/ahoang/Nim/commit/compiler/packagehandling.nim?h=devel&id=9eb909baf985b8f6d2b8bc55fee8e67744e9b6fe'>9eb909baf ^
64517445e ^

9eb909baf ^

7eb39d9d2 ^
9eb909baf ^


7ec7731f8 ^




0121dda9b ^
378289c6a ^


5783cd67a ^
378289c6a ^
0121dda9b ^
ddad57e7a ^
657e09e79 ^
7804b5c55 ^
86556ebfd ^

832b0a023 ^



9eb909baf ^
832b0a023 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61