1265 lines · 43.8 KB · C
RawDownload
#ifndef Py_UNICODEOBJECT_H#define Py_UNICODEOBJECT_H /* Unicode implementation based on original code by Fredrik Lundh,modified by Marc-Andre Lemburg (mal@lemburg.com) according to theUnicode Integration Proposal (see file Misc/unicode.txt). Copyright (c) Corporation for National Research Initiatives.   Original header: --------------------------------------------------------------------  * Yet another Unicode string type for Python.  This type supports the * 16-bit Basic Multilingual Plane (BMP) only. * * Written by Fredrik Lundh, January 1999. * * Copyright (c) 1999 by Secret Labs AB. * Copyright (c) 1999 by Fredrik Lundh. * * fredrik@pythonware.com * http://www.pythonware.com * * -------------------------------------------------------------------- * This Unicode String Type is *  * Copyright (c) 1999 by Secret Labs AB * Copyright (c) 1999 by Fredrik Lundh *  * By obtaining, using, and/or copying this software and/or its * associated documentation, you agree that you have read, understood, * and will comply with the following terms and conditions: *  * Permission to use, copy, modify, and distribute this software and its * associated documentation for any purpose and without fee is hereby * granted, provided that the above copyright notice appears in all * copies, and that both that copyright notice and this permission notice * appear in supporting documentation, and that the name of Secret Labs * AB or the author not be used in advertising or publicity pertaining to * distribution of the software without specific, written prior * permission. *  * SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS.  IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * -------------------------------------------------------------------- */ #include <ctype.h> /* === Internal API ======================================================= */ /* --- Internal Unicode Format -------------------------------------------- */ #ifndef Py_USING_UNICODE #define PyUnicode_Check(op)                 0#define PyUnicode_CheckExact(op)            0 #else /* FIXME: MvL's new implementation assumes that Py_UNICODE_SIZE is   properly set, but the default rules below doesn't set it.  I'll   sort this out some other day -- fredrik@pythonware.com */ #ifndef Py_UNICODE_SIZE#error Must define Py_UNICODE_SIZE#endif /* Setting Py_UNICODE_WIDE enables UCS-4 storage.  Otherwise, Unicode   strings are stored as UCS-2 (with limited support for UTF-16) */ #if Py_UNICODE_SIZE >= 4#define Py_UNICODE_WIDE#endif /* Set these flags if the platform has "wchar.h", "wctype.h" and the   wchar_t type is a 16-bit unsigned type *//* #define HAVE_WCHAR_H *//* #define HAVE_USABLE_WCHAR_T */ /* Defaults for various platforms */#ifndef PY_UNICODE_TYPE /* Windows has a usable wchar_t type (unless we're using UCS-4) */# if defined(MS_WIN32) && Py_UNICODE_SIZE == 2#  define HAVE_USABLE_WCHAR_T#  define PY_UNICODE_TYPE wchar_t# endif # if defined(Py_UNICODE_WIDE)#  define PY_UNICODE_TYPE Py_UCS4# endif #endif /* If the compiler provides a wchar_t type we try to support it   through the interface functions PyUnicode_FromWideChar() and   PyUnicode_AsWideChar(). */ #ifdef HAVE_USABLE_WCHAR_T# ifndef HAVE_WCHAR_H#  define HAVE_WCHAR_H# endif#endif #ifdef HAVE_WCHAR_H/* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */# ifdef _HAVE_BSDI#  include <time.h># endif#  include <wchar.h>#endif /* * Use this typedef when you need to represent a UTF-16 surrogate pair * as single unsigned integer. */#if SIZEOF_INT >= 4 typedef unsigned int Py_UCS4; #elif SIZEOF_LONG >= 4typedef unsigned long Py_UCS4; #endif typedef PY_UNICODE_TYPE Py_UNICODE; /* --- UCS-2/UCS-4 Name Mangling ------------------------------------------ */ /* Unicode API names are mangled to assure that UCS-2 and UCS-4 builds   produce different external names and thus cause import errors in   case Python interpreters and extensions with mixed compiled in   Unicode width assumptions are combined. */ #ifndef Py_UNICODE_WIDE # define PyUnicode_AsASCIIString PyUnicodeUCS2_AsASCIIString# define PyUnicode_AsCharmapString PyUnicodeUCS2_AsCharmapString# define PyUnicode_AsEncodedObject PyUnicodeUCS2_AsEncodedObject# define PyUnicode_AsEncodedString PyUnicodeUCS2_AsEncodedString# define PyUnicode_AsLatin1String PyUnicodeUCS2_AsLatin1String# define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS2_AsRawUnicodeEscapeString# define PyUnicode_AsUTF16String PyUnicodeUCS2_AsUTF16String# define PyUnicode_AsUTF8String PyUnicodeUCS2_AsUTF8String# define PyUnicode_AsUnicode PyUnicodeUCS2_AsUnicode# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS2_AsUnicodeEscapeString# define PyUnicode_AsWideChar PyUnicodeUCS2_AsWideChar# define PyUnicode_Compare PyUnicodeUCS2_Compare# define PyUnicode_Concat PyUnicodeUCS2_Concat# define PyUnicode_Contains PyUnicodeUCS2_Contains# define PyUnicode_Count PyUnicodeUCS2_Count# define PyUnicode_Decode PyUnicodeUCS2_Decode# define PyUnicode_DecodeASCII PyUnicodeUCS2_DecodeASCII# define PyUnicode_DecodeCharmap PyUnicodeUCS2_DecodeCharmap# define PyUnicode_DecodeLatin1 PyUnicodeUCS2_DecodeLatin1# define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS2_DecodeRawUnicodeEscape# define PyUnicode_DecodeUTF16 PyUnicodeUCS2_DecodeUTF16# define PyUnicode_DecodeUTF16Stateful PyUnicodeUCS2_DecodeUTF16Stateful# define PyUnicode_DecodeUTF8 PyUnicodeUCS2_DecodeUTF8# define PyUnicode_DecodeUTF8Stateful PyUnicodeUCS2_DecodeUTF8Stateful# define PyUnicode_DecodeUnicodeEscape PyUnicodeUCS2_DecodeUnicodeEscape# define PyUnicode_Encode PyUnicodeUCS2_Encode# define PyUnicode_EncodeASCII PyUnicodeUCS2_EncodeASCII# define PyUnicode_EncodeCharmap PyUnicodeUCS2_EncodeCharmap# define PyUnicode_EncodeDecimal PyUnicodeUCS2_EncodeDecimal# define PyUnicode_EncodeLatin1 PyUnicodeUCS2_EncodeLatin1# define PyUnicode_EncodeRawUnicodeEscape PyUnicodeUCS2_EncodeRawUnicodeEscape# define PyUnicode_EncodeUTF16 PyUnicodeUCS2_EncodeUTF16# define PyUnicode_EncodeUTF8 PyUnicodeUCS2_EncodeUTF8# define PyUnicode_EncodeUnicodeEscape PyUnicodeUCS2_EncodeUnicodeEscape# define PyUnicode_Find PyUnicodeUCS2_Find# define PyUnicode_Format PyUnicodeUCS2_Format# define PyUnicode_FromEncodedObject PyUnicodeUCS2_FromEncodedObject# define PyUnicode_FromObject PyUnicodeUCS2_FromObject# define PyUnicode_FromOrdinal PyUnicodeUCS2_FromOrdinal# define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode# define PyUnicode_FromWideChar PyUnicodeUCS2_FromWideChar# define PyUnicode_GetDefaultEncoding PyUnicodeUCS2_GetDefaultEncoding# define PyUnicode_GetMax PyUnicodeUCS2_GetMax# define PyUnicode_GetSize PyUnicodeUCS2_GetSize# define PyUnicode_Join PyUnicodeUCS2_Join# define PyUnicode_Partition PyUnicodeUCS2_Partition# define PyUnicode_RPartition PyUnicodeUCS2_RPartition# define PyUnicode_RSplit PyUnicodeUCS2_RSplit# define PyUnicode_Replace PyUnicodeUCS2_Replace# define PyUnicode_Resize PyUnicodeUCS2_Resize# define PyUnicode_RichCompare PyUnicodeUCS2_RichCompare# define PyUnicode_SetDefaultEncoding PyUnicodeUCS2_SetDefaultEncoding# define PyUnicode_Split PyUnicodeUCS2_Split# define PyUnicode_Splitlines PyUnicodeUCS2_Splitlines# define PyUnicode_Tailmatch PyUnicodeUCS2_Tailmatch# define PyUnicode_Translate PyUnicodeUCS2_Translate# define PyUnicode_TranslateCharmap PyUnicodeUCS2_TranslateCharmap# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString# define _PyUnicode_Fini _PyUnicodeUCS2_Fini# define _PyUnicode_Init _PyUnicodeUCS2_Init# define _PyUnicode_IsAlpha _PyUnicodeUCS2_IsAlpha# define _PyUnicode_IsDecimalDigit _PyUnicodeUCS2_IsDecimalDigit# define _PyUnicode_IsDigit _PyUnicodeUCS2_IsDigit# define _PyUnicode_IsLinebreak _PyUnicodeUCS2_IsLinebreak# define _PyUnicode_IsLowercase _PyUnicodeUCS2_IsLowercase# define _PyUnicode_IsNumeric _PyUnicodeUCS2_IsNumeric# define _PyUnicode_IsTitlecase _PyUnicodeUCS2_IsTitlecase# define _PyUnicode_IsUppercase _PyUnicodeUCS2_IsUppercase# define _PyUnicode_IsWhitespace _PyUnicodeUCS2_IsWhitespace# define _PyUnicode_ToDecimalDigit _PyUnicodeUCS2_ToDecimalDigit# define _PyUnicode_ToDigit _PyUnicodeUCS2_ToDigit# define _PyUnicode_ToLowercase _PyUnicodeUCS2_ToLowercase# define _PyUnicode_ToNumeric _PyUnicodeUCS2_ToNumeric# define _PyUnicode_ToTitlecase _PyUnicodeUCS2_ToTitlecase# define _PyUnicode_ToUppercase _PyUnicodeUCS2_ToUppercase #else # define PyUnicode_AsASCIIString PyUnicodeUCS4_AsASCIIString# define PyUnicode_AsCharmapString PyUnicodeUCS4_AsCharmapString# define PyUnicode_AsEncodedObject PyUnicodeUCS4_AsEncodedObject# define PyUnicode_AsEncodedString PyUnicodeUCS4_AsEncodedString# define PyUnicode_AsLatin1String PyUnicodeUCS4_AsLatin1String# define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS4_AsRawUnicodeEscapeString# define PyUnicode_AsUTF16String PyUnicodeUCS4_AsUTF16String# define PyUnicode_AsUTF8String PyUnicodeUCS4_AsUTF8String# define PyUnicode_AsUnicode PyUnicodeUCS4_AsUnicode# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS4_AsUnicodeEscapeString# define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar# define PyUnicode_Compare PyUnicodeUCS4_Compare# define PyUnicode_Concat PyUnicodeUCS4_Concat# define PyUnicode_Contains PyUnicodeUCS4_Contains# define PyUnicode_Count PyUnicodeUCS4_Count# define PyUnicode_Decode PyUnicodeUCS4_Decode# define PyUnicode_DecodeASCII PyUnicodeUCS4_DecodeASCII# define PyUnicode_DecodeCharmap PyUnicodeUCS4_DecodeCharmap# define PyUnicode_DecodeLatin1 PyUnicodeUCS4_DecodeLatin1# define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS4_DecodeRawUnicodeEscape# define PyUnicode_DecodeUTF16 PyUnicodeUCS4_DecodeUTF16# define PyUnicode_DecodeUTF16Stateful PyUnicodeUCS4_DecodeUTF16Stateful# define PyUnicode_DecodeUTF8 PyUnicodeUCS4_DecodeUTF8# define PyUnicode_DecodeUTF8Stateful PyUnicodeUCS4_DecodeUTF8Stateful# define PyUnicode_DecodeUnicodeEscape PyUnicodeUCS4_DecodeUnicodeEscape# define PyUnicode_Encode PyUnicodeUCS4_Encode# define PyUnicode_EncodeASCII PyUnicodeUCS4_EncodeASCII# define PyUnicode_EncodeCharmap PyUnicodeUCS4_EncodeCharmap# define PyUnicode_EncodeDecimal PyUnicodeUCS4_EncodeDecimal# define PyUnicode_EncodeLatin1 PyUnicodeUCS4_EncodeLatin1# define PyUnicode_EncodeRawUnicodeEscape PyUnicodeUCS4_EncodeRawUnicodeEscape# define PyUnicode_EncodeUTF16 PyUnicodeUCS4_EncodeUTF16# define PyUnicode_EncodeUTF8 PyUnicodeUCS4_EncodeUTF8# define PyUnicode_EncodeUnicodeEscape PyUnicodeUCS4_EncodeUnicodeEscape# define PyUnicode_Find PyUnicodeUCS4_Find# define PyUnicode_Format PyUnicodeUCS4_Format# define PyUnicode_FromEncodedObject PyUnicodeUCS4_FromEncodedObject# define PyUnicode_FromObject PyUnicodeUCS4_FromObject# define PyUnicode_FromOrdinal PyUnicodeUCS4_FromOrdinal# define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode# define PyUnicode_FromWideChar PyUnicodeUCS4_FromWideChar# define PyUnicode_GetDefaultEncoding PyUnicodeUCS4_GetDefaultEncoding# define PyUnicode_GetMax PyUnicodeUCS4_GetMax# define PyUnicode_GetSize PyUnicodeUCS4_GetSize# define PyUnicode_Join PyUnicodeUCS4_Join# define PyUnicode_Partition PyUnicodeUCS4_Partition# define PyUnicode_RPartition PyUnicodeUCS4_RPartition# define PyUnicode_RSplit PyUnicodeUCS4_RSplit# define PyUnicode_Replace PyUnicodeUCS4_Replace# define PyUnicode_Resize PyUnicodeUCS4_Resize# define PyUnicode_RichCompare PyUnicodeUCS4_RichCompare# define PyUnicode_SetDefaultEncoding PyUnicodeUCS4_SetDefaultEncoding# define PyUnicode_Split PyUnicodeUCS4_Split# define PyUnicode_Splitlines PyUnicodeUCS4_Splitlines# define PyUnicode_Tailmatch PyUnicodeUCS4_Tailmatch# define PyUnicode_Translate PyUnicodeUCS4_Translate# define PyUnicode_TranslateCharmap PyUnicodeUCS4_TranslateCharmap# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString# define _PyUnicode_Fini _PyUnicodeUCS4_Fini# define _PyUnicode_Init _PyUnicodeUCS4_Init# define _PyUnicode_IsAlpha _PyUnicodeUCS4_IsAlpha# define _PyUnicode_IsDecimalDigit _PyUnicodeUCS4_IsDecimalDigit# define _PyUnicode_IsDigit _PyUnicodeUCS4_IsDigit# define _PyUnicode_IsLinebreak _PyUnicodeUCS4_IsLinebreak# define _PyUnicode_IsLowercase _PyUnicodeUCS4_IsLowercase# define _PyUnicode_IsNumeric _PyUnicodeUCS4_IsNumeric# define _PyUnicode_IsTitlecase _PyUnicodeUCS4_IsTitlecase# define _PyUnicode_IsUppercase _PyUnicodeUCS4_IsUppercase# define _PyUnicode_IsWhitespace _PyUnicodeUCS4_IsWhitespace# define _PyUnicode_ToDecimalDigit _PyUnicodeUCS4_ToDecimalDigit# define _PyUnicode_ToDigit _PyUnicodeUCS4_ToDigit# define _PyUnicode_ToLowercase _PyUnicodeUCS4_ToLowercase# define _PyUnicode_ToNumeric _PyUnicodeUCS4_ToNumeric# define _PyUnicode_ToTitlecase _PyUnicodeUCS4_ToTitlecase# define _PyUnicode_ToUppercase _PyUnicodeUCS4_ToUppercase  #endif /* --- Internal Unicode Operations ---------------------------------------- */ /* If you want Python to use the compiler's wctype.h functions instead   of the ones supplied with Python, define WANT_WCTYPE_FUNCTIONS or   configure Python using --with-wctype-functions.  This reduces the   interpreter's code size. */ #if defined(HAVE_USABLE_WCHAR_T) && defined(WANT_WCTYPE_FUNCTIONS) #include <wctype.h> #define Py_UNICODE_ISSPACE(ch) iswspace(ch) #define Py_UNICODE_ISLOWER(ch) iswlower(ch)#define Py_UNICODE_ISUPPER(ch) iswupper(ch)#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch) #define Py_UNICODE_TOLOWER(ch) towlower(ch)#define Py_UNICODE_TOUPPER(ch) towupper(ch)#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch) #define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch) #define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch) #define Py_UNICODE_ISALPHA(ch) iswalpha(ch) #else #define Py_UNICODE_ISSPACE(ch) _PyUnicode_IsWhitespace(ch) #define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch)#define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch)#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch) #define Py_UNICODE_TOLOWER(ch) _PyUnicode_ToLowercase(ch)#define Py_UNICODE_TOUPPER(ch) _PyUnicode_ToUppercase(ch)#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch) #define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch) #define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch) #define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch) #endif #define Py_UNICODE_ISALNUM(ch) \       (Py_UNICODE_ISALPHA(ch) || \        Py_UNICODE_ISDECIMAL(ch) || \        Py_UNICODE_ISDIGIT(ch) || \        Py_UNICODE_ISNUMERIC(ch)) #define Py_UNICODE_COPY(target, source, length)				\	Py_MEMCPY((target), (source), (length)*sizeof(Py_UNICODE)) #define Py_UNICODE_FILL(target, value, length) do\    {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\        for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\    } while (0) /* check if substring matches at given offset.  the offset must be   valid, and the substring must not be empty */#define Py_UNICODE_MATCH(string, offset, substring) \    ((*((string)->str + (offset)) == *((substring)->str)) && \    ((*((string)->str + (offset) + (substring)->length-1) == *((substring)->str + (substring)->length-1))) && \     !memcmp((string)->str + (offset), (substring)->str, (substring)->length*sizeof(Py_UNICODE))) #ifdef __cplusplusextern "C" {#endif /* --- Unicode Type ------------------------------------------------------- */ typedef struct {    PyObject_HEAD    Py_ssize_t length;		/* Length of raw Unicode data in buffer */    Py_UNICODE *str;		/* Raw Unicode buffer */    long hash;			/* Hash value; -1 if not set */    PyObject *defenc;		/* (Default) Encoded version as Python				   string, or NULL; this is used for				   implementing the buffer protocol */} PyUnicodeObject; PyAPI_DATA(PyTypeObject) PyUnicode_Type; #define PyUnicode_Check(op) PyObject_TypeCheck(op, &PyUnicode_Type)#define PyUnicode_CheckExact(op) ((op)->ob_type == &PyUnicode_Type) /* Fast access macros */#define PyUnicode_GET_SIZE(op) \        (((PyUnicodeObject *)(op))->length)#define PyUnicode_GET_DATA_SIZE(op) \        (((PyUnicodeObject *)(op))->length * sizeof(Py_UNICODE))#define PyUnicode_AS_UNICODE(op) \        (((PyUnicodeObject *)(op))->str)#define PyUnicode_AS_DATA(op) \        ((const char *)((PyUnicodeObject *)(op))->str) /* --- Constants ---------------------------------------------------------- */ /* This Unicode character will be used as replacement character during   decoding if the errors argument is set to "replace". Note: the   Unicode character U+FFFD is the official REPLACEMENT CHARACTER in   Unicode 3.0. */ #define Py_UNICODE_REPLACEMENT_CHARACTER ((Py_UNICODE) 0xFFFD) /* === Public API ========================================================= */ /* --- Plain Py_UNICODE --------------------------------------------------- */ /* Create a Unicode Object from the Py_UNICODE buffer u of the given   size.     u may be NULL which causes the contents to be undefined. It is the   user's responsibility to fill in the needed data afterwards. Note   that modifying the Unicode object contents after construction is   only allowed if u was set to NULL.    The buffer is copied into the new object. */ PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(    const Py_UNICODE *u,        /* Unicode buffer */    Py_ssize_t size             /* size of buffer */    ); /* Return a read-only pointer to the Unicode object's internal   Py_UNICODE buffer. */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(    PyObject *unicode	 	/* Unicode object */    ); /* Get the length of the Unicode object. */ PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(    PyObject *unicode	 	/* Unicode object */    ); /* Get the maximum ordinal for a Unicode character. */PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void); /* Resize an already allocated Unicode object to the new size length.    *unicode is modified to point to the new (resized) object and 0   returned on success.    This API may only be called by the function which also called the   Unicode constructor. The refcount on the object must be 1. Otherwise,   an error is returned.    Error handling is implemented as follows: an exception is set, -1   is returned and *unicode left untouched. */ PyAPI_FUNC(int) PyUnicode_Resize(    PyObject **unicode,		/* Pointer to the Unicode object */    Py_ssize_t length		/* New length */    ); /* Coerce obj to an Unicode object and return a reference with   *incremented* refcount.    Coercion is done in the following way:    1. String and other char buffer compatible objects are decoded      under the assumptions that they contain data using the current      default encoding. Decoding is done in "strict" mode.    2. All other objects (including Unicode objects) raise an      exception.    The API returns NULL in case of an error. The caller is responsible   for decref'ing the returned objects. */ PyAPI_FUNC(PyObject*) PyUnicode_FromEncodedObject(    register PyObject *obj, 	/* Object */    const char *encoding,       /* encoding */    const char *errors          /* error handling */    ); /* Coerce obj to an Unicode object and return a reference with   *incremented* refcount.      Unicode objects are passed back as-is (subclasses are converted to   true Unicode objects), all other objects are delegated to   PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in   using the default encoding as basis for decoding the object.

Lines 1–500 of 1265.