diff --git a/CHANGES.rst b/CHANGES.rst index d34245e6046992c35553606e4f774f723ac6eda7..e05a5f6b766c8a6d39f9d4a05ceb4c2620cb8adb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -22,6 +22,9 @@ Features added * Keyword arguments are supported for cdef functions. +* Added c_string_type and c_string_encoding directives to more easily convert between + Python and C strings. + Bugs fixed ---------- diff --git a/docs/src/reference/compilation.rst b/docs/src/reference/compilation.rst index e3862777a6fbf25b34d41553962145ac1ebfff6d..71e81bfd5bebf3dc808db2e28909f87cae47278d 100644 --- a/docs/src/reference/compilation.rst +++ b/docs/src/reference/compilation.rst @@ -208,6 +208,15 @@ Cython code. Here is the list of currently supported directives: setting from the module being compiled, unless they explicitly set their own language level. +``c_string_type`` (bytes / str / unicode) + Globally set the type of an implicit coercion from char* or std::string. + +``c_string_encoding`` (ascii, default, utf-8, etc.) + Globally set the encoding to use when implicitly coercing char* or std:string + to a unicode object. Coercion from a unicode object to C type is only allowed + when set to ``ascii`` or ``default``, the latter being utf-8 in Python 3 and + nearly-always ascii in Python 2. + How to set directives --------------------- diff --git a/docs/src/tutorial/strings.rst b/docs/src/tutorial/strings.rst index 25c5346754a1c4e46f5d2496a735d15c7a2e26c6..a3e82dfbd46fe01be1b890321c8a059f8a5f68e0 100644 --- a/docs/src/tutorial/strings.rst +++ b/docs/src/tutorial/strings.rst @@ -5,10 +5,12 @@ Unicode and passing strings Similar to the string semantics in Python 3, Cython also strictly separates byte strings and unicode strings. Above all, this means -that there is no automatic conversion between byte strings and unicode -strings (except for what Python 2 does in string operations). All -encoding and decoding must pass through an explicit encoding/decoding -step. +that by default there is no automatic conversion between byte strings +and unicode strings (except for what Python 2 does in string operations). +All encoding and decoding must pass through an explicit encoding/decoding +step. For simple cases, the module-level ``c_string_type`` and +``c_string_encoding`` directives can be used to implicitly insert these +encoding/decoding steps to ease conversion between Python and C strings. General notes about C strings -----------------------------