From 509dd90f4684e40af3105dd3e754fa4b9c1530c1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 5 Feb 2020 14:24:17 +0100 Subject: bpo-39542: Convert PyType_Check() to static inline function (GH-18364) Convert PyType_HasFeature(), PyType_Check() and PyType_CheckExact() macros to static inline functions. --- Doc/c-api/type.rst | 12 ++++----- Include/cpython/object.h | 2 -- Include/object.h | 31 +++++++++++++++------- .../C API/2020-02-05-13-14-20.bpo-39542.5mleGX.rst | 2 ++ 4 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2020-02-05-13-14-20.bpo-39542.5mleGX.rst diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst index 41956b7..f774ca3 100644 --- a/Doc/c-api/type.rst +++ b/Doc/c-api/type.rst @@ -21,14 +21,14 @@ Type Objects .. c:function:: int PyType_Check(PyObject *o) - Return true if the object *o* is a type object, including instances of types - derived from the standard type object. Return false in all other cases. + Return non-zero if the object *o* is a type object, including instances of + types derived from the standard type object. Return 0 in all other cases. .. c:function:: int PyType_CheckExact(PyObject *o) - Return true if the object *o* is a type object, but not a subtype of the - standard type object. Return false in all other cases. + Return non-zero if the object *o* is a type object, but not a subtype of the + standard type object. Return 0 in all other cases. .. c:function:: unsigned int PyType_ClearCache() @@ -57,8 +57,8 @@ Type Objects .. c:function:: int PyType_HasFeature(PyTypeObject *o, int feature) - Return true if the type object *o* sets the feature *feature*. Type features - are denoted by single bit flags. + Return non-zero if the type object *o* sets the feature *feature*. + Type features are denoted by single bit flags. .. c:function:: int PyType_IS_GC(PyTypeObject *o) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index e36f824..0b5260e 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -341,8 +341,6 @@ PyAPI_FUNC(int) _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *, PyObject *, PyObject *); -#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0) - PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *); /* Safely decref `op` and set `op` to `op2`. diff --git a/Include/object.h b/Include/object.h index 91855d0..3a20e66 100644 --- a/Include/object.h +++ b/Include/object.h @@ -207,10 +207,6 @@ PyAPI_DATA(struct _typeobject) PySuper_Type; /* built-in 'super' */ PyAPI_FUNC(unsigned long) PyType_GetFlags(struct _typeobject*); -#define PyType_Check(op) \ - PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS) -#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type) - PyAPI_FUNC(int) PyType_Ready(struct _typeobject *); PyAPI_FUNC(PyObject *) PyType_GenericAlloc(struct _typeobject *, Py_ssize_t); PyAPI_FUNC(PyObject *) PyType_GenericNew(struct _typeobject *, @@ -342,11 +338,6 @@ given type object has a specified feature. /* Type structure has tp_finalize member (3.4) */ #define Py_TPFLAGS_HAVE_FINALIZE (1UL << 0) -#ifdef Py_LIMITED_API -# define PyType_HasFeature(t,f) ((PyType_GetFlags(t) & (f)) != 0) -#endif -#define PyType_FastSubclass(t,f) PyType_HasFeature(t,f) - /* The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement @@ -600,6 +591,28 @@ times. # undef Py_CPYTHON_OBJECT_H #endif + +static inline int +PyType_HasFeature(PyTypeObject *type, unsigned long feature) { +#ifdef Py_LIMITED_API + return ((PyType_GetFlags(type) & feature) != 0); +#else + return ((type->tp_flags & feature) != 0); +#endif +} + +#define PyType_FastSubclass(type, flag) PyType_HasFeature(type, flag) + +static inline int _PyType_Check(PyObject *op) { + return PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS); +} +#define PyType_Check(op) _PyType_Check(_PyObject_CAST(op)) + +static inline int _PyType_CheckExact(PyObject *op) { + return (Py_TYPE(op) == &PyType_Type); +} +#define PyType_CheckExact(op) _PyType_CheckExact(_PyObject_CAST(op)) + #ifdef __cplusplus } #endif diff --git a/Misc/NEWS.d/next/C API/2020-02-05-13-14-20.bpo-39542.5mleGX.rst b/Misc/NEWS.d/next/C API/2020-02-05-13-14-20.bpo-39542.5mleGX.rst new file mode 100644 index 0000000..46fb1d2 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-02-05-13-14-20.bpo-39542.5mleGX.rst @@ -0,0 +1,2 @@ +Convert :c:func:`PyType_HasFeature`, :c:func:`PyType_Check` and +:c:func:`PyType_CheckExact` macros to static inline functions. -- cgit v0.12 ref='#n14'>14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
        QtVariantPropertyManager *variantPropertyManager;
        QtProperty *property;

        variantPropertyManager->setValue(property, 10);
//! [0]


//! [1]
        QtVariantPropertyManager *variantPropertyManager;
        QtVariantProperty *property;

        property->setValue(10);
//! [1]