Rename PyUnicode_AsString -> _PyUnicode_AsString and

PyUnicode_AsStringAndSize -> _PyUnicode_AsStringAndSize to mark
them for interpreter internal use only.

We'll have to rework these APIs or create new ones for the
purpose of accessing the UTF-8 representation of Unicode objects
for 3.1.
This commit is contained in:
Marc-André Lemburg 2008-08-07 18:54:33 +00:00
parent 28bd1a3bd5
commit 4cc0f24857
60 changed files with 156 additions and 137 deletions

View File

@ -466,7 +466,7 @@ PyAPI_FUNC(long) _Py_HashDouble(double);
PyAPI_FUNC(long) _Py_HashPointer(void*); PyAPI_FUNC(long) _Py_HashPointer(void*);
/* Helper for passing objects to printf and the like */ /* Helper for passing objects to printf and the like */
#define PyObject_REPR(obj) PyUnicode_AsString(PyObject_Repr(obj)) #define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
/* Flag bits for printing: */ /* Flag bits for printing: */
#define Py_PRINT_RAW 1 /* No string quotes etc. */ #define Py_PRINT_RAW 1 /* No string quotes etc. */

View File

@ -704,9 +704,15 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefaultAndSize(
In case of an error, no *size is set. In case of an error, no *size is set.
*** This API is for interpreter INTERNAL USE ONLY and will likely
*** be removed or changed for Python 3.1.
*** If you need to access the Unicode object as UTF-8 bytes string,
*** please use PyUnicode_AsUTF8String() instead.
*/ */
PyAPI_FUNC(char *) PyUnicode_AsStringAndSize( PyAPI_FUNC(char *) _PyUnicode_AsStringAndSize(
PyObject *unicode, PyObject *unicode,
Py_ssize_t *size); Py_ssize_t *size);
@ -714,12 +720,17 @@ PyAPI_FUNC(char *) PyUnicode_AsStringAndSize(
Unicode object unicode. Unicode object unicode.
Use of this API is DEPRECATED since no size information can be Use of this API is DEPRECATED since no size information can be
extracted from the returned data. Use PyUnicode_AsStringAndSize() extracted from the returned data.
instead.
*** This API is for interpreter INTERNAL USE ONLY and will likely
*** be removed or changed for Python 3.1.
*** If you need to access the Unicode object as UTF-8 bytes string,
*** please use PyUnicode_AsUTF8String() instead.
*/ */
PyAPI_FUNC(char *) PyUnicode_AsString(PyObject *unicode); PyAPI_FUNC(char *) _PyUnicode_AsString(PyObject *unicode);
/* Returns the currently active default encoding. /* Returns the currently active default encoding.

View File

@ -15,6 +15,14 @@ Core and Builtins
- Issue #1819: function calls with several named parameters are now on - Issue #1819: function calls with several named parameters are now on
average 35% faster (as measured by pybench). average 35% faster (as measured by pybench).
- The undocumented C APIs PyUnicode_AsString() and
PyUnicode_AsStringAndSize() were made private to the interpreter, in
order to be able to refine their interfaces for Python 3.1.
If you need to access the UTF-8 representation of a Unicode object
as bytes string, please use PyUnicode_AsUTF8String() instead.
Library Library
------- -------

View File

@ -683,8 +683,8 @@ StructType_setattro(PyObject *self, PyObject *key, PyObject *value)
return -1; return -1;
if (value && PyUnicode_Check(key) && if (value && PyUnicode_Check(key) &&
/* XXX struni PyUnicode_AsString can fail (also in other places)! */ /* XXX struni _PyUnicode_AsString can fail (also in other places)! */
0 == strcmp(PyUnicode_AsString(key), "_fields_")) 0 == strcmp(_PyUnicode_AsString(key), "_fields_"))
return StructUnionType_update_stgdict(self, value, 1); return StructUnionType_update_stgdict(self, value, 1);
return 0; return 0;
} }
@ -698,7 +698,7 @@ UnionType_setattro(PyObject *self, PyObject *key, PyObject *value)
return -1; return -1;
if (PyUnicode_Check(key) && if (PyUnicode_Check(key) &&
0 == strcmp(PyUnicode_AsString(key), "_fields_")) 0 == strcmp(_PyUnicode_AsString(key), "_fields_"))
return StructUnionType_update_stgdict(self, value, 0); return StructUnionType_update_stgdict(self, value, 0);
return 0; return 0;
} }
@ -1681,7 +1681,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
if (stgd && CDataObject_Check(value) && stgd->proto && PyUnicode_Check(stgd->proto)) { if (stgd && CDataObject_Check(value) && stgd->proto && PyUnicode_Check(stgd->proto)) {
PyCArgObject *parg; PyCArgObject *parg;
switch (PyUnicode_AsString(stgd->proto)[0]) { switch (_PyUnicode_AsString(stgd->proto)[0]) {
case 'z': /* c_char_p */ case 'z': /* c_char_p */
case 'Z': /* c_wchar_p */ case 'Z': /* c_wchar_p */
parg = new_CArgObject(); parg = new_CArgObject();
@ -1791,7 +1791,7 @@ SimpleType_paramfunc(CDataObject *self)
dict = PyObject_stgdict((PyObject *)self); dict = PyObject_stgdict((PyObject *)self);
assert(dict); /* Cannot be NULL for CDataObject instances */ assert(dict); /* Cannot be NULL for CDataObject instances */
fmt = PyUnicode_AsString(dict->proto); fmt = _PyUnicode_AsString(dict->proto);
assert(fmt); assert(fmt);
fd = getentry(fmt); fd = getentry(fmt);
@ -2012,7 +2012,7 @@ SimpleType_from_param(PyObject *type, PyObject *value)
assert(dict); assert(dict);
/* I think we can rely on this being a one-character string */ /* I think we can rely on this being a one-character string */
fmt = PyUnicode_AsString(dict->proto); fmt = _PyUnicode_AsString(dict->proto);
assert(fmt); assert(fmt);
fd = getentry(fmt); fd = getentry(fmt);
@ -3058,7 +3058,7 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index)
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */ /* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
&& PyUnicode_Check(dict->proto) && PyUnicode_Check(dict->proto)
/* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */ /* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */
&& (strchr("PzZ", PyUnicode_AsString(dict->proto)[0]))) { && (strchr("PzZ", _PyUnicode_AsString(dict->proto)[0]))) {
return 1; return 1;
} }
@ -3148,7 +3148,7 @@ _get_name(PyObject *obj, char **pname)
return *pname ? 1 : 0; return *pname ? 1 : 0;
} }
if (PyUnicode_Check(obj)) { if (PyUnicode_Check(obj)) {
*pname = PyUnicode_AsString(obj); *pname = _PyUnicode_AsString(obj);
return *pname ? 1 : 0; return *pname ? 1 : 0;
} }
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
@ -5127,7 +5127,7 @@ cast_check_pointertype(PyObject *arg)
dict = PyType_stgdict(arg); dict = PyType_stgdict(arg);
if (dict) { if (dict) {
if (PyUnicode_Check(dict->proto) if (PyUnicode_Check(dict->proto)
&& (strchr("sPzUZXO", PyUnicode_AsString(dict->proto)[0]))) { && (strchr("sPzUZXO", _PyUnicode_AsString(dict->proto)[0]))) {
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */ /* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
return 1; return 1;
} }

View File

@ -1750,7 +1750,7 @@ POINTER(PyObject *self, PyObject *cls)
return result; return result;
} }
if (PyUnicode_CheckExact(cls)) { if (PyUnicode_CheckExact(cls)) {
char *name = PyUnicode_AsString(cls); char *name = _PyUnicode_AsString(cls);
buf = alloca(strlen(name) + 3 + 1); buf = alloca(strlen(name) + 3 + 1);
sprintf(buf, "LP_%s", name); sprintf(buf, "LP_%s", name);
result = PyObject_CallFunction((PyObject *)Py_TYPE(&Pointer_Type), result = PyObject_CallFunction((PyObject *)Py_TYPE(&Pointer_Type),

View File

@ -479,7 +479,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
bitsize = 0; bitsize = 0;
if (isStruct && !isPacked) { if (isStruct && !isPacked) {
char *fieldfmt = dict->format ? dict->format : "B"; char *fieldfmt = dict->format ? dict->format : "B";
char *fieldname = PyUnicode_AsString(name); char *fieldname = _PyUnicode_AsString(name);
char *ptr; char *ptr;
Py_ssize_t len = strlen(fieldname) + strlen(fieldfmt); Py_ssize_t len = strlen(fieldname) + strlen(fieldfmt);
char *buf = alloca(len + 2 + 1); char *buf = alloca(len + 2 + 1);

View File

@ -1303,7 +1303,7 @@ element_getattro(ElementObject* self, PyObject* nameobj)
char *name = ""; char *name = "";
if (PyUnicode_Check(nameobj)) if (PyUnicode_Check(nameobj))
name = PyUnicode_AsString(nameobj); name = _PyUnicode_AsString(nameobj);
if (strcmp(name, "tag") == 0) if (strcmp(name, "tag") == 0)
res = self->tag; res = self->tag;
@ -2529,7 +2529,7 @@ xmlparser_getattro(XMLParserObject* self, PyObject* nameobj)
char *name = ""; char *name = "";
if (PyUnicode_Check(nameobj)) if (PyUnicode_Check(nameobj))
name = PyUnicode_AsString(nameobj); name = _PyUnicode_AsString(nameobj);
PyErr_Clear(); PyErr_Clear();

View File

@ -38,7 +38,7 @@ convert_to_OSType(PyObject *v, OSType *pr)
"OSType arg must be string of 4 chars"); "OSType arg must be string of 4 chars");
return 0; return 0;
} }
memcpy((char *)&tmp, PyUnicode_AsString(v), 4); memcpy((char *)&tmp, _PyUnicode_AsString(v), 4);
*pr = (OSType)ntohl(tmp); *pr = (OSType)ntohl(tmp);
return 1; return 1;
} }

View File

@ -241,7 +241,7 @@ EVP_repr(PyObject *self)
{ {
char buf[100]; char buf[100];
PyOS_snprintf(buf, sizeof(buf), "<%s HASH object @ %p>", PyOS_snprintf(buf, sizeof(buf), "<%s HASH object @ %p>",
PyUnicode_AsString(((EVPobject *)self)->name), self); _PyUnicode_AsString(((EVPobject *)self)->name), self);
return PyUnicode_FromString(buf); return PyUnicode_FromString(buf);
} }

View File

@ -180,7 +180,7 @@ normalizeUserObj(PyObject *obj)
PyObject *mod = fn->m_module; PyObject *mod = fn->m_module;
const char *modname; const char *modname;
if (mod && PyUnicode_Check(mod)) { if (mod && PyUnicode_Check(mod)) {
modname = PyUnicode_AsString(mod); modname = _PyUnicode_AsString(mod);
} }
else if (mod && PyModule_Check(mod)) { else if (mod && PyModule_Check(mod)) {
modname = PyModule_GetName(mod); modname = PyModule_GetName(mod);

View File

@ -927,7 +927,7 @@ save_long(PicklerObject *self, PyObject *obj)
repr = PyUnicode_FromStringAndSize(NULL, (int)nbytes); repr = PyUnicode_FromStringAndSize(NULL, (int)nbytes);
if (repr == NULL) if (repr == NULL)
goto error; goto error;
pdata = (unsigned char *)PyUnicode_AsString(repr); pdata = (unsigned char *)_PyUnicode_AsString(repr);
i = _PyLong_AsByteArray((PyLongObject *)obj, i = _PyLong_AsByteArray((PyLongObject *)obj,
pdata, nbytes, pdata, nbytes,
1 /* little endian */ , 1 /* signed */ ); 1 /* little endian */ , 1 /* signed */ );
@ -972,7 +972,7 @@ save_long(PicklerObject *self, PyObject *obj)
if (repr == NULL) if (repr == NULL)
goto error; goto error;
string = PyUnicode_AsStringAndSize(repr, &size); string = _PyUnicode_AsStringAndSize(repr, &size);
if (string == NULL) if (string == NULL)
goto error; goto error;
@ -1869,7 +1869,7 @@ save_pers(PicklerObject *self, PyObject *obj, PyObject *func)
/* XXX: Should it check whether the persistent id only contains /* XXX: Should it check whether the persistent id only contains
ASCII characters? And what if the pid contains embedded ASCII characters? And what if the pid contains embedded
newlines? */ newlines? */
pid_ascii_bytes = PyUnicode_AsStringAndSize(pid_str, &size); pid_ascii_bytes = _PyUnicode_AsStringAndSize(pid_str, &size);
Py_DECREF(pid_str); Py_DECREF(pid_str);
if (pid_ascii_bytes == NULL) if (pid_ascii_bytes == NULL)
goto error; goto error;

View File

@ -434,7 +434,7 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
} else if (PyFloat_Check(py_val)) { } else if (PyFloat_Check(py_val)) {
sqlite3_result_double(context, PyFloat_AsDouble(py_val)); sqlite3_result_double(context, PyFloat_AsDouble(py_val));
} else if (PyUnicode_Check(py_val)) { } else if (PyUnicode_Check(py_val)) {
sqlite3_result_text(context, PyUnicode_AsString(py_val), -1, SQLITE_TRANSIENT); sqlite3_result_text(context, _PyUnicode_AsString(py_val), -1, SQLITE_TRANSIENT);
} else if (PyObject_CheckBuffer(py_val)) { } else if (PyObject_CheckBuffer(py_val)) {
if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) { if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) {
PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
@ -901,7 +901,7 @@ static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, Py
return -1; return -1;
} }
statement = PyUnicode_AsStringAndSize(begin_statement, &size); statement = _PyUnicode_AsStringAndSize(begin_statement, &size);
if (!statement) { if (!statement) {
Py_DECREF(statement); Py_DECREF(statement);
return -1; return -1;
@ -1194,7 +1194,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
goto finally; goto finally;
} }
chk = PyUnicode_AsString(uppercase_name); chk = _PyUnicode_AsString(uppercase_name);
while (*chk) { while (*chk) {
if ((*chk >= '0' && *chk <= '9') if ((*chk >= '0' && *chk <= '9')
|| (*chk >= 'A' && *chk <= 'Z') || (*chk >= 'A' && *chk <= 'Z')
@ -1219,7 +1219,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
} }
rc = sqlite3_create_collation(self->db, rc = sqlite3_create_collation(self->db,
PyUnicode_AsString(uppercase_name), _PyUnicode_AsString(uppercase_name),
SQLITE_UTF8, SQLITE_UTF8,
(callable != Py_None) ? callable : NULL, (callable != Py_None) ? callable : NULL,
(callable != Py_None) ? pysqlite_collation_callback : NULL); (callable != Py_None) ? pysqlite_collation_callback : NULL);

View File

@ -490,7 +490,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
rc = pysqlite_statement_reset(self->statement); rc = pysqlite_statement_reset(self->statement);
} }
operation_cstr = PyUnicode_AsStringAndSize(operation, &operation_len); operation_cstr = _PyUnicode_AsStringAndSize(operation, &operation_len);
if (operation == NULL) if (operation == NULL)
goto error; goto error;
@ -793,7 +793,7 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
} }
if (PyUnicode_Check(script_obj)) { if (PyUnicode_Check(script_obj)) {
script_cstr = PyUnicode_AsString(script_obj); script_cstr = _PyUnicode_AsString(script_obj);
if (!script_cstr) { if (!script_cstr) {
return NULL; return NULL;
} }

View File

@ -82,12 +82,12 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
Py_XINCREF(item); Py_XINCREF(item);
return item; return item;
} else if (PyUnicode_Check(idx)) { } else if (PyUnicode_Check(idx)) {
key = PyUnicode_AsString(idx); key = _PyUnicode_AsString(idx);
nitems = PyTuple_Size(self->description); nitems = PyTuple_Size(self->description);
for (i = 0; i < nitems; i++) { for (i = 0; i < nitems; i++) {
compare_key = PyUnicode_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0)); compare_key = _PyUnicode_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
if (!compare_key) { if (!compare_key) {
return NULL; return NULL;
} }

View File

@ -59,7 +59,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
self->st = NULL; self->st = NULL;
self->in_use = 0; self->in_use = 0;
sql_cstr = PyUnicode_AsStringAndSize(sql, &sql_cstr_len); sql_cstr = _PyUnicode_AsStringAndSize(sql, &sql_cstr_len);
if (sql_cstr == NULL) { if (sql_cstr == NULL) {
rc = PYSQLITE_SQL_WRONG_TYPE; rc = PYSQLITE_SQL_WRONG_TYPE;
return rc; return rc;
@ -140,7 +140,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter)); rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
break; break;
case TYPE_UNICODE: case TYPE_UNICODE:
string = PyUnicode_AsString(parameter); string = _PyUnicode_AsString(parameter);
rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
break; break;
case TYPE_BUFFER: case TYPE_BUFFER:
@ -296,7 +296,7 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
Py_ssize_t sql_len; Py_ssize_t sql_len;
sqlite3_stmt* new_st; sqlite3_stmt* new_st;
sql_cstr = PyUnicode_AsStringAndSize(self->sql, &sql_len); sql_cstr = _PyUnicode_AsStringAndSize(self->sql, &sql_len);
if (sql_cstr == NULL) { if (sql_cstr == NULL) {
rc = PYSQLITE_SQL_WRONG_TYPE; rc = PYSQLITE_SQL_WRONG_TYPE;
return rc; return rc;

View File

@ -1461,7 +1461,7 @@ PySSL_RAND_egd(PyObject *self, PyObject *arg)
return PyErr_Format(PyExc_TypeError, return PyErr_Format(PyExc_TypeError,
"RAND_egd() expected string, found %s", "RAND_egd() expected string, found %s",
Py_TYPE(arg)->tp_name); Py_TYPE(arg)->tp_name);
bytes = RAND_egd(PyUnicode_AsString(arg)); bytes = RAND_egd(_PyUnicode_AsString(arg));
if (bytes == -1) { if (bytes == -1) {
PyErr_SetString(PySSLErrorObject, PyErr_SetString(PySSLErrorObject,
"EGD connection failed or EGD did not return " "EGD connection failed or EGD did not return "

View File

@ -406,7 +406,7 @@ _range_error(const formatdef *f, int is_unsigned)
if (msg == NULL) if (msg == NULL)
return -1; return -1;
rval = PyErr_WarnEx(PyExc_DeprecationWarning, rval = PyErr_WarnEx(PyExc_DeprecationWarning,
PyUnicode_AsString(msg), 2); _PyUnicode_AsString(msg), 2);
Py_DECREF(msg); Py_DECREF(msg);
if (rval == 0) if (rval == 0)
return 0; return 0;

View File

@ -788,7 +788,7 @@ test_string_from_format(PyObject *self, PyObject *args)
result = PyUnicode_FromFormat(FORMAT, (TYPE)1); \ result = PyUnicode_FromFormat(FORMAT, (TYPE)1); \
if (result == NULL) \ if (result == NULL) \
return NULL; \ return NULL; \
if (strcmp(PyUnicode_AsString(result), "1")) { \ if (strcmp(_PyUnicode_AsString(result), "1")) { \
msg = FORMAT " failed at 1"; \ msg = FORMAT " failed at 1"; \
goto Fail; \ goto Fail; \
} \ } \

View File

@ -1424,7 +1424,7 @@ varname_converter(PyObject *in, void *_out)
return 1; return 1;
} }
if (PyUnicode_Check(in)) { if (PyUnicode_Check(in)) {
*out = PyUnicode_AsString(in); *out = _PyUnicode_AsString(in);
return 1; return 1;
} }
if (PyTclObject_Check(in)) { if (PyTclObject_Check(in)) {

View File

@ -266,7 +266,7 @@ getcodec(PyObject *self, PyObject *encoding)
"encoding name must be a string."); "encoding name must be a string.");
return NULL; return NULL;
} }
enc = PyUnicode_AsString(encoding); enc = _PyUnicode_AsString(encoding);
if (enc == NULL) if (enc == NULL)
return NULL; return NULL;

View File

@ -95,7 +95,7 @@ call_error_callback(PyObject *errors, PyObject *exc)
const char *str; const char *str;
assert(PyUnicode_Check(errors)); assert(PyUnicode_Check(errors));
str = PyUnicode_AsString(errors); str = _PyUnicode_AsString(errors);
if (str == NULL) if (str == NULL)
return NULL; return NULL;
cb = PyCodec_LookupError(str); cb = PyCodec_LookupError(str);
@ -148,7 +148,7 @@ codecctx_errors_set(MultibyteStatefulCodecContext *self, PyObject *value,
return -1; return -1;
} }
str = PyUnicode_AsString(value); str = _PyUnicode_AsString(value);
if (str == NULL) if (str == NULL)
return -1; return -1;

View File

@ -1219,7 +1219,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
assert(object && format && timetuple); assert(object && format && timetuple);
assert(PyUnicode_Check(format)); assert(PyUnicode_Check(format));
/* Convert the input format to a C string and size */ /* Convert the input format to a C string and size */
pin = PyUnicode_AsStringAndSize(format, &flen); pin = _PyUnicode_AsStringAndSize(format, &flen);
if (!pin) if (!pin)
return NULL; return NULL;
@ -1312,7 +1312,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
} }
assert(Zreplacement != NULL); assert(Zreplacement != NULL);
assert(PyUnicode_Check(Zreplacement)); assert(PyUnicode_Check(Zreplacement));
ptoappend = PyUnicode_AsStringAndSize(Zreplacement, ptoappend = _PyUnicode_AsStringAndSize(Zreplacement,
&ntoappend); &ntoappend);
ntoappend = Py_SIZE(Zreplacement); ntoappend = Py_SIZE(Zreplacement);
} }

