mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-89188: Implement PyUnicode_KIND() as a function (#129412)
Implement PyUnicode_KIND() and PyUnicode_DATA() as function, in addition to the macros with the same names. The macros rely on C bit fields which have compiler-specific layout.
This commit is contained in:
parent
e1c4ba9288
commit
a810cb89f1
3 changed files with 30 additions and 2 deletions
|
@ -16486,3 +16486,24 @@ PyInit__string(void)
|
|||
{
|
||||
return PyModuleDef_Init(&_string_module);
|
||||
}
|
||||
|
||||
|
||||
#undef PyUnicode_KIND
|
||||
int PyUnicode_KIND(PyObject *op)
|
||||
{
|
||||
if (!PyUnicode_Check(op)) {
|
||||
PyErr_Format(PyExc_TypeError, "expect str, got %T", op);
|
||||
return -1;
|
||||
}
|
||||
return _PyASCIIObject_CAST(op)->state.kind;
|
||||
}
|
||||
|
||||
#undef PyUnicode_DATA
|
||||
void* PyUnicode_DATA(PyObject *op)
|
||||
{
|
||||
if (!PyUnicode_Check(op)) {
|
||||
PyErr_Format(PyExc_TypeError, "expect str, got %T", op);
|
||||
return NULL;
|
||||
}
|
||||
return _PyUnicode_DATA(op);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue