Skip to content

Commit

Permalink
Introduce __Pyx_PyLong_Check and use it in TypeConversion.c
Browse files Browse the repository at this point in the history
  • Loading branch information
fangerer committed Apr 20, 2022
1 parent 99a0093 commit 8ce1877
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Cython/Utility/ModuleSetupCode.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ static CYTHON_INLINE int _HPy_IsSubclass(HPyContext *ctx, HPy derived, HPy cls)
#define __Pyx_PyExc_RuntimeError PyExc_RuntimeError
#define __Pyx_PyErr_WriteUnraisable PyErr_WriteUnraisable

#define __Pyx_PyLong_Check PyLong_Check

#define __Pyx_PyModule_GetDict PyModule_GetDict
#define __Pyx_PyImport_AddModule PyImport_AddModule
#define __Pyx_PyImport_GetModuleDict PyImport_GetModuleDict
Expand Down Expand Up @@ -725,6 +727,7 @@ static CYTHON_INLINE int _HPy_IsSubclass(HPyContext *ctx, HPy derived, HPy cls)

#define HPyLong_Check(ctx, x) HPy_TypeCheck(ctx, x, ctx->h_LongType)
#define HPyLong_CheckExact(ctx, x) HPy_Is(ctx, HPy_Type(ctx, x), ctx->h_LongType)
#define __Pyx_PyLong_Check(ctx, x) HPy_TypeCheck(ctx, x, ctx->h_LongType)
#define HPyBytes_CheckExact HPyBytes_Check
#define HPyUnicode_Check(ctx, x) HPy_TypeCheck(ctx, x, ctx->h_UnicodeType)
#define HPyUnicode_CheckExact(ctx, x) HPy_Is(ctx, HPy_Type(ctx, x), ctx->h_UnicodeType)
Expand Down
12 changes: 2 additions & 10 deletions Cython/Utility/TypeConversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,11 +1067,7 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(HPyContext *, HPy);

{{py: from Cython.Utility import pylong_join }}

#if !CYTHON_COMPILING_IN_HPY
static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
#else /* CYTHON_COMPILING_IN_HPY */
static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(HPyContext *$hpy_context_cname, HPy x) {
#endif /* CYTHON_COMPILING_IN_HPY */
static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(__PYX_CONTEXT_DECL __PYX_OBJECT_CTYPE x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
Expand All @@ -1094,11 +1090,7 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(HPyContext *$hpy_context_cnam
}
} else
#endif
#if CYTHON_COMPILING_IN_HPY
if (likely(HPyLong_Check($hpy_context_cname, x))) {
#else
if (likely(PyLong_Check(x))) {
#endif
if (likely(__PYX_API_CALL(__Pyx_PyLong_Check, x))) {
if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
const digit* digits = ((PyLongObject*)x)->ob_digit;
Expand Down

0 comments on commit 8ce1877

Please sign in to comment.