Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
cf4bf9b5
Commit
cf4bf9b5
authored
Jan 16, 2018
by
Alex Henrie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite documentation paragraph on automatic string encoding for clarity
parent
5d3a1346
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
docs/src/tutorial/strings.rst
docs/src/tutorial/strings.rst
+9
-9
No files found.
docs/src/tutorial/strings.rst
View file @
cf4bf9b5
...
@@ -528,15 +528,15 @@ string type to :obj:`str`::
...
@@ -528,15 +528,15 @@ string type to :obj:`str`::
py_bytes_object = <unicode>c_string
py_bytes_object = <unicode>c_string
The other direction, i.e. automatic encoding to C strings, is only
The other direction, i.e. automatic encoding to C strings, is only
supported for
the ASCII codec (and the "default encoding", which is
supported for
ASCII and the "default encoding", which is usually UTF-8
runtime specific and may or may not be ASCII). This is because
in Python 3 and usually ASCII in Python 2. CPython handles the memory
CPython handles the memory management in this case by keeping an
management in this case by keeping an encoded copy of the string alive
encoded copy of the string alive together with the original unicode
together with the original unicode string. Otherwise, there would be no
string. Otherwise, there would be no way to limit the lifetime of
way to limit the lifetime of the encoded string in any sensible way,
th
e encoded string in any sensible way, thus rendering any attempt to
th
us rendering any attempt to extract a C string pointer from it a
extract a C string pointer from it a dangerous endeavour. As long
dangerous endeavour. The following safely converts a Unicode string to
as you stick to the ASCII encoding for the ``c_string_encoding``
ASCII (change ``c_string_encoding`` to ``default`` to use the default
directive, though, the following will work
::
encoding instead)
::
# cython: c_string_type=unicode, c_string_encoding=ascii
# cython: c_string_type=unicode, c_string_encoding=ascii
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment