Commit 565431cc authored by scoder's avatar scoder

Merge pull request #276 from kmike/fix-strings-tutorial

fix deprecated imports in "Unicode and passing strings" tutorial
parents 120fe47b ecca40fe
......@@ -139,13 +139,13 @@ exception, e.g. due to insufficient memory. If you need to
:c:func:`free()` the string after the conversion, you should wrap
the assignment in a try-finally construct::
cimport stdlib
from libc.stdlib cimport free
cdef bytes py_string
cdef char* c_string = c_call_creating_a_new_c_string()
try:
py_string = c_string
finally:
stdlib.free(c_string)
free(c_string)
To convert the byte string back into a C :c:type:`char*`, use the
opposite assignment::
......@@ -376,8 +376,7 @@ conversions in general) in dedicated functions, as this needs to be
done in exactly the same way whenever receiving text from C. This
could look as follows::
cimport python_unicode
cimport stdlib
from libc.stdlib cimport free
cdef unicode tounicode(char* s):
return s.decode('UTF-8', 'strict')
......@@ -391,7 +390,7 @@ could look as follows::
try:
return s[:length].decode('UTF-8', 'strict')
finally:
stdlib.free(s)
free(s)
Most likely, you will prefer shorter function names in your code based
on the kind of string being handled. Different types of content often
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment