Fix T85573: Building with Python 3.10a5 fails
Replace deprecated _PyUnicode_AsString{AndSize} usage. T83626 still needs to be resolved before 3.10 is usable.
This commit is contained in:
@@ -257,7 +257,7 @@ int PyC_ParseBool(PyObject *o, void *p)
|
||||
int PyC_ParseStringEnum(PyObject *o, void *p)
|
||||
{
|
||||
struct PyC_StringEnum *e = p;
|
||||
const char *value = _PyUnicode_AsString(o);
|
||||
const char *value = PyUnicode_AsUTF8(o);
|
||||
if (value == NULL) {
|
||||
PyErr_Format(PyExc_ValueError, "expected a string, got %s", Py_TYPE(o)->tp_name);
|
||||
return 0;
|
||||
@@ -343,7 +343,7 @@ void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var)
|
||||
(int)var->ob_refcnt,
|
||||
(void *)var,
|
||||
type ? type->tp_name : null_str,
|
||||
var_str ? _PyUnicode_AsString(var_str) : "<error>");
|
||||
var_str ? PyUnicode_AsUTF8(var_str) : "<error>");
|
||||
if (var_str != NULL) {
|
||||
Py_DECREF(var_str);
|
||||
}
|
||||
@@ -405,7 +405,7 @@ void PyC_FileAndNum(const char **r_filename, int *r_lineno)
|
||||
|
||||
/* when executing a script */
|
||||
if (r_filename) {
|
||||
*r_filename = _PyUnicode_AsString(frame->f_code->co_filename);
|
||||
*r_filename = PyUnicode_AsUTF8(frame->f_code->co_filename);
|
||||
}
|
||||
|
||||
/* when executing a module */
|
||||
@@ -418,7 +418,7 @@ void PyC_FileAndNum(const char **r_filename, int *r_lineno)
|
||||
if (mod) {
|
||||
PyObject *mod_file = PyModule_GetFilenameObject(mod);
|
||||
if (mod_file) {
|
||||
*r_filename = _PyUnicode_AsString(mod_name);
|
||||
*r_filename = PyUnicode_AsUTF8(mod_name);
|
||||
Py_DECREF(mod_file);
|
||||
}
|
||||
else {
|
||||
@@ -428,7 +428,7 @@ void PyC_FileAndNum(const char **r_filename, int *r_lineno)
|
||||
|
||||
/* unlikely, fallback */
|
||||
if (*r_filename == NULL) {
|
||||
*r_filename = _PyUnicode_AsString(mod_name);
|
||||
*r_filename = PyUnicode_AsUTF8(mod_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -569,9 +569,9 @@ void PyC_Err_PrintWithFunc(PyObject *py_func)
|
||||
/* use py style error */
|
||||
fprintf(stderr,
|
||||
"File \"%s\", line %d, in %s\n",
|
||||
_PyUnicode_AsString(f_code->co_filename),
|
||||
PyUnicode_AsUTF8(f_code->co_filename),
|
||||
f_code->co_firstlineno,
|
||||
_PyUnicode_AsString(((PyFunctionObject *)py_func)->func_name));
|
||||
PyUnicode_AsUTF8(((PyFunctionObject *)py_func)->func_name));
|
||||
}
|
||||
|
||||
/** \} */
|
||||
@@ -740,7 +740,7 @@ const char *PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObjec
|
||||
{
|
||||
const char *result;
|
||||
|
||||
result = _PyUnicode_AsStringAndSize(py_str, size);
|
||||
result = PyUnicode_AsUTF8AndSize(py_str, size);
|
||||
|
||||
if (result) {
|
||||
/* 99% of the time this is enough but we better support non unicode
|
||||
@@ -767,7 +767,7 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
|
||||
{
|
||||
const char *result;
|
||||
|
||||
result = _PyUnicode_AsString(py_str);
|
||||
result = PyUnicode_AsUTF8(py_str);
|
||||
|
||||
if (result) {
|
||||
/* 99% of the time this is enough but we better support non unicode
|
||||
@@ -1146,7 +1146,7 @@ int PyC_FlagSet_ToBitfield(PyC_FlagSet *items,
|
||||
*r_value = 0;
|
||||
|
||||
while (_PySet_NextEntry(value, &pos, &key, &hash)) {
|
||||
const char *param = _PyUnicode_AsString(key);
|
||||
const char *param = PyUnicode_AsUTF8(key);
|
||||
|
||||
if (param == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
@@ -1324,7 +1324,7 @@ bool PyC_RunString_AsStringAndSize(const char *imports[],
|
||||
const char *val;
|
||||
Py_ssize_t val_len;
|
||||
|
||||
val = _PyUnicode_AsStringAndSize(retval, &val_len);
|
||||
val = PyUnicode_AsUTF8AndSize(retval, &val_len);
|
||||
if (val == NULL && PyErr_Occurred()) {
|
||||
ok = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user