From 2ad6b9672c0522c2ae7391c26566ee94dcf0c77a Mon Sep 17 00:00:00 2001 From: flywind Date: Sat, 7 Nov 2020 23:18:18 +0800 Subject: [PATCH 01/14] follow #8463 #14157 and document cstring literals --- doc/manual.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/manual.rst b/doc/manual.rst index d9f9cc9b9670..cbfc64d27532 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,6 +1282,13 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr +You shouldn't modify cstring literals. Otherwise unexpected situations may happen. + +.. code-block:: nim + # this is wrong!!! + var x = cstring"literals" + x[1] = 'A' + Structured types ---------------- A variable of a structured type can hold multiple values at the same From 31d379a4ec4e4c2666642bfae657562e7c41f77b Mon Sep 17 00:00:00 2001 From: flywind Date: Sun, 8 Nov 2020 11:11:07 +0800 Subject: [PATCH 02/14] Thanks for timotheecour's advice --- doc/manual.rst | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/doc/manual.rst b/doc/manual.rst index cbfc64d27532..57dfa9ad26c6 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,12 +1282,18 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr -You shouldn't modify cstring literals. Otherwise unexpected situations may happen. +In C backend You shouldn't modify cstring literals. Otherwise your program will crash. .. code-block:: nim - # this is wrong!!! var x = cstring"literals" - x[1] = 'A' + x[1] = 'A' # This is wrong!!! + +cstring could be modified if it originates from a regular memory(not read-only memory): + +.. code-block:: nim + var x = "123456" + var s: cstring = x + s[0] = 'u' # This is ok Structured types ---------------- From 59b4d964fc7febd8bf55b1a01b9a68771ac75714 Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 10 Nov 2020 23:19:58 +0800 Subject: [PATCH 03/14] begin --- doc/manual.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index 57dfa9ad26c6..56a3ca5b9bf6 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,7 +1282,7 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr -In C backend You shouldn't modify cstring literals. Otherwise your program will crash. +In C backend, cstring literals shouldn't be modified. Otherwise the program will crash. .. code-block:: nim var x = cstring"literals" From 9acf6d5d22377b0197e50b82ce1613d6ccd3ce53 Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 10 Nov 2020 23:22:40 +0800 Subject: [PATCH 04/14] minor --- doc/manual.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/manual.rst b/doc/manual.rst index 56a3ca5b9bf6..f9b49bcc424b 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,13 +1282,13 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr -In C backend, cstring literals shouldn't be modified. Otherwise the program will crash. +In C backend, cstring literals shouldn't be modified. Otherwise the program will crash: .. code-block:: nim var x = cstring"literals" x[1] = 'A' # This is wrong!!! -cstring could be modified if it originates from a regular memory(not read-only memory): +If cstring originates from a regular memory(not read-only memory), it could be modified: .. code-block:: nim var x = "123456" From 28889f616f49502c0451d9aa51efad0a7e363445 Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 10 Nov 2020 23:26:24 +0800 Subject: [PATCH 05/14] segmentation fault --- doc/manual.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index f9b49bcc424b..c319ba6e4af4 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,7 +1282,7 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr -In C backend, cstring literals shouldn't be modified. Otherwise the program will crash: +In C backend, cstring literals shouldn't be modified. Otherwise it will cause segmentation fault: .. code-block:: nim var x = cstring"literals" From 41064f96198880e967c99bcdaf4c31873760f9fe Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 10 Nov 2020 23:29:10 +0800 Subject: [PATCH 06/14] minor --- doc/manual.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/manual.rst b/doc/manual.rst index c319ba6e4af4..2ae1bd1974f1 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,13 +1282,13 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr -In C backend, cstring literals shouldn't be modified. Otherwise it will cause segmentation fault: +In C backend, ``cstring`` literals shouldn't be modified. Otherwise it will cause segmentation fault: .. code-block:: nim var x = cstring"literals" x[1] = 'A' # This is wrong!!! -If cstring originates from a regular memory(not read-only memory), it could be modified: +If ``cstring`` originates from a regular memory(not read-only memory), it could be modified: .. code-block:: nim var x = "123456" From d67a5f970235133a6962194f6079cefabaf1d43e Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 10 Nov 2020 23:30:13 +0800 Subject: [PATCH 07/14] minor --- doc/manual.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index 2ae1bd1974f1..431fa30616b7 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,7 +1282,7 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr -In C backend, ``cstring`` literals shouldn't be modified. Otherwise it will cause segmentation fault: +For the C C backend, ``cstring`` literals shouldn't be modified. Otherwise it will cause segmentation fault: .. code-block:: nim var x = cstring"literals" From 1197bcb33a4a00d057701350cd546c51c41bf9e8 Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 10 Nov 2020 23:30:20 +0800 Subject: [PATCH 08/14] minor --- doc/manual.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index 431fa30616b7..a7fe42e6d7e6 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,7 +1282,7 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr -For the C C backend, ``cstring`` literals shouldn't be modified. Otherwise it will cause segmentation fault: +For the C backend, ``cstring`` literals shouldn't be modified. Otherwise it will cause segmentation fault: .. code-block:: nim var x = cstring"literals" From 03588793723f54a5d90bb3f4ac4843c1bb4da200 Mon Sep 17 00:00:00 2001 From: flywind Date: Tue, 10 Nov 2020 23:31:36 +0800 Subject: [PATCH 09/14] minor --- doc/manual.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/manual.rst b/doc/manual.rst index a7fe42e6d7e6..bff6363ac3cb 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,13 +1282,15 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr -For the C backend, ``cstring`` literals shouldn't be modified. Otherwise it will cause segmentation fault: +For the C backend, ``cstring`` literals shouldn't be modified. +Otherwise it will cause segmentation fault: .. code-block:: nim var x = cstring"literals" x[1] = 'A' # This is wrong!!! -If ``cstring`` originates from a regular memory(not read-only memory), it could be modified: +If ``cstring`` originates from a regular memory(not read-only memory), +it could be modified: .. code-block:: nim var x = "123456" From b1f25d9cb49975172b879bb9d7114dc27002c4a7 Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Wed, 11 Nov 2020 09:26:01 +0800 Subject: [PATCH 10/14] Update doc/manual.rst Co-authored-by: Juan Carlos --- doc/manual.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index bff6363ac3cb..46727ef0d53e 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1289,7 +1289,7 @@ Otherwise it will cause segmentation fault: var x = cstring"literals" x[1] = 'A' # This is wrong!!! -If ``cstring`` originates from a regular memory(not read-only memory), +If the ``cstring`` originates from a regular memory (not read-only memory), it could be modified: .. code-block:: nim From 2c96ef6924180be18b86998d62828d9832666acc Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Thu, 12 Nov 2020 18:18:00 +0800 Subject: [PATCH 11/14] Update doc/manual.rst --- doc/manual.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index 46727ef0d53e..88cdeb0419fa 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,7 +1282,7 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr -For the C backend, ``cstring`` literals shouldn't be modified. +For the C/C++ backend, ``cstring`` literals shouldn't be modified. Otherwise it will cause segmentation fault: .. code-block:: nim From dad3d5f81230a5c0dc4c1074840d603f67755d1a Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 12 Nov 2020 14:34:12 +0100 Subject: [PATCH 12/14] Update doc/manual.rst --- doc/manual.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index 88cdeb0419fa..32cd7de7fad5 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1283,7 +1283,6 @@ string from a cstring: var newstr: string = $cstr For the C/C++ backend, ``cstring`` literals shouldn't be modified. -Otherwise it will cause segmentation fault: .. code-block:: nim var x = cstring"literals" From b72cdcdfa8d23528b18c9824436580bffd5a11fb Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 12 Nov 2020 14:34:18 +0100 Subject: [PATCH 13/14] Update doc/manual.rst --- doc/manual.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index 32cd7de7fad5..41bd827f1c3b 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1282,7 +1282,7 @@ string from a cstring: var cstr: cstring = str var newstr: string = $cstr -For the C/C++ backend, ``cstring`` literals shouldn't be modified. +``cstring`` literals shouldn't be modified. .. code-block:: nim var x = cstring"literals" From 82ef01113c5ee9e4f219c8de30f8182e86f7423f Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 12 Nov 2020 14:34:37 +0100 Subject: [PATCH 14/14] Update doc/manual.rst --- doc/manual.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual.rst b/doc/manual.rst index 41bd827f1c3b..f8d8abbc85e2 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -1289,7 +1289,7 @@ string from a cstring: x[1] = 'A' # This is wrong!!! If the ``cstring`` originates from a regular memory (not read-only memory), -it could be modified: +it can be modified: .. code-block:: nim var x = "123456"