Skip to content

Commit

Permalink
Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringA…
Browse files Browse the repository at this point in the history
…ndSize

with PyUnicode_AsUTF8 and PyUnicode_AsUTF8AndSize.
  • Loading branch information
serhiy-storchaka committed Nov 20, 2016
1 parent 4285800 commit 81ea51e
Show file tree
Hide file tree
Showing 31 changed files with 62 additions and 62 deletions.
12 changes: 6 additions & 6 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
if (stgd && CDataObject_Check(value) && stgd->proto && PyUnicode_Check(stgd->proto)) {
PyCArgObject *parg;

switch (_PyUnicode_AsString(stgd->proto)[0]) {
switch (PyUnicode_AsUTF8(stgd->proto)[0]) {
case 'z': /* c_char_p */
case 'Z': /* c_wchar_p */
parg = PyCArgObject_new();
Expand Down Expand Up @@ -1835,7 +1835,7 @@ PyCSimpleType_paramfunc(CDataObject *self)

dict = PyObject_stgdict((PyObject *)self);
assert(dict); /* Cannot be NULL for CDataObject instances */
fmt = _PyUnicode_AsString(dict->proto);
fmt = PyUnicode_AsUTF8(dict->proto);
assert(fmt);

fd = _ctypes_get_fielddesc(fmt);
Expand Down Expand Up @@ -2059,7 +2059,7 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
assert(dict);

/* I think we can rely on this being a one-character string */
fmt = _PyUnicode_AsString(dict->proto);
fmt = PyUnicode_AsUTF8(dict->proto);
assert(fmt);

fd = _ctypes_get_fielddesc(fmt);
Expand Down Expand Up @@ -3128,7 +3128,7 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index)
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
&& PyUnicode_Check(dict->proto)
/* 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_AsUTF8(dict->proto)[0]))) {
return 1;
}

Expand Down Expand Up @@ -3218,7 +3218,7 @@ _get_name(PyObject *obj, const char **pname)
return *pname ? 1 : 0;
}
if (PyUnicode_Check(obj)) {
*pname = _PyUnicode_AsString(obj);
*pname = PyUnicode_AsUTF8(obj);
return *pname ? 1 : 0;
}
PyErr_SetString(PyExc_TypeError,
Expand Down Expand Up @@ -5233,7 +5233,7 @@ cast_check_pointertype(PyObject *arg)
dict = PyType_stgdict(arg);
if (dict) {
if (PyUnicode_Check(dict->proto)
&& (strchr("sPzUZXO", _PyUnicode_AsString(dict->proto)[0]))) {
&& (strchr("sPzUZXO", PyUnicode_AsUTF8(dict->proto)[0]))) {
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/stgdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct

if (isStruct && !isPacked) {
char *fieldfmt = dict->format ? dict->format : "B";
char *fieldname = _PyUnicode_AsString(name);
char *fieldname = PyUnicode_AsUTF8(name);
char *ptr;
Py_ssize_t len;
char *buf;
Expand Down
4 changes: 2 additions & 2 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
assert(object && format && timetuple);
assert(PyUnicode_Check(format));
/* Convert the input format to a C string and size */
pin = _PyUnicode_AsStringAndSize(format, &flen);
pin = PyUnicode_AsUTF8AndSize(format, &flen);
if (!pin)
return NULL;

Expand Down Expand Up @@ -1287,7 +1287,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
}
assert(Zreplacement != NULL);
assert(PyUnicode_Check(Zreplacement));
ptoappend = _PyUnicode_AsStringAndSize(Zreplacement,
ptoappend = PyUnicode_AsUTF8AndSize(Zreplacement,
&ntoappend);
if (ptoappend == NULL)
goto Done;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_io/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
Py_TYPE(newline_obj)->tp_name);
return -1;
}
newline = _PyUnicode_AsString(newline_obj);
newline = PyUnicode_AsUTF8(newline_obj);
if (newline == NULL)
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
Py_CLEAR(self->encoding);
}
if (self->encoding != NULL) {
encoding = _PyUnicode_AsString(self->encoding);
encoding = PyUnicode_AsUTF8(self->encoding);
if (encoding == NULL)
goto error;
}
Expand Down Expand Up @@ -964,7 +964,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
}
self->writetranslate = (newline == NULL || newline[0] != '\0');
if (!self->readuniversal && self->readnl) {
self->writenl = _PyUnicode_AsString(self->readnl);
self->writenl = PyUnicode_AsUTF8(self->readnl);
if (self->writenl == NULL)
goto error;
if (!strcmp(self->writenl, "\n"))
Expand Down
2 changes: 1 addition & 1 deletion Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ save_long(PicklerObject *self, PyObject *obj)
if (repr == NULL)
goto error;

string = _PyUnicode_AsStringAndSize(repr, &size);
string = PyUnicode_AsUTF8AndSize(repr, &size);
if (string == NULL)
goto error;

Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
} else if (PyFloat_Check(py_val)) {
sqlite3_result_double(context, PyFloat_AsDouble(py_val));
} else if (PyUnicode_Check(py_val)) {
const char *str = _PyUnicode_AsString(py_val);
const char *str = PyUnicode_AsUTF8(py_val);
if (str == NULL)
return -1;
sqlite3_result_text(context, str, -1, SQLITE_TRANSIENT);
Expand Down Expand Up @@ -1527,7 +1527,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
}
}

