GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-89653: PEP 670: Convert PyUnicode_KIND() macro to function by vstinner · Pull Request #92705 · python/cpython

gh-89653: PEP 670: Convert PyUnicode_KIND() macro to function #92705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
vstinner merged 1 commit into python:main from vstinner:kind_func
May 13, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

gh-89653: PEP 670: Convert PyUnicode_KIND() macro to function #92705

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
3bce0ec
gh-89653: PEP 670: Convert PyUnicode_KIND() macro to function
vstinner May 12, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

16 changes: 15 additions & 1 deletion 16 Include/cpython/unicodeobject.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,23 @@ enum PyUnicode_Kind {
PyUnicode_4BYTE_KIND = 4
};

/* Return one of the PyUnicode_*_KIND values defined above. */
// PyUnicode_KIND(): Return one of the PyUnicode_*_KIND values defined above.
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030c0000
// gh-89653: Converting this macro to a static inline function would introduce
// new compiler warnings on "kind < PyUnicode_KIND(str)" (compare signed and
// unsigned numbers) where kind type is an int or on
// "unsigned int kind = PyUnicode_KIND(str)" (cast signed to unsigned).
// Only declare the function as static inline function in the limited C API
// version 3.12 which is stricter.
#define PyUnicode_KIND(op) \
(_PyASCIIObject_CAST(op)->state.kind)
#else
// Limited C API 3.12 and newer
static inline int PyUnicode_KIND(PyObject *op) {
assert(PyUnicode_IS_READY(op));
return _PyASCIIObject_CAST(op)->state.kind;
}
#endif

/* Return a void pointer to the raw unicode buffer. */
static inline void* _PyUnicode_COMPACT_DATA(PyObject *op) {
Expand Down
12 changes: 6 additions & 6 deletions 12 Modules/_decimal/_decimal.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ is_space(enum PyUnicode_Kind kind, const void *data, Py_ssize_t pos)
Return NULL if malloc fails and an empty string if invalid characters
are found. */
static char *
numeric_as_ascii(const PyObject *u, int strip_ws, int ignore_underscores)
numeric_as_ascii(PyObject *u, int strip_ws, int ignore_underscores)
{
enum PyUnicode_Kind kind;
const void *data;
Expand Down Expand Up @@ -2047,7 +2047,7 @@ PyDecType_FromCStringExact(PyTypeObject *type, const char *s,

/* Return a new PyDecObject or a subtype from a PyUnicodeObject. */
static PyObject *
PyDecType_FromUnicode(PyTypeObject *type, const PyObject *u,
PyDecType_FromUnicode(PyTypeObject *type, PyObject *u,
PyObject *context)
{
PyObject *dec;
Expand All @@ -2067,7 +2067,7 @@ PyDecType_FromUnicode(PyTypeObject *type, const PyObject *u,
* conversion. If the conversion is not exact, fail with InvalidOperation.
* Allow leading and trailing whitespace in the input operand. */
static PyObject *
PyDecType_FromUnicodeExactWS(PyTypeObject *type, const PyObject *u,
PyDecType_FromUnicodeExactWS(PyTypeObject *type, PyObject *u,
PyObject *context)
{
PyObject *dec;
Expand Down Expand Up @@ -2150,7 +2150,7 @@ PyDecType_FromSsizeExact(PyTypeObject *type, mpd_ssize_t v, PyObject *context)
/* Convert from a PyLongObject. The context is not modified; flags set
during conversion are accumulated in the status parameter. */
static PyObject *
dec_from_long(PyTypeObject *type, const PyObject *v,
dec_from_long(PyTypeObject *type, PyObject *v,
const mpd_context_t *ctx, uint32_t *status)
{
PyObject *dec;
Expand Down Expand Up @@ -2201,7 +2201,7 @@ dec_from_long(PyTypeObject *type, const PyObject *v,
/* Return a new PyDecObject from a PyLongObject. Use the context for
conversion. */
static PyObject *
PyDecType_FromLong(PyTypeObject *type, const PyObject *v, PyObject *context)
PyDecType_FromLong(PyTypeObject *type, PyObject *v, PyObject *context)
{
PyObject *dec;
uint32_t status = 0;
Expand All @@ -2227,7 +2227,7 @@ PyDecType_FromLong(PyTypeObject *type, const PyObject *v, PyObject *context)
/* Return a new PyDecObject from a PyLongObject. Use a maximum context
for conversion. If the conversion is not exact, set InvalidOperation. */
static PyObject *
PyDecType_FromLongExact(PyTypeObject *type, const PyObject *v,
PyDecType_FromLongExact(PyTypeObject *type, PyObject *v,
PyObject *context)
{
PyObject *dec;
Expand Down
3 changes: 0 additions & 3 deletions 3 Objects/stringlib/eq.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
Py_LOCAL_INLINE(int)
unicode_eq(PyObject *a, PyObject *b)
{
assert(PyUnicode_Check(a));
assert(PyUnicode_Check(b));

if (PyUnicode_GET_LENGTH(a) != PyUnicode_GET_LENGTH(b))
return 0;
if (PyUnicode_GET_LENGTH(a) == 0)
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.