Commit f372acae authored by Mikhail Korobov's avatar Mikhail Korobov

DOC fix deprecated imports in "Unicode and passing strings" tutorial

parent 120fe47b
...@@ -139,13 +139,13 @@ exception, e.g. due to insufficient memory. If you need to ...@@ -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 :c:func:`free()` the string after the conversion, you should wrap
the assignment in a try-finally construct:: the assignment in a try-finally construct::
cimport stdlib from libc.stdlib cimport free
cdef bytes py_string cdef bytes py_string
cdef char* c_string = c_call_creating_a_new_c_string() cdef char* c_string = c_call_creating_a_new_c_string()
try: try:
py_string = c_string py_string = c_string
finally: finally:
stdlib.free(c_string) free(c_string)
To convert the byte string back into a C :c:type:`char*`, use the To convert the byte string back into a C :c:type:`char*`, use the
opposite assignment:: opposite assignment::
...@@ -376,8 +376,7 @@ conversions in general) in dedicated functions, as this needs to be ...@@ -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 done in exactly the same way whenever receiving text from C. This
could look as follows:: could look as follows::
cimport python_unicode from libc.stdlib cimport free
cimport stdlib
cdef unicode tounicode(char* s): cdef unicode tounicode(char* s):
return s.decode('UTF-8', 'strict') return s.decode('UTF-8', 'strict')
...@@ -811,7 +810,7 @@ Here is an example of how one would call a Unicode API on Windows:: ...@@ -811,7 +810,7 @@ Here is an example of how one would call a Unicode API on Windows::
ctypedef const WCHAR* LPCWSTR ctypedef const WCHAR* LPCWSTR
ctypedef void* HWND ctypedef void* HWND
int MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, int uType) int MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, int uType)
title = u"Windows Interop Demo - Python %d.%d.%d" % sys.version_info[:3] title = u"Windows Interop Demo - Python %d.%d.%d" % sys.version_info[:3]
MessageBoxW(NULL, u"Hello Cython \u263a", title, 0) MessageBoxW(NULL, u"Hello Cython \u263a", title, 0)
......
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