uppercase_name_str = _PyUnicode_AsString(uppercase_name);
uppercase_name_str = PyUnicode_AsUTF8(uppercase_name);
if (!uppercase_name_str)
goto finally;

Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
pysqlite_statement_reset(self->statement);
}

operation_cstr = _PyUnicode_AsStringAndSize(operation, &operation_len);
operation_cstr = PyUnicode_AsUTF8AndSize(operation, &operation_len);
if (operation_cstr == NULL)
goto error;

Expand Down Expand Up @@ -689,7 +689,7 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
self->reset = 0;

if (PyUnicode_Check(script_obj)) {
script_cstr = _PyUnicode_AsString(script_obj);
script_cstr = PyUnicode_AsUTF8(script_obj);
if (!script_cstr) {
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/row.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
Py_XINCREF(item);
return item;
} else if (PyUnicode_Check(idx)) {
key = _PyUnicode_AsString(idx);
key = PyUnicode_AsUTF8(idx);
if (key == NULL)
return NULL;

Expand All @@ -108,7 +108,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
PyObject *obj;
obj = PyTuple_GET_ITEM(self->description, i);
obj = PyTuple_GET_ITEM(obj, 0);
compare_key = _PyUnicode_AsString(obj);
compare_key = PyUnicode_AsUTF8(obj);
if (!compare_key) {
return NULL;
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
self->st = NULL;
self->in_use = 0;

sql_cstr = _PyUnicode_AsStringAndSize(sql, &sql_cstr_len);
sql_cstr = PyUnicode_AsUTF8AndSize(sql, &sql_cstr_len);
if (sql_cstr == NULL) {
rc = PYSQLITE_SQL_WRONG_TYPE;
return rc;
Expand Down Expand Up @@ -152,7 +152,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
break;
case TYPE_UNICODE:
string = _PyUnicode_AsStringAndSize(parameter, &buflen);
string = PyUnicode_AsUTF8AndSize(parameter, &buflen);
if (string == NULL)
return -1;
if (buflen > INT_MAX) {
Expand Down Expand Up @@ -325,7 +325,7 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
Py_ssize_t sql_len;
sqlite3_stmt* new_st;

sql_cstr = _PyUnicode_AsStringAndSize(self->sql, &sql_len);
sql_cstr = PyUnicode_AsUTF8AndSize(self->sql, &sql_len);
if (sql_cstr == NULL) {
rc = PYSQLITE_SQL_WRONG_TYPE;
return rc;
Expand Down
2 changes: 1 addition & 1 deletion Modules/cjkcodecs/cjkcodecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ getcodec(PyObject *self, PyObject *encoding)
"encoding name must be a string.");
return NULL;
}
enc = _PyUnicode_AsString(encoding);
enc = PyUnicode_AsUTF8(encoding);
if (enc == NULL)
return NULL;

Expand Down
4 changes: 2 additions & 2 deletions Modules/cjkcodecs/multibytecodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ call_error_callback(PyObject *errors, PyObject *exc)
const char *str;

assert(PyUnicode_Check(errors));
str = _PyUnicode_AsString(errors);
str = PyUnicode_AsUTF8(errors);
if (str == NULL)
return NULL;
cb = PyCodec_LookupError(str);
Expand Down Expand Up @@ -138,7 +138,7 @@ codecctx_errors_set(MultibyteStatefulCodecContext *self, PyObject *value,
return -1;
}

str = _PyUnicode_AsString(value);
str = PyUnicode_AsUTF8(value);
if (str == NULL)
return -1;

Expand Down
4 changes: 2 additions & 2 deletions Modules/parsermodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
Py_DECREF(o);
}
}
temp_str = _PyUnicode_AsStringAndSize(temp, &len);
temp_str = PyUnicode_AsUTF8AndSize(temp, &len);
if (temp_str == NULL) {
Py_DECREF(temp);
Py_XDECREF(elem);
Expand Down Expand Up @@ -1013,7 +1013,7 @@ build_node_tree(PyObject *tuple)
if (res && encoding) {
Py_ssize_t len;
const char *temp;
temp = _PyUnicode_AsStringAndSize(encoding, &len);
temp = PyUnicode_AsUTF8AndSize(encoding, &len);
if (temp == NULL) {
Py_DECREF(res);
Py_DECREF(encoding);
Expand Down
2 changes: 1 addition & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -9325,7 +9325,7 @@ conv_confname(PyObject *arg, int *valuep, struct constdef *table,
"configuration names must be strings or integers");
return 0;
}
confname = _PyUnicode_AsString(arg);
confname = PyUnicode_AsUTF8(arg);
if (confname == NULL)
return 0;
while (lo < hi) {
Expand Down
2 changes: 1 addition & 1 deletion Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -5989,7 +5989,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value);
pptr = pbuf;
} else if (PyUnicode_Check(pobj)) {
pptr = _PyUnicode_AsString(pobj);
pptr = PyUnicode_AsUTF8(pobj);
if (pptr == NULL)
goto err;
} else if (PyBytes_Check(pobj)) {
Expand Down
4 changes: 2 additions & 2 deletions Modules/syslogmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ syslog_openlog(PyObject * self, PyObject * args, PyObject *kwds)
* If NULL, just let openlog figure it out (probably using C argv[0]).
*/
if (S_ident_o) {
ident = _PyUnicode_AsString(S_ident_o);
ident = PyUnicode_AsUTF8(S_ident_o);
if (ident == NULL)
return NULL;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ syslog_syslog(PyObject * self, PyObject * args)
return NULL;
}

message = _PyUnicode_AsString(message_object);
message = PyUnicode_AsUTF8(message_object);
if (message == NULL)
return NULL;

Expand Down
2 changes: 1 addition & 1 deletion Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ gettmarg(PyObject *args, struct tm *p)
if (Py_TYPE(args) == &StructTimeType) {
PyObject *item;
item = PyTuple_GET_ITEM(args, 9);
p->tm_zone = item == Py_None ? NULL : _PyUnicode_AsString(item);
p->tm_zone = item == Py_None ? NULL : PyUnicode_AsUTF8(item);
item = PyTuple_GET_ITEM(args, 10);
p->tm_gmtoff = item == Py_None ? 0 : PyLong_AsLong(item);
if (PyErr_Occurred())
Expand Down
4 changes: 2 additions & 2 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ float_fromhex(PyObject *cls, PyObject *arg)
* exp+4*ndigits and exp-4*ndigits are within the range of a long.
*/

s = _PyUnicode_AsStringAndSize(arg, &length);
s = PyUnicode_AsUTF8AndSize(arg, &length);
if (s == NULL)
return NULL;
s_end = s + length;
Expand Down Expand Up @@ -1628,7 +1628,7 @@ float_getformat(PyTypeObject *v, PyObject* arg)
Py_TYPE(arg)->tp_name);
return NULL;
}
s = _PyUnicode_AsString(arg);
s = PyUnicode_AsUTF8(arg);
if (s == NULL)
return NULL;
if (strcmp(s, "double") == 0) {
Expand Down
8 changes: 4 additions & 4 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ PyModule_GetName(PyObject *m)
if (name == NULL)
return NULL;
Py_DECREF(name); /* module dict has still a reference */
return _PyUnicode_AsString(name);
return PyUnicode_AsUTF8(name);
}

PyObject*
Expand Down Expand Up @@ -516,7 +516,7 @@ PyModule_GetFilename(PyObject *m)
fileobj = PyModule_GetFilenameObject(m);
if (fileobj == NULL)
return NULL;
utf8 = _PyUnicode_AsString(fileobj);
utf8 = PyUnicode_AsUTF8(fileobj);
Py_DECREF(fileobj); /* module dict has still a reference */
return utf8;
}
Expand Down Expand Up @@ -569,7 +569,7 @@ _PyModule_ClearDict(PyObject *d)
if (PyUnicode_READ_CHAR(key, 0) == '_' &&
PyUnicode_READ_CHAR(key, 1) != '_') {
if (Py_VerboseFlag > 1) {
const char *s = _PyUnicode_AsString(key);
const char *s = PyUnicode_AsUTF8(key);
if (s != NULL)
PySys_WriteStderr("# clear[1] %s\n", s);
else
Expand All @@ -589,7 +589,7 @@ _PyModule_ClearDict(PyObject *d)
!_PyUnicode_EqualToASCIIString(key, "__builtins__"))
{
if (Py_VerboseFlag > 1) {
const char *s = _PyUnicode_AsString(key);
const char *s = PyUnicode_AsUTF8(key);
if (s != NULL)
PySys_WriteStderr("# clear[2] %s\n", s);
else
Expand Down
4 changes: 2 additions & 2 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
if (tp->tp_getattro != NULL)
return (*tp->tp_getattro)(v, name);
if (tp->tp_getattr != NULL) {
char *name_str = _PyUnicode_AsString(name);
char *name_str = PyUnicode_AsUTF8(name);
if (name_str == NULL)
return NULL;
return (*tp->tp_getattr)(v, name_str);
Expand Down Expand Up @@ -934,7 +934,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
return err;
}
if (tp->tp_setattr != NULL) {
char *name_str = _PyUnicode_AsString(name);
char *name_str = PyUnicode_AsUTF8(name);
if (name_str == NULL)
return -1;
err = (*tp->tp_setattr)(v, name_str, value);
Expand Down
2 changes: 1 addition & 1 deletion Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2466,7 +2466,7 @@ test_c_api(PySetObject *so)
/* Exercise direct iteration */
i = 0, count = 0;
while (_PySet_NextEntry((PyObject *)dup, &i, &x, &hash)) {
s = _PyUnicode_AsString(x);
s = PyUnicode_AsUTF8(x);
assert(s && (s[0] == 'a' || s[0] == 'b' || s[0] == 'c'));
count++;
}
Expand Down
2 changes: 1 addition & 1 deletion Objects/structseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ structseq_repr(PyStructSequence *obj)
repr = PyObject_Repr(val);
if (repr == NULL)
return NULL;
crepr = _PyUnicode_AsString(repr);
crepr = PyUnicode_AsUTF8(repr);
if (crepr == NULL) {
Py_DECREF(repr);
return NULL;
Expand Down
Loading

0 comments on commit 81ea51e

Please sign in to comment.