Skip to content

Commit 0651583

Browse files
Replaced outdated macros _PyUnicode_AsString and _PyUnicode_AsStringAndSize
with PyUnicode_AsUTF8 and PyUnicode_AsUTF8AndSize.
1 parent e209739 commit 0651583

31 files changed

Lines changed: 62 additions & 62 deletions

Modules/_ctypes/_ctypes.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
17231723
if (stgd && CDataObject_Check(value) && stgd->proto && PyUnicode_Check(stgd->proto)) {
17241724
PyCArgObject *parg;
17251725

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

18361836
dict = PyObject_stgdict((PyObject *)self);
18371837
assert(dict); /* Cannot be NULL for CDataObject instances */
1838-
fmt = _PyUnicode_AsString(dict->proto);
1838+
fmt = PyUnicode_AsUTF8(dict->proto);
18391839
assert(fmt);
18401840

18411841
fd = _ctypes_get_fielddesc(fmt);
@@ -2059,7 +2059,7 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
20592059
assert(dict);
20602060

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

20652065
fd = _ctypes_get_fielddesc(fmt);
@@ -3128,7 +3128,7 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index)
31283128
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
31293129
&& PyUnicode_Check(dict->proto)
31303130
/* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */
3131-
&& (strchr("PzZ", _PyUnicode_AsString(dict->proto)[0]))) {
3131+
&& (strchr("PzZ", PyUnicode_AsUTF8(dict->proto)[0]))) {
31323132
return 1;
31333133
}
31343134

@@ -3218,7 +3218,7 @@ _get_name(PyObject *obj, const char **pname)
32183218
return *pname ? 1 : 0;
32193219
}
32203220
if (PyUnicode_Check(obj)) {
3221-
*pname = _PyUnicode_AsString(obj);
3221+
*pname = PyUnicode_AsUTF8(obj);
32223222
return *pname ? 1 : 0;
32233223
}
32243224
PyErr_SetString(PyExc_TypeError,
@@ -5233,7 +5233,7 @@ cast_check_pointertype(PyObject *arg)
52335233
dict = PyType_stgdict(arg);
52345234
if (dict) {
52355235
if (PyUnicode_Check(dict->proto)
5236-
&& (strchr("sPzUZXO", _PyUnicode_AsString(dict->proto)[0]))) {
5236+
&& (strchr("sPzUZXO", PyUnicode_AsUTF8(dict->proto)[0]))) {
52375237
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
52385238
return 1;
52395239
}

Modules/_ctypes/stgdict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
489489

490490
if (isStruct && !isPacked) {
491491
char *fieldfmt = dict->format ? dict->format : "B";
492-
char *fieldname = _PyUnicode_AsString(name);
492+
char *fieldname = PyUnicode_AsUTF8(name);
493493
char *ptr;
494494
Py_ssize_t len;
495495
char *buf;

Modules/_datetimemodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
12191219
assert(object && format && timetuple);
12201220
assert(PyUnicode_Check(format));
12211221
/* Convert the input format to a C string and size */
1222-
pin = _PyUnicode_AsStringAndSize(format, &flen);
1222+
pin = PyUnicode_AsUTF8AndSize(format, &flen);
12231223
if (!pin)
12241224
return NULL;
12251225

@@ -1287,7 +1287,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
12871287
}
12881288
assert(Zreplacement != NULL);
12891289
assert(PyUnicode_Check(Zreplacement));
1290-
ptoappend = _PyUnicode_AsStringAndSize(Zreplacement,
1290+
ptoappend = PyUnicode_AsUTF8AndSize(Zreplacement,
12911291
&ntoappend);
12921292
if (ptoappend == NULL)
12931293
goto Done;

Modules/_io/stringio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
708708
Py_TYPE(newline_obj)->tp_name);
709709
return -1;
710710
}
711-
newline = _PyUnicode_AsString(newline_obj);
711+
newline = PyUnicode_AsUTF8(newline_obj);
712712
if (newline == NULL)
713713
return -1;
714714
}