View File

@ -113,7 +113,7 @@ grp_getgrnam(PyObject *self, PyObject *pyo_name)
py_str_name = PyObject_Str(pyo_name); py_str_name = PyObject_Str(pyo_name);
if (!py_str_name) if (!py_str_name)
return NULL; return NULL;
name = PyUnicode_AsString(py_str_name); name = _PyUnicode_AsString(py_str_name);
if ((p = getgrnam(name)) == NULL) { if ((p = getgrnam(name)) == NULL) {
PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name); PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %s", name);

View File

@ -449,7 +449,7 @@ dotted_getattr(PyObject *obj, PyObject *attr)
return NULL; return NULL;
} }
s = PyUnicode_AsString(attr); s = _PyUnicode_AsString(attr);
Py_INCREF(obj); Py_INCREF(obj);
for (;;) { for (;;) {
PyObject *newobj, *str; PyObject *newobj, *str;

View File

@ -809,7 +809,7 @@ oss_getattro(oss_audio_t *self, PyObject *nameobj)
PyObject * rval = NULL; PyObject * rval = NULL;
if (PyUnicode_Check(nameobj)) if (PyUnicode_Check(nameobj))
name = PyUnicode_AsString(nameobj); name = _PyUnicode_AsString(nameobj);
if (strcmp(name, "closed") == 0) { if (strcmp(name, "closed") == 0) {
rval = (self->fd == -1) ? Py_True : Py_False; rval = (self->fd == -1) ? Py_True : Py_False;

View File

@ -718,7 +718,7 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
Py_DECREF(o); Py_DECREF(o);
} }
} }
temp_str = PyUnicode_AsStringAndSize(temp, &len); temp_str = _PyUnicode_AsStringAndSize(temp, &len);
strn = (char *)PyObject_MALLOC(len + 1); strn = (char *)PyObject_MALLOC(len + 1);
if (strn != NULL) if (strn != NULL)
(void) memcpy(strn, temp_str, len + 1); (void) memcpy(strn, temp_str, len + 1);
@ -807,7 +807,7 @@ build_node_tree(PyObject *tuple)
if (res && encoding) { if (res && encoding) {
Py_ssize_t len; Py_ssize_t len;
const char *temp; const char *temp;
temp = PyUnicode_AsStringAndSize(encoding, &len); temp = _PyUnicode_AsStringAndSize(encoding, &len);
res->n_str = (char *)PyObject_MALLOC(len + 1); res->n_str = (char *)PyObject_MALLOC(len + 1);
if (res->n_str != NULL && temp != NULL) if (res->n_str != NULL && temp != NULL)
(void) memcpy(res->n_str, temp, len + 1); (void) memcpy(res->n_str, temp, len + 1);

View File

@ -5566,7 +5566,7 @@ conv_confname(PyObject *arg, int *valuep, struct constdef *table,
"configuration names must be strings or integers"); "configuration names must be strings or integers");
return 0; return 0;
} }
confname = PyUnicode_AsString(arg); confname = _PyUnicode_AsString(arg);
if (confname == NULL) if (confname == NULL)
return 0; return 0;
while (lo < hi) { while (lo < hi) {
@ -5897,7 +5897,7 @@ posix_confstr(PyObject *self, PyObject *args)
if ((unsigned int)len >= sizeof(buffer)) { if ((unsigned int)len >= sizeof(buffer)) {
result = PyUnicode_FromStringAndSize(NULL, len-1); result = PyUnicode_FromStringAndSize(NULL, len-1);
if (result != NULL) if (result != NULL)
confstr(name, PyUnicode_AsString(result), len); confstr(name, _PyUnicode_AsString(result), len);
} }
else else
result = PyUnicode_FromStringAndSize(buffer, len-1); result = PyUnicode_FromStringAndSize(buffer, len-1);

View File

@ -1338,7 +1338,7 @@ xmlparse_getattro(xmlparseobject *self, PyObject *nameobj)
int handlernum = -1; int handlernum = -1;
if (PyUnicode_Check(nameobj)) if (PyUnicode_Check(nameobj))
name = PyUnicode_AsString(nameobj); name = _PyUnicode_AsString(nameobj);
handlernum = handlername2int(name); handlernum = handlername2int(name);

View File

@ -724,7 +724,7 @@ on_completion(const char *text, int state)
result = NULL; result = NULL;
} }
else { else {
char *s = PyUnicode_AsString(r); char *s = _PyUnicode_AsString(r);
if (s == NULL) if (s == NULL)
goto error; goto error;
result = strdup(s); result = strdup(s);

View File

@ -3744,7 +3744,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value); PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value);
pptr = pbuf; pptr = pbuf;
} else if (PyUnicode_Check(pobj)) { } else if (PyUnicode_Check(pobj)) {
pptr = PyUnicode_AsString(pobj); pptr = _PyUnicode_AsString(pobj);
} else if (PyBytes_Check(pobj)) { } else if (PyBytes_Check(pobj)) {
pptr = PyBytes_AsString(pobj); pptr = PyBytes_AsString(pobj);
} else if (pobj == Py_None) { } else if (pobj == Py_None) {

View File

@ -72,7 +72,7 @@ syslog_openlog(PyObject * self, PyObject * args)
S_ident_o = new_S_ident_o; S_ident_o = new_S_ident_o;
Py_INCREF(S_ident_o); Py_INCREF(S_ident_o);
ident = PyUnicode_AsString(S_ident_o); ident = _PyUnicode_AsString(S_ident_o);
if (ident == NULL) if (ident == NULL)
return NULL; return NULL;
openlog(ident, logopt, facility); openlog(ident, logopt, facility);
@ -97,7 +97,7 @@ syslog_syslog(PyObject * self, PyObject * args)
return NULL; return NULL;
} }
message = PyUnicode_AsString(message_object); message = _PyUnicode_AsString(message_object);
if (message == NULL) if (message == NULL)
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;

View File

@ -509,7 +509,7 @@ time_strftime(PyObject *self, PyObject *args)
} }
/* Convert the unicode string to an ascii one */ /* Convert the unicode string to an ascii one */
fmt = PyUnicode_AsString(format); fmt = _PyUnicode_AsString(format);
fmtlen = strlen(fmt); fmtlen = strlen(fmt);

View File

@ -180,9 +180,9 @@ zipimporter_repr(ZipImporter *self)
char *prefix = ""; char *prefix = "";
if (self->archive != NULL && PyUnicode_Check(self->archive)) if (self->archive != NULL && PyUnicode_Check(self->archive))
archive = PyUnicode_AsString(self->archive); archive = _PyUnicode_AsString(self->archive);
if (self->prefix != NULL && PyUnicode_Check(self->prefix)) if (self->prefix != NULL && PyUnicode_Check(self->prefix))
prefix = PyUnicode_AsString(self->prefix); prefix = _PyUnicode_AsString(self->prefix);
if (prefix != NULL && *prefix) if (prefix != NULL && *prefix)
return PyUnicode_FromFormat("<zipimporter object \"%.300s%c%.150s\">", return PyUnicode_FromFormat("<zipimporter object \"%.300s%c%.150s\">",
archive, SEP, prefix); archive, SEP, prefix);
@ -248,7 +248,7 @@ get_module_info(ZipImporter *self, char *fullname)
subname = get_subname(fullname); subname = get_subname(fullname);
len = make_filename(PyUnicode_AsString(self->prefix), subname, path); len = make_filename(_PyUnicode_AsString(self->prefix), subname, path);
if (len < 0) if (len < 0)
return MI_ERROR; return MI_ERROR;
@ -321,12 +321,12 @@ zipimporter_load_module(PyObject *obj, PyObject *args)
/* add __path__ to the module *before* the code gets /* add __path__ to the module *before* the code gets
executed */ executed */
PyObject *pkgpath, *fullpath; PyObject *pkgpath, *fullpath;
char *prefix = PyUnicode_AsString(self->prefix); char *prefix = _PyUnicode_AsString(self->prefix);
char *subname = get_subname(fullname); char *subname = get_subname(fullname);
int err; int err;
fullpath = PyUnicode_FromFormat("%s%c%s%s", fullpath = PyUnicode_FromFormat("%s%c%s%s",
PyUnicode_AsString(self->archive), _PyUnicode_AsString(self->archive),
SEP, SEP,
prefix ? prefix : "", prefix ? prefix : "",
subname); subname);
@ -404,7 +404,7 @@ zipimporter_get_data(PyObject *obj, PyObject *args)
} }
path = buf; path = buf;
#endif #endif
archive_str = PyUnicode_AsStringAndSize(self->archive, &len); archive_str = _PyUnicode_AsStringAndSize(self->archive, &len);
if ((size_t)len < strlen(path) && if ((size_t)len < strlen(path) &&
strncmp(path, archive_str, len) == 0 && strncmp(path, archive_str, len) == 0 &&
path[len] == SEP) { path[len] == SEP) {
@ -453,7 +453,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
} }
subname = get_subname(fullname); subname = get_subname(fullname);
len = make_filename(PyUnicode_AsString(self->prefix), subname, path); len = make_filename(_PyUnicode_AsString(self->prefix), subname, path);
if (len < 0) if (len < 0)
return NULL; return NULL;
@ -466,7 +466,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
toc_entry = PyDict_GetItemString(self->files, path); toc_entry = PyDict_GetItemString(self->files, path);
if (toc_entry != NULL) { if (toc_entry != NULL) {
PyObject *bytes = get_data(PyUnicode_AsString(self->archive), toc_entry); PyObject *bytes = get_data(_PyUnicode_AsString(self->archive), toc_entry);
PyObject *res = PyUnicode_FromString(PyByteArray_AsString(bytes)); PyObject *res = PyUnicode_FromString(PyByteArray_AsString(bytes));
Py_XDECREF(bytes); Py_XDECREF(bytes);
return res; return res;
@ -1053,7 +1053,7 @@ get_code_from_data(ZipImporter *self, int ispackage, int isbytecode,
{ {
PyObject *data, *code; PyObject *data, *code;
char *modpath; char *modpath;
char *archive = PyUnicode_AsString(self->archive); char *archive = _PyUnicode_AsString(self->archive);
if (archive == NULL) if (archive == NULL)
return NULL; return NULL;
@ -1062,7 +1062,7 @@ get_code_from_data(ZipImporter *self, int ispackage, int isbytecode,
if (data == NULL) if (data == NULL)
return NULL; return NULL;
modpath = PyUnicode_AsString(PyTuple_GetItem(toc_entry, 0)); modpath = _PyUnicode_AsString(PyTuple_GetItem(toc_entry, 0));
if (isbytecode) { if (isbytecode) {
code = unmarshal_code(modpath, data, mtime); code = unmarshal_code(modpath, data, mtime);
@ -1087,7 +1087,7 @@ get_module_code(ZipImporter *self, char *fullname,
subname = get_subname(fullname); subname = get_subname(fullname);
len = make_filename(PyUnicode_AsString(self->prefix), subname, path); len = make_filename(_PyUnicode_AsString(self->prefix), subname, path);
if (len < 0) if (len < 0)
return NULL; return NULL;
@ -1097,7 +1097,7 @@ get_module_code(ZipImporter *self, char *fullname,
strcpy(path + len, zso->suffix); strcpy(path + len, zso->suffix);
if (Py_VerboseFlag > 1) if (Py_VerboseFlag > 1)
PySys_WriteStderr("# trying %s%c%s\n", PySys_WriteStderr("# trying %s%c%s\n",
PyUnicode_AsString(self->archive), _PyUnicode_AsString(self->archive),
SEP, path); SEP, path);
toc_entry = PyDict_GetItemString(self->files, path); toc_entry = PyDict_GetItemString(self->files, path);
if (toc_entry != NULL) { if (toc_entry != NULL) {
@ -1119,7 +1119,7 @@ get_module_code(ZipImporter *self, char *fullname,
continue; continue;
} }
if (code != NULL && p_modpath != NULL) if (code != NULL && p_modpath != NULL)
*p_modpath = PyUnicode_AsString( *p_modpath = _PyUnicode_AsString(
PyTuple_GetItem(toc_entry, 0)); PyTuple_GetItem(toc_entry, 0));
return code; return code;
} }

View File

@ -3230,7 +3230,7 @@ _PyBytes_FormatLong(PyObject *val, int flags, int prec, int type,
if (!result) if (!result)
return NULL; return NULL;
buf = PyUnicode_AsString(result); buf = _PyUnicode_AsString(result);
if (!buf) { if (!buf) {
Py_DECREF(result); Py_DECREF(result);
return NULL; return NULL;

View File

@ -296,7 +296,7 @@ code_repr(PyCodeObject *co)
if (co->co_firstlineno != 0) if (co->co_firstlineno != 0)
lineno = co->co_firstlineno; lineno = co->co_firstlineno;
if (co->co_filename && PyUnicode_Check(co->co_filename)) if (co->co_filename && PyUnicode_Check(co->co_filename))
filename = PyUnicode_AsString(co->co_filename); filename = _PyUnicode_AsString(co->co_filename);
return PyUnicode_FromFormat( return PyUnicode_FromFormat(
"<code object %.100U at %p, file \"%.300s\", line %d>", "<code object %.100U at %p, file \"%.300s\", line %d>",
co->co_name, co, filename, lineno); co->co_name, co, filename, lineno);

View File

@ -943,7 +943,7 @@ SyntaxError_str(PySyntaxErrorObject *self)
lineno here */ lineno here */
if (self->filename && PyUnicode_Check(self->filename)) { if (self->filename && PyUnicode_Check(self->filename)) {
filename = PyUnicode_AsString(self->filename); filename = _PyUnicode_AsString(self->filename);
} }
have_lineno = (self->lineno != NULL) && PyLong_CheckExact(self->lineno); have_lineno = (self->lineno != NULL) && PyLong_CheckExact(self->lineno);

View File

@ -1229,7 +1229,7 @@ float_fromhex(PyObject *cls, PyObject *arg)
* exp+4*ndigits and exp-4*ndigits are within the range of a long. * exp+4*ndigits and exp-4*ndigits are within the range of a long.
*/ */
s = PyUnicode_AsStringAndSize(arg, &length); s = _PyUnicode_AsStringAndSize(arg, &length);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
s_end = s + length; s_end = s + length;
@ -1597,7 +1597,7 @@ float_getformat(PyTypeObject *v, PyObject* arg)
Py_TYPE(arg)->tp_name); Py_TYPE(arg)->tp_name);
return NULL; return NULL;
} }
s = PyUnicode_AsString(arg); s = _PyUnicode_AsString(arg);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
if (strcmp(s, "double") == 0) { if (strcmp(s, "double") == 0) {

View File

@ -297,7 +297,7 @@ func_set_code(PyFunctionObject *op, PyObject *value)
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"%s() requires a code object with %zd free vars," "%s() requires a code object with %zd free vars,"
" not %zd", " not %zd",
PyUnicode_AsString(op->func_name), _PyUnicode_AsString(op->func_name),
nclosure, nfree); nclosure, nfree);
return -1; return -1;
} }

View File

@ -187,7 +187,7 @@ PyModule_GetName(PyObject *m)
PyErr_SetString(PyExc_SystemError, "nameless module"); PyErr_SetString(PyExc_SystemError, "nameless module");
return NULL; return NULL;
} }
return PyUnicode_AsString(nameobj); return _PyUnicode_AsString(nameobj);
} }
const char * const char *
@ -207,7 +207,7 @@ PyModule_GetFilename(PyObject *m)
PyErr_SetString(PyExc_SystemError, "module filename missing"); PyErr_SetString(PyExc_SystemError, "module filename missing");
return NULL; return NULL;
} }
return PyUnicode_AsString(fileobj); return _PyUnicode_AsString(fileobj);
} }
PyModuleDef* PyModuleDef*
@ -252,7 +252,7 @@ _PyModule_Clear(PyObject *m)
pos = 0; pos = 0;
while (PyDict_Next(d, &pos, &key, &value)) { while (PyDict_Next(d, &pos, &key, &value)) {
if (value != Py_None && PyUnicode_Check(key)) { if (value != Py_None && PyUnicode_Check(key)) {
const char *s = PyUnicode_AsString(key); const char *s = _PyUnicode_AsString(key);
if (s[0] == '_' && s[1] != '_') { if (s[0] == '_' && s[1] != '_') {
if (Py_VerboseFlag > 1) if (Py_VerboseFlag > 1)
PySys_WriteStderr("# clear[1] %s\n", s); PySys_WriteStderr("# clear[1] %s\n", s);
@ -265,7 +265,7 @@ _PyModule_Clear(PyObject *m)
pos = 0; pos = 0;
while (PyDict_Next(d, &pos, &key, &value)) { while (PyDict_Next(d, &pos, &key, &value)) {
if (value != Py_None && PyUnicode_Check(key)) { if (value != Py_None && PyUnicode_Check(key)) {
const char *s = PyUnicode_AsString(key); const char *s = _PyUnicode_AsString(key);
if (s[0] != '_' || strcmp(s, "__builtins__") != 0) { if (s[0] != '_' || strcmp(s, "__builtins__") != 0) {
if (Py_VerboseFlag > 1) if (Py_VerboseFlag > 1)
PySys_WriteStderr("# clear[2] %s\n", s); PySys_WriteStderr("# clear[2] %s\n", s);

View File

@ -856,7 +856,7 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
if (tp->tp_getattro != NULL) if (tp->tp_getattro != NULL)
return (*tp->tp_getattro)(v, name); return (*tp->tp_getattro)(v, name);
if (tp->tp_getattr != NULL) if (tp->tp_getattr != NULL)
return (*tp->tp_getattr)(v, PyUnicode_AsString(name)); return (*tp->tp_getattr)(v, _PyUnicode_AsString(name));
PyErr_Format(PyExc_AttributeError, PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%U'", "'%.50s' object has no attribute '%U'",
tp->tp_name, name); tp->tp_name, name);
@ -896,7 +896,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
return err; return err;
} }
if (tp->tp_setattr != NULL) { if (tp->tp_setattr != NULL) {
err = (*tp->tp_setattr)(v, PyUnicode_AsString(name), value); err = (*tp->tp_setattr)(v, _PyUnicode_AsString(name), value);
Py_DECREF(name); Py_DECREF(name);
return err; return err;
} }
@ -1062,7 +1062,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
PyErr_Format(PyExc_AttributeError, PyErr_Format(PyExc_AttributeError,
"'%.50s' object has no attribute '%.400s'", "'%.50s' object has no attribute '%.400s'",
tp->tp_name, PyUnicode_AsString(name)); tp->tp_name, _PyUnicode_AsString(name));
done: done:
Py_DECREF(name); Py_DECREF(name);
return res; return res;

View File

@ -2390,7 +2390,7 @@ test_c_api(PySetObject *so)
/* Exercise direct iteration */ /* Exercise direct iteration */
i = 0, count = 0; i = 0, count = 0;
while (_PySet_NextEntry((PyObject *)dup, &i, &x, &hash)) { while (_PySet_NextEntry((PyObject *)dup, &i, &x, &hash)) {
s = PyUnicode_AsString(x); s = _PyUnicode_AsString(x);
assert(s && (s[0] == 'a' || s[0] == 'b' || s[0] == 'c')); assert(s && (s[0] == 'a' || s[0] == 'b' || s[0] == 'c'));
count++; count++;
} }

View File

@ -270,7 +270,7 @@ structseq_repr(PyStructSequence *obj)
Py_DECREF(tup); Py_DECREF(tup);
return NULL; return NULL;
} }
crepr = PyUnicode_AsString(repr); crepr = _PyUnicode_AsString(repr);
if (crepr == NULL) { if (crepr == NULL) {
Py_DECREF(tup); Py_DECREF(tup);
Py_DECREF(repr); Py_DECREF(repr);

View File

@ -258,7 +258,7 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
} }
Py_DECREF(tmp); Py_DECREF(tmp);
tp_name = PyUnicode_AsString(value); tp_name = _PyUnicode_AsString(value);
if (tp_name == NULL) if (tp_name == NULL)
return -1; return -1;
@ -1255,7 +1255,7 @@ check_duplicates(PyObject *list)
o = class_name(o); o = class_name(o);
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"duplicate base class %.400s", "duplicate base class %.400s",
o ? PyUnicode_AsString(o) : "?"); o ? _PyUnicode_AsString(o) : "?");
Py_XDECREF(o); Py_XDECREF(o);
return -1; return -1;
} }
@ -1301,7 +1301,7 @@ consistent method resolution\norder (MRO) for bases");
while (PyDict_Next(set, &i, &k, &v) && (size_t)off < sizeof(buf)) { while (PyDict_Next(set, &i, &k, &v) && (size_t)off < sizeof(buf)) {
PyObject *name = class_name(k); PyObject *name = class_name(k);
off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s", off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s",
name ? PyUnicode_AsString(name) : "?"); name ? _PyUnicode_AsString(name) : "?");
Py_XDECREF(name); Py_XDECREF(name);
if (--n && (size_t)(off+1) < sizeof(buf)) { if (--n && (size_t)(off+1) < sizeof(buf)) {
buf[off++] = ','; buf[off++] = ',';
@ -2094,7 +2094,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
type->tp_as_sequence = &et->as_sequence; type->tp_as_sequence = &et->as_sequence;
type->tp_as_mapping = &et->as_mapping; type->tp_as_mapping = &et->as_mapping;
type->tp_as_buffer = &et->as_buffer; type->tp_as_buffer = &et->as_buffer;
type->tp_name = PyUnicode_AsString(name); type->tp_name = _PyUnicode_AsString(name);
if (!type->tp_name) { if (!type->tp_name) {
Py_DECREF(type); Py_DECREF(type);
return NULL; return NULL;
@ -2136,7 +2136,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
char *doc_str; char *doc_str;
char *tp_doc; char *tp_doc;
doc_str = PyUnicode_AsStringAndSize(doc, &len); doc_str = _PyUnicode_AsStringAndSize(doc, &len);
if (doc_str == NULL) { if (doc_str == NULL) {
Py_DECREF(type); Py_DECREF(type);
return NULL; return NULL;
@ -2175,7 +2175,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
slotoffset = base->tp_basicsize; slotoffset = base->tp_basicsize;
if (slots != NULL) { if (slots != NULL) {
for (i = 0; i < nslots; i++, mp++) { for (i = 0; i < nslots; i++, mp++) {
mp->name = PyUnicode_AsString( mp->name = _PyUnicode_AsString(
PyTuple_GET_ITEM(slots, i)); PyTuple_GET_ITEM(slots, i));
mp->type = T_OBJECT_EX; mp->type = T_OBJECT_EX;
mp->offset = slotoffset; mp->offset = slotoffset;

View File

@ -1452,7 +1452,7 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
} }
char* char*
PyUnicode_AsStringAndSize(PyObject *unicode, Py_ssize_t *psize) _PyUnicode_AsStringAndSize(PyObject *unicode, Py_ssize_t *psize)
{ {
PyObject *bytes; PyObject *bytes;
if (!PyUnicode_Check(unicode)) { if (!PyUnicode_Check(unicode)) {
@ -1468,9 +1468,9 @@ PyUnicode_AsStringAndSize(PyObject *unicode, Py_ssize_t *psize)
} }
char* char*
PyUnicode_AsString(PyObject *unicode) _PyUnicode_AsString(PyObject *unicode)
{ {
return PyUnicode_AsStringAndSize(unicode, NULL); return _PyUnicode_AsStringAndSize(unicode, NULL);
} }
Py_UNICODE *PyUnicode_AsUnicode(PyObject *unicode) Py_UNICODE *PyUnicode_AsUnicode(PyObject *unicode)

View File

@ -167,7 +167,7 @@ weakref_repr(PyWeakReference *self)
if (nameobj == NULL) if (nameobj == NULL)
PyErr_Clear(); PyErr_Clear();
else if (PyUnicode_Check(nameobj)) else if (PyUnicode_Check(nameobj))
name = PyUnicode_AsString(nameobj); name = _PyUnicode_AsString(nameobj);
PyOS_snprintf(buffer, sizeof(buffer), PyOS_snprintf(buffer, sizeof(buffer),
name ? "<weakref at %p; to '%.50s' at %p (%s)>" name ? "<weakref at %p; to '%.50s' at %p (%s)>"
: "<weakref at %p; to '%.50s' at %p>", : "<weakref at %p; to '%.50s' at %p>",

View File

@ -391,7 +391,7 @@ fp_readl(char *s, int size, struct tok_state *tok)
} }
if (PyUnicode_CheckExact(bufobj)) if (PyUnicode_CheckExact(bufobj))
{ {
buf = PyUnicode_AsStringAndSize(bufobj, &buflen); buf = _PyUnicode_AsStringAndSize(bufobj, &buflen);
if (buf == NULL) { if (buf == NULL) {
goto error; goto error;
} }

View File

@ -132,7 +132,7 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
return NULL; return NULL;
if (good_msg && is_subclass && good_mod && (ln == 0 || lineno == ln)) if (good_msg && is_subclass && good_mod && (ln == 0 || lineno == ln))
return PyUnicode_AsString(action); return _PyUnicode_AsString(action);
} }
m = PyImport_ImportModule(MODULE_NAME); m = PyImport_ImportModule(MODULE_NAME);
@ -144,7 +144,7 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
return NULL; return NULL;
action = PyDict_GetItemString(d, DEFAULT_ACTION_NAME); action = PyDict_GetItemString(d, DEFAULT_ACTION_NAME);
if (action != NULL) if (action != NULL)
return PyUnicode_AsString(action); return _PyUnicode_AsString(action);
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
MODULE_NAME "." DEFAULT_ACTION_NAME " not found"); MODULE_NAME "." DEFAULT_ACTION_NAME " not found");
@ -186,7 +186,7 @@ normalize_module(PyObject *filename)
else if (rc == 0) else if (rc == 0)
return PyUnicode_FromString("<unknown>"); return PyUnicode_FromString("<unknown>");
mod_str = PyUnicode_AsString(filename); mod_str = _PyUnicode_AsString(filename);
if (mod_str == NULL) if (mod_str == NULL)
return NULL; return NULL;
len = PyUnicode_GetSize(filename); len = PyUnicode_GetSize(filename);
@ -257,7 +257,7 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject
/* Print " source_line\n" */ /* Print " source_line\n" */
if (sourceline) { if (sourceline) {
char *source_line_str = PyUnicode_AsString(sourceline); char *source_line_str = _PyUnicode_AsString(sourceline);
while (*source_line_str == ' ' || *source_line_str == '\t' || while (*source_line_str == ' ' || *source_line_str == '\t' ||
*source_line_str == '\014') *source_line_str == '\014')
source_line_str++; source_line_str++;
@ -266,7 +266,7 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject
PyFile_WriteString("\n", f_stderr); PyFile_WriteString("\n", f_stderr);
} }
else else
_Py_DisplaySourceLine(f_stderr, PyUnicode_AsString(filename), _Py_DisplaySourceLine(f_stderr, _PyUnicode_AsString(filename),
lineno, 2); lineno, 2);
PyErr_Clear(); PyErr_Clear();
} }
@ -367,7 +367,7 @@ warn_explicit(PyObject *category, PyObject *message,
const char *err_str = "???"; const char *err_str = "???";
if (to_str != NULL) if (to_str != NULL)
err_str = PyUnicode_AsString(to_str); err_str = _PyUnicode_AsString(to_str);
PyErr_Format(PyExc_RuntimeError, PyErr_Format(PyExc_RuntimeError,
"Unrecognized action (%s) in warnings.filters:\n %s", "Unrecognized action (%s) in warnings.filters:\n %s",
action, err_str); action, err_str);
@ -388,7 +388,7 @@ warn_explicit(PyObject *category, PyObject *message,
else { else {
const char *msg = "functions overriding warnings.showwarning() " const char *msg = "functions overriding warnings.showwarning() "
"must support the 'line' argument"; "must support the 'line' argument";
const char *text_char = PyUnicode_AsString(text); const char *text_char = _PyUnicode_AsString(text);
if (strcmp(msg, text_char) == 0) { if (strcmp(msg, text_char) == 0) {
/* Prevent infinite recursion by using built-in implementation /* Prevent infinite recursion by using built-in implementation
@ -503,7 +503,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
*filename = PyDict_GetItemString(globals, "__file__"); *filename = PyDict_GetItemString(globals, "__file__");
if (*filename != NULL) { if (*filename != NULL) {
Py_ssize_t len = PyUnicode_GetSize(*filename); Py_ssize_t len = PyUnicode_GetSize(*filename);
const char *file_str = PyUnicode_AsString(*filename); const char *file_str = _PyUnicode_AsString(*filename);
if (file_str == NULL || (len < 0 && PyErr_Occurred())) if (file_str == NULL || (len < 0 && PyErr_Occurred()))
goto handle_error; goto handle_error;
@ -523,7 +523,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
Py_INCREF(*filename); Py_INCREF(*filename);
} }
else { else {
const char *module_str = PyUnicode_AsString(*module); const char *module_str = _PyUnicode_AsString(*module);
if (module_str && strcmp(module_str, "__main__") == 0) { if (module_str && strcmp(module_str, "__main__") == 0) {
PyObject *argv = PySys_GetObject("argv"); PyObject *argv = PySys_GetObject("argv");
if (argv != NULL && PyList_Size(argv) > 0) { if (argv != NULL && PyList_Size(argv) > 0) {

View File

@ -1324,7 +1324,7 @@ ast_for_atom(struct compiling *c, const node *n)
if (errstr) { if (errstr) {
char *s = ""; char *s = "";
char buf[128]; char buf[128];
s = PyUnicode_AsString(errstr); s = _PyUnicode_AsString(errstr);
PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s); PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s);
ast_error(n, buf); ast_error(n, buf);
} else { } else {

View File

@ -1606,7 +1606,7 @@ builtin_input(PyObject *self, PyObject *args)
Py_DECREF(stdin_encoding); Py_DECREF(stdin_encoding);
return NULL; return NULL;
} }
prompt = PyUnicode_AsString(po); prompt = _PyUnicode_AsString(po);
if (prompt == NULL) { if (prompt == NULL) {
Py_DECREF(stdin_encoding); Py_DECREF(stdin_encoding);
Py_DECREF(po); Py_DECREF(po);
@ -1639,7 +1639,7 @@ builtin_input(PyObject *self, PyObject *args)
else { else {
result = PyUnicode_Decode result = PyUnicode_Decode
(s, len-1, (s, len-1,
PyUnicode_AsString(stdin_encoding), _PyUnicode_AsString(stdin_encoding),
NULL); NULL);
} }
} }

View File

@ -859,7 +859,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
lltrace = PyDict_GetItemString(f->f_globals, "__lltrace__") != NULL; lltrace = PyDict_GetItemString(f->f_globals, "__lltrace__") != NULL;
#endif #endif
#if defined(Py_DEBUG) || defined(LLTRACE) #if defined(Py_DEBUG) || defined(LLTRACE)
filename = PyUnicode_AsString(co->co_filename); filename = _PyUnicode_AsString(co->co_filename);
#endif #endif
why = WHY_NOT; why = WHY_NOT;
@ -3291,7 +3291,7 @@ PyEval_GetFuncName(PyObject *func)
if (PyMethod_Check(func)) if (PyMethod_Check(func))
return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func)); return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func));
else if (PyFunction_Check(func)) else if (PyFunction_Check(func))
return PyUnicode_AsString(((PyFunctionObject*)func)->func_name); return _PyUnicode_AsString(((PyFunctionObject*)func)->func_name);
else if (PyCFunction_Check(func)) else if (PyCFunction_Check(func))
return ((PyCFunctionObject*)func)->m_ml->ml_name; return ((PyCFunctionObject*)func)->m_ml->ml_name;
else else
@ -3527,7 +3527,7 @@ update_keyword_args(PyObject *orig_kwdict, int nk, PyObject ***pp_stack,
"for keyword argument '%.200s'", "for keyword argument '%.200s'",
PyEval_GetFuncName(func), PyEval_GetFuncName(func),
PyEval_GetFuncDesc(func), PyEval_GetFuncDesc(func),
PyUnicode_AsString(key)); _PyUnicode_AsString(key));
Py_DECREF(key); Py_DECREF(key);
Py_DECREF(value); Py_DECREF(value);
Py_DECREF(kwdict); Py_DECREF(kwdict);
@ -3874,7 +3874,7 @@ format_exc_check_arg(PyObject *exc, const char *format_str, PyObject *obj)
if (!obj) if (!obj)
return; return;
obj_str = PyUnicode_AsString(obj); obj_str = _PyUnicode_AsString(obj);
if (!obj_str) if (!obj_str)
return; return;

View File

@ -1300,7 +1300,7 @@ compiler_make_closure(struct compiler *c, PyCodeObject *co, int args)
PyObject_REPR(name), PyObject_REPR(name),
PyBytes_AS_STRING(c->u->u_name), PyBytes_AS_STRING(c->u->u_name),
reftype, arg, reftype, arg,
PyUnicode_AsString(co->co_name), _PyUnicode_AsString(co->co_name),
PyObject_REPR(co->co_freevars)); PyObject_REPR(co->co_freevars));
Py_FatalError("compiler_make_closure()"); Py_FatalError("compiler_make_closure()");
} }

View File

@ -709,7 +709,7 @@ PyErr_WriteUnraisable(PyObject *obj)
if (moduleName == NULL) if (moduleName == NULL)
PyFile_WriteString("<unknown>", f); PyFile_WriteString("<unknown>", f);
else { else {
char* modstr = PyUnicode_AsString(moduleName); char* modstr = _PyUnicode_AsString(moduleName);
if (modstr && if (modstr &&
strcmp(modstr, "builtins") != 0) strcmp(modstr, "builtins") != 0)
{ {

View File

@ -20,7 +20,7 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)
names = s->v.ImportFrom.names; names = s->v.ImportFrom.names;
for (i = 0; i < asdl_seq_LEN(names); i++) { for (i = 0; i < asdl_seq_LEN(names); i++) {
alias_ty name = (alias_ty)asdl_seq_GET(names, i); alias_ty name = (alias_ty)asdl_seq_GET(names, i);
const char *feature = PyUnicode_AsString(name->name); const char *feature = _PyUnicode_AsString(name->name);
if (!feature) if (!feature)
return 0; return 0;
if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) { if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) {

View File

@ -1537,7 +1537,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
"keywords must be strings"); "keywords must be strings");
return cleanreturn(0, freelist); return cleanreturn(0, freelist);
} }
ks = PyUnicode_AsString(key); ks = _PyUnicode_AsString(key);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (!strcmp(ks, kwlist[i])) { if (!strcmp(ks, kwlist[i])) {
match = 1; match = 1;

View File

@ -470,7 +470,7 @@ PyImport_Cleanup(void)
if (value->ob_refcnt != 1) if (value->ob_refcnt != 1)
continue; continue;
if (PyUnicode_Check(key) && PyModule_Check(value)) { if (PyUnicode_Check(key) && PyModule_Check(value)) {
name = PyUnicode_AsString(key); name = _PyUnicode_AsString(key);
if (strcmp(name, "builtins") == 0) if (strcmp(name, "builtins") == 0)
continue; continue;
if (strcmp(name, "sys") == 0) if (strcmp(name, "sys") == 0)
@ -489,7 +489,7 @@ PyImport_Cleanup(void)
pos = 0; pos = 0;
while (PyDict_Next(modules, &pos, &key, &value)) { while (PyDict_Next(modules, &pos, &key, &value)) {
if (PyUnicode_Check(key) && PyModule_Check(value)) { if (PyUnicode_Check(key) && PyModule_Check(value)) {
name = PyUnicode_AsString(key); name = _PyUnicode_AsString(key);
if (strcmp(name, "builtins") == 0) if (strcmp(name, "builtins") == 0)
continue; continue;
if (strcmp(name, "sys") == 0) if (strcmp(name, "sys") == 0)
@ -1296,7 +1296,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
if (path != NULL && PyUnicode_Check(path)) { if (path != NULL && PyUnicode_Check(path)) {
/* The only type of submodule allowed inside a "frozen" /* The only type of submodule allowed inside a "frozen"
package are other frozen modules or packages. */ package are other frozen modules or packages. */
char *p = PyUnicode_AsString(path); char *p = _PyUnicode_AsString(path);
if (strlen(p) + 1 + strlen(name) >= (size_t)buflen) { if (strlen(p) + 1 + strlen(name) >= (size_t)buflen) {
PyErr_SetString(PyExc_ImportError, PyErr_SetString(PyExc_ImportError,
"full frozen module name too long"); "full frozen module name too long");
@ -2197,7 +2197,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
"__package__ set to non-string"); "__package__ set to non-string");
return NULL; return NULL;
} }
pkgname_str = PyUnicode_AsStringAndSize(pkgname, &len); pkgname_str = _PyUnicode_AsStringAndSize(pkgname, &len);
if (len == 0) { if (len == 0) {
if (level > 0) { if (level > 0) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
@ -2225,7 +2225,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
Py_ssize_t len; Py_ssize_t len;
int error; int error;
modname_str = PyUnicode_AsStringAndSize(modname, &len); modname_str = _PyUnicode_AsStringAndSize(modname, &len);
if (len > MAXPATHLEN) { if (len > MAXPATHLEN) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"Module name too long"); "Module name too long");
@ -2240,7 +2240,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
} }
} else { } else {
/* Normal module, so work out the package name if any */ /* Normal module, so work out the package name if any */
char *start = PyUnicode_AsString(modname); char *start = _PyUnicode_AsString(modname);
char *lastdot = strrchr(start, '.'); char *lastdot = strrchr(start, '.');
size_t len; size_t len;
int error; int error;
@ -2635,7 +2635,7 @@ PyImport_ReloadModule(PyObject *m)
if (parent == NULL) { if (parent == NULL) {
PyErr_Format(PyExc_ImportError, PyErr_Format(PyExc_ImportError,
"reload(): parent %.200s not in sys.modules", "reload(): parent %.200s not in sys.modules",
PyUnicode_AsString(parentname)); _PyUnicode_AsString(parentname));
Py_DECREF(parentname); Py_DECREF(parentname);
imp_modules_reloading_clear(); imp_modules_reloading_clear();
return NULL; return NULL;

View File

@ -407,7 +407,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
case LOAD_NAME: case LOAD_NAME:
case LOAD_GLOBAL: case LOAD_GLOBAL:
j = GETARG(codestr, i); j = GETARG(codestr, i);
name = PyUnicode_AsString(PyTuple_GET_ITEM(names, j)); name = _PyUnicode_AsString(PyTuple_GET_ITEM(names, j));
h = load_global(codestr, i, name, consts); h = load_global(codestr, i, name, consts);
if (h < 0) if (h < 0)
goto exitUnchanged; goto exitUnchanged;

View File

@ -803,7 +803,7 @@ initstdio(void)
encoding_attr = PyObject_GetAttrString(std, "encoding"); encoding_attr = PyObject_GetAttrString(std, "encoding");
if (encoding_attr != NULL) { if (encoding_attr != NULL) {
const char * encoding; const char * encoding;
encoding = PyUnicode_AsString(encoding_attr); encoding = _PyUnicode_AsString(encoding_attr);
if (encoding != NULL) { if (encoding != NULL) {
_PyCodec_Lookup(encoding); _PyCodec_Lookup(encoding);
} }
@ -909,7 +909,7 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
oenc = PyObject_GetAttrString(v, "encoding"); oenc = PyObject_GetAttrString(v, "encoding");
if (!oenc) if (!oenc)
return -1; return -1;
enc = PyUnicode_AsString(oenc); enc = _PyUnicode_AsString(oenc);
} }
v = PySys_GetObject("ps1"); v = PySys_GetObject("ps1");
if (v != NULL) { if (v != NULL) {
@ -917,7 +917,7 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
if (v == NULL) if (v == NULL)
PyErr_Clear(); PyErr_Clear();
else if (PyUnicode_Check(v)) else if (PyUnicode_Check(v))
ps1 = PyUnicode_AsString(v); ps1 = _PyUnicode_AsString(v);
} }
w = PySys_GetObject("ps2"); w = PySys_GetObject("ps2");
if (w != NULL) { if (w != NULL) {
@ -925,7 +925,7 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
if (w == NULL) if (w == NULL)
PyErr_Clear(); PyErr_Clear();
else if (PyUnicode_Check(w)) else if (PyUnicode_Check(w))
ps2 = PyUnicode_AsString(w); ps2 = _PyUnicode_AsString(w);
} }
arena = PyArena_New(); arena = PyArena_New();
if (arena == NULL) { if (arena == NULL) {
@ -1101,7 +1101,7 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
goto finally; goto finally;
if (v == Py_None) if (v == Py_None)
*filename = NULL; *filename = NULL;
else if (! (*filename = PyUnicode_AsString(v))) else if (! (*filename = _PyUnicode_AsString(v)))
goto finally; goto finally;
Py_DECREF(v); Py_DECREF(v);
@ -1134,7 +1134,7 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
if (v == Py_None) if (v == Py_None)
*text = NULL; *text = NULL;
else if (!PyUnicode_Check(v) || else if (!PyUnicode_Check(v) ||
!(*text = PyUnicode_AsString(v))) !(*text = _PyUnicode_AsString(v)))
goto finally; goto finally;
Py_DECREF(v); Py_DECREF(v);
return 1; return 1;
@ -1357,7 +1357,7 @@ print_exception(PyObject *f, PyObject *value)
err = PyFile_WriteString("<unknown>", f); err = PyFile_WriteString("<unknown>", f);
} }
else { else {
char* modstr = PyUnicode_AsString(moduleName); char* modstr = _PyUnicode_AsString(moduleName);
if (modstr && strcmp(modstr, "builtins")) if (modstr && strcmp(modstr, "builtins"))
{ {
err = PyFile_WriteString(modstr, f); err = PyFile_WriteString(modstr, f);
@ -1806,7 +1806,7 @@ err_input(perrdetail *err)
if (value != NULL) { if (value != NULL) {
u = PyObject_Str(value); u = PyObject_Str(value);
if (u != NULL) { if (u != NULL) {
msg = PyUnicode_AsString(u); msg = _PyUnicode_AsString(u);
} }
} }
if (msg == NULL) if (msg == NULL)

View File

@ -247,7 +247,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
PyErr_BadArgument(); PyErr_BadArgument();
return -1; return -1;
} }
string = PyUnicode_AsStringAndSize(v, &len); string = _PyUnicode_AsStringAndSize(v, &len);
if (len != 1) { if (len != 1) {
PyErr_BadArgument(); PyErr_BadArgument();
return -1; return -1;

View File

@ -1142,7 +1142,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
asdl_seq *seq = s->v.Global.names; asdl_seq *seq = s->v.Global.names;
for (i = 0; i < asdl_seq_LEN(seq); i++) { for (i = 0; i < asdl_seq_LEN(seq); i++) {
identifier name = (identifier)asdl_seq_GET(seq, i); identifier name = (identifier)asdl_seq_GET(seq, i);
char *c_name = PyUnicode_AsString(name); char *c_name = _PyUnicode_AsString(name);
long cur = symtable_lookup(st, name); long cur = symtable_lookup(st, name);
if (cur < 0) if (cur < 0)
return 0; return 0;
@ -1169,7 +1169,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
asdl_seq *seq = s->v.Nonlocal.names; asdl_seq *seq = s->v.Nonlocal.names;
for (i = 0; i < asdl_seq_LEN(seq); i++) { for (i = 0; i < asdl_seq_LEN(seq); i++) {
identifier name = (identifier)asdl_seq_GET(seq, i); identifier name = (identifier)asdl_seq_GET(seq, i);
char *c_name = PyUnicode_AsString(name); char *c_name = _PyUnicode_AsString(name);
long cur = symtable_lookup(st, name); long cur = symtable_lookup(st, name);
if (cur < 0) if (cur < 0)
return 0; return 0;

View File

@ -257,10 +257,10 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)
while (tb != NULL && err == 0) { while (tb != NULL && err == 0) {
if (depth <= limit) { if (depth <= limit) {
err = tb_displayline(f, err = tb_displayline(f,
PyUnicode_AsString( _PyUnicode_AsString(
tb->tb_frame->f_code->co_filename), tb->tb_frame->f_code->co_filename),
tb->tb_lineno, tb->tb_lineno,
PyUnicode_AsString(tb->tb_frame->f_code->co_name)); _PyUnicode_AsString(tb->tb_frame->f_code->co_name));
} }
depth--; depth--;
tb = tb->tb_next; tb = tb->tb_next;