Modules/_io/textio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
921921
Py_CLEAR(self->encoding);
922922
}
923923
if (self->encoding != NULL) {
924-
encoding = _PyUnicode_AsString(self->encoding);
924+
encoding = PyUnicode_AsUTF8(self->encoding);
925925
if (encoding == NULL)
926926
goto error;
927927
}
@@ -964,7 +964,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
964964
}
965965
self->writetranslate = (newline == NULL || newline[0] != '\0');
966966
if (!self->readuniversal && self->readnl) {
967-
self->writenl = _PyUnicode_AsString(self->readnl);
967+
self->writenl = PyUnicode_AsUTF8(self->readnl);
968968
if (self->writenl == NULL)
969969
goto error;
970970
if (!strcmp(self->writenl, "\n"))

Modules/_pickle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ save_long(PicklerObject *self, PyObject *obj)
19511951
if (repr == NULL)
19521952
goto error;
19531953

1954-
string = _PyUnicode_AsStringAndSize(repr, &size);
1954+
string = PyUnicode_AsUTF8AndSize(repr, &size);
19551955
if (string == NULL)
19561956
goto error;
19571957

Modules/_sqlite/connection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
505505
} else if (PyFloat_Check(py_val)) {
506506
sqlite3_result_double(context, PyFloat_AsDouble(py_val));
507507
} else if (PyUnicode_Check(py_val)) {
508-
const char *str = _PyUnicode_AsString(py_val);
508+
const char *str = PyUnicode_AsUTF8(py_val);
509509
if (str == NULL)
510510
return -1;
511511
sqlite3_result_text(context, str, -1, SQLITE_TRANSIENT);
@@ -1527,7 +1527,7 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
15271527
}
15281528
}
15291529

1530-
uppercase_name_str = _PyUnicode_AsString(uppercase_name);
1530+
uppercase_name_str = PyUnicode_AsUTF8(uppercase_name);
15311531
if (!uppercase_name_str)
15321532
goto finally;
15331533

Modules/_sqlite/cursor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
465465
pysqlite_statement_reset(self->statement);
466466
}
467467

468-
operation_cstr = _PyUnicode_AsStringAndSize(operation, &operation_len);
468+
operation_cstr = PyUnicode_AsUTF8AndSize(operation, &operation_len);
469469
if (operation_cstr == NULL)
470470
goto error;
471471

@@ -689,7 +689,7 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args)
689689
self->reset = 0;
690690

691691
if (PyUnicode_Check(script_obj)) {
692-
script_cstr = _PyUnicode_AsString(script_obj);
692+
script_cstr = PyUnicode_AsUTF8(script_obj);
693693
if (!script_cstr) {
694694
return NULL;
695695
}

Modules/_sqlite/row.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
9898
Py_XINCREF(item);
9999
return item;
100100
} else if (PyUnicode_Check(idx)) {
101-
key = _PyUnicode_AsString(idx);
101+
key = PyUnicode_AsUTF8(idx);
102102
if (key == NULL)
103103
return NULL;
104104

@@ -108,7 +108,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
108108
PyObject *obj;
109109
obj = PyTuple_GET_ITEM(self->description, i);
110110
obj = PyTuple_GET_ITEM(obj, 0);
111-
compare_key = _PyUnicode_AsString(obj);
111+
compare_key = PyUnicode_AsUTF8(obj);
112112
if (!compare_key) {
113113
return NULL;
114114
}

Modules/_sqlite/statement.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
5959
self->st = NULL;
6060
self->in_use = 0;
6161

62-
sql_cstr = _PyUnicode_AsStringAndSize(sql, &sql_cstr_len);
62+
sql_cstr = PyUnicode_AsUTF8AndSize(sql, &sql_cstr_len);
6363
if (sql_cstr == NULL) {
6464
rc = PYSQLITE_SQL_WRONG_TYPE;
6565
return rc;
@@ -152,7 +152,7 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
152152
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
153153
break;
154154
case TYPE_UNICODE:
155-
string = _PyUnicode_AsStringAndSize(parameter, &buflen);
155+
string = PyUnicode_AsUTF8AndSize(parameter, &buflen);
156156
if (string == NULL)
157157
return -1;
158158
if (buflen > INT_MAX) {
@@ -325,7 +325,7 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
325325
Py_ssize_t sql_len;
326326
sqlite3_stmt* new_st;
327327

328-
sql_cstr = _PyUnicode_AsStringAndSize(self->sql, &sql_len);
328+
sql_cstr = PyUnicode_AsUTF8AndSize(self->sql, &sql_len);
329329
if (sql_cstr == NULL) {
330330
rc = PYSQLITE_SQL_WRONG_TYPE;
331331
return rc;

0 commit comments

Comments
 (0)