diff options
author | shadchin <shadchin@yandex-team.com> | 2023-12-08 17:43:34 +0300 |
---|---|---|
committer | shadchin <shadchin@yandex-team.com> | 2023-12-08 20:15:01 +0300 |
commit | 213cda016d72c7d8d0e55ac7a7351959fa6ca2b8 (patch) | |
tree | a0a9170141dd91d1ff0727c0faa1af58d7b81133 | |
parent | 914f57e3243f53dd89dd3adb4d8b6d35c47f46ce (diff) | |
download | ydb-213cda016d72c7d8d0e55ac7a7351959fa6ca2b8.tar.gz |
Update kiwisolver to 1.2.0
44 files changed, 2345 insertions, 2532 deletions
diff --git a/contrib/python/cppy/.dist-info/METADATA b/contrib/python/cppy/.dist-info/METADATA new file mode 100644 index 0000000000..27e6479ad2 --- /dev/null +++ b/contrib/python/cppy/.dist-info/METADATA @@ -0,0 +1,58 @@ +Metadata-Version: 2.1 +Name: cppy +Version: 1.2.1 +Summary: UNKNOWN +Home-page: https://github.com/nucleic/cppy +Author-email: The Nucleic Development Team <sccolbert@gmail.com> +Maintainer-email: "Matthieu C. Dartiailh" <m.dartiailh@gmail.com> +License: Copyright (c) 2014, Nucleic + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +Project-URL: homepage, https://github.com/nucleic/cppy +Project-URL: documentation, https://cppy.readthedocs.io/en/latest/ +Project-URL: repository, https://github.com/nucleic/cppy +Project-URL: changelog, https://github.com/nucleic/cppy/blob/main/releasenotes.rst +Platform: UNKNOWN +Classifier: License :: OSI Approved :: BSD License +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: 3.8 +Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 +Classifier: Programming Language :: Python :: Implementation :: CPython +Requires-Python: >=3.7 +Description-Content-Type: text/x-rst +License-File: LICENSE + +Cppy +==== + +.. image:: https://github.com/nucleic/cppy/actions/workflows/ci.yml/badge.svg + :target: https://github.com/nucleic/cppy/actions/workflows/ci.yml + +A small C++ header library which makes it easier to write Python extension +modules. The primary feature is a PyObject smart pointer which automatically +handles reference counting and provides convenience methods for performing +common object operations. + + diff --git a/contrib/python/cppy/.dist-info/top_level.txt b/contrib/python/cppy/.dist-info/top_level.txt new file mode 100644 index 0000000000..9d2b4aaeee --- /dev/null +++ b/contrib/python/cppy/.dist-info/top_level.txt @@ -0,0 +1 @@ +cppy diff --git a/contrib/python/cppy/LICENSE b/contrib/python/cppy/LICENSE new file mode 100644 index 0000000000..fb725a39c4 --- /dev/null +++ b/contrib/python/cppy/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2014, Nucleic +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/contrib/python/cppy/README.rst b/contrib/python/cppy/README.rst new file mode 100644 index 0000000000..fb3cb24234 --- /dev/null +++ b/contrib/python/cppy/README.rst @@ -0,0 +1,10 @@ +Cppy +==== + +.. image:: https://github.com/nucleic/cppy/actions/workflows/ci.yml/badge.svg + :target: https://github.com/nucleic/cppy/actions/workflows/ci.yml + +A small C++ header library which makes it easier to write Python extension +modules. The primary feature is a PyObject smart pointer which automatically +handles reference counting and provides convenience methods for performing +common object operations. diff --git a/contrib/python/cppy/cppy/__init__.py b/contrib/python/cppy/cppy/__init__.py new file mode 100644 index 0000000000..24671128d3 --- /dev/null +++ b/contrib/python/cppy/cppy/__init__.py @@ -0,0 +1,59 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) 2014-2022, Nucleic Development Team. +# +# Distributed under the terms of the BSD 3-Clause License. +# +# The full license is in the file LICENSE, distributed with this software. +# -------------------------------------------------------------------------------------- +import os +import sys + +from setuptools.command.build_ext import build_ext + +from .version import __version__, __version_info__ + + +def get_include(): + import os + return os.path.join(os.path.dirname(__file__), 'include') + + +class CppyBuildExt(build_ext): + """A custom build extension enforcing c++11 standard on all platforms. + + On Windows, FH4 Exception Handling can be disabled by setting the CPPY_DISABLE_FH4 + environment variable. This avoids requiring VCRUNTIME140_1.dll + + """ + + # MSVC does not have a c++11 flag and default to c++14 anyway + c_opts = {"msvc": ["/EHsc"], "unix": ["-std=c++11"]} + + def build_extensions(self): + + ct = self.compiler.compiler_type + opts = self.c_opts.get(ct, []) + cppy_includes = get_include() + + for ext in self.extensions: + ext.include_dirs.insert(0, cppy_includes) + ext.extra_compile_args = opts + if sys.platform == "darwin": + # Only Unix compilers and their ports have `compiler_so` so on MacOS + # we can sure it will be present. + compiler_cmd = self.compiler.compiler_so + # Check if we are using Clang, accounting for absolute path + if compiler_cmd is not None and 'clang' in compiler_cmd[0]: + # If so ensure we use a recent enough version of the stdlib + ext.extra_compile_args += ["-stdlib=libc++"] + ext.extra_link_args += ["-stdlib=libc++"] + if ct == "msvc" and os.environ.get("CPPY_DISABLE_FH4"): + # Disable FH4 Exception Handling implementation so that we don't + # require VCRUNTIME140_1.dll. For more details, see: + # https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/ + # https://github.com/joerick/cibuildwheel/issues/423#issuecomment-677763904 + ext.extra_compile_args.append("/d2FH4-") + build_ext.build_extensions(self) + + +__all__ = ["__version__", "__version_info__", "get_include", "CppyBuildExt"] diff --git a/contrib/python/cppy/cppy/include/cppy/cppy.h b/contrib/python/cppy/cppy/include/cppy/cppy.h new file mode 100644 index 0000000000..0bfe3e7477 --- /dev/null +++ b/contrib/python/cppy/cppy/include/cppy/cppy.h @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------- +| Copyright (c) 2014-2020, Nucleic +| +| Distributed under the terms of the BSD 3-Clause License. +| +| The full license is in the file LICENSE, distributed with this software. +|----------------------------------------------------------------------------*/ +#pragma once + +#define pyobject_cast( o ) ( reinterpret_cast<PyObject*>( o ) ) +#define pytype_cast( o ) ( reinterpret_cast<PyTypeObject*>( o ) ) +// Used to cast PyDoc_STRVAR to void* in PyType_Slot +#define cast_py_tp_doc( o ) ( reinterpret_cast<void*>( const_cast<char *>( o ) ) ) +#define void_cast( o ) ( reinterpret_cast<void*>( o ) ) + +#include "defines.h" +#include "errors.h" +#include "ptr.h" diff --git a/contrib/python/cppy/cppy/include/cppy/defines.h b/contrib/python/cppy/cppy/include/cppy/defines.h new file mode 100644 index 0000000000..dd17e73f3f --- /dev/null +++ b/contrib/python/cppy/cppy/include/cppy/defines.h @@ -0,0 +1,16 @@ +/*----------------------------------------------------------------------------- +| Copyright (c) 2014-2020, Nucleic +| +| Distributed under the terms of the BSD 3-Clause License. +| +| The full license is in the file LICENSE, distributed with this software. +|----------------------------------------------------------------------------*/ +#pragma once + +#include <Python.h> + +#define CPPY_MAJOR_VERSION 1 +#define CPPY_MINOR_VERSION 1 +#define CPPY_PATCH_VERSION 0 + +#define CPPY_VERSION "1.1.0" diff --git a/contrib/python/cppy/cppy/include/cppy/errors.h b/contrib/python/cppy/cppy/include/cppy/errors.h new file mode 100644 index 0000000000..0e8c609f06 --- /dev/null +++ b/contrib/python/cppy/cppy/include/cppy/errors.h @@ -0,0 +1,72 @@ +/*----------------------------------------------------------------------------- +| Copyright (c) 2014-2020, Nucleic +| +| Distributed under the terms of the BSD 3-Clause License. +| +| The full license is in the file LICENSE, distributed with this software. +|----------------------------------------------------------------------------*/ +#pragma once + +#include <Python.h> + + +namespace cppy +{ + +inline PyObject* system_error( const char* message ) +{ + PyErr_SetString( PyExc_SystemError, message ); + return 0; +} + + +inline PyObject* type_error( const char* message ) +{ + PyErr_SetString( PyExc_TypeError, message ); + return 0; +} + + +inline PyObject* type_error( PyObject* ob, const char* expected ) +{ + PyErr_Format( + PyExc_TypeError, + "Expected object of type `%s`. Got object of type `%s` instead.", + expected, + Py_TYPE( ob )->tp_name ); + return 0; +} + + +inline PyObject* value_error( const char* message ) +{ + PyErr_SetString( PyExc_ValueError, message ); + return 0; +} + + +inline PyObject* runtime_error( const char* message ) +{ + PyErr_SetString( PyExc_RuntimeError, message ); + return 0; +} + + +inline PyObject* attribute_error( const char* message ) +{ + PyErr_SetString( PyExc_AttributeError, message ); + return 0; +} + + +inline PyObject* attribute_error( PyObject* ob, const char* attr ) +{ + PyErr_Format( + PyExc_AttributeError, + "'%s' object has no attribute '%s'", + Py_TYPE( ob )->tp_name, + attr ); + return 0; +} + +} // namespace cppy diff --git a/contrib/python/cppy/cppy/include/cppy/ptr.h b/contrib/python/cppy/cppy/include/cppy/ptr.h new file mode 100644 index 0000000000..a77b64287a --- /dev/null +++ b/contrib/python/cppy/cppy/include/cppy/ptr.h @@ -0,0 +1,502 @@ +/*----------------------------------------------------------------------------- +| Copyright (c) 2014-2020, Nucleic +| +| Distributed under the terms of the BSD 3-Clause License. +| +| The full license is in the file LICENSE, distributed with this software. +|----------------------------------------------------------------------------*/ +#pragma once + +#include <string> +#include <Python.h> +#include "defines.h" + + +namespace cppy +{ + +template <typename T> +inline T* incref( T* ob ) +{ + Py_INCREF( ob ); + return ob; +} + + +template <typename T> +inline T* xincref( T* ob ) +{ + Py_XINCREF( ob ); + return ob; +} + + +template <typename T> +inline T* decref( T* ob ) +{ + Py_DECREF( ob ); + return ob; +} + + +template <typename T> +inline T* xdecref( T* ob ) +{ + Py_XDECREF( ob ); + return ob; +} + + +template <typename T> +inline void clear( T** ob ) +{ + T* temp = *ob; + *ob = 0; + Py_XDECREF( temp ); +} + + +template <typename T> +inline void replace( T** src, T* ob ) +{ + T* temp = *src; + *src = ob; + Py_XINCREF( ob ); + Py_XDECREF( temp ); +} + + +class ptr +{ + +public: + ptr() : m_ob( 0 ) + { + } + + ptr( const ptr& other ) : m_ob( cppy::xincref( other.get() ) ) + { + } + + ptr( PyObject* ob, bool incref = false ) + : m_ob( incref ? cppy::xincref( ob ) : ob ) + { + } + + ~ptr() + { + PyObject* temp = m_ob; + m_ob = 0; + Py_XDECREF( temp ); + } + + ptr& operator=( PyObject* other ) + { + PyObject* temp = m_ob; + m_ob = other; + Py_XDECREF( temp ); + return *this; + } + + ptr& operator=( const ptr& other ) + { + PyObject* temp = m_ob; + m_ob = other.get(); + Py_XINCREF( m_ob ); + Py_XDECREF( temp ); + return *this; + } + + PyObject* get() const + { + return m_ob; + } + + void set( PyObject* ob, bool incref = false ) + { + PyObject* temp = m_ob; + m_ob = incref ? cppy::xincref( ob ) : ob; + Py_XDECREF( temp ); + } + + void set( const ptr& other ) + { + PyObject* temp = m_ob; + m_ob = other.get(); + Py_XINCREF( m_ob ); + Py_XDECREF( temp ); + } + + PyObject* release() + { + PyObject* temp = m_ob; + m_ob = 0; + return temp; + } + + operator void*() const + { + return static_cast<void*>( m_ob ); + } + + bool is_none() const + { + return m_ob == Py_None; + } + + bool is_true() const + { + return m_ob == Py_True; + } + + bool is_false() const + { + return m_ob == Py_False; + } + + bool is_bool() const + { + return is_true() || is_false(); + } + + bool is_int() const + { + return PyLong_Check( m_ob ) != 0; + } + + bool is_float() const + { + return PyFloat_Check( m_ob ) != 0; + } + + bool is_list() const + { + return PyList_Check( m_ob ) != 0; + } + + bool is_dict() const + { + return PyDict_Check( m_ob ) != 0; + } + + bool is_set() const + { + return PySet_Check( m_ob ) != 0; + } + + bool is_bytes() const + { + return PyBytes_Check( m_ob ) != 0; + } + + bool is_str() const + { + return PyUnicode_Check( m_ob ) != 0; + } + + bool is_unicode() const + { + return PyUnicode_Check( m_ob ) != 0; + } + + bool is_callable() const + { + return PyCallable_Check( m_ob ) != 0; + } + + bool is_iter() const + { + return PyIter_Check( m_ob ) != 0; + } + + bool is_type( PyTypeObject* cls ) const + { + return PyObject_TypeCheck( m_ob, cls ) != 0; + } + + int is_truthy() const + { + return PyObject_IsTrue( m_ob ); + } + + int is_instance( PyObject* cls ) const + { + return PyObject_IsInstance( m_ob, cls ); + } + + int is_instance( const ptr& cls ) const + { + return is_instance( cls.get() ); + } + + int is_subclass( PyObject* cls ) const + { + return PyObject_IsSubclass( m_ob, cls ); + } + + int is_subclass( const ptr& cls ) const + { + return is_subclass( cls.get() ); + } + + PyObject* iter() const + { + return PyObject_GetIter( m_ob ); + } + + PyObject* next() const + { + return PyIter_Next( m_ob ); + } + + PyObject* repr() const + { + return PyObject_Repr( m_ob ); + } + + PyObject* str() const + { + return PyObject_Str( m_ob ); + } + + PyObject* bytes() const + { + return PyObject_Bytes( m_ob ); + } + + PyObject* unicode() const + { + return PyObject_Str( m_ob ); + } + + Py_ssize_t length() const + { + return PyObject_Length( m_ob ); + } + + PyTypeObject* type() const + { + return Py_TYPE( m_ob ); + } + + int richcmp( PyObject* other, int opid ) const + { + return PyObject_RichCompareBool( m_ob, other, opid ); + } + + int richcmp( const ptr& other, int opid ) const + { + return richcmp( other.get(), opid ); + } + + Py_hash_t hash() const + { + return PyObject_Hash( m_ob ); + } + + bool hasattr( PyObject* attr ) const + { + return PyObject_HasAttr( m_ob, attr ) == 1; + } + + bool hasattr( const ptr& attr ) const + { + return hasattr( attr.get() ); + } + + bool hasattr( const char* attr ) const + { + return PyObject_HasAttrString( m_ob, attr ) == 1; + } + + bool hasattr( const std::string& attr ) const + { + return hasattr( attr.c_str() ); + } + + PyObject* getattr( PyObject* attr ) const + { + return PyObject_GetAttr( m_ob, attr ); + } + + PyObject* getattr( const ptr& attr ) const + { + return getattr( attr.get() ); + } + + PyObject* getattr( const char* attr ) const + { + return PyObject_GetAttrString( m_ob, attr ); + } + + PyObject* getattr( const std::string& attr ) const + { + return getattr( attr.c_str() ); + } + + bool setattr( PyObject* attr, PyObject* value ) const + { + return PyObject_SetAttr( m_ob, attr, value ) == 0; + } + + bool setattr( const ptr& attr, PyObject* value ) const + { + return setattr( attr.get(), value ); + } + + bool setattr( PyObject* attr, const ptr& value ) const + { + return setattr( attr, value.get() ); + } + + bool setattr( const ptr& attr, const ptr& value ) const + { + return setattr( attr.get(), value.get() ); + } + + bool setattr( const char* attr, PyObject* value ) const + { + return PyObject_SetAttrString( m_ob, attr, value ) == 0; + } + + bool setattr( const char* attr, const ptr& value ) const + { + return setattr( attr, value.get() ); + } + + bool setattr( const std::string& attr, PyObject* value ) const + { + return setattr( attr.c_str(), value ); + } + + bool setattr( const std::string& attr, const ptr& value ) const + { + return setattr( attr.c_str(), value.get() ); + } + + bool delattr( PyObject* attr ) const + { + return PyObject_DelAttr( m_ob, attr ) == 0; + } + + bool delattr( const ptr& attr ) const + { + return delattr( attr.get() ); + } + + bool delattr( const char* attr ) const + { + return PyObject_DelAttrString( m_ob, attr ) == 0; + } + + bool delattr( const std::string& attr ) const + { + return delattr( attr.c_str() ); + } + + PyObject* getitem( PyObject* key ) const + { + return PyObject_GetItem( m_ob, key ); + } + + PyObject* getitem( const ptr& key ) const + { + return getitem( key.get() ); + } + + bool setitem( PyObject* key, PyObject* value ) const + { + return PyObject_SetItem( m_ob, key, value ) == 0; + } + + bool setitem( const ptr& key, PyObject* value ) const + { + return setitem( key.get(), value ); + } + + bool setitem( PyObject* key, const ptr& value ) const + { + return setitem( key, value.get() ); + } + + bool setitem( const ptr& key, const ptr& value ) const + { + return setitem( key.get(), value.get() ); + } + + bool delitem( PyObject* key ) + { + return PyObject_DelItem( m_ob, key ) == 0; + } + + bool delitem( const ptr& key ) + { + return delitem( key.get() ); + } + + PyObject* call( PyObject* args, PyObject* kwargs = 0 ) const + { + return PyObject_Call( m_ob, args, kwargs ); + } + + PyObject* call( const ptr& args ) const + { + return call( args.get() ); + } + + PyObject* call( const ptr& args, const ptr& kwargs ) const + { + return call( args.get(), kwargs.get() ); + } + + PyObject* call( const ptr& args, PyObject* kwargs ) const + { + return call( args.get(), kwargs ); + } + + PyObject* call( PyObject* args, const ptr& kwargs ) const + { + return call( args, kwargs.get() ); + } + +protected: + PyObject* m_ob; +}; + + +inline bool operator!=( const ptr& lhs, const ptr& rhs ) +{ + return lhs.get() != rhs.get(); +} + + +inline bool operator!=( PyObject* lhs, const ptr& rhs ) +{ + return lhs != rhs.get(); +} + + +inline bool operator!=( const ptr& lhs, PyObject* rhs ) +{ + return lhs.get() != rhs; +} + + +inline bool operator==( const ptr& lhs, const ptr& rhs ) +{ + return lhs.get() == rhs.get(); +} + + +inline bool operator==( PyObject* lhs, const ptr& rhs ) +{ + return lhs == rhs.get(); +} + + +inline bool operator==( const ptr& lhs, PyObject* rhs ) +{ + return lhs.get() == rhs; +} + +} // namespace cppy diff --git a/contrib/python/cppy/cppy/version.py b/contrib/python/cppy/cppy/version.py new file mode 100644 index 0000000000..28bb8b4cc8 --- /dev/null +++ b/contrib/python/cppy/cppy/version.py @@ -0,0 +1,26 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) 2014-2022, Nucleic Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file LICENSE, distributed with this software. +# ----------------------------------------------------------------------------- +# This file is auto-generated by setuptools-scm do NOT edit it. + +from collections import namedtuple + +#: A namedtuple of the version info for the current release. +_version_info = namedtuple("_version_info", "major minor micro status") + +parts = "1.2.1".split(".", 3) +__version_info__ = _version_info( + int(parts[0]), + int(parts[1]), + int(parts[2]), + parts[3] if len(parts) == 4 else "", +) + +# Remove everything but the 'version_info' from this module. +del namedtuple, _version_info, parts + +__version__ = "1.2.1" diff --git a/contrib/python/cppy/ya.make b/contrib/python/cppy/ya.make new file mode 100644 index 0000000000..8a38da1124 --- /dev/null +++ b/contrib/python/cppy/ya.make @@ -0,0 +1,27 @@ +# Generated by devtools/yamaker (pypi). + +PY3_LIBRARY() + +VERSION(1.2.1) + +LICENSE(BSD-3-Clause) + +PEERDIR( + contrib/python/setuptools +) + +NO_LINT() + +PY_SRCS( + TOP_LEVEL + cppy/__init__.py + cppy/version.py +) + +RESOURCE_FILES( + PREFIX contrib/python/cppy/ + .dist-info/METADATA + .dist-info/top_level.txt +) + +END() diff --git a/contrib/python/kiwisolver/py3/.dist-info/METADATA b/contrib/python/kiwisolver/py3/.dist-info/METADATA index 6c363cae42..5eb4a95c2d 100644 --- a/contrib/python/kiwisolver/py3/.dist-info/METADATA +++ b/contrib/python/kiwisolver/py3/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: kiwisolver -Version: 1.1.0 +Version: 1.2.0 Summary: A fast implementation of the Cassowary constraint solver Home-page: https://github.com/nucleic/kiwi Author: The Nucleic Development Team @@ -8,16 +8,12 @@ Author-email: sccolbert@gmail.com License: BSD Platform: UNKNOWN Classifier: Programming Language :: Python -Classifier: Programming Language :: Python :: 2 -Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.4 -Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: Implementation :: CPython -Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* -Requires-Dist: setuptools +Requires-Python: >=3.6 Welcome to Kiwi =============== @@ -39,4 +35,7 @@ cases gaining a 40x improvement. Memory savings are consistently > 5x. In addition to the C++ solver, Kiwi ships with hand-rolled Python bindings. +The version 1.1.0 of the Python bindings will be the last one to support +Python 2, moving forward support will be limited to Python 3.5+. + diff --git a/contrib/python/kiwisolver/py3/LICENSE b/contrib/python/kiwisolver/py3/LICENSE new file mode 100644 index 0000000000..c34aff71cb --- /dev/null +++ b/contrib/python/kiwisolver/py3/LICENSE @@ -0,0 +1,71 @@ +========================= + The Kiwi licensing terms +========================= +Kiwi is licensed under the terms of the Modified BSD License (also known as +New or Revised BSD), as follows: + +Copyright (c) 2013, Nucleic Development Team + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +Neither the name of the Nucleic Development Team nor the names of its +contributors may be used to endorse or promote products derived from this +software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +About Kiwi +---------- +Chris Colbert began the Kiwi project in December 2013 in an effort to +create a blisteringly fast UI constraint solver. Chris is still the +project lead. + +The Nucleic Development Team is the set of all contributors to the Nucleic +project and its subprojects. + +The core team that coordinates development on GitHub can be found here: +http://github.com/nucleic. The current team consists of: + +* Chris Colbert + +Our Copyright Policy +-------------------- +Nucleic uses a shared copyright model. Each contributor maintains copyright +over their contributions to Nucleic. But, it is important to note that these +contributions are typically only changes to the repositories. Thus, the Nucleic +source code, in its entirety is not the copyright of any single person or +institution. Instead, it is the collective copyright of the entire Nucleic +Development Team. If individual contributors want to maintain a record of what +changes/contributions they have specific copyright on, they should indicate +their copyright in the commit message of the change, when they commit the +change to one of the Nucleic repositories. + +With this in mind, the following banner should be used in any source code file +to indicate the copyright and license terms: + +#------------------------------------------------------------------------------ +# Copyright (c) 2013, Nucleic Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file LICENSE, distributed with this software. +#------------------------------------------------------------------------------ diff --git a/contrib/python/kiwisolver/py3/README.rst b/contrib/python/kiwisolver/py3/README.rst index 4faa3c329b..98dabebefe 100644 --- a/contrib/python/kiwisolver/py3/README.rst +++ b/contrib/python/kiwisolver/py3/README.rst @@ -17,3 +17,6 @@ from 10x to 500x faster than the original Cassowary solver with typical use cases gaining a 40x improvement. Memory savings are consistently > 5x. In addition to the C++ solver, Kiwi ships with hand-rolled Python bindings. + +The version 1.1.0 of the Python bindings will be the last one to support +Python 2, moving forward support will be limited to Python 3.5+. diff --git a/contrib/python/kiwisolver/py3/kiwi/AssocVector.h b/contrib/python/kiwisolver/py3/kiwi/AssocVector.h index 0d5eb288ef..2a50924166 100644 --- a/contrib/python/kiwisolver/py3/kiwi/AssocVector.h +++ b/contrib/python/kiwisolver/py3/kiwi/AssocVector.h @@ -12,6 +12,8 @@ // suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// +// Updated 2019 by Matthieu Dartiailh for C++11 compliancy +//////////////////////////////////////////////////////////////////////////////// #pragma once // $Id: AssocVector.h 765 2006-10-18 13:55:32Z syntheticpp $ @@ -107,7 +109,7 @@ namespace Loki typedef typename Base::const_reverse_iterator const_reverse_iterator; class value_compare - : public std::binary_function<value_type, value_type, bool> + : public std::function<bool(value_type, value_type)> , private key_compare { friend class AssocVector; diff --git a/contrib/python/kiwisolver/py3/kiwi/constraint.h b/contrib/python/kiwisolver/py3/kiwi/constraint.h index 558dd924ae..9d8322b94d 100644 --- a/contrib/python/kiwisolver/py3/kiwi/constraint.h +++ b/contrib/python/kiwisolver/py3/kiwi/constraint.h @@ -3,7 +3,7 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <map> @@ -14,111 +14,106 @@ #include "term.h" #include "variable.h" - namespace kiwi { -enum RelationalOperator { OP_LE, OP_GE, OP_EQ }; - +enum RelationalOperator +{ + OP_LE, + OP_GE, + OP_EQ +}; class Constraint { public: + Constraint() : m_data(0) {} - Constraint() : m_data( 0 ) {} - - Constraint( const Expression& expr, - RelationalOperator op, - double strength = strength::required ) : - m_data( new ConstraintData( expr, op, strength ) ) {} + Constraint(const Expression &expr, + RelationalOperator op, + double strength = strength::required) : m_data(new ConstraintData(expr, op, strength)) {} - Constraint( const Constraint& other, double strength ) : - m_data( new ConstraintData( other, strength ) ) {} + Constraint(const Constraint &other, double strength) : m_data(new ConstraintData(other, strength)) {} - ~Constraint() {} + ~Constraint() {} - const Expression& expression() const - { - return m_data->m_expression; - } + const Expression &expression() const + { + return m_data->m_expression; + } - RelationalOperator op() const - { - return m_data->m_op; - } + RelationalOperator op() const + { + return m_data->m_op; + } - double strength() const - { - return m_data->m_strength; - } + double strength() const + { + return m_data->m_strength; + } - bool operator!() const - { - return !m_data; - } + bool operator!() const + { + return !m_data; + } private: - - static Expression reduce( const Expression& expr ) - { - std::map<Variable, double> vars; - typedef std::vector<Term>::const_iterator iter_t; - iter_t end = expr.terms().end(); - for( iter_t it = expr.terms().begin(); it != end; ++it ) - vars[ it->variable() ] += it->coefficient(); - std::vector<Term> terms( vars.begin(), vars.end() ); - return Expression( terms, expr.constant() ); - } - - class ConstraintData : public SharedData - { - - public: - - ConstraintData( const Expression& expr, - RelationalOperator op, - double strength ) : - SharedData(), - m_expression( reduce( expr ) ), - m_strength( strength::clip( strength ) ), - m_op( op ) {} - - ConstraintData( const Constraint& other, double strength ) : - SharedData(), - m_expression( other.expression() ), - m_strength( strength::clip( strength ) ), - m_op( other.op() ) {} - - ~ConstraintData() {} - - Expression m_expression; - double m_strength; - RelationalOperator m_op; - - private: - - ConstraintData( const ConstraintData& other ); - - ConstraintData& operator=( const ConstraintData& other ); - }; - - SharedDataPtr<ConstraintData> m_data; - - friend bool operator<( const Constraint& lhs, const Constraint& rhs ) - { - return lhs.m_data < rhs.m_data; - } - - friend bool operator==( const Constraint& lhs, const Constraint& rhs ) - { - return lhs.m_data == rhs.m_data; - } - - friend bool operator!=( const Constraint& lhs, const Constraint& rhs ) - { - return lhs.m_data != rhs.m_data; - } + static Expression reduce(const Expression &expr) + { + std::map<Variable, double> vars; + typedef std::vector<Term>::const_iterator iter_t; + iter_t end = expr.terms().end(); + for (iter_t it = expr.terms().begin(); it != end; ++it) + vars[it->variable()] += it->coefficient(); + std::vector<Term> terms(vars.begin(), vars.end()); + return Expression(terms, expr.constant()); + } + + class ConstraintData : public SharedData + { + + public: + ConstraintData(const Expression &expr, + RelationalOperator op, + double strength) : SharedData(), + m_expression(reduce(expr)), + m_strength(strength::clip(strength)), + m_op(op) {} + + ConstraintData(const Constraint &other, double strength) : SharedData(), + m_expression(other.expression()), + m_strength(strength::clip(strength)), + m_op(other.op()) {} + + ~ConstraintData() {} + + Expression m_expression; + double m_strength; + RelationalOperator m_op; + + private: + ConstraintData(const ConstraintData &other); + + ConstraintData &operator=(const ConstraintData &other); + }; + + SharedDataPtr<ConstraintData> m_data; + + friend bool operator<(const Constraint &lhs, const Constraint &rhs) + { + return lhs.m_data < rhs.m_data; + } + + friend bool operator==(const Constraint &lhs, const Constraint &rhs) + { + return lhs.m_data == rhs.m_data; + } + + friend bool operator!=(const Constraint &lhs, const Constraint &rhs) + { + return lhs.m_data != rhs.m_data; + } }; } // namespace kiwi diff --git a/contrib/python/kiwisolver/py3/kiwi/debug.h b/contrib/python/kiwisolver/py3/kiwi/debug.h index 007a24da5e..0d86091b25 100644 --- a/contrib/python/kiwisolver/py3/kiwi/debug.h +++ b/contrib/python/kiwisolver/py3/kiwi/debug.h @@ -3,7 +3,7 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <iostream> @@ -13,7 +13,6 @@ #include "solverimpl.h" #include "term.h" - namespace kiwi { @@ -24,178 +23,176 @@ class DebugHelper { public: - - static void dump( const SolverImpl& solver, std::ostream& out ) - { - out << "Objective" << std::endl; - out << "---------" << std::endl; - dump( *solver.m_objective, out ); - out << std::endl; - out << "Tableau" << std::endl; - out << "-------" << std::endl; - dump( solver.m_rows, out ); - out << std::endl; - out << "Infeasible" << std::endl; - out << "----------" << std::endl; - dump( solver.m_infeasible_rows, out ); - out << std::endl; - out << "Variables" << std::endl; - out << "---------" << std::endl; - dump( solver.m_vars, out ); - out << std::endl; - out << "Edit Variables" << std::endl; - out << "--------------" << std::endl; - dump( solver.m_edits, out ); - out << std::endl; - out << "Constraints" << std::endl; - out << "-----------" << std::endl; - dump( solver.m_cns, out ); - out << std::endl; - out << std::endl; - } - - static void dump( const SolverImpl::RowMap& rows, std::ostream& out ) - { - typedef SolverImpl::RowMap::const_iterator iter_t; - iter_t end = rows.end(); - for( iter_t it = rows.begin(); it != end; ++it ) - { - dump( it->first, out ); - out << " | "; - dump( *it->second, out ); - } - } - - static void dump( const std::vector<Symbol>& symbols, std::ostream& out ) - { - typedef std::vector<Symbol>::const_iterator iter_t; - iter_t end = symbols.end(); - for( iter_t it = symbols.begin(); it != end; ++it ) - { - dump( *it, out ); - out << std::endl; - } - } - - static void dump( const SolverImpl::VarMap& vars, std::ostream& out ) - { - typedef SolverImpl::VarMap::const_iterator iter_t; - iter_t end = vars.end(); - for( iter_t it = vars.begin(); it != end; ++it ) - { - out << it->first.name() << " = "; - dump( it->second, out ); - out << std::endl; - } - } - - static void dump( const SolverImpl::CnMap& cns, std::ostream& out ) - { - typedef SolverImpl::CnMap::const_iterator iter_t; - iter_t end = cns.end(); - for( iter_t it = cns.begin(); it != end; ++it ) - dump( it->first, out ); - } - - static void dump( const SolverImpl::EditMap& edits, std::ostream& out ) - { - typedef SolverImpl::EditMap::const_iterator iter_t; - iter_t end = edits.end(); - for( iter_t it = edits.begin(); it != end; ++it ) - out << it->first.name() << std::endl; - } - - static void dump( const Row& row, std::ostream& out ) - { - typedef Row::CellMap::const_iterator iter_t; - out << row.constant(); - iter_t end = row.cells().end(); - for( iter_t it = row.cells().begin(); it != end; ++it ) - { - out << " + " << it->second << " * "; - dump( it->first, out ); - } - out << std::endl; - } - - static void dump( const Symbol& symbol, std::ostream& out ) - { - switch( symbol.type() ) - { - case Symbol::Invalid: - out << "i"; - break; - case Symbol::External: - out << "v"; - break; - case Symbol::Slack: - out << "s"; - break; - case Symbol::Error: - out << "e"; - break; - case Symbol::Dummy: - out << "d"; - break; - default: - break; - } - out << symbol.id(); - } - - static void dump( const Constraint& cn, std::ostream& out ) - { - typedef std::vector<Term>::const_iterator iter_t; - iter_t begin = cn.expression().terms().begin(); - iter_t end = cn.expression().terms().end(); - for( iter_t it = begin; it != end; ++it ) - { - out << it->coefficient() << " * "; - out << it->variable().name() << " + "; - } - out << cn.expression().constant(); - switch( cn.op() ) - { - case OP_LE: - out << " <= 0 "; - break; - case OP_GE: - out << " >= 0 "; - break; - case OP_EQ: - out << " == 0 "; - break; - default: - break; - } - out << " | strength = " << cn.strength() << std::endl; - } + static void dump(const SolverImpl &solver, std::ostream &out) + { + out << "Objective" << std::endl; + out << "---------" << std::endl; + dump(*solver.m_objective, out); + out << std::endl; + out << "Tableau" << std::endl; + out << "-------" << std::endl; + dump(solver.m_rows, out); + out << std::endl; + out << "Infeasible" << std::endl; + out << "----------" << std::endl; + dump(solver.m_infeasible_rows, out); + out << std::endl; + out << "Variables" << std::endl; + out << "---------" << std::endl; + dump(solver.m_vars, out); + out << std::endl; + out << "Edit Variables" << std::endl; + out << "--------------" << std::endl; + dump(solver.m_edits, out); + out << std::endl; + out << "Constraints" << std::endl; + out << "-----------" << std::endl; + dump(solver.m_cns, out); + out << std::endl; + out << std::endl; + } + + static void dump(const SolverImpl::RowMap &rows, std::ostream &out) + { + typedef SolverImpl::RowMap::const_iterator iter_t; + iter_t end = rows.end(); + for (iter_t it = rows.begin(); it != end; ++it) + { + dump(it->first, out); + out << " | "; + dump(*it->second, out); + } + } + + static void dump(const std::vector<Symbol> &symbols, std::ostream &out) + { + typedef std::vector<Symbol>::const_iterator iter_t; + iter_t end = symbols.end(); + for (iter_t it = symbols.begin(); it != end; ++it) + { + dump(*it, out); + out << std::endl; + } + } + + static void dump(const SolverImpl::VarMap &vars, std::ostream &out) + { + typedef SolverImpl::VarMap::const_iterator iter_t; + iter_t end = vars.end(); + for (iter_t it = vars.begin(); it != end; ++it) + { + out << it->first.name() << " = "; + dump(it->second, out); + out << std::endl; + } + } + + static void dump(const SolverImpl::CnMap &cns, std::ostream &out) + { + typedef SolverImpl::CnMap::const_iterator iter_t; + iter_t end = cns.end(); + for (iter_t it = cns.begin(); it != end; ++it) + dump(it->first, out); + } + + static void dump(const SolverImpl::EditMap &edits, std::ostream &out) + { + typedef SolverImpl::EditMap::const_iterator iter_t; + iter_t end = edits.end(); + for (iter_t it = edits.begin(); it != end; ++it) + out << it->first.name() << std::endl; + } + + static void dump(const Row &row, std::ostream &out) + { + typedef Row::CellMap::const_iterator iter_t; + out << row.constant(); + iter_t end = row.cells().end(); + for (iter_t it = row.cells().begin(); it != end; ++it) + { + out << " + " << it->second << " * "; + dump(it->first, out); + } + out << std::endl; + } + + static void dump(const Symbol &symbol, std::ostream &out) + { + switch (symbol.type()) + { + case Symbol::Invalid: + out << "i"; + break; + case Symbol::External: + out << "v"; + break; + case Symbol::Slack: + out << "s"; + break; + case Symbol::Error: + out << "e"; + break; + case Symbol::Dummy: + out << "d"; + break; + default: + break; + } + out << symbol.id(); + } + + static void dump(const Constraint &cn, std::ostream &out) + { + typedef std::vector<Term>::const_iterator iter_t; + iter_t begin = cn.expression().terms().begin(); + iter_t end = cn.expression().terms().end(); + for (iter_t it = begin; it != end; ++it) + { + out << it->coefficient() << " * "; + out << it->variable().name() << " + "; + } + out << cn.expression().constant(); + switch (cn.op()) + { + case OP_LE: + out << " <= 0 "; + break; + case OP_GE: + out << " >= 0 "; + break; + case OP_EQ: + out << " == 0 "; + break; + default: + break; + } + out << " | strength = " << cn.strength() << std::endl; + } }; } // namespace impl - namespace debug { -template<typename T> -void dump( const T& value ) +template <typename T> +void dump(const T &value) { - impl::DebugHelper::dump( value, std::cout ); + impl::DebugHelper::dump(value, std::cout); } -template<typename T> -void dump( const T& value, std::ostream& out ) +template <typename T> +void dump(const T &value, std::ostream &out) { - impl::DebugHelper::dump( value, out ); + impl::DebugHelper::dump(value, out); } -template<typename T> -std::string dumps( const T& value ) +template <typename T> +std::string dumps(const T &value) { - std::stringstream stream; - impl::DebugHelper::dump( value, stream ); - return stream.str(); + std::stringstream stream; + impl::DebugHelper::dump(value, stream); + return stream.str(); } } // namespace debug diff --git a/contrib/python/kiwisolver/py3/kiwi/errors.h b/contrib/python/kiwisolver/py3/kiwi/errors.h index 6c77eee0b7..eb54560f4e 100644 --- a/contrib/python/kiwisolver/py3/kiwi/errors.h +++ b/contrib/python/kiwisolver/py3/kiwi/errors.h @@ -3,7 +3,7 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <exception> @@ -11,178 +11,152 @@ #include "constraint.h" #include "variable.h" - namespace kiwi { - class UnsatisfiableConstraint : public std::exception { public: + UnsatisfiableConstraint(const Constraint &constraint) : m_constraint(constraint) {} - UnsatisfiableConstraint( const Constraint& constraint ) : - m_constraint( constraint ) {} - - ~UnsatisfiableConstraint() throw() {} + ~UnsatisfiableConstraint() throw() {} - const char* what() const throw() - { - return "The constraint can not be satisfied."; - } + const char *what() const throw() + { + return "The constraint can not be satisfied."; + } - const Constraint& constraint() const - { - return m_constraint; - } + const Constraint &constraint() const + { + return m_constraint; + } private: - - Constraint m_constraint; + Constraint m_constraint; }; - class UnknownConstraint : public std::exception { public: + UnknownConstraint(const Constraint &constraint) : m_constraint(constraint) {} - UnknownConstraint( const Constraint& constraint ) : - m_constraint( constraint ) {} - - ~UnknownConstraint() throw() {} + ~UnknownConstraint() throw() {} - const char* what() const throw() - { - return "The constraint has not been added to the solver."; - } + const char *what() const throw() + { + return "The constraint has not been added to the solver."; + } - const Constraint& constraint() const - { - return m_constraint; - } + const Constraint &constraint() const + { + return m_constraint; + } private: - - Constraint m_constraint; + Constraint m_constraint; }; - class DuplicateConstraint : public std::exception { public: + DuplicateConstraint(const Constraint &constraint) : m_constraint(constraint) {} - DuplicateConstraint( const Constraint& constraint ) : - m_constraint( constraint ) {} - - ~DuplicateConstraint() throw() {} + ~DuplicateConstraint() throw() {} - const char* what() const throw() - { - return "The constraint has already been added to the solver."; - } + const char *what() const throw() + { + return "The constraint has already been added to the solver."; + } - const Constraint& constraint() const - { - return m_constraint; - } + const Constraint &constraint() const + { + return m_constraint; + } private: - - Constraint m_constraint; + Constraint m_constraint; }; - class UnknownEditVariable : public std::exception { public: + UnknownEditVariable(const Variable &variable) : m_variable(variable) {} - UnknownEditVariable( const Variable& variable ) : - m_variable( variable ) {} + ~UnknownEditVariable() throw() {} - ~UnknownEditVariable() throw() {} + const char *what() const throw() + { + return "The edit variable has not been added to the solver."; + } - const char* what() const throw() - { - return "The edit variable has not been added to the solver."; - } - - const Variable& variable() const - { - return m_variable; - } + const Variable &variable() const + { + return m_variable; + } private: - - Variable m_variable; + Variable m_variable; }; - class DuplicateEditVariable : public std::exception { public: + DuplicateEditVariable(const Variable &variable) : m_variable(variable) {} - DuplicateEditVariable( const Variable& variable ) : - m_variable( variable ) {} + ~DuplicateEditVariable() throw() {} - ~DuplicateEditVariable() throw() {} + const char *what() const throw() + { + return "The edit variable has already been added to the solver."; + } - const char* what() const throw() - { - return "The edit variable has already been added to the solver."; - } - - const Variable& variable() const - { - return m_variable; - } + const Variable &variable() const + { + return m_variable; + } private: - - Variable m_variable; + Variable m_variable; }; - class BadRequiredStrength : public std::exception { public: + BadRequiredStrength() {} - BadRequiredStrength() {} - - ~BadRequiredStrength() throw() {} + ~BadRequiredStrength() throw() {} - const char* what() const throw() - { - return "A required strength cannot be used in this context."; - } + const char *what() const throw() + { + return "A required strength cannot be used in this context."; + } }; - class InternalSolverError : public std::exception { public: + InternalSolverError() : m_msg("An internal solver error ocurred.") {} - InternalSolverError() : m_msg( "An internal solver error ocurred." ) {} + InternalSolverError(const char *msg) : m_msg(msg) {} - InternalSolverError( const char* msg ) : m_msg( msg ) {} + InternalSolverError(const std::string &msg) : m_msg(msg) {} - InternalSolverError( const std::string& msg ) : m_msg( msg ) {} + ~InternalSolverError() throw() {} - ~InternalSolverError() throw() {} - - const char* what() const throw() - { - return m_msg.c_str(); - } + const char *what() const throw() + { + return m_msg.c_str(); + } private: - - std::string m_msg; + std::string m_msg; }; } // namespace kiwi diff --git a/contrib/python/kiwisolver/py3/kiwi/expression.h b/contrib/python/kiwisolver/py3/kiwi/expression.h index 6d757206bd..e2b5ae6683 100644 --- a/contrib/python/kiwisolver/py3/kiwi/expression.h +++ b/contrib/python/kiwisolver/py3/kiwi/expression.h @@ -3,13 +3,12 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <vector> #include "term.h" - namespace kiwi { @@ -17,41 +16,37 @@ class Expression { public: + Expression(double constant = 0.0) : m_constant(constant) {} - Expression( double constant = 0.0 ) : m_constant( constant ) {} - - Expression( const Term& term, double constant = 0.0 ) : - m_terms( 1, term ), m_constant( constant ) {} + Expression(const Term &term, double constant = 0.0) : m_terms(1, term), m_constant(constant) {} - Expression( const std::vector<Term>& terms, double constant = 0.0 ) : - m_terms( terms ), m_constant( constant ) {} + Expression(const std::vector<Term> &terms, double constant = 0.0) : m_terms(terms), m_constant(constant) {} - ~Expression() {} + ~Expression() {} - const std::vector<Term>& terms() const - { - return m_terms; - } + const std::vector<Term> &terms() const + { + return m_terms; + } - double constant() const - { - return m_constant; - } + double constant() const + { + return m_constant; + } - double value() const - { - typedef std::vector<Term>::const_iterator iter_t; - double result = m_constant; - iter_t end = m_terms.end(); - for( iter_t it = m_terms.begin(); it != end; ++it ) - result += it->value(); - return result; - } + double value() const + { + typedef std::vector<Term>::const_iterator iter_t; + double result = m_constant; + iter_t end = m_terms.end(); + for (iter_t it = m_terms.begin(); it != end; ++it) + result += it->value(); + return result; + } private: - - std::vector<Term> m_terms; - double m_constant; + std::vector<Term> m_terms; + double m_constant; }; } // namespace kiwi diff --git a/contrib/python/kiwisolver/py3/kiwi/kiwi.h b/contrib/python/kiwisolver/py3/kiwi/kiwi.h index e5e3d85c90..77bb6a8ec2 100644 --- a/contrib/python/kiwisolver/py3/kiwi/kiwi.h +++ b/contrib/python/kiwisolver/py3/kiwi/kiwi.h @@ -3,7 +3,7 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include "constraint.h" diff --git a/contrib/python/kiwisolver/py3/kiwi/maptype.h b/contrib/python/kiwisolver/py3/kiwi/maptype.h index d125b07cc2..9b19a21734 100644 --- a/contrib/python/kiwisolver/py3/kiwi/maptype.h +++ b/contrib/python/kiwisolver/py3/kiwi/maptype.h @@ -1,9 +1,9 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <functional> @@ -12,26 +12,25 @@ #include <utility> #include "AssocVector.h" - namespace kiwi { namespace impl { -template< - typename K, - typename V, - typename C = std::less<K>, - typename A = std::allocator< std::pair<K, V> > > -class MapType -{ -public: - typedef Loki::AssocVector<K, V, C, A> Type; - //typedef std::map<K, V, C, A> Type; -private: - MapType(); -}; +template < + typename K, + typename V, + typename C = std::less<K>, + typename A = std::allocator<std::pair<K, V>>> +using MapType = Loki::AssocVector<K, V, C, A>; + +// template< +// typename K, +// typename V, +// typename C = std::less<K>, +// typename A = std::allocator< std::pair<const K, V> > > +// using MapType = std::map<K, V, C, A>; } // namespace impl diff --git a/contrib/python/kiwisolver/py3/kiwi/row.h b/contrib/python/kiwisolver/py3/kiwi/row.h index 33b501df76..29b25135bb 100644 --- a/contrib/python/kiwisolver/py3/kiwi/row.h +++ b/contrib/python/kiwisolver/py3/kiwi/row.h @@ -3,14 +3,13 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include "maptype.h" #include "symbol.h" #include "util.h" - namespace kiwi { @@ -21,94 +20,92 @@ class Row { public: + typedef MapType<Symbol, double> CellMap; - typedef MapType<Symbol, double>::Type CellMap; - - Row() : m_constant( 0.0 ) {} + Row() : m_constant(0.0) {} - Row( double constant ) : m_constant( constant ) {} + Row(double constant) : m_constant(constant) {} - Row( const Row& other ) : - m_cells( other.m_cells ), m_constant( other.m_constant ) {} + Row(const Row &other) : m_cells(other.m_cells), m_constant(other.m_constant) {} - ~Row() {} + ~Row() {} - const CellMap& cells() const - { - return m_cells; - } + const CellMap &cells() const + { + return m_cells; + } - double constant() const - { - return m_constant; - } + double constant() const + { + return m_constant; + } - /* Add a constant value to the row constant. + /* Add a constant value to the row constant. The new value of the constant is returned. */ - double add( double value ) - { - return m_constant += value; - } + double add(double value) + { + return m_constant += value; + } - /* Insert a symbol into the row with a given coefficient. + /* Insert a symbol into the row with a given coefficient. If the symbol already exists in the row, the coefficient will be added to the existing coefficient. If the resulting coefficient is zero, the symbol will be removed from the row. */ - void insert( const Symbol& symbol, double coefficient = 1.0 ) - { - if( nearZero( m_cells[ symbol ] += coefficient ) ) - m_cells.erase( symbol ); - } + void insert(const Symbol &symbol, double coefficient = 1.0) + { + if (nearZero(m_cells[symbol] += coefficient)) + m_cells.erase(symbol); + } - /* Insert a row into this row with a given coefficient. + /* Insert a row into this row with a given coefficient. The constant and the cells of the other row will be multiplied by the coefficient and added to this row. Any cell with a resulting coefficient of zero will be removed from the row. */ - void insert( const Row& other, double coefficient = 1.0 ) - { - typedef CellMap::const_iterator iter_t; - m_constant += other.m_constant * coefficient; - iter_t end = other.m_cells.end(); - for( iter_t it = other.m_cells.begin(); it != end; ++it ) - { - double coeff = it->second * coefficient; - if( nearZero( m_cells[ it->first ] += coeff ) ) - m_cells.erase( it->first ); - } - } - - /* Remove the given symbol from the row. + void insert(const Row &other, double coefficient = 1.0) + { + typedef CellMap::const_iterator iter_t; + m_constant += other.m_constant * coefficient; + iter_t end = other.m_cells.end(); + for (iter_t it = other.m_cells.begin(); it != end; ++it) + { + double coeff = it->second * coefficient; + if (nearZero(m_cells[it->first] += coeff)) + m_cells.erase(it->first); + } + } + + /* Remove the given symbol from the row. */ - void remove( const Symbol& symbol ) - { - CellMap::iterator it = m_cells.find( symbol ); - if( it != m_cells.end() ) - m_cells.erase( it ); - } + void remove(const Symbol &symbol) + { + CellMap::iterator it = m_cells.find(symbol); + if (it != m_cells.end()) + m_cells.erase(it); + } - /* Reverse the sign of the constant and all cells in the row. + /* Reverse the sign of the constant and all cells in the row. */ - void reverseSign() - { - typedef CellMap::iterator iter_t; - m_constant = -m_constant; - iter_t end = m_cells.end(); - for( iter_t it = m_cells.begin(); it != end; ++it ) - it->second = -it->second; - } + void reverseSign() + { + typedef CellMap::iterator iter_t; + m_constant = -m_constant; + iter_t end = m_cells.end(); + for (iter_t it = m_cells.begin(); it != end; ++it) + it->second = -it->second; + } - /* Solve the row for the given symbol. + /* Solve the row for the given symbol. This method assumes the row is of the form a * x + b * y + c = 0 and (assuming solve for x) will modify the row to represent the @@ -119,18 +116,18 @@ public: The given symbol *must* exist in the row. */ - void solveFor( const Symbol& symbol ) - { - typedef CellMap::iterator iter_t; - double coeff = -1.0 / m_cells[ symbol ]; - m_cells.erase( symbol ); - m_constant *= coeff; - iter_t end = m_cells.end(); - for( iter_t it = m_cells.begin(); it != end; ++it ) - it->second *= coeff; - } - - /* Solve the row for the given symbols. + void solveFor(const Symbol &symbol) + { + typedef CellMap::iterator iter_t; + double coeff = -1.0 / m_cells[symbol]; + m_cells.erase(symbol); + m_constant *= coeff; + iter_t end = m_cells.end(); + for (iter_t it = m_cells.begin(); it != end; ++it) + it->second *= coeff; + } + + /* Solve the row for the given symbols. This method assumes the row is of the form x = b * y + c and will solve the row such that y = x / b - c / b. The rhs symbol will be @@ -141,26 +138,26 @@ public: *must* exist in the row. */ - void solveFor( const Symbol& lhs, const Symbol& rhs ) - { - insert( lhs, -1.0 ); - solveFor( rhs ); - } + void solveFor(const Symbol &lhs, const Symbol &rhs) + { + insert(lhs, -1.0); + solveFor(rhs); + } - /* Get the coefficient for the given symbol. + /* Get the coefficient for the given symbol. If the symbol does not exist in the row, zero will be returned. */ - double coefficientFor( const Symbol& symbol ) const - { - CellMap::const_iterator it = m_cells.find( symbol ); - if( it == m_cells.end() ) - return 0.0; - return it->second; - } + double coefficientFor(const Symbol &symbol) const + { + CellMap::const_iterator it = m_cells.find(symbol); + if (it == m_cells.end()) + return 0.0; + return it->second; + } - /* Substitute a symbol with the data from another row. + /* Substitute a symbol with the data from another row. Given a row of the form a * x + b and a substitution of the form x = 3 * y + c the row will be updated to reflect the @@ -169,24 +166,23 @@ public: If the symbol does not exist in the row, this is a no-op. */ - void substitute( const Symbol& symbol, const Row& row ) - { - typedef CellMap::iterator iter_t; - iter_t it = m_cells.find( symbol ); - if( it != m_cells.end() ) - { - double coefficient = it->second; - m_cells.erase( it ); - insert( row, coefficient ); - } - } + void substitute(const Symbol &symbol, const Row &row) + { + typedef CellMap::iterator iter_t; + iter_t it = m_cells.find(symbol); + if (it != m_cells.end()) + { + double coefficient = it->second; + m_cells.erase(it); + insert(row, coefficient); + } + } private: - - CellMap m_cells; - double m_constant; + CellMap m_cells; + double m_constant; }; } // namespace impl -} // namespace +} // namespace kiwi diff --git a/contrib/python/kiwisolver/py3/kiwi/shareddata.h b/contrib/python/kiwisolver/py3/kiwi/shareddata.h index b7d389ee6d..9b1bc2c012 100644 --- a/contrib/python/kiwisolver/py3/kiwi/shareddata.h +++ b/contrib/python/kiwisolver/py3/kiwi/shareddata.h @@ -3,11 +3,10 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once - namespace kiwi { @@ -15,143 +14,138 @@ class SharedData { public: + SharedData() : m_refcount(0) {} - SharedData() : m_refcount( 0 ) {} - - SharedData( const SharedData& other ) : m_refcount( 0 ) {} + SharedData(const SharedData &other) : m_refcount(0) {} int m_refcount; private: - - SharedData& operator=( const SharedData& other ); + SharedData &operator=(const SharedData &other); }; - -template<typename T> +template <typename T> class SharedDataPtr { public: - - typedef T Type; - - SharedDataPtr() : m_data( 0 ) {} - - explicit SharedDataPtr( T* data ) : m_data( data ) - { - incref( m_data ); - } - - ~SharedDataPtr() - { - decref( m_data ); - } - - T* data() - { - return m_data; - } - - const T* data() const - { - return m_data; - } - - operator T*() - { - return m_data; - } - - operator const T*() const - { - return m_data; - } - - T* operator->() - { - return m_data; - } - - const T* operator->() const - { - return m_data; - } - - T& operator*() - { - return *m_data; - } - - const T& operator*() const - { - return *m_data; - } - - bool operator!() const - { - return !m_data; - } - - bool operator<( const SharedDataPtr<T>& other ) const - { - return m_data < other.m_data; - } - - bool operator==( const SharedDataPtr<T>& other ) const - { - return m_data == other.m_data; - } - - bool operator!=( const SharedDataPtr<T>& other ) const - { - return m_data != other.m_data; - } - - SharedDataPtr( const SharedDataPtr<T>& other ) : m_data( other.m_data ) - { - incref( m_data ); - } - - SharedDataPtr<T>& operator=( const SharedDataPtr<T>& other ) - { - if( m_data != other.m_data ) - { - T* temp = m_data; - m_data = other.m_data; - incref( m_data ); - decref( temp ); - } - return *this; - } - - SharedDataPtr<T>& operator=( T* other ) - { - if( m_data != other ) - { - T* temp = m_data; - m_data = other; - incref( m_data ); - decref( temp ); - } - return *this; - } + typedef T Type; + + SharedDataPtr() : m_data(0) {} + + explicit SharedDataPtr(T *data) : m_data(data) + { + incref(m_data); + } + + ~SharedDataPtr() + { + decref(m_data); + } + + T *data() + { + return m_data; + } + + const T *data() const + { + return m_data; + } + + operator T *() + { + return m_data; + } + + operator const T *() const + { + return m_data; + } + + T *operator->() + { + return m_data; + } + + const T *operator->() const + { + return m_data; + } + + T &operator*() + { + return *m_data; + } + + const T &operator*() const + { + return *m_data; + } + + bool operator!() const + { + return !m_data; + } + + bool operator<(const SharedDataPtr<T> &other) const + { + return m_data < other.m_data; + } + + bool operator==(const SharedDataPtr<T> &other) const + { + return m_data == other.m_data; + } + + bool operator!=(const SharedDataPtr<T> &other) const + { + return m_data != other.m_data; + } + + SharedDataPtr(const SharedDataPtr<T> &other) : m_data(other.m_data) + { + incref(m_data); + } + + SharedDataPtr<T> &operator=(const SharedDataPtr<T> &other) + { + if (m_data != other.m_data) + { + T *temp = m_data; + m_data = other.m_data; + incref(m_data); + decref(temp); + } + return *this; + } + + SharedDataPtr<T> &operator=(T *other) + { + if (m_data != other) + { + T *temp = m_data; + m_data = other; + incref(m_data); + decref(temp); + } + return *this; + } private: - - static void incref( T* data ) - { - if( data ) - ++data->m_refcount; - } - - static void decref( T* data ) - { - if( data && --data->m_refcount == 0 ) - delete data; - } - - T* m_data; + static void incref(T *data) + { + if (data) + ++data->m_refcount; + } + + static void decref(T *data) + { + if (data && --data->m_refcount == 0) + delete data; + } + + T *m_data; }; } // namespace kiwi diff --git a/contrib/python/kiwisolver/py3/kiwi/solver.h b/contrib/python/kiwisolver/py3/kiwi/solver.h index 8eed1841bf..678df8ac75 100644 --- a/contrib/python/kiwisolver/py3/kiwi/solver.h +++ b/contrib/python/kiwisolver/py3/kiwi/solver.h @@ -3,7 +3,7 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include "constraint.h" diff --git a/contrib/python/kiwisolver/py3/kiwi/solverimpl.h b/contrib/python/kiwisolver/py3/kiwi/solverimpl.h index 9b56ee2818..bb6690aeb8 100644 --- a/contrib/python/kiwisolver/py3/kiwi/solverimpl.h +++ b/contrib/python/kiwisolver/py3/kiwi/solverimpl.h @@ -3,7 +3,7 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <algorithm> @@ -44,13 +44,13 @@ class SolverImpl double constant; }; - typedef MapType<Variable, Symbol>::Type VarMap; + typedef MapType<Variable, Symbol> VarMap; - typedef MapType<Symbol, Row*>::Type RowMap; + typedef MapType<Symbol, Row*> RowMap; - typedef MapType<Constraint, Tag>::Type CnMap; + typedef MapType<Constraint, Tag> CnMap; - typedef MapType<Variable, EditInfo>::Type EditMap; + typedef MapType<Variable, EditInfo> EditMap; struct DualOptimizeGuard { @@ -88,7 +88,7 @@ public: // constraints and since exceptional conditions are uncommon, // i'm not too worried about aggressive cleanup of the var map. Tag tag; - std::auto_ptr<Row> rowptr( createRow( constraint, tag ) ); + std::unique_ptr<Row> rowptr( createRow( constraint, tag ) ); Symbol subject( chooseSubject( *rowptr, tag ) ); // If chooseSubject could not find a valid entering symbol, one @@ -155,7 +155,7 @@ public: RowMap::iterator row_it = m_rows.find( tag.marker ); if( row_it != m_rows.end() ) { - std::auto_ptr<Row> rowptr( row_it->second ); + std::unique_ptr<Row> rowptr( row_it->second ); m_rows.erase( row_it ); } else @@ -164,7 +164,7 @@ public: if( row_it == m_rows.end() ) throw InternalSolverError( "failed to find leaving row" ); Symbol leaving( row_it->first ); - std::auto_ptr<Row> rowptr( row_it->second ); + std::unique_ptr<Row> rowptr( row_it->second ); m_rows.erase( row_it ); rowptr->solveFor( leaving, tag.marker ); substitute( tag.marker, *rowptr ); @@ -511,7 +511,7 @@ private: RowMap::iterator it = m_rows.find( art ); if( it != m_rows.end() ) { - std::auto_ptr<Row> rowptr( it->second ); + std::unique_ptr<Row> rowptr( it->second ); m_rows.erase( it ); if( rowptr->cells().empty() ) return success; @@ -830,8 +830,8 @@ private: VarMap m_vars; EditMap m_edits; std::vector<Symbol> m_infeasible_rows; - std::auto_ptr<Row> m_objective; - std::auto_ptr<Row> m_artificial; + std::unique_ptr<Row> m_objective; + std::unique_ptr<Row> m_artificial; Symbol::Id m_id_tick; }; diff --git a/contrib/python/kiwisolver/py3/kiwi/strength.h b/contrib/python/kiwisolver/py3/kiwi/strength.h index b077f3e17c..11732e98f1 100644 --- a/contrib/python/kiwisolver/py3/kiwi/strength.h +++ b/contrib/python/kiwisolver/py3/kiwi/strength.h @@ -3,7 +3,7 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <algorithm> diff --git a/contrib/python/kiwisolver/py3/kiwi/symbol.h b/contrib/python/kiwisolver/py3/kiwi/symbol.h index b971efbdd2..ec422ad12d 100644 --- a/contrib/python/kiwisolver/py3/kiwi/symbol.h +++ b/contrib/python/kiwisolver/py3/kiwi/symbol.h @@ -3,7 +3,7 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once diff --git a/contrib/python/kiwisolver/py3/kiwi/symbolics.h b/contrib/python/kiwisolver/py3/kiwi/symbolics.h index 51ac6a8a37..23eed60f59 100644 --- a/contrib/python/kiwisolver/py3/kiwi/symbolics.h +++ b/contrib/python/kiwisolver/py3/kiwi/symbolics.h @@ -3,7 +3,7 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <vector> diff --git a/contrib/python/kiwisolver/py3/kiwi/term.h b/contrib/python/kiwisolver/py3/kiwi/term.h index 1ee962287c..aecfdf06dc 100644 --- a/contrib/python/kiwisolver/py3/kiwi/term.h +++ b/contrib/python/kiwisolver/py3/kiwi/term.h @@ -3,7 +3,7 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <utility> diff --git a/contrib/python/kiwisolver/py3/kiwi/util.h b/contrib/python/kiwisolver/py3/kiwi/util.h index 0d36a33eb1..560a43a746 100644 --- a/contrib/python/kiwisolver/py3/kiwi/util.h +++ b/contrib/python/kiwisolver/py3/kiwi/util.h @@ -3,23 +3,22 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once - namespace kiwi { namespace impl { -inline bool nearZero( double value ) +inline bool nearZero(double value) { - const double eps = 1.0e-8; - return value < 0.0 ? -value < eps : value < eps; + const double eps = 1.0e-8; + return value < 0.0 ? -value < eps : value < eps; } } // namespace impl -} // namespace +} // namespace kiwi diff --git a/contrib/python/kiwisolver/py3/kiwi/variable.h b/contrib/python/kiwisolver/py3/kiwi/variable.h index eaee93f2a1..a4db777069 100644 --- a/contrib/python/kiwisolver/py3/kiwi/variable.h +++ b/contrib/python/kiwisolver/py3/kiwi/variable.h @@ -3,14 +3,13 @@ | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <memory> #include <string> #include "shareddata.h" - namespace kiwi { @@ -18,104 +17,95 @@ class Variable { public: - - class Context - { - public: - Context() {} - virtual ~Context() {} // LCOV_EXCL_LINE - }; - - Variable( Context* context = 0 ) : - m_data( new VariableData( "", context ) ) {} - - Variable( const std::string& name, Context* context = 0 ) : - m_data( new VariableData( name, context ) ) {} - - Variable( const char* name, Context* context = 0 ) : - m_data( new VariableData( name, context ) ) {} - - ~Variable() {} - - const std::string& name() const - { - return m_data->m_name; - } - - void setName( const char* name ) - { - m_data->m_name = name; - } - - void setName( const std::string& name ) - { - m_data->m_name = name; - } - - Context* context() const - { - return m_data->m_context.get(); - } - - void setContext( Context* context ) - { - m_data->m_context.reset( context ); - } - - double value() const - { - return m_data->m_value; - } - - void setValue( double value ) - { - m_data->m_value = value; - } - - // operator== is used for symbolics - bool equals( const Variable& other ) - { - return m_data == other.m_data; - } + class Context + { + public: + Context() {} + virtual ~Context() {} // LCOV_EXCL_LINE + }; + + Variable(Context *context = 0) : m_data(new VariableData("", context)) {} + + Variable(const std::string &name, Context *context = 0) : m_data(new VariableData(name, context)) {} + + Variable(const char *name, Context *context = 0) : m_data(new VariableData(name, context)) {} + + ~Variable() {} + + const std::string &name() const + { + return m_data->m_name; + } + + void setName(const char *name) + { + m_data->m_name = name; + } + + void setName(const std::string &name) + { + m_data->m_name = name; + } + + Context *context() const + { + return m_data->m_context.get(); + } + + void setContext(Context *context) + { + m_data->m_context.reset(context); + } + + double value() const + { + return m_data->m_value; + } + + void setValue(double value) + { + m_data->m_value = value; + } + + // operator== is used for symbolics + bool equals(const Variable &other) + { + return m_data == other.m_data; + } private: + class VariableData : public SharedData + { - class VariableData : public SharedData - { - - public: - - VariableData( const std::string& name, Context* context ) : - SharedData(), - m_name( name ), - m_context( context ), - m_value( 0.0 ) {} - - VariableData( const char* name, Context* context ) : - SharedData(), - m_name( name ), - m_context( context ), - m_value( 0.0 ) {} + public: + VariableData(const std::string &name, Context *context) : SharedData(), + m_name(name), + m_context(context), + m_value(0.0) {} - ~VariableData() {} + VariableData(const char *name, Context *context) : SharedData(), + m_name(name), + m_context(context), + m_value(0.0) {} - std::string m_name; - std::auto_ptr<Context> m_context; - double m_value; + ~VariableData() {} - private: + std::string m_name; + std::unique_ptr<Context> m_context; + double m_value; - VariableData( const VariableData& other ); + private: + VariableData(const VariableData &other); - VariableData& operator=( const VariableData& other ); - }; + VariableData &operator=(const VariableData &other); + }; - SharedDataPtr<VariableData> m_data; + SharedDataPtr<VariableData> m_data; - friend bool operator<( const Variable& lhs, const Variable& rhs ) - { - return lhs.m_data < rhs.m_data; - } + friend bool operator<(const Variable &lhs, const Variable &rhs) + { + return lhs.m_data < rhs.m_data; + } }; } // namespace kiwi diff --git a/contrib/python/kiwisolver/py3/kiwi/version.h b/contrib/python/kiwisolver/py3/kiwi/version.h index 197f3ce186..f6154482ae 100644 --- a/contrib/python/kiwisolver/py3/kiwi/version.h +++ b/contrib/python/kiwisolver/py3/kiwi/version.h @@ -1,14 +1,14 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2020, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #define KIWI_MAJOR_VERSION 1 -#define KIWI_MINOR_VERSION 0 -#define KIWI_MICRO_VERSION 1 -#define KIWI_VERSION_HEX 0x010001 -#define KIWI_VERSION "1.1.0" +#define KIWI_MINOR_VERSION 2 +#define KIWI_MICRO_VERSION 0 +#define KIWI_VERSION_HEX 0x010200 +#define KIWI_VERSION "1.2.0" diff --git a/contrib/python/kiwisolver/py3/py/constraint.cpp b/contrib/python/kiwisolver/py3/py/constraint.cpp index 2fbdd0aeb8..e5b516919e 100644 --- a/contrib/python/kiwisolver/py3/py/constraint.cpp +++ b/contrib/python/kiwisolver/py3/py/constraint.cpp @@ -1,299 +1,201 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #include <algorithm> #include <sstream> -#include <Python.h> +#include <cppy/cppy.h> #include <kiwi/kiwi.h> -#include "pythonhelpers.h" #include "types.h" #include "util.h" +namespace kiwisolver +{ -using namespace PythonHelpers; - +namespace +{ -static PyObject* -Constraint_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) +PyObject * +Constraint_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { - static const char *kwlist[] = { "expression", "op", "strength", 0 }; - PyObject* pyexpr; - PyObject* pyop; - PyObject* pystrength = 0; - if( !PyArg_ParseTupleAndKeywords( - args, kwargs, "OO|O:__new__", const_cast<char**>( kwlist ), - &pyexpr, &pyop, &pystrength ) ) + static const char *kwlist[] = {"expression", "op", "strength", 0}; + PyObject *pyexpr; + PyObject *pyop; + PyObject *pystrength = 0; + if (!PyArg_ParseTupleAndKeywords( + args, kwargs, "OO|O:__new__", const_cast<char **>(kwlist), + &pyexpr, &pyop, &pystrength)) return 0; - if( !Expression::TypeCheck( pyexpr ) ) - return py_expected_type_fail( pyexpr, "Expression" ); + if (!Expression::TypeCheck(pyexpr)) + return cppy::type_error(pyexpr, "Expression"); kiwi::RelationalOperator op; - if( !convert_to_relational_op( pyop, op ) ) + if (!convert_to_relational_op(pyop, op)) return 0; double strength = kiwi::strength::required; - if( pystrength && !convert_to_strength( pystrength, strength ) ) + if (pystrength && !convert_to_strength(pystrength, strength)) return 0; - PyObjectPtr pycn( PyType_GenericNew( type, args, kwargs ) ); - if( !pycn ) + cppy::ptr pycn(PyType_GenericNew(type, args, kwargs)); + if (!pycn) return 0; - Constraint* cn = reinterpret_cast<Constraint*>( pycn.get() ); - cn->expression = reduce_expression( pyexpr ); - if( !cn->expression ) + Constraint *cn = reinterpret_cast<Constraint *>(pycn.get()); + cn->expression = reduce_expression(pyexpr); + if (!cn->expression) return 0; - kiwi::Expression expr( convert_to_kiwi_expression( cn->expression ) ); - new( &cn->constraint ) kiwi::Constraint( expr, op, strength ); + kiwi::Expression expr(convert_to_kiwi_expression(cn->expression)); + new (&cn->constraint) kiwi::Constraint(expr, op, strength); return pycn.release(); } - -static void -Constraint_clear( Constraint* self ) +void Constraint_clear(Constraint *self) { - Py_CLEAR( self->expression ); + Py_CLEAR(self->expression); } - -static int -Constraint_traverse( Constraint* self, visitproc visit, void* arg ) +int Constraint_traverse(Constraint *self, visitproc visit, void *arg) { - Py_VISIT( self->expression ); + Py_VISIT(self->expression); return 0; } - -static void -Constraint_dealloc( Constraint* self ) +void Constraint_dealloc(Constraint *self) { - PyObject_GC_UnTrack( self ); - Constraint_clear( self ); + PyObject_GC_UnTrack(self); + Constraint_clear(self); self->constraint.~Constraint(); - Py_TYPE( self )->tp_free( pyobject_cast( self ) ); + Py_TYPE(self)->tp_free(pyobject_cast(self)); } - -static PyObject* -Constraint_repr( Constraint* self ) +PyObject * +Constraint_repr(Constraint *self) { std::stringstream stream; - Expression* expr = reinterpret_cast<Expression*>( self->expression ); - Py_ssize_t size = PyTuple_GET_SIZE( expr->terms ); - for( Py_ssize_t i = 0; i < size; ++i ) + Expression *expr = reinterpret_cast<Expression *>(self->expression); + Py_ssize_t size = PyTuple_GET_SIZE(expr->terms); + for (Py_ssize_t i = 0; i < size; ++i) { - PyObject* item = PyTuple_GET_ITEM( expr->terms, i ); - Term* term = reinterpret_cast<Term*>( item ); + PyObject *item = PyTuple_GET_ITEM(expr->terms, i); + Term *term = reinterpret_cast<Term *>(item); stream << term->coefficient << " * "; - stream << reinterpret_cast<Variable*>( term->variable )->variable.name(); + stream << reinterpret_cast<Variable *>(term->variable)->variable.name(); stream << " + "; } stream << expr->constant; - switch( self->constraint.op() ) + switch (self->constraint.op()) { - case kiwi::OP_EQ: - stream << " == 0"; - break; - case kiwi::OP_LE: - stream << " <= 0"; - break; - case kiwi::OP_GE: - stream << " >= 0"; - break; + case kiwi::OP_EQ: + stream << " == 0"; + break; + case kiwi::OP_LE: + stream << " <= 0"; + break; + case kiwi::OP_GE: + stream << " >= 0"; + break; } stream << " | strength = " << self->constraint.strength(); - return FROM_STRING( stream.str().c_str() ); + return PyUnicode_FromString(stream.str().c_str()); } - -static PyObject* -Constraint_expression( Constraint* self ) +PyObject * +Constraint_expression(Constraint *self) { - return newref( self->expression ); + return cppy::incref(self->expression); } - -static PyObject* -Constraint_op( Constraint* self ) +PyObject * +Constraint_op(Constraint *self) { - PyObject* res = 0; - switch( self->constraint.op() ) + PyObject *res = 0; + switch (self->constraint.op()) { - case kiwi::OP_EQ: - res = FROM_STRING( "==" ); - break; - case kiwi::OP_LE: - res = FROM_STRING( "<=" ); - break; - case kiwi::OP_GE: - res = FROM_STRING( ">=" ); - break; + case kiwi::OP_EQ: + res = PyUnicode_FromString("=="); + break; + case kiwi::OP_LE: + res = PyUnicode_FromString("<="); + break; + case kiwi::OP_GE: + res = PyUnicode_FromString(">="); + break; } return res; } - -static PyObject* -Constraint_strength( Constraint* self ) +PyObject * +Constraint_strength(Constraint *self) { - return PyFloat_FromDouble( self->constraint.strength() ); + return PyFloat_FromDouble(self->constraint.strength()); } - -static PyObject* -Constraint_or( PyObject* pyoldcn, PyObject* value ) +PyObject * +Constraint_or(PyObject *pyoldcn, PyObject *value) { - if( !Constraint::TypeCheck( pyoldcn ) ) - std::swap( pyoldcn, value ); + if (!Constraint::TypeCheck(pyoldcn)) + std::swap(pyoldcn, value); double strength; - if( !convert_to_strength( value, strength ) ) + if (!convert_to_strength(value, strength)) return 0; - PyObject* pynewcn = PyType_GenericNew( &Constraint_Type, 0, 0 ); - if( !pynewcn ) + PyObject *pynewcn = PyType_GenericNew(Constraint::TypeObject, 0, 0); + if (!pynewcn) return 0; - Constraint* oldcn = reinterpret_cast<Constraint*>( pyoldcn ); - Constraint* newcn = reinterpret_cast<Constraint*>( pynewcn ); - newcn->expression = newref( oldcn->expression ); - new( &newcn->constraint ) kiwi::Constraint( oldcn->constraint, strength ); + Constraint *oldcn = reinterpret_cast<Constraint *>(pyoldcn); + Constraint *newcn = reinterpret_cast<Constraint *>(pynewcn); + newcn->expression = cppy::incref(oldcn->expression); + new (&newcn->constraint) kiwi::Constraint(oldcn->constraint, strength); return pynewcn; } - static PyMethodDef -Constraint_methods[] = { - { "expression", ( PyCFunction )Constraint_expression, METH_NOARGS, - "Get the expression object for the constraint." }, - { "op", ( PyCFunction )Constraint_op, METH_NOARGS, - "Get the relational operator for the constraint." }, - { "strength", ( PyCFunction )Constraint_strength, METH_NOARGS, - "Get the strength for the constraint." }, - { 0 } // sentinel + Constraint_methods[] = { + {"expression", (PyCFunction)Constraint_expression, METH_NOARGS, + "Get the expression object for the constraint."}, + {"op", (PyCFunction)Constraint_op, METH_NOARGS, + "Get the relational operator for the constraint."}, + {"strength", (PyCFunction)Constraint_strength, METH_NOARGS, + "Get the strength for the constraint."}, + {0} // sentinel }; - -static PyNumberMethods -Constraint_as_number = { - 0, /* nb_add */ - 0, /* nb_subtract */ - 0, /* nb_multiply */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_divide */ -#endif - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - 0, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ -#if PY_MAJOR_VERSION >= 3 - 0, /* nb_bool */ -#else - 0, /* nb_nonzero */ -#endif - 0, /* nb_invert */ - 0, /* nb_lshift */ - 0, /* nb_rshift */ - 0, /* nb_and */ - 0, /* nb_xor */ - (binaryfunc)Constraint_or, /* nb_or */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_coerce */ -#endif - 0, /* nb_int */ - 0, /* nb_long */ - 0, /* nb_float */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_oct */ - 0, /* nb_hex */ -#endif - 0, /* nb_inplace_add */ - 0, /* nb_inplace_subtract */ - 0, /* nb_inplace_multiply */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_inplace_divide */ -#endif - 0, /* nb_inplace_remainder */ - 0, /* nb_inplace_power */ - 0, /* nb_inplace_lshift */ - 0, /* nb_inplace_rshift */ - 0, /* nb_inplace_and */ - 0, /* nb_inplace_xor */ - 0, /* nb_inplace_or */ - (binaryfunc)0, /* nb_floor_divide */ - (binaryfunc)0, /* nb_true_divide */ - 0, /* nb_inplace_floor_divide */ - 0, /* nb_inplace_true_divide */ -#if PY_VERSION_HEX >= 0x02050000 - (unaryfunc)0, /* nb_index */ -#endif -#if PY_VERSION_HEX >= 0x03050000 - (binaryfunc)0, /* nb_matrix_multiply */ - (binaryfunc)0, /* nb_inplace_matrix_multiply */ -#endif +static PyType_Slot Constraint_Type_slots[] = { + {Py_tp_dealloc, void_cast(Constraint_dealloc)}, /* tp_dealloc */ + {Py_tp_traverse, void_cast(Constraint_traverse)}, /* tp_traverse */ + {Py_tp_clear, void_cast(Constraint_clear)}, /* tp_clear */ + {Py_tp_repr, void_cast(Constraint_repr)}, /* tp_repr */ + {Py_tp_methods, void_cast(Constraint_methods)}, /* tp_methods */ + {Py_tp_new, void_cast(Constraint_new)}, /* tp_new */ + {Py_tp_alloc, void_cast(PyType_GenericAlloc)}, /* tp_alloc */ + {Py_tp_free, void_cast(PyObject_GC_Del)}, /* tp_free */ + {Py_nb_or, void_cast(Constraint_or)}, /* nb_or */ + {0, 0}, }; +} // namespace -PyTypeObject Constraint_Type = { - PyVarObject_HEAD_INIT( &PyType_Type, 0 ) - "kiwisolver.Constraint", /* tp_name */ - sizeof( Constraint ), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Constraint_dealloc, /* tp_dealloc */ - (printfunc)0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX >= 0x03050000 - ( PyAsyncMethods* )0, /* tp_as_async */ -#elif PY_VERSION_HEX >= 0x03000000 - ( void* ) 0, /* tp_reserved */ -#else - ( cmpfunc )0, /* tp_compare */ -#endif - (reprfunc)Constraint_repr, /* tp_repr */ - (PyNumberMethods*)&Constraint_as_number,/* tp_as_number */ - (PySequenceMethods*)0, /* tp_as_sequence */ - (PyMappingMethods*)0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)0, /* tp_setattro */ - (PyBufferProcs*)0, /* tp_as_buffer */ -#if PY_MAJOR_VERSION >= 3 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE, /* tp_flags */ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /* tp_flags */ -#endif - 0, /* Documentation string */ - (traverseproc)Constraint_traverse, /* tp_traverse */ - (inquiry)Constraint_clear, /* tp_clear */ - (richcmpfunc)0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)0, /* tp_iter */ - (iternextfunc)0, /* tp_iternext */ - (struct PyMethodDef*)Constraint_methods,/* tp_methods */ - (struct PyMemberDef*)0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - (descrgetfunc)0, /* tp_descr_get */ - (descrsetfunc)0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)0, /* tp_init */ - (allocfunc)PyType_GenericAlloc, /* tp_alloc */ - (newfunc)Constraint_new, /* tp_new */ - (freefunc)PyObject_GC_Del, /* tp_free */ - (inquiry)0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ - (destructor)0 /* tp_del */ -}; +// Initialize static variables (otherwise the compiler eliminates them) +PyTypeObject *Constraint::TypeObject = NULL; +PyType_Spec Constraint::TypeObject_Spec = { + "kiwisolver.Constraint", /* tp_name */ + sizeof(Constraint), /* tp_basicsize */ + 0, /* tp_itemsize */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_HAVE_GC | + Py_TPFLAGS_BASETYPE, /* tp_flags */ + Constraint_Type_slots /* slots */ +}; -int import_constraint() +bool Constraint::Ready() { - return PyType_Ready( &Constraint_Type ); + // The reference will be handled by the module to which we will add the type + TypeObject = pytype_cast(PyType_FromSpec(&TypeObject_Spec)); + if (!TypeObject) + { + return false; + } + return true; } + +} // namespace kiwisolver diff --git a/contrib/python/kiwisolver/py3/py/expression.cpp b/contrib/python/kiwisolver/py3/py/expression.cpp index 5cd34e4c12..235e463f12 100644 --- a/contrib/python/kiwisolver/py3/py/expression.cpp +++ b/contrib/python/kiwisolver/py3/py/expression.cpp @@ -1,22 +1,24 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #include <sstream> -#include <Python.h> -#include "pythonhelpers.h" +#include <cppy/cppy.h> #include "symbolics.h" #include "types.h" #include "util.h" -using namespace PythonHelpers; +namespace kiwisolver +{ +namespace +{ -static PyObject* +PyObject* Expression_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) { static const char *kwlist[] = { "terms", "constant", 0 }; @@ -26,7 +28,7 @@ Expression_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) args, kwargs, "O|O:__new__", const_cast<char**>( kwlist ), &pyterms, &pyconstant ) ) return 0; - PyObjectPtr terms( PySequence_Tuple( pyterms ) ); + cppy::ptr terms( PySequence_Tuple( pyterms ) ); if( !terms ) return 0; Py_ssize_t end = PyTuple_GET_SIZE( terms.get() ); @@ -34,7 +36,7 @@ Expression_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) { PyObject* item = PyTuple_GET_ITEM( terms.get(), i ); if( !Term::TypeCheck( item ) ) - return py_expected_type_fail( item, "Term" ); + return cppy::type_error( item, "Term" ); } double constant = 0.0; if( pyconstant && !convert_to_double( pyconstant, constant ) ) @@ -49,14 +51,14 @@ Expression_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) } -static void +void Expression_clear( Expression* self ) { Py_CLEAR( self->terms ); } -static int +int Expression_traverse( Expression* self, visitproc visit, void* arg ) { Py_VISIT( self->terms ); @@ -64,7 +66,7 @@ Expression_traverse( Expression* self, visitproc visit, void* arg ) } -static void +void Expression_dealloc( Expression* self ) { PyObject_GC_UnTrack( self ); @@ -73,7 +75,7 @@ Expression_dealloc( Expression* self ) } -static PyObject* +PyObject* Expression_repr( Expression* self ) { std::stringstream stream; @@ -87,25 +89,25 @@ Expression_repr( Expression* self ) stream << " + "; } stream << self->constant; - return FROM_STRING( stream.str().c_str() ); + return PyUnicode_FromString( stream.str().c_str() ); } -static PyObject* +PyObject* Expression_terms( Expression* self ) { - return newref( self->terms ); + return cppy::incref( self->terms ); } -static PyObject* +PyObject* Expression_constant( Expression* self ) { return PyFloat_FromDouble( self->constant ); } -static PyObject* +PyObject* Expression_value( Expression* self ) { double result = self->constant; @@ -121,42 +123,42 @@ Expression_value( Expression* self ) } -static PyObject* +PyObject* Expression_add( PyObject* first, PyObject* second ) { return BinaryInvoke<BinaryAdd, Expression>()( first, second ); } -static PyObject* +PyObject* Expression_sub( PyObject* first, PyObject* second ) { return BinaryInvoke<BinarySub, Expression>()( first, second ); } -static PyObject* +PyObject* Expression_mul( PyObject* first, PyObject* second ) { return BinaryInvoke<BinaryMul, Expression>()( first, second ); } -static PyObject* +PyObject* Expression_div( PyObject* first, PyObject* second ) { return BinaryInvoke<BinaryDiv, Expression>()( first, second ); } -static PyObject* +PyObject* Expression_neg( PyObject* value ) { return UnaryInvoke<UnaryNeg, Expression>()( value ); } -static PyObject* +PyObject* Expression_richcmp( PyObject* first, PyObject* second, int op ) { switch( op ) @@ -194,133 +196,52 @@ Expression_methods[] = { }; -static PyNumberMethods -Expression_as_number = { - (binaryfunc)Expression_add, /* nb_add */ - (binaryfunc)Expression_sub, /* nb_subtract */ - (binaryfunc)Expression_mul, /* nb_multiply */ -#if PY_MAJOR_VERSION < 3 - (binaryfunc)Expression_div, /* nb_divide */ -#endif - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - (unaryfunc)Expression_neg, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ -#if PY_MAJOR_VERSION >= 3 - 0, /* nb_bool */ -#else - 0, /* nb_nonzero */ -#endif - 0, /* nb_invert */ - 0, /* nb_lshift */ - 0, /* nb_rshift */ - 0, /* nb_and */ - 0, /* nb_xor */ - (binaryfunc)0, /* nb_or */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_coerce */ -#endif - 0, /* nb_int */ -#if PY_MAJOR_VERSION >= 3 - (void *)0, /* nb_reserved */ -#else - 0, /* nb_long */ -#endif - 0, /* nb_float */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_oct */ - 0, /* nb_hex */ -#endif - 0, /* nb_inplace_add */ - 0, /* nb_inplace_subtract */ - 0, /* nb_inplace_multiply */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_inplace_divide */ -#endif - 0, /* nb_inplace_remainder */ - 0, /* nb_inplace_power */ - 0, /* nb_inplace_lshift */ - 0, /* nb_inplace_rshift */ - 0, /* nb_inplace_and */ - 0, /* nb_inplace_xor */ - 0, /* nb_inplace_or */ - (binaryfunc)0, /* nb_floor_divide */ - (binaryfunc)Expression_div, /* nb_true_divide */ - 0, /* nb_inplace_floor_divide */ - 0, /* nb_inplace_true_divide */ -#if PY_VERSION_HEX >= 0x02050000 - (unaryfunc)0, /* nb_index */ -#endif -#if PY_VERSION_HEX >= 0x03050000 - (binaryfunc)0, /* nb_matrix_multiply */ - (binaryfunc)0, /* nb_inplace_matrix_multiply */ -#endif +static PyType_Slot Expression_Type_slots[] = { + { Py_tp_dealloc, void_cast( Expression_dealloc ) }, /* tp_dealloc */ + { Py_tp_traverse, void_cast( Expression_traverse ) }, /* tp_traverse */ + { Py_tp_clear, void_cast( Expression_clear ) }, /* tp_clear */ + { Py_tp_repr, void_cast( Expression_repr ) }, /* tp_repr */ + { Py_tp_richcompare, void_cast( Expression_richcmp ) }, /* tp_richcompare */ + { Py_tp_methods, void_cast( Expression_methods ) }, /* tp_methods */ + { Py_tp_new, void_cast( Expression_new ) }, /* tp_new */ + { Py_tp_alloc, void_cast( PyType_GenericAlloc ) }, /* tp_alloc */ + { Py_tp_free, void_cast( PyObject_GC_Del ) }, /* tp_free */ + { Py_nb_add, void_cast( Expression_add ) }, /* nb_add */ + { Py_nb_subtract, void_cast( Expression_sub ) }, /* nb_sub */ + { Py_nb_multiply, void_cast( Expression_mul ) }, /* nb_mul */ + { Py_nb_negative, void_cast( Expression_neg ) }, /* nb_neg */ + { Py_nb_true_divide, void_cast( Expression_div ) }, /* nb_div */ + { 0, 0 }, }; -PyTypeObject Expression_Type = { - PyVarObject_HEAD_INIT( &PyType_Type, 0 ) - "kiwisolver.Expression", /* tp_name */ - sizeof( Expression ), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Expression_dealloc, /* tp_dealloc */ - (printfunc)0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX >= 0x03050000 - ( PyAsyncMethods* )0, /* tp_as_async */ -#elif PY_VERSION_HEX >= 0x03000000 - ( void* ) 0, /* tp_reserved */ -#else - ( cmpfunc )0, /* tp_compare */ -#endif - (reprfunc)Expression_repr, /* tp_repr */ - (PyNumberMethods*)&Expression_as_number,/* tp_as_number */ - (PySequenceMethods*)0, /* tp_as_sequence */ - (PyMappingMethods*)0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)0, /* tp_setattro */ - (PyBufferProcs*)0, /* tp_as_buffer */ -#if PY_MAJOR_VERSION >= 3 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE, -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /* tp_flags */ -#endif - 0, /* Documentation string */ - (traverseproc)Expression_traverse, /* tp_traverse */ - (inquiry)Expression_clear, /* tp_clear */ - (richcmpfunc)Expression_richcmp, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)0, /* tp_iter */ - (iternextfunc)0, /* tp_iternext */ - (struct PyMethodDef*)Expression_methods,/* tp_methods */ - (struct PyMemberDef*)0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - (descrgetfunc)0, /* tp_descr_get */ - (descrsetfunc)0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)0, /* tp_init */ - (allocfunc)PyType_GenericAlloc, /* tp_alloc */ - (newfunc)Expression_new, /* tp_new */ - (freefunc)PyObject_GC_Del, /* tp_free */ - (inquiry)0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ - (destructor)0 /* tp_del */ +} // namespace + + +// Initialize static variables (otherwise the compiler eliminates them) +PyTypeObject* Expression::TypeObject = NULL; + + +PyType_Spec Expression::TypeObject_Spec = { + "kiwisolver.Expression", /* tp_name */ + sizeof( Expression ), /* tp_basicsize */ + 0, /* tp_itemsize */ + Py_TPFLAGS_DEFAULT| + Py_TPFLAGS_HAVE_GC| + Py_TPFLAGS_BASETYPE, /* tp_flags */ + Expression_Type_slots /* slots */ }; -int import_expression() +bool Expression::Ready() { - return PyType_Ready( &Expression_Type ); + // The reference will be handled by the module to which we will add the type + TypeObject = pytype_cast( PyType_FromSpec( &TypeObject_Spec ) ); + if( !TypeObject ) + { + return false; + } + return true; } + +} // namesapce kiwisolver diff --git a/contrib/python/kiwisolver/py3/py/kiwisolver.cpp b/contrib/python/kiwisolver/py3/py/kiwisolver.cpp index 54b333a2c8..d82e67fde2 100644 --- a/contrib/python/kiwisolver/py3/py/kiwisolver.cpp +++ b/contrib/python/kiwisolver/py3/py/kiwisolver.cpp @@ -1,86 +1,187 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ -#include <Python.h> +#include <cppy/cppy.h> #include <kiwi/kiwi.h> -#include "pythonhelpers.h" #include "types.h" -#define PY_KIWI_VERSION "1.1.0" +#define PY_KIWI_VERSION "1.2.0" + +namespace +{ + + +bool ready_types() +{ + using namespace kiwisolver; + if( !Variable::Ready() ) + { + return false; + } + if( !Term::Ready() ) + { + return false; + } + if( !Expression::Ready() ) + { + return false; + } + if( !Constraint::Ready() ) + { + return false; + } + if( !strength::Ready() ) + { + return false; + } + if( !Solver::Ready() ) + { + return false; + } + return true; +} + +bool add_objects( PyObject* mod ) +{ + using namespace kiwisolver; + + cppy::ptr kiwiversion( PyUnicode_FromString( KIWI_VERSION ) ); + if( !kiwiversion ) + { + return false; + } + cppy::ptr pyversion( PyUnicode_FromString( PY_KIWI_VERSION ) ); + if( !pyversion ) + { + return false; + } + cppy::ptr pystrength( PyType_GenericNew( strength::TypeObject, 0, 0 ) ); + if( !pystrength ) + { + return false; + } + + if( PyModule_AddObject( mod, "__version__", pyversion.get() ) < 0 ) + { + return false; + } + pyversion.release(); + + if( PyModule_AddObject( mod, "__kiwi_version__", kiwiversion.get() ) < 0 ) + { + return false; + } + kiwiversion.release(); + + if( PyModule_AddObject( mod, "strength", pystrength.get() ) < 0 ) + { + return false; + } + pystrength.release(); + + // Variable + cppy::ptr var( pyobject_cast( Variable::TypeObject ) ); + if( PyModule_AddObject( mod, "Variable", var.get() ) < 0 ) + { + return false; + } + var.release(); + + // Term + cppy::ptr term( pyobject_cast( Term::TypeObject ) ); + if( PyModule_AddObject( mod, "Term", term.get() ) < 0 ) + { + return false; + } + term.release(); + + // Expression + cppy::ptr expr( pyobject_cast( Expression::TypeObject ) ); + if( PyModule_AddObject( mod, "Expression", expr.get() ) < 0 ) + { + return false; + } + expr.release(); + + // Constraint + cppy::ptr cons( pyobject_cast( Constraint::TypeObject ) ); + if( PyModule_AddObject( mod, "Constraint", cons.get() ) < 0 ) + { + return false; + } + cons.release(); + + cppy::ptr solver( pyobject_cast( Solver::TypeObject ) ); + if( PyModule_AddObject( mod, "Solver", solver.get() ) < 0 ) + { + return false; + } + solver.release(); + + PyModule_AddObject( mod, "DuplicateConstraint", DuplicateConstraint ); + PyModule_AddObject( mod, "UnsatisfiableConstraint", UnsatisfiableConstraint ); + PyModule_AddObject( mod, "UnknownConstraint", UnknownConstraint ); + PyModule_AddObject( mod, "DuplicateEditVariable", DuplicateEditVariable ); + PyModule_AddObject( mod, "UnknownEditVariable", UnknownEditVariable ); + PyModule_AddObject( mod, "BadRequiredStrength", BadRequiredStrength ); + + return true; +} + + +int +catom_modexec( PyObject *mod ) +{ + if( !ready_types() ) + { + return -1; + } + if( !kiwisolver::init_exceptions() ) + { + return -1; + } + if( !add_objects( mod ) ) + { + return -1; + } + + + return 0; +} -using namespace PythonHelpers; static PyMethodDef kiwisolver_methods[] = { { 0 } // Sentinel }; -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef kiwisolver_moduledef = { - PyModuleDef_HEAD_INIT, - "kiwisolver", - NULL, - sizeof( struct module_state ), - kiwisolver_methods, - NULL + +PyModuleDef_Slot kiwisolver_slots[] = { + {Py_mod_exec, reinterpret_cast<void*>( catom_modexec ) }, + {0, NULL} }; -PyMODINIT_FUNC -PyInit_kiwisolver( void ) -#else -PyMODINIT_FUNC -initkiwisolver( void ) -#endif + +struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "kiwisolver", + "kiwisolver extension module", + 0, + kiwisolver_methods, + kiwisolver_slots, + NULL, + NULL, + NULL +}; + +} // namespace + + +PyMODINIT_FUNC PyInit_kiwisolver( void ) { -#if PY_MAJOR_VERSION >= 3 - PyObject *mod = PyModule_Create( &kiwisolver_moduledef ); -#else - PyObject* mod = Py_InitModule( "kiwisolver", kiwisolver_methods ); -#endif - if( !mod ) - INITERROR; - if( import_variable() < 0 ) - INITERROR; - if( import_term() < 0 ) - INITERROR; - if( import_expression() < 0 ) - INITERROR; - if( import_constraint() < 0 ) - INITERROR; - if( import_solver() < 0 ) - INITERROR; - if( import_strength() < 0 ) - INITERROR; - PyObject* kiwiversion = FROM_STRING( KIWI_VERSION ); - if( !kiwiversion ) - INITERROR; - PyObject* pyversion = FROM_STRING( PY_KIWI_VERSION ); - if( !pyversion ) - INITERROR; - PyObject* pystrength = PyType_GenericNew( &strength_Type, 0, 0 ); - if( !pystrength ) - INITERROR; - - PyModule_AddObject( mod, "__version__", pyversion ); - PyModule_AddObject( mod, "__kiwi_version__", kiwiversion ); - PyModule_AddObject( mod, "strength", pystrength ); - PyModule_AddObject( mod, "Variable", newref( pyobject_cast( &Variable_Type ) ) ); - PyModule_AddObject( mod, "Term", newref( pyobject_cast( &Term_Type ) ) ); - PyModule_AddObject( mod, "Expression", newref( pyobject_cast( &Expression_Type ) ) ); - PyModule_AddObject( mod, "Constraint", newref( pyobject_cast( &Constraint_Type ) ) ); - PyModule_AddObject( mod, "Solver", newref( pyobject_cast( &Solver_Type ) ) ); - PyModule_AddObject( mod, "DuplicateConstraint", newref( DuplicateConstraint ) ); - PyModule_AddObject( mod, "UnsatisfiableConstraint", newref( UnsatisfiableConstraint ) ); - PyModule_AddObject( mod, "UnknownConstraint", newref( UnknownConstraint ) ); - PyModule_AddObject( mod, "DuplicateEditVariable", newref( DuplicateEditVariable ) ); - PyModule_AddObject( mod, "UnknownEditVariable", newref( UnknownEditVariable ) ); - PyModule_AddObject( mod, "BadRequiredStrength", newref( BadRequiredStrength ) ); - -#if PY_MAJOR_VERSION >= 3 - return mod; -#endif + return PyModuleDef_Init( &moduledef ); } diff --git a/contrib/python/kiwisolver/py3/py/pythonhelpers.h b/contrib/python/kiwisolver/py3/py/pythonhelpers.h deleted file mode 100644 index a9e0db634d..0000000000 --- a/contrib/python/kiwisolver/py3/py/pythonhelpers.h +++ /dev/null @@ -1,771 +0,0 @@ -/*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. -| -| Distributed under the terms of the Modified BSD License. -| -| The full license is in the file COPYING.txt, distributed with this software. -|----------------------------------------------------------------------------*/ -#pragma once -#include <Python.h> -#include <structmember.h> -#include <string> - -#if PY_MAJOR_VERSION >= 3 -#define FROM_STRING PyUnicode_FromString -#define INITERROR return NULL -#define MOD_INIT_FUNC(name) PyMODINIT_FUNC PyInit_##name(void) -#else -#define FROM_STRING PyString_FromString -#define INITERROR return -#define MOD_INIT_FUNC(name) PyMODINIT_FUNC init##name(void) -#endif - -#ifndef Py_RETURN_NOTIMPLEMENTED -#define Py_RETURN_NOTIMPLEMENTED \ - return Py_INCREF(Py_NotImplemented), Py_NotImplemented -#endif - -#define pyobject_cast( o ) ( reinterpret_cast<PyObject*>( o ) ) -#define pytype_cast( o ) ( reinterpret_cast<PyTypeObject*>( o ) ) - -struct module_state { - PyObject *error; -}; - - -namespace PythonHelpers -{ - - -/*----------------------------------------------------------------------------- -| Exception Handling -|----------------------------------------------------------------------------*/ -inline PyObject* -py_bad_internal_call( const char* message ) -{ - PyErr_SetString( PyExc_SystemError, message ); - return 0; -} - - -inline PyObject* -py_type_fail( const char* message ) -{ - PyErr_SetString( PyExc_TypeError, message ); - return 0; -} - - -inline PyObject* -py_expected_type_fail( PyObject* pyobj, const char* expected_type ) -{ - PyErr_Format( - PyExc_TypeError, - "Expected object of type `%s`. Got object of type `%s` instead.", - expected_type, pyobj->ob_type->tp_name - ); - return 0; -} - - -inline PyObject* -py_value_fail( const char* message ) -{ - PyErr_SetString( PyExc_ValueError, message ); - return 0; -} - - -inline PyObject* -py_runtime_fail( const char* message ) -{ - PyErr_SetString( PyExc_RuntimeError, message ); - return 0; -} - - -inline PyObject* -py_attr_fail( const char* message ) -{ - PyErr_SetString( PyExc_AttributeError, message ); - return 0; -} - - -inline PyObject* -py_no_attr_fail( PyObject* pyobj, const char* attr ) -{ - PyErr_Format( - PyExc_AttributeError, - "'%s' object has no attribute '%s'", - pyobj->ob_type->tp_name, attr - ); - return 0; -} - - -/*----------------------------------------------------------------------------- -| Utilities -|----------------------------------------------------------------------------*/ -inline PyObject* -newref( PyObject* pyobj ) -{ - Py_INCREF( pyobj ); - return pyobj; -} - - -inline PyObject* -xnewref( PyObject* pyobj ) -{ - Py_XINCREF( pyobj ); - return pyobj; -} - - -inline PyObject* -py_bool( bool val ) -{ - return newref( val ? Py_True : Py_False ); -} - - -inline PyCFunction -lookup_method( PyTypeObject* type, const char* name ) -{ - PyMethodDef* method = type->tp_methods; - for( ; method->ml_name != 0; ++method ) - { - if( strcmp( method->ml_name, name ) == 0 ) - return method->ml_meth; - } - return 0; -} - - -/*----------------------------------------------------------------------------- -| Object Ptr -|----------------------------------------------------------------------------*/ -class PyObjectPtr { - -public: - - PyObjectPtr() : m_pyobj( 0 ) {} - - PyObjectPtr( const PyObjectPtr& objptr ) : - m_pyobj( PythonHelpers::xnewref( objptr.m_pyobj ) ) {} - - PyObjectPtr( PyObject* pyobj ) : m_pyobj( pyobj ) {} - - ~PyObjectPtr() - { - xdecref_release(); - } - - PyObject* get() const - { - return m_pyobj; - } - - void set( PyObject* pyobj ) - { - PyObject* old = m_pyobj; - m_pyobj = pyobj; - Py_XDECREF( old ); - } - - PyObject* release() - { - PyObject* pyobj = m_pyobj; - m_pyobj = 0; - return pyobj; - } - - PyObject* decref_release() - { - PyObject* pyobj = m_pyobj; - m_pyobj = 0; - Py_DECREF( pyobj ); - return pyobj; - } - - PyObject* xdecref_release() - { - PyObject* pyobj = m_pyobj; - m_pyobj = 0; - Py_XDECREF( pyobj ); - return pyobj; - } - - PyObject* incref_release() - { - PyObject* pyobj = m_pyobj; - m_pyobj = 0; - Py_INCREF( pyobj ); - return pyobj; - } - - PyObject* xincref_release() - { - PyObject* pyobj = m_pyobj; - m_pyobj = 0; - Py_XINCREF( pyobj ); - return pyobj; - } - - void incref() const - { - Py_INCREF( m_pyobj ); - } - - void decref() const - { - Py_DECREF( m_pyobj ); - } - - void xincref() const - { - Py_XINCREF( m_pyobj ); - } - - void xdecref() const - { - Py_XDECREF( m_pyobj ); - } - - PyObject* newref() const - { - Py_INCREF( m_pyobj ); - return m_pyobj; - } - - PyObject* xnewref() const - { - Py_XINCREF( m_pyobj ); - return m_pyobj; - } - - size_t refcount() const - { - if( m_pyobj ) - return m_pyobj->ob_refcnt; - return 0; - } - - bool is_true( bool clear_err=true ) const - { - int truth = PyObject_IsTrue( m_pyobj ); - if( truth == 1 ) - return true; - if( truth == 0 ) - return false; - if( clear_err ) - PyErr_Clear(); - return false; - } - - bool is_None() const - { - return m_pyobj == Py_None; - } - - bool is_True() const - { - return m_pyobj == Py_True; - } - - bool is_False() const - { - return m_pyobj == Py_False; - } - - bool load_dict( PyObjectPtr& out, bool forcecreate=false ) - { - PyObject** dict = _PyObject_GetDictPtr( m_pyobj ); - if( !dict ) - return false; - if( forcecreate && !*dict ) - *dict = PyDict_New(); - out = PythonHelpers::xnewref( *dict ); - return true; - } - - bool richcompare( PyObject* other, int opid, bool clear_err=true ) - { - int r = PyObject_RichCompareBool( m_pyobj, other, opid ); - if( r == 1 ) - return true; - if( r == 0 ) - return false; - if( clear_err && PyErr_Occurred() ) - PyErr_Clear(); - return false; - } - - bool richcompare( PyObjectPtr& other, int opid, bool clear_err=true ) - { - return richcompare( other.m_pyobj, opid, clear_err ); - } - - bool hasattr( PyObject* attr ) - { - return PyObject_HasAttr( m_pyobj, attr ) == 1; - } - - bool hasattr( PyObjectPtr& attr ) - { - return PyObject_HasAttr( m_pyobj, attr.get() ) == 1; - } - - bool hasattr( const char* attr ) - { - return PyObject_HasAttrString( m_pyobj, attr ) == 1; - } - - bool hasattr( std::string& attr ) - { - return hasattr( attr.c_str() ); - } - - PyObjectPtr getattr( PyObject* attr ) - { - return PyObjectPtr( PyObject_GetAttr( m_pyobj, attr ) ); - } - - PyObjectPtr getattr( PyObjectPtr& attr ) - { - return PyObjectPtr( PyObject_GetAttr( m_pyobj, attr.get() ) ); - } - - PyObjectPtr getattr( const char* attr ) - { - return PyObjectPtr( PyObject_GetAttrString( m_pyobj, attr ) ); - } - - PyObjectPtr getattr( std::string& attr ) - { - return getattr( attr.c_str() ); - } - - bool setattr( PyObject* attr, PyObject* value ) - { - return PyObject_SetAttr( m_pyobj, attr, value ) == 0; - } - - bool setattr( PyObjectPtr& attr, PyObjectPtr& value ) - { - return PyObject_SetAttr( m_pyobj, attr.get(), value.get() ) == 0; - } - - PyObjectPtr operator()( PyObjectPtr& args ) const - { - return PyObjectPtr( PyObject_Call( m_pyobj, args.get(), 0 ) ); - } - - PyObjectPtr operator()( PyObjectPtr& args, PyObjectPtr& kwargs ) const - { - return PyObjectPtr( PyObject_Call( m_pyobj, args.get(), kwargs.get() ) ); - } - - operator void*() const - { - return static_cast<void*>( m_pyobj ); - } - - PyObjectPtr& operator=( const PyObjectPtr& rhs ) - { - PyObject* old = m_pyobj; - m_pyobj = rhs.m_pyobj; - Py_XINCREF( m_pyobj ); - Py_XDECREF( old ); - return *this; - } - - PyObjectPtr& operator=( PyObject* rhs ) - { - PyObject* old = m_pyobj; - m_pyobj = rhs; - Py_XDECREF( old ); - return *this; - } - -protected: - - PyObject* m_pyobj; - -}; - - -inline bool -operator!=( const PyObjectPtr& lhs, const PyObjectPtr& rhs ) -{ - return lhs.get() != rhs.get(); -} - - -inline bool -operator!=( const PyObject* lhs, const PyObjectPtr& rhs ) -{ - return lhs != rhs.get(); -} - - -inline bool -operator!=( const PyObjectPtr& lhs, const PyObject* rhs ) -{ - return lhs.get() != rhs; -} - - -inline bool -operator==( const PyObjectPtr& lhs, const PyObjectPtr& rhs ) -{ - return lhs.get() == rhs.get(); -} - - -inline bool -operator==( const PyObject* lhs, const PyObjectPtr& rhs ) -{ - return lhs == rhs.get(); -} - - -inline bool -operator==( const PyObjectPtr& lhs, const PyObject* rhs ) -{ - return lhs.get() == rhs; -} - - -/*----------------------------------------------------------------------------- -| Tuple Ptr -|----------------------------------------------------------------------------*/ -class PyTuplePtr : public PyObjectPtr { - -public: - - PyTuplePtr() : PyObjectPtr() {} - - PyTuplePtr( const PyObjectPtr& objptr ) : PyObjectPtr( objptr ) {} - - PyTuplePtr( PyObject* pytuple ) : PyObjectPtr( pytuple ) {} - - bool check() - { - return PyTuple_Check( m_pyobj ); - } - - bool check_exact() - { - return PyTuple_CheckExact( m_pyobj ); - } - - Py_ssize_t size() const - { - return PyTuple_GET_SIZE( m_pyobj ); - } - - PyObjectPtr get_item( Py_ssize_t index ) const - { - return PyObjectPtr( PythonHelpers::newref( PyTuple_GET_ITEM( m_pyobj, index ) ) ); - } - - void set_item( Py_ssize_t index, PyObject* pyobj ) - { - PyObject* old_item = PyTuple_GET_ITEM( m_pyobj, index ); - PyTuple_SET_ITEM( m_pyobj, index, pyobj ); - Py_XDECREF( old_item ); - } - - void set_item( Py_ssize_t index, PyObjectPtr& item ) - { - PyObject* old_item = PyTuple_GET_ITEM( m_pyobj, index ); - PyTuple_SET_ITEM( m_pyobj, index, item.get() ); - Py_XINCREF( item.get() ); - Py_XDECREF( old_item ); - } - - // pyobj must not be null, only use to fill a new empty tuple - void initialize( Py_ssize_t index, PyObject* pyobj ) - { - PyTuple_SET_ITEM( m_pyobj, index, pyobj ); - } - - // ptr must not be empty, only use to fill a new empty tuple - void initialize( Py_ssize_t index, PyObjectPtr& item ) - { - PyTuple_SET_ITEM( m_pyobj, index, item.get() ); - Py_INCREF( item.get() ); - } - -}; - - -/*----------------------------------------------------------------------------- -| List Ptr -|----------------------------------------------------------------------------*/ -class PyListPtr : public PyObjectPtr { - -public: - - PyListPtr() : PyObjectPtr() {} - - PyListPtr( const PyObjectPtr& objptr ) : PyObjectPtr( objptr ) {} - - PyListPtr( PyObject* pylist ) : PyObjectPtr( pylist ) {} - - bool check() const - { - return PyList_Check( m_pyobj ); - } - - bool check_exact() const - { - return PyList_CheckExact( m_pyobj ); - } - - Py_ssize_t size() const - { - return PyList_GET_SIZE( m_pyobj ); - } - - PyObject* borrow_item( Py_ssize_t index ) const - { - return PyList_GET_ITEM( m_pyobj, index ); - } - - PyObjectPtr get_item( Py_ssize_t index ) const - { - return PyObjectPtr( PythonHelpers::newref( PyList_GET_ITEM( m_pyobj, index ) ) ); - } - - void set_item( Py_ssize_t index, PyObject* pyobj ) const - { - PyObject* old_item = PyList_GET_ITEM( m_pyobj, index ); - PyList_SET_ITEM( m_pyobj, index, pyobj ); - Py_XDECREF( old_item ); - } - - void set_item( Py_ssize_t index, PyObjectPtr& item ) const - { - PyObject* old_item = PyList_GET_ITEM( m_pyobj, index ); - PyList_SET_ITEM( m_pyobj, index, item.get() ); - Py_XINCREF( item.get() ); - Py_XDECREF( old_item ); - } - - bool del_item( Py_ssize_t index ) const - { - if( PySequence_DelItem( m_pyobj, index ) == -1 ) - return false; - return true; - } - - bool append( PyObjectPtr& pyobj ) const - { - if( PyList_Append( m_pyobj, pyobj.get() ) == 0 ) - return true; - return false; - } - - Py_ssize_t index( PyObjectPtr& item ) const - { - Py_ssize_t maxidx = size(); - for( Py_ssize_t idx = 0; idx < maxidx; idx++ ) - { - PyObjectPtr other( get_item( idx ) ); - if( item.richcompare( other, Py_EQ ) ) - return idx; - } - return -1; - } - -}; - - -/*----------------------------------------------------------------------------- -| Dict Ptr -|----------------------------------------------------------------------------*/ -class PyDictPtr : public PyObjectPtr { - -public: - - PyDictPtr() : PyObjectPtr() {} - - PyDictPtr( const PyObjectPtr& objptr ) : PyObjectPtr( objptr ) {} - - PyDictPtr( PyObject* pydict ) : PyObjectPtr( pydict ) {} - - bool check() - { - return PyDict_Check( m_pyobj ); - } - - bool check_exact() - { - return PyDict_CheckExact( m_pyobj ); - } - - Py_ssize_t size() const - { - return PyDict_Size( m_pyobj ); - } - - PyObjectPtr get_item( PyObject* key ) const - { - return PyObjectPtr( PythonHelpers::xnewref( PyDict_GetItem( m_pyobj, key ) ) ) ; - } - - PyObjectPtr get_item( PyObjectPtr& key ) const - { - return PyObjectPtr( PythonHelpers::xnewref( PyDict_GetItem( m_pyobj, key.get() ) ) ); - } - - PyObjectPtr get_item( const char* key ) const - { - return PyObjectPtr( PythonHelpers::xnewref( PyDict_GetItemString( m_pyobj, key ) ) ); - } - - PyObjectPtr get_item( std::string& key ) const - { - return get_item( key.c_str() ); - } - - bool set_item( PyObject* key, PyObject* value ) const - { - if( PyDict_SetItem( m_pyobj, key, value ) == 0 ) - return true; - return false; - } - - bool set_item( PyObject* key, PyObjectPtr& value ) const - { - if( PyDict_SetItem( m_pyobj, key, value.get() ) == 0 ) - return true; - return false; - } - - bool set_item( PyObjectPtr& key, PyObject* value ) const - { - if( PyDict_SetItem( m_pyobj, key.get(), value ) == 0 ) - return true; - return false; - } - - bool set_item( PyObjectPtr& key, PyObjectPtr& value ) const - { - if( PyDict_SetItem( m_pyobj, key.get(), value.get() ) == 0 ) - return true; - return false; - } - - bool set_item( const char* key, PyObjectPtr& value ) const - { - if( PyDict_SetItemString( m_pyobj, key, value.get() ) == 0 ) - return true; - return false; - } - - bool set_item( const char* key, PyObject* value ) const - { - if( PyDict_SetItemString( m_pyobj, key, value ) == 0 ) - return true; - return false; - } - - bool set_item( std::string& key, PyObjectPtr& value ) const - { - return set_item( key.c_str(), value ); - } - - bool del_item( PyObjectPtr& key ) const - { - if( PyDict_DelItem( m_pyobj, key.get() ) == 0 ) - return true; - return false; - } - - bool del_item( const char* key ) const - { - if( PyDict_DelItemString( m_pyobj, key ) == 0 ) - return true; - return false; - } - - bool del_item( std::string& key ) const - { - return del_item( key.c_str() ); - } - -}; - - -/*----------------------------------------------------------------------------- -| Method Ptr -|----------------------------------------------------------------------------*/ -class PyMethodPtr : public PyObjectPtr { - -public: - - PyMethodPtr() : PyObjectPtr() {} - - PyMethodPtr( const PyObjectPtr& objptr ) : PyObjectPtr( objptr ) {} - - PyMethodPtr( PyObject* pymethod ) : PyObjectPtr( pymethod ) {} - - bool check() - { - return PyMethod_Check( m_pyobj ); - } - - PyObjectPtr get_self() const - { - return PyObjectPtr( PythonHelpers::xnewref( PyMethod_GET_SELF( m_pyobj ) ) ); - } - - PyObjectPtr get_function() const - { - return PyObjectPtr( PythonHelpers::xnewref( PyMethod_GET_FUNCTION( m_pyobj ) ) ); - } - -#if PY_MAJOR_VERSION < 3 - PyObjectPtr get_class() const - { - return PyObjectPtr( PythonHelpers::xnewref( PyMethod_GET_CLASS( m_pyobj ) ) ); - } -#endif -}; - - -/*----------------------------------------------------------------------------- -| Weakref Ptr -|----------------------------------------------------------------------------*/ -class PyWeakrefPtr : public PyObjectPtr { - -public: - - PyWeakrefPtr() : PyObjectPtr() {} - - PyWeakrefPtr( const PyObjectPtr& objptr ) : PyObjectPtr( objptr ) {} - - PyWeakrefPtr( PyObject* pyweakref ) : PyObjectPtr( pyweakref ) {} - - bool check() - { - return PyWeakref_CheckRef( m_pyobj ); - } - - bool check_exact() - { - return PyWeakref_CheckRefExact( m_pyobj ); - } - - PyObjectPtr get_object() const - { - return PyObjectPtr( PythonHelpers::newref( PyWeakref_GET_OBJECT( m_pyobj ) ) ); - } - -}; - -} // namespace PythonHelpers diff --git a/contrib/python/kiwisolver/py3/py/solver.cpp b/contrib/python/kiwisolver/py3/py/solver.cpp index 7a2ef23ca3..cd6af8c724 100644 --- a/contrib/python/kiwisolver/py3/py/solver.cpp +++ b/contrib/python/kiwisolver/py3/py/solver.cpp @@ -1,25 +1,27 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ -#include <Python.h> +#include <cppy/cppy.h> #include <kiwi/kiwi.h> -#include "pythonhelpers.h" #include "types.h" #include "util.h" -using namespace PythonHelpers; +namespace kiwisolver +{ +namespace +{ -static PyObject* +PyObject* Solver_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) { if( PyTuple_GET_SIZE( args ) != 0 || ( kwargs && PyDict_Size( kwargs ) != 0 ) ) - return py_type_fail( "Solver.__new__ takes no arguments" ); + return cppy::type_error( "Solver.__new__ takes no arguments" ); PyObject* pysolver = PyType_GenericNew( type, args, kwargs ); if( !pysolver ) return 0; @@ -29,7 +31,7 @@ Solver_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) } -static void +void Solver_dealloc( Solver* self ) { self->solver.~Solver(); @@ -37,11 +39,11 @@ Solver_dealloc( Solver* self ) } -static PyObject* +PyObject* Solver_addConstraint( Solver* self, PyObject* other ) { if( !Constraint::TypeCheck( other ) ) - return py_expected_type_fail( other, "Constraint" ); + return cppy::type_error( other, "Constraint" ); Constraint* cn = reinterpret_cast<Constraint*>( other ); try { @@ -61,11 +63,11 @@ Solver_addConstraint( Solver* self, PyObject* other ) } -static PyObject* +PyObject* Solver_removeConstraint( Solver* self, PyObject* other ) { if( !Constraint::TypeCheck( other ) ) - return py_expected_type_fail( other, "Constraint" ); + return cppy::type_error( other, "Constraint" ); Constraint* cn = reinterpret_cast<Constraint*>( other ); try { @@ -80,17 +82,17 @@ Solver_removeConstraint( Solver* self, PyObject* other ) } -static PyObject* +PyObject* Solver_hasConstraint( Solver* self, PyObject* other ) { if( !Constraint::TypeCheck( other ) ) - return py_expected_type_fail( other, "Constraint" ); + return cppy::type_error( other, "Constraint" ); Constraint* cn = reinterpret_cast<Constraint*>( other ); - return newref( self->solver.hasConstraint( cn->constraint ) ? Py_True : Py_False ); + return cppy::incref( self->solver.hasConstraint( cn->constraint ) ? Py_True : Py_False ); } -static PyObject* +PyObject* Solver_addEditVariable( Solver* self, PyObject* args ) { PyObject* pyvar; @@ -98,7 +100,7 @@ Solver_addEditVariable( Solver* self, PyObject* args ) if( !PyArg_ParseTuple( args, "OO", &pyvar, &pystrength ) ) return 0; if( !Variable::TypeCheck( pyvar ) ) - return py_expected_type_fail( pyvar, "Variable" ); + return cppy::type_error( pyvar, "Variable" ); double strength; if( !convert_to_strength( pystrength, strength ) ) return 0; @@ -121,11 +123,11 @@ Solver_addEditVariable( Solver* self, PyObject* args ) } -static PyObject* +PyObject* Solver_removeEditVariable( Solver* self, PyObject* other ) { if( !Variable::TypeCheck( other ) ) - return py_expected_type_fail( other, "Variable" ); + return cppy::type_error( other, "Variable" ); Variable* var = reinterpret_cast<Variable*>( other ); try { @@ -140,17 +142,17 @@ Solver_removeEditVariable( Solver* self, PyObject* other ) } -static PyObject* +PyObject* Solver_hasEditVariable( Solver* self, PyObject* other ) { if( !Variable::TypeCheck( other ) ) - return py_expected_type_fail( other, "Variable" ); + return cppy::type_error( other, "Variable" ); Variable* var = reinterpret_cast<Variable*>( other ); - return newref( self->solver.hasEditVariable( var->variable ) ? Py_True : Py_False ); + return cppy::incref( self->solver.hasEditVariable( var->variable ) ? Py_True : Py_False ); } -static PyObject* +PyObject* Solver_suggestValue( Solver* self, PyObject* args ) { PyObject* pyvar; @@ -158,7 +160,7 @@ Solver_suggestValue( Solver* self, PyObject* args ) if( !PyArg_ParseTuple( args, "OO", &pyvar, &pyvalue ) ) return 0; if( !Variable::TypeCheck( pyvar ) ) - return py_expected_type_fail( pyvar, "Variable" ); + return cppy::type_error( pyvar, "Variable" ); double value; if( !convert_to_double( pyvalue, value ) ) return 0; @@ -176,7 +178,7 @@ Solver_suggestValue( Solver* self, PyObject* args ) } -static PyObject* +PyObject* Solver_updateVariables( Solver* self ) { self->solver.updateVariables(); @@ -184,7 +186,7 @@ Solver_updateVariables( Solver* self ) } -static PyObject* +PyObject* Solver_reset( Solver* self ) { self->solver.reset(); @@ -192,15 +194,15 @@ Solver_reset( Solver* self ) } -static PyObject* +PyObject* Solver_dump( Solver* self ) { - PyObjectPtr dump_str( PyUnicode_FromString( self->solver.dumps().c_str() ) ); + cppy::ptr dump_str( PyUnicode_FromString( self->solver.dumps().c_str() ) ); PyObject_Print( dump_str.get(), stdout, 0 ); Py_RETURN_NONE; } -static PyObject* +PyObject* Solver_dumps( Solver* self ) { return PyUnicode_FromString( self->solver.dumps().c_str() ); @@ -234,62 +236,45 @@ Solver_methods[] = { }; -PyTypeObject Solver_Type = { - PyVarObject_HEAD_INIT( &PyType_Type, 0 ) - "kiwisolver.Solver", /* tp_name */ - sizeof( Solver ), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Solver_dealloc, /* tp_dealloc */ - (printfunc)0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX >= 0x03050000 - ( PyAsyncMethods* )0, /* tp_as_async */ -#elif PY_VERSION_HEX >= 0x03000000 - ( void* ) 0, /* tp_reserved */ -#else - ( cmpfunc )0, /* tp_compare */ -#endif - (reprfunc)0, /* tp_repr */ - (PyNumberMethods*)0, /* tp_as_number */ - (PySequenceMethods*)0, /* tp_as_sequence */ - (PyMappingMethods*)0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)0, /* tp_setattro */ - (PyBufferProcs*)0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /* Documentation string */ - (traverseproc)0, /* tp_traverse */ - (inquiry)0, /* tp_clear */ - (richcmpfunc)0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)0, /* tp_iter */ - (iternextfunc)0, /* tp_iternext */ - (struct PyMethodDef*)Solver_methods, /* tp_methods */ - (struct PyMemberDef*)0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - (descrgetfunc)0, /* tp_descr_get */ - (descrsetfunc)0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)0, /* tp_init */ - (allocfunc)PyType_GenericAlloc, /* tp_alloc */ - (newfunc)Solver_new, /* tp_new */ - (freefunc)PyObject_Del, /* tp_free */ - (inquiry)0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ - (destructor)0 /* tp_del */ +static PyType_Slot Solver_Type_slots[] = { + { Py_tp_dealloc, void_cast( Solver_dealloc ) }, /* tp_dealloc */ + { Py_tp_methods, void_cast( Solver_methods ) }, /* tp_methods */ + { Py_tp_new, void_cast( Solver_new ) }, /* tp_new */ + { Py_tp_alloc, void_cast( PyType_GenericAlloc ) }, /* tp_alloc */ + { Py_tp_free, void_cast( PyObject_Del ) }, /* tp_free */ + { 0, 0 }, +}; + + +} // namespace + + +// Initialize static variables (otherwise the compiler eliminates them) +PyTypeObject* Solver::TypeObject = NULL; + + +PyType_Spec Solver::TypeObject_Spec = { + "kiwisolver.Solver", /* tp_name */ + sizeof( Solver ), /* tp_basicsize */ + 0, /* tp_itemsize */ + Py_TPFLAGS_DEFAULT| + Py_TPFLAGS_BASETYPE, /* tp_flags */ + Solver_Type_slots /* slots */ }; +bool Solver::Ready() +{ + // The reference will be handled by the module to which we will add the type + TypeObject = pytype_cast( PyType_FromSpec( &TypeObject_Spec ) ); + if( !TypeObject ) + { + return false; + } + return true; +} + + PyObject* DuplicateConstraint; PyObject* UnsatisfiableConstraint; @@ -303,31 +288,51 @@ PyObject* UnknownEditVariable; PyObject* BadRequiredStrength; -int import_solver() +bool init_exceptions() { DuplicateConstraint = PyErr_NewException( const_cast<char*>( "kiwisolver.DuplicateConstraint" ), 0, 0 ); if( !DuplicateConstraint ) - return -1; + { + return false; + } + UnsatisfiableConstraint = PyErr_NewException( const_cast<char*>( "kiwisolver.UnsatisfiableConstraint" ), 0, 0 ); if( !UnsatisfiableConstraint ) - return -1; + { + return false; + } + UnknownConstraint = PyErr_NewException( const_cast<char*>( "kiwisolver.UnknownConstraint" ), 0, 0 ); if( !UnknownConstraint ) - return -1; + { + return false; + } + DuplicateEditVariable = PyErr_NewException( const_cast<char*>( "kiwisolver.DuplicateEditVariable" ), 0, 0 ); if( !DuplicateEditVariable ) - return -1; + { + return false; + } + UnknownEditVariable = PyErr_NewException( const_cast<char*>( "kiwisolver.UnknownEditVariable" ), 0, 0 ); if( !UnknownEditVariable ) - return -1; + { + return false; + } + BadRequiredStrength = PyErr_NewException( const_cast<char*>( "kiwisolver.BadRequiredStrength" ), 0, 0 ); if( !BadRequiredStrength ) - return -1; - return PyType_Ready( &Solver_Type ); + { + return false; + } + + return true; } + +} // namespace diff --git a/contrib/python/kiwisolver/py3/py/strength.cpp b/contrib/python/kiwisolver/py3/py/strength.cpp index df1552d194..03611311f9 100644 --- a/contrib/python/kiwisolver/py3/py/strength.cpp +++ b/contrib/python/kiwisolver/py3/py/strength.cpp @@ -1,61 +1,68 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ -#include <Python.h> +#include <cppy/cppy.h> #include <kiwi/kiwi.h> -#include "pythonhelpers.h" #include "util.h" -using namespace PythonHelpers; +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wdeprecated-writable-strings" +#endif + +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wwrite-strings" +#endif -struct strength +namespace kiwisolver { - PyObject_HEAD; -}; -static void +namespace +{ + + +void strength_dealloc( PyObject* self ) { Py_TYPE( self )->tp_free( self ); } -static PyObject* +PyObject* strength_weak( strength* self ) { return PyFloat_FromDouble( kiwi::strength::weak ); } -static PyObject* +PyObject* strength_medium( strength* self ) { return PyFloat_FromDouble( kiwi::strength::medium ); } -static PyObject* +PyObject* strength_strong( strength* self ) { return PyFloat_FromDouble( kiwi::strength::strong ); } -static PyObject* +PyObject* strength_required( strength* self ) { return PyFloat_FromDouble( kiwi::strength::required ); } -static PyObject* +PyObject* strength_create( strength* self, PyObject* args ) { PyObject* pya; @@ -100,63 +107,43 @@ strength_methods[] = { }; -PyTypeObject strength_Type = { - PyVarObject_HEAD_INIT( &PyType_Type, 0 ) - "kiwisolver.strength", /* tp_name */ - sizeof( strength ), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)strength_dealloc, /* tp_dealloc */ - (printfunc)0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX >= 0x03050000 - ( PyAsyncMethods* )0, /* tp_as_async */ -#elif PY_VERSION_HEX >= 0x03000000 - ( void* ) 0, /* tp_reserved */ -#else - ( cmpfunc )0, /* tp_compare */ -#endif - (reprfunc)0, /* tp_repr */ - (PyNumberMethods*)0, /* tp_as_number */ - (PySequenceMethods*)0, /* tp_as_sequence */ - (PyMappingMethods*)0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)0, /* tp_setattro */ - (PyBufferProcs*)0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /* Documentation string */ - (traverseproc)0, /* tp_traverse */ - (inquiry)0, /* tp_clear */ - (richcmpfunc)0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)0, /* tp_iter */ - (iternextfunc)0, /* tp_iternext */ - (struct PyMethodDef*)strength_methods, /* tp_methods */ - (struct PyMemberDef*)0, /* tp_members */ - strength_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - (descrgetfunc)0, /* tp_descr_get */ - (descrsetfunc)0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)0, /* tp_init */ - (allocfunc)PyType_GenericAlloc, /* tp_alloc */ - (newfunc)0, /* tp_new */ - (freefunc)PyObject_Del, /* tp_free */ - (inquiry)0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ - (destructor)0 /* tp_del */ + +static PyType_Slot strength_Type_slots[] = { + { Py_tp_dealloc, void_cast( strength_dealloc ) }, /* tp_dealloc */ + { Py_tp_getset, void_cast( strength_getset ) }, /* tp_getset */ + { Py_tp_methods, void_cast( strength_methods ) }, /* tp_methods */ + { Py_tp_alloc, void_cast( PyType_GenericAlloc ) }, /* tp_alloc */ + { Py_tp_free, void_cast( PyObject_Del ) }, /* tp_free */ + { 0, 0 }, }; -int import_strength() +} // namespace + + +// Initialize static variables (otherwise the compiler eliminates them) +PyTypeObject* strength::TypeObject = NULL; + + +PyType_Spec strength::TypeObject_Spec = { + "kiwisolver.strength", /* tp_name */ + sizeof( strength ), /* tp_basicsize */ + 0, /* tp_itemsize */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + strength_Type_slots /* slots */ +}; + + +bool strength::Ready() { - return PyType_Ready( &strength_Type ); + // The reference will be handled by the module to which we will add the type + TypeObject = pytype_cast( PyType_FromSpec( &TypeObject_Spec ) ); + if( !TypeObject ) + { + return false; + } + return true; } + + +} // namespace diff --git a/contrib/python/kiwisolver/py3/py/symbolics.h b/contrib/python/kiwisolver/py3/py/symbolics.h index ac57553740..69ea5404c7 100644 --- a/contrib/python/kiwisolver/py3/py/symbolics.h +++ b/contrib/python/kiwisolver/py3/py/symbolics.h @@ -1,17 +1,19 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once -#include <Python.h> -#include "pythonhelpers.h" +#include <cppy/cppy.h> #include "types.h" #include "util.h" +namespace kiwisolver +{ + template<typename Op, typename T> struct UnaryInvoke { @@ -61,10 +63,6 @@ struct BinaryInvoke return Invk()( primary, reinterpret_cast<Variable*>( secondary ) ); if( PyFloat_Check( secondary ) ) return Invk()( primary, PyFloat_AS_DOUBLE( secondary ) ); -#if PY_MAJOR_VERSION < 3 - if( PyInt_Check( secondary ) ) - return Invk()( primary, double( PyInt_AS_LONG( secondary ) ) ); -#endif if( PyLong_Check( secondary ) ) { double v = PyLong_AsDouble( secondary ); @@ -90,11 +88,11 @@ struct BinaryMul template<> inline PyObject* BinaryMul::operator()( Variable* first, double second ) { - PyObject* pyterm = PyType_GenericNew( &Term_Type, 0, 0 ); + PyObject* pyterm = PyType_GenericNew( Term::TypeObject, 0, 0 ); if( !pyterm ) return 0; Term* term = reinterpret_cast<Term*>( pyterm ); - term->variable = PythonHelpers::newref( pyobject_cast( first ) ); + term->variable = cppy::incref( pyobject_cast( first ) ); term->coefficient = second; return pyterm; } @@ -103,11 +101,11 @@ PyObject* BinaryMul::operator()( Variable* first, double second ) template<> inline PyObject* BinaryMul::operator()( Term* first, double second ) { - PyObject* pyterm = PyType_GenericNew( &Term_Type, 0, 0 ); + PyObject* pyterm = PyType_GenericNew( Term::TypeObject, 0, 0 ); if( !pyterm ) return 0; Term* term = reinterpret_cast<Term*>( pyterm ); - term->variable = PythonHelpers::newref( first->variable ); + term->variable = cppy::incref( first->variable ); term->coefficient = first->coefficient * second; return pyterm; } @@ -116,12 +114,11 @@ PyObject* BinaryMul::operator()( Term* first, double second ) template<> inline PyObject* BinaryMul::operator()( Expression* first, double second ) { - using namespace PythonHelpers; - PyObjectPtr pyexpr( PyType_GenericNew( &Expression_Type, 0, 0 ) ); + cppy::ptr pyexpr( PyType_GenericNew( Expression::TypeObject, 0, 0 ) ); if( !pyexpr ) return 0; Expression* expr = reinterpret_cast<Expression*>( pyexpr.get() ); - PyObjectPtr terms( PyTuple_New( PyTuple_GET_SIZE( first->terms ) ) ); + cppy::ptr terms( PyTuple_New( PyTuple_GET_SIZE( first->terms ) ) ); if( !terms ) return 0; Py_ssize_t end = PyTuple_GET_SIZE( first->terms ); @@ -252,7 +249,7 @@ struct BinaryAdd template<> inline PyObject* BinaryAdd::operator()( Expression* first, Expression* second ) { - PythonHelpers::PyObjectPtr pyexpr( PyType_GenericNew( &Expression_Type, 0, 0 ) ); + cppy::ptr pyexpr( PyType_GenericNew( Expression::TypeObject, 0, 0 ) ); if( !pyexpr ) return 0; Expression* expr = reinterpret_cast<Expression*>( pyexpr.get() ); @@ -267,8 +264,7 @@ PyObject* BinaryAdd::operator()( Expression* first, Expression* second ) template<> inline PyObject* BinaryAdd::operator()( Expression* first, Term* second ) { - using namespace PythonHelpers; - PyObjectPtr pyexpr( PyType_GenericNew( &Expression_Type, 0, 0 ) ); + cppy::ptr pyexpr( PyType_GenericNew( Expression::TypeObject, 0, 0 ) ); if( !pyexpr ) return 0; PyObject* terms = PyTuple_New( PyTuple_GET_SIZE( first->terms ) + 1 ); @@ -278,9 +274,9 @@ PyObject* BinaryAdd::operator()( Expression* first, Term* second ) for( Py_ssize_t i = 0; i < end; ++i ) { PyObject* item = PyTuple_GET_ITEM( first->terms, i ); - PyTuple_SET_ITEM( terms, i, newref( item ) ); + PyTuple_SET_ITEM( terms, i, cppy::incref( item ) ); } - PyTuple_SET_ITEM( terms, end, newref( pyobject_cast( second ) ) ); + PyTuple_SET_ITEM( terms, end, cppy::incref( pyobject_cast( second ) ) ); Expression* expr = reinterpret_cast<Expression*>( pyexpr.get() ); expr->terms = terms; expr->constant = first->constant; @@ -291,7 +287,7 @@ PyObject* BinaryAdd::operator()( Expression* first, Term* second ) template<> inline PyObject* BinaryAdd::operator()( Expression* first, Variable* second ) { - PythonHelpers::PyObjectPtr temp( BinaryMul()( second, 1.0 ) ); + cppy::ptr temp( BinaryMul()( second, 1.0 ) ); if( !temp ) return 0; return operator()( first, reinterpret_cast<Term*>( temp.get() ) ); @@ -301,12 +297,11 @@ PyObject* BinaryAdd::operator()( Expression* first, Variable* second ) template<> inline PyObject* BinaryAdd::operator()( Expression* first, double second ) { - using namespace PythonHelpers; - PyObjectPtr pyexpr( PyType_GenericNew( &Expression_Type, 0, 0 ) ); + cppy::ptr pyexpr( PyType_GenericNew( Expression::TypeObject, 0, 0 ) ); if( !pyexpr ) return 0; Expression* expr = reinterpret_cast<Expression*>( pyexpr.get() ); - expr->terms = newref( first->terms ); + expr->terms = cppy::incref( first->terms ); expr->constant = first->constant + second; return pyexpr.release(); } @@ -315,7 +310,7 @@ PyObject* BinaryAdd::operator()( Expression* first, double second ) template<> inline PyObject* BinaryAdd::operator()( Term* first, double second ) { - PythonHelpers::PyObjectPtr pyexpr( PyType_GenericNew( &Expression_Type, 0, 0 ) ); + cppy::ptr pyexpr( PyType_GenericNew( Expression::TypeObject, 0, 0 ) ); if( !pyexpr ) return 0; Expression* expr = reinterpret_cast<Expression*>( pyexpr.get() ); @@ -337,7 +332,7 @@ PyObject* BinaryAdd::operator()( Term* first, Expression* second ) template<> inline PyObject* BinaryAdd::operator()( Term* first, Term* second ) { - PythonHelpers::PyObjectPtr pyexpr( PyType_GenericNew( &Expression_Type, 0, 0 ) ); + cppy::ptr pyexpr( PyType_GenericNew( Expression::TypeObject, 0, 0 ) ); if( !pyexpr ) return 0; Expression* expr = reinterpret_cast<Expression*>( pyexpr.get() ); @@ -352,7 +347,7 @@ PyObject* BinaryAdd::operator()( Term* first, Term* second ) template<> inline PyObject* BinaryAdd::operator()( Term* first, Variable* second ) { - PythonHelpers::PyObjectPtr temp( BinaryMul()( second, 1.0 ) ); + cppy::ptr temp( BinaryMul()( second, 1.0 ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Term*>( temp.get() ) ); @@ -362,7 +357,7 @@ PyObject* BinaryAdd::operator()( Term* first, Variable* second ) template<> inline PyObject* BinaryAdd::operator()( Variable* first, double second ) { - PythonHelpers::PyObjectPtr temp( BinaryMul()( first, 1.0 ) ); + cppy::ptr temp( BinaryMul()( first, 1.0 ) ); if( !temp ) return 0; return operator()( reinterpret_cast<Term*>( temp.get() ), second ); @@ -372,7 +367,7 @@ PyObject* BinaryAdd::operator()( Variable* first, double second ) template<> inline PyObject* BinaryAdd::operator()( Variable* first, Variable* second ) { - PythonHelpers::PyObjectPtr temp( BinaryMul()( first, 1.0 ) ); + cppy::ptr temp( BinaryMul()( first, 1.0 ) ); if( !temp ) return 0; return operator()( reinterpret_cast<Term*>( temp.get() ), second ); @@ -382,7 +377,7 @@ PyObject* BinaryAdd::operator()( Variable* first, Variable* second ) template<> inline PyObject* BinaryAdd::operator()( Variable* first, Term* second ) { - PythonHelpers::PyObjectPtr temp( BinaryMul()( first, 1.0 ) ); + cppy::ptr temp( BinaryMul()( first, 1.0 ) ); if( !temp ) return 0; return operator()( reinterpret_cast<Term*>( temp.get() ), second ); @@ -392,7 +387,7 @@ PyObject* BinaryAdd::operator()( Variable* first, Term* second ) template<> inline PyObject* BinaryAdd::operator()( Variable* first, Expression* second ) { - PythonHelpers::PyObjectPtr temp( BinaryMul()( first, 1.0 ) ); + cppy::ptr temp( BinaryMul()( first, 1.0 ) ); if( !temp ) return 0; return operator()( reinterpret_cast<Term*>( temp.get() ), second ); @@ -440,7 +435,7 @@ PyObject* BinarySub::operator()( Variable* first, double second ) template<> inline PyObject* BinarySub::operator()( Variable* first, Variable* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Term*>( temp.get() ) ); @@ -450,7 +445,7 @@ PyObject* BinarySub::operator()( Variable* first, Variable* second ) template<> inline PyObject* BinarySub::operator()( Variable* first, Term* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Term*>( temp.get() ) ); @@ -460,7 +455,7 @@ PyObject* BinarySub::operator()( Variable* first, Term* second ) template<> inline PyObject* BinarySub::operator()( Variable* first, Expression* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Expression*>( temp.get() ) ); @@ -477,7 +472,7 @@ PyObject* BinarySub::operator()( Term* first, double second ) template<> inline PyObject* BinarySub::operator()( Term* first, Variable* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Term*>( temp.get() ) ); @@ -487,7 +482,7 @@ PyObject* BinarySub::operator()( Term* first, Variable* second ) template<> inline PyObject* BinarySub::operator()( Term* first, Term* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Term*>( temp.get() ) ); @@ -497,7 +492,7 @@ PyObject* BinarySub::operator()( Term* first, Term* second ) template<> inline PyObject* BinarySub::operator()( Term* first, Expression* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Expression*>( temp.get() ) ); @@ -514,7 +509,7 @@ PyObject* BinarySub::operator()( Expression* first, double second ) template<> inline PyObject* BinarySub::operator()( Expression* first, Variable* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Term*>( temp.get() ) ); @@ -524,7 +519,7 @@ PyObject* BinarySub::operator()( Expression* first, Variable* second ) template<> inline PyObject* BinarySub::operator()( Expression* first, Term* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Term*>( temp.get() ) ); @@ -534,7 +529,7 @@ PyObject* BinarySub::operator()( Expression* first, Term* second ) template<> inline PyObject* BinarySub::operator()( Expression* first, Expression* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Expression*>( temp.get() ) ); @@ -544,7 +539,7 @@ PyObject* BinarySub::operator()( Expression* first, Expression* second ) template<> inline PyObject* BinarySub::operator()( double first, Variable* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Term*>( temp.get() ) ); @@ -554,7 +549,7 @@ PyObject* BinarySub::operator()( double first, Variable* second ) template<> inline PyObject* BinarySub::operator()( double first, Term* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Term*>( temp.get() ) ); @@ -564,7 +559,7 @@ PyObject* BinarySub::operator()( double first, Term* second ) template<> inline PyObject* BinarySub::operator()( double first, Expression* second ) { - PythonHelpers::PyObjectPtr temp( UnaryNeg()( second ) ); + cppy::ptr temp( UnaryNeg()( second ) ); if( !temp ) return 0; return BinaryAdd()( first, reinterpret_cast<Expression*>( temp.get() ) ); @@ -574,10 +569,10 @@ PyObject* BinarySub::operator()( double first, Expression* second ) template<typename T, typename U> PyObject* makecn( T first, U second, kiwi::RelationalOperator op ) { - PythonHelpers::PyObjectPtr pyexpr( BinarySub()( first, second ) ); + cppy::ptr pyexpr( BinarySub()( first, second ) ); if( !pyexpr ) return 0; - PythonHelpers::PyObjectPtr pycn( PyType_GenericNew( &Constraint_Type, 0, 0 ) ); + cppy::ptr pycn( PyType_GenericNew( Constraint::TypeObject, 0, 0 ) ); if( !pycn ) return 0; Constraint* cn = reinterpret_cast<Constraint*>( pycn.get() ); @@ -618,3 +613,6 @@ struct CmpGE return makecn( first, second, kiwi::OP_GE ); } }; + + +} // namespace kiwisolver diff --git a/contrib/python/kiwisolver/py3/py/term.cpp b/contrib/python/kiwisolver/py3/py/term.cpp index 4be64a1eea..923e0cf858 100644 --- a/contrib/python/kiwisolver/py3/py/term.cpp +++ b/contrib/python/kiwisolver/py3/py/term.cpp @@ -1,22 +1,26 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #include <sstream> -#include <Python.h> -#include "pythonhelpers.h" +#include <cppy/cppy.h> #include "symbolics.h" #include "types.h" #include "util.h" -using namespace PythonHelpers; +namespace kiwisolver +{ + +namespace +{ -static PyObject* + +PyObject* Term_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) { static const char *kwlist[] = { "variable", "coefficient", 0 }; @@ -27,7 +31,7 @@ Term_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) &pyvar, &pycoeff ) ) return 0; if( !Variable::TypeCheck( pyvar ) ) - return py_expected_type_fail( pyvar, "Variable" ); + return cppy::type_error( pyvar, "Variable" ); double coefficient = 1.0; if( pycoeff && !convert_to_double( pycoeff, coefficient ) ) return 0; @@ -35,20 +39,20 @@ Term_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) if( !pyterm ) return 0; Term* self = reinterpret_cast<Term*>( pyterm ); - self->variable = newref( pyvar ); + self->variable = cppy::incref( pyvar ); self->coefficient = coefficient; return pyterm; } -static void +void Term_clear( Term* self ) { Py_CLEAR( self->variable ); } -static int +int Term_traverse( Term* self, visitproc visit, void* arg ) { Py_VISIT( self->variable ); @@ -56,7 +60,7 @@ Term_traverse( Term* self, visitproc visit, void* arg ) } -static void +void Term_dealloc( Term* self ) { PyObject_GC_UnTrack( self ); @@ -65,31 +69,31 @@ Term_dealloc( Term* self ) } -static PyObject* +PyObject* Term_repr( Term* self ) { std::stringstream stream; stream << self->coefficient << " * "; stream << reinterpret_cast<Variable*>( self->variable )->variable.name(); - return FROM_STRING( stream.str().c_str() ); + return PyUnicode_FromString( stream.str().c_str() ); } -static PyObject* +PyObject* Term_variable( Term* self ) { - return newref( self->variable ); + return cppy::incref( self->variable ); } -static PyObject* +PyObject* Term_coefficient( Term* self ) { return PyFloat_FromDouble( self->coefficient ); } -static PyObject* +PyObject* Term_value( Term* self ) { Variable* pyvar = reinterpret_cast<Variable*>( self->variable ); @@ -97,42 +101,42 @@ Term_value( Term* self ) } -static PyObject* +PyObject* Term_add( PyObject* first, PyObject* second ) { return BinaryInvoke<BinaryAdd, Term>()( first, second ); } -static PyObject* +PyObject* Term_sub( PyObject* first, PyObject* second ) { return BinaryInvoke<BinarySub, Term>()( first, second ); } -static PyObject* +PyObject* Term_mul( PyObject* first, PyObject* second ) { return BinaryInvoke<BinaryMul, Term>()( first, second ); } -static PyObject* +PyObject* Term_div( PyObject* first, PyObject* second ) { return BinaryInvoke<BinaryDiv, Term>()( first, second ); } -static PyObject* +PyObject* Term_neg( PyObject* value ) { return UnaryInvoke<UnaryNeg, Term>()( value ); } -static PyObject* +PyObject* Term_richcmp( PyObject* first, PyObject* second, int op ) { switch( op ) @@ -170,129 +174,52 @@ Term_methods[] = { }; -static PyNumberMethods -Term_as_number = { - (binaryfunc)Term_add, /* nb_add */ - (binaryfunc)Term_sub, /* nb_subtract */ - (binaryfunc)Term_mul, /* nb_multiply */ -#if PY_MAJOR_VERSION < 3 - (binaryfunc)Term_div, /* nb_divide */ -#endif - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - (unaryfunc)Term_neg, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ -#if PY_MAJOR_VERSION >= 3 - 0, /* nb_bool */ -#else - 0, /* nb_nonzero */ -#endif - 0, /* nb_invert */ - 0, /* nb_lshift */ - 0, /* nb_rshift */ - 0, /* nb_and */ - 0, /* nb_xor */ - (binaryfunc)0, /* nb_or */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_coerce */ -#endif - 0, /* nb_int */ - 0, /* nb_long */ - 0, /* nb_float */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_oct */ - 0, /* nb_hex */ -#endif - 0, /* nb_inplace_add */ - 0, /* nb_inplace_subtract */ - 0, /* nb_inplace_multiply */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_inplace_divide */ -#endif - 0, /* nb_inplace_remainder */ - 0, /* nb_inplace_power */ - 0, /* nb_inplace_lshift */ - 0, /* nb_inplace_rshift */ - 0, /* nb_inplace_and */ - 0, /* nb_inplace_xor */ - 0, /* nb_inplace_or */ - (binaryfunc)0, /* nb_floor_divide */ - (binaryfunc)Term_div, /* nb_true_divide */ - 0, /* nb_inplace_floor_divide */ - 0, /* nb_inplace_true_divide */ -#if PY_VERSION_HEX >= 0x02050000 - (unaryfunc)0, /* nb_index */ -#endif -#if PY_VERSION_HEX >= 0x03050000 - (binaryfunc)0, /* nb_matrix_multiply */ - (binaryfunc)0, /* nb_inplace_matrix_multiply */ -#endif +static PyType_Slot Term_Type_slots[] = { + { Py_tp_dealloc, void_cast( Term_dealloc ) }, /* tp_dealloc */ + { Py_tp_traverse, void_cast( Term_traverse ) }, /* tp_traverse */ + { Py_tp_clear, void_cast( Term_clear ) }, /* tp_clear */ + { Py_tp_repr, void_cast( Term_repr ) }, /* tp_repr */ + { Py_tp_richcompare, void_cast( Term_richcmp ) }, /* tp_richcompare */ + { Py_tp_methods, void_cast( Term_methods ) }, /* tp_methods */ + { Py_tp_new, void_cast( Term_new ) }, /* tp_new */ + { Py_tp_alloc, void_cast( PyType_GenericAlloc ) }, /* tp_alloc */ + { Py_tp_free, void_cast( PyObject_GC_Del ) }, /* tp_free */ + { Py_nb_add, void_cast( Term_add ) }, /* nb_add */ + { Py_nb_subtract, void_cast( Term_sub ) }, /* nb_subatract */ + { Py_nb_multiply, void_cast( Term_mul ) }, /* nb_multiply */ + { Py_nb_negative, void_cast( Term_neg ) }, /* nb_negative */ + { Py_nb_true_divide, void_cast( Term_div ) }, /* nb_true_divide */ + { 0, 0 }, }; -PyTypeObject Term_Type = { - PyVarObject_HEAD_INIT( &PyType_Type, 0 ) - "kiwisolver.Term", /* tp_name */ - sizeof( Term ), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Term_dealloc, /* tp_dealloc */ - (printfunc)0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX >= 0x03050000 - ( PyAsyncMethods* )0, /* tp_as_async */ -#elif PY_VERSION_HEX >= 0x03000000 - ( void* ) 0, /* tp_reserved */ -#else - ( cmpfunc )0, /* tp_compare */ -#endif - (reprfunc)Term_repr, /* tp_repr */ - (PyNumberMethods*)&Term_as_number, /* tp_as_number */ - (PySequenceMethods*)0, /* tp_as_sequence */ - (PyMappingMethods*)0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)0, /* tp_setattro */ - (PyBufferProcs*)0, /* tp_as_buffer */ -#if PY_MAJOR_VERSION >= 3 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE, /* tp_flags */ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /* tp_flags */ -#endif - 0, /* Documentation string */ - (traverseproc)Term_traverse, /* tp_traverse */ - (inquiry)Term_clear, /* tp_clear */ - (richcmpfunc)Term_richcmp, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)0, /* tp_iter */ - (iternextfunc)0, /* tp_iternext */ - (struct PyMethodDef*)Term_methods, /* tp_methods */ - (struct PyMemberDef*)0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - (descrgetfunc)0, /* tp_descr_get */ - (descrsetfunc)0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)0, /* tp_init */ - (allocfunc)PyType_GenericAlloc, /* tp_alloc */ - (newfunc)Term_new, /* tp_new */ - (freefunc)PyObject_GC_Del, /* tp_free */ - (inquiry)0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ - (destructor)0 /* tp_del */ +} // namespace + + +// Initialize static variables (otherwise the compiler eliminates them) +PyTypeObject* Term::TypeObject = NULL; + + +PyType_Spec Term::TypeObject_Spec = { + "kiwisolver.Term", /* tp_name */ + sizeof( Term ), /* tp_basicsize */ + 0, /* tp_itemsize */ + Py_TPFLAGS_DEFAULT| + Py_TPFLAGS_HAVE_GC| + Py_TPFLAGS_BASETYPE, /* tp_flags */ + Term_Type_slots /* slots */ }; -int import_term() +bool Term::Ready() { - return PyType_Ready( &Term_Type ); + // The reference will be handled by the module to which we will add the type + TypeObject = pytype_cast( PyType_FromSpec( &TypeObject_Spec ) ); + if( !TypeObject ) + { + return false; + } + return true; } + +} // namespace kiwisolver diff --git a/contrib/python/kiwisolver/py3/py/types.h b/contrib/python/kiwisolver/py3/py/types.h index 628efafbca..afd5b8d79e 100644 --- a/contrib/python/kiwisolver/py3/py/types.h +++ b/contrib/python/kiwisolver/py3/py/types.h @@ -1,39 +1,17 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <Python.h> #include <kiwi/kiwi.h> -int import_variable(); - -int import_term(); - -int import_expression(); - -int import_constraint(); - -int import_solver(); - -int import_strength(); - - -extern PyTypeObject Variable_Type; - -extern PyTypeObject Term_Type; - -extern PyTypeObject Expression_Type; - -extern PyTypeObject Constraint_Type; - -extern PyTypeObject Solver_Type; - -extern PyTypeObject strength_Type; +namespace kiwisolver +{ extern PyObject* DuplicateConstraint; @@ -48,15 +26,33 @@ extern PyObject* UnknownEditVariable; extern PyObject* BadRequiredStrength; +struct strength +{ + PyObject_HEAD; + + static PyType_Spec TypeObject_Spec; + + static PyTypeObject* TypeObject; + + static bool Ready(); +}; + + struct Variable { PyObject_HEAD PyObject* context; kiwi::Variable variable; + static PyType_Spec TypeObject_Spec; + + static PyTypeObject* TypeObject; + + static bool Ready(); + static bool TypeCheck( PyObject* obj ) { - return PyObject_TypeCheck( obj, &Variable_Type ) != 0; + return PyObject_TypeCheck( obj, TypeObject ) != 0; } }; @@ -67,9 +63,15 @@ struct Term PyObject* variable; double coefficient; + static PyType_Spec TypeObject_Spec; + + static PyTypeObject* TypeObject; + + static bool Ready(); + static bool TypeCheck( PyObject* obj ) { - return PyObject_TypeCheck( obj, &Term_Type ) != 0; + return PyObject_TypeCheck( obj, TypeObject ) != 0; } }; @@ -80,9 +82,15 @@ struct Expression PyObject* terms; double constant; + static PyType_Spec TypeObject_Spec; + + static PyTypeObject* TypeObject; + + static bool Ready(); + static bool TypeCheck( PyObject* obj ) { - return PyObject_TypeCheck( obj, &Expression_Type ) != 0; + return PyObject_TypeCheck( obj, TypeObject ) != 0; } }; @@ -93,9 +101,15 @@ struct Constraint PyObject* expression; kiwi::Constraint constraint; + static PyType_Spec TypeObject_Spec; + + static PyTypeObject* TypeObject; + + static bool Ready(); + static bool TypeCheck( PyObject* obj ) { - return PyObject_TypeCheck( obj, &Constraint_Type ) != 0; + return PyObject_TypeCheck( obj, TypeObject ) != 0; } }; @@ -105,8 +119,20 @@ struct Solver PyObject_HEAD kiwi::Solver solver; + static PyType_Spec TypeObject_Spec; + + static PyTypeObject* TypeObject; + + static bool Ready(); + static bool TypeCheck( PyObject* obj ) { - return PyObject_TypeCheck( obj, &Solver_Type ) != 0; + return PyObject_TypeCheck( obj, TypeObject ) != 0; } }; + + +bool init_exceptions(); + + +} // namespace kiwisolver diff --git a/contrib/python/kiwisolver/py3/py/util.h b/contrib/python/kiwisolver/py3/py/util.h index 78e9cbd0b8..4b00fa76e6 100644 --- a/contrib/python/kiwisolver/py3/py/util.h +++ b/contrib/python/kiwisolver/py3/py/util.h @@ -1,19 +1,21 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ #pragma once #include <map> #include <string> -#include <Python.h> +#include <cppy/cppy.h> #include <kiwi/kiwi.h> -#include "pythonhelpers.h" #include "types.h" +namespace kiwisolver +{ + inline bool convert_to_double( PyObject* obj, double& out ) { @@ -22,13 +24,6 @@ convert_to_double( PyObject* obj, double& out ) out = PyFloat_AS_DOUBLE( obj ); return true; } -#if PY_MAJOR_VERSION < 3 - if( PyInt_Check( obj ) ) - { - out = double( PyInt_AsLong( obj ) ); - return true; - } -#endif if( PyLong_Check( obj ) ) { out = PyLong_AsDouble( obj ); @@ -36,7 +31,7 @@ convert_to_double( PyObject* obj, double& out ) return false; return true; } - PythonHelpers::py_expected_type_fail( obj, "float, int, or long" ); + cppy::type_error( obj, "float, int, or long" ); return false; } @@ -44,19 +39,7 @@ convert_to_double( PyObject* obj, double& out ) inline bool convert_pystr_to_str( PyObject* value, std::string& out ) { -#if PY_MAJOR_VERSION >= 3 out = PyUnicode_AsUTF8( value ); -#else - if( PyUnicode_Check( value ) ) - { - PythonHelpers::PyObjectPtr py_str( PyUnicode_AsUTF8String( value ) ); - if( !py_str ) - return false; // LCOV_EXCL_LINE - out = PyString_AS_STRING( py_str.get() ); - } - else - out = PyString_AS_STRING( value ); -#endif return true; } @@ -64,13 +47,8 @@ convert_pystr_to_str( PyObject* value, std::string& out ) inline bool convert_to_strength( PyObject* value, double& out ) { -#if PY_MAJOR_VERSION >= 3 if( PyUnicode_Check( value ) ) { -#else - if( PyString_Check( value ) | PyUnicode_Check( value )) - { -#endif std::string str; if( !convert_pystr_to_str( value, str ) ) return false; @@ -103,19 +81,11 @@ convert_to_strength( PyObject* value, double& out ) inline bool convert_to_relational_op( PyObject* value, kiwi::RelationalOperator& out ) { -#if PY_MAJOR_VERSION >= 3 if( !PyUnicode_Check( value ) ) { - PythonHelpers::py_expected_type_fail( value, "unicode" ); + cppy::type_error( value, "str" ); return false; } -#else - if( !(PyString_Check( value ) | PyUnicode_Check( value ) ) ) - { - PythonHelpers::py_expected_type_fail( value, "str or unicode" ); - return false; - } -#endif std::string str; if( !convert_pystr_to_str( value, str ) ) return false; @@ -142,7 +112,7 @@ inline PyObject* make_terms( const std::map<PyObject*, double>& coeffs ) { typedef std::map<PyObject*, double>::const_iterator iter_t; - PythonHelpers::PyObjectPtr terms( PyTuple_New( coeffs.size() ) ); + cppy::ptr terms( PyTuple_New( coeffs.size() ) ); if( !terms ) return 0; Py_ssize_t size = PyTuple_GET_SIZE( terms.get() ); @@ -153,11 +123,11 @@ make_terms( const std::map<PyObject*, double>& coeffs ) iter_t end = coeffs.end(); for( ; it != end; ++it, ++i ) { - PyObject* pyterm = PyType_GenericNew( &Term_Type, 0, 0 ); + PyObject* pyterm = PyType_GenericNew( Term::TypeObject, 0, 0 ); if( !pyterm ) return 0; Term* term = reinterpret_cast<Term*>( pyterm ); - term->variable = PythonHelpers::newref( it->first ); + term->variable = cppy::incref( it->first ); term->coefficient = it->second; PyTuple_SET_ITEM( terms.get(), i, pyterm ); } @@ -177,10 +147,10 @@ reduce_expression( PyObject* pyexpr ) // pyexpr must be an Expression Term* term = reinterpret_cast<Term*>( item ); coeffs[ term->variable ] += term->coefficient; } - PythonHelpers::PyObjectPtr terms( make_terms( coeffs ) ); + cppy::ptr terms( make_terms( coeffs ) ); if( !terms ) return 0; - PyObject* pynewexpr = PyType_GenericNew( &Expression_Type, 0, 0 ); + PyObject* pynewexpr = PyType_GenericNew( Expression::TypeObject, 0, 0 ); if( !pynewexpr ) return 0; Expression* newexpr = reinterpret_cast<Expression*>( pynewexpr ); @@ -228,3 +198,6 @@ pyop_str( int op ) return ""; } } + + +} // namespace kiwisolver diff --git a/contrib/python/kiwisolver/py3/py/variable.cpp b/contrib/python/kiwisolver/py3/py/variable.cpp index a622e8529a..1a9c69f8f6 100644 --- a/contrib/python/kiwisolver/py3/py/variable.cpp +++ b/contrib/python/kiwisolver/py3/py/variable.cpp @@ -1,22 +1,26 @@ /*----------------------------------------------------------------------------- -| Copyright (c) 2013-2017, Nucleic Development Team. +| Copyright (c) 2013-2019, Nucleic Development Team. | | Distributed under the terms of the Modified BSD License. | -| The full license is in the file COPYING.txt, distributed with this software. +| The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ -#include <Python.h> +#include <cppy/cppy.h> #include <kiwi/kiwi.h> -#include "pythonhelpers.h" #include "symbolics.h" #include "types.h" #include "util.h" -using namespace PythonHelpers; +namespace kiwisolver +{ + + +namespace +{ -static PyObject* +PyObject* Variable_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) { static const char *kwlist[] = { "name", "context", 0 }; @@ -28,24 +32,17 @@ Variable_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) &name, &context ) ) return 0; - PyObjectPtr pyvar( PyType_GenericNew( type, args, kwargs ) ); + cppy::ptr pyvar( PyType_GenericNew( type, args, kwargs ) ); if( !pyvar ) return 0; Variable* self = reinterpret_cast<Variable*>( pyvar.get() ); - self->context = xnewref( context ); + self->context = cppy::xincref( context ); if( name != 0 ) { -#if PY_MAJOR_VERSION >= 3 if( !PyUnicode_Check( name ) ) - return py_expected_type_fail( name, "unicode" ); -#else - if( !( PyString_Check( name ) | PyUnicode_Check( name ) ) ) - { - return py_expected_type_fail( name, "str or unicode" ); - } -#endif + return cppy::type_error( name, "str" ); std::string c_name; if( !convert_pystr_to_str(name, c_name) ) return 0; // LCOV_EXCL_LINE @@ -60,14 +57,14 @@ Variable_new( PyTypeObject* type, PyObject* args, PyObject* kwargs ) } -static void +void Variable_clear( Variable* self ) { Py_CLEAR( self->context ); } -static int +int Variable_traverse( Variable* self, visitproc visit, void* arg ) { Py_VISIT( self->context ); @@ -75,7 +72,7 @@ Variable_traverse( Variable* self, visitproc visit, void* arg ) } -static void +void Variable_dealloc( Variable* self ) { PyObject_GC_UnTrack( self ); @@ -85,32 +82,25 @@ Variable_dealloc( Variable* self ) } -static PyObject* +PyObject* Variable_repr( Variable* self ) { - return FROM_STRING( self->variable.name().c_str() ); + return PyUnicode_FromString( self->variable.name().c_str() ); } -static PyObject* +PyObject* Variable_name( Variable* self ) { - return FROM_STRING( self->variable.name().c_str() ); + return PyUnicode_FromString( self->variable.name().c_str() ); } -static PyObject* +PyObject* Variable_setName( Variable* self, PyObject* pystr ) { -#if PY_MAJOR_VERSION >= 3 if( !PyUnicode_Check( pystr ) ) - return py_expected_type_fail( pystr, "unicode" ); -#else - if( !(PyString_Check( pystr ) | PyUnicode_Check( pystr ) ) ) - { - return py_expected_type_fail( pystr, "str or unicode" ); - } -#endif + return cppy::type_error( pystr, "str" ); std::string str; if( !convert_pystr_to_str( pystr, str ) ) return 0; @@ -119,71 +109,71 @@ Variable_setName( Variable* self, PyObject* pystr ) } -static PyObject* +PyObject* Variable_context( Variable* self ) { if( self->context ) - return newref( self->context ); + return cppy::incref( self->context ); Py_RETURN_NONE; } -static PyObject* +PyObject* Variable_setContext( Variable* self, PyObject* value ) { if( value != self->context ) { PyObject* temp = self->context; - self->context = newref( value ); + self->context = cppy::incref( value ); Py_XDECREF( temp ); } Py_RETURN_NONE; } -static PyObject* +PyObject* Variable_value( Variable* self ) { return PyFloat_FromDouble( self->variable.value() ); } -static PyObject* +PyObject* Variable_add( PyObject* first, PyObject* second ) { return BinaryInvoke<BinaryAdd, Variable>()( first, second ); } -static PyObject* +PyObject* Variable_sub( PyObject* first, PyObject* second ) { return BinaryInvoke<BinarySub, Variable>()( first, second ); } -static PyObject* +PyObject* Variable_mul( PyObject* first, PyObject* second ) { return BinaryInvoke<BinaryMul, Variable>()( first, second ); } -static PyObject* +PyObject* Variable_div( PyObject* first, PyObject* second ) { return BinaryInvoke<BinaryDiv, Variable>()( first, second ); } -static PyObject* +PyObject* Variable_neg( PyObject* value ) { return UnaryInvoke<UnaryNeg, Variable>()( value ); } -static PyObject* +PyObject* Variable_richcmp( PyObject* first, PyObject* second, int op ) { switch( op ) @@ -225,129 +215,52 @@ Variable_methods[] = { }; -static PyNumberMethods -Variable_as_number = { - (binaryfunc)Variable_add, /* nb_add */ - (binaryfunc)Variable_sub, /* nb_subtract */ - (binaryfunc)Variable_mul, /* nb_multiply */ -#if PY_MAJOR_VERSION < 3 - (binaryfunc)Variable_div, /* nb_divide */ -#endif - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - (unaryfunc)Variable_neg, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ -#if PY_MAJOR_VERSION >= 3 - 0, /* nb_bool */ -#else - 0, /* nb_nonzero */ -#endif - 0, /* nb_invert */ - 0, /* nb_lshift */ - 0, /* nb_rshift */ - 0, /* nb_and */ - 0, /* nb_xor */ - (binaryfunc)0, /* nb_or */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_coerce */ -#endif - 0, /* nb_int */ - 0, /* nb_long */ - 0, /* nb_float */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_oct */ - 0, /* nb_hex */ -#endif - 0, /* nb_inplace_add */ - 0, /* nb_inplace_subtract */ - 0, /* nb_inplace_multiply */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_inplace_divide */ -#endif - 0, /* nb_inplace_remainder */ - 0, /* nb_inplace_power */ - 0, /* nb_inplace_lshift */ - 0, /* nb_inplace_rshift */ - 0, /* nb_inplace_and */ - 0, /* nb_inplace_xor */ - 0, /* nb_inplace_or */ - (binaryfunc)0, /* nb_floor_divide */ - (binaryfunc)Variable_div, /* nb_true_divide */ - 0, /* nb_inplace_floor_divide */ - 0, /* nb_inplace_true_divide */ -#if PY_VERSION_HEX >= 0x02050000 - (unaryfunc)0, /* nb_index */ -#endif -#if PY_VERSION_HEX >= 0x03050000 - (binaryfunc)0, /* nb_matrix_multiply */ - (binaryfunc)0, /* nb_inplace_matrix_multiply */ -#endif +static PyType_Slot Variable_Type_slots[] = { + { Py_tp_dealloc, void_cast( Variable_dealloc ) }, /* tp_dealloc */ + { Py_tp_traverse, void_cast( Variable_traverse ) }, /* tp_traverse */ + { Py_tp_clear, void_cast( Variable_clear ) }, /* tp_clear */ + { Py_tp_repr, void_cast( Variable_repr ) }, /* tp_repr */ + { Py_tp_richcompare, void_cast( Variable_richcmp ) }, /* tp_richcompare */ + { Py_tp_methods, void_cast( Variable_methods ) }, /* tp_methods */ + { Py_tp_new, void_cast( Variable_new ) }, /* tp_new */ + { Py_tp_alloc, void_cast( PyType_GenericAlloc ) }, /* tp_alloc */ + { Py_tp_free, void_cast( PyObject_GC_Del ) }, /* tp_free */ + { Py_nb_add, void_cast( Variable_add ) }, /* nb_add */ + { Py_nb_subtract, void_cast( Variable_sub ) }, /* nb_subtract */ + { Py_nb_multiply, void_cast( Variable_mul ) }, /* nb_multiply */ + { Py_nb_negative, void_cast( Variable_neg ) }, /* nb_negative */ + { Py_nb_true_divide, void_cast( Variable_div ) }, /* nb_true_divide */ + { 0, 0 }, }; -PyTypeObject Variable_Type = { - PyVarObject_HEAD_INIT( &PyType_Type, 0 ) - "kiwisolver.Variable", /* tp_name */ - sizeof( Variable ), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Variable_dealloc, /* tp_dealloc */ - (printfunc)0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX >= 0x03050000 - ( PyAsyncMethods* )0, /* tp_as_async */ -#elif PY_VERSION_HEX >= 0x03000000 - ( void* ) 0, /* tp_reserved */ -#else - ( cmpfunc )0, /* tp_compare */ -#endif - (reprfunc)Variable_repr, /* tp_repr */ - (PyNumberMethods*)&Variable_as_number, /* tp_as_number */ - (PySequenceMethods*)0, /* tp_as_sequence */ - (PyMappingMethods*)0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)0, /* tp_str */ - (getattrofunc)0, /* tp_getattro */ - (setattrofunc)0, /* tp_setattro */ - (PyBufferProcs*)0, /* tp_as_buffer */ -#if PY_MAJOR_VERSION >= 3 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE, /* tp_flags */ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /* tp_flags */ -#endif - 0, /* Documentation string */ - (traverseproc)Variable_traverse, /* tp_traverse */ - (inquiry)Variable_clear, /* tp_clear */ - (richcmpfunc)Variable_richcmp, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)0, /* tp_iter */ - (iternextfunc)0, /* tp_iternext */ - (struct PyMethodDef*)Variable_methods, /* tp_methods */ - (struct PyMemberDef*)0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - (descrgetfunc)0, /* tp_descr_get */ - (descrsetfunc)0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)0, /* tp_init */ - (allocfunc)PyType_GenericAlloc, /* tp_alloc */ - (newfunc)Variable_new, /* tp_new */ - (freefunc)PyObject_GC_Del, /* tp_free */ - (inquiry)0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ - (destructor)0 /* tp_del */ +} // namespace + + +// Initialize static variables (otherwise the compiler eliminates them) +PyTypeObject* Variable::TypeObject = NULL; + + +PyType_Spec Variable::TypeObject_Spec = { + "kiwisolver.Variable", /* tp_name */ + sizeof( Variable ), /* tp_basicsize */ + 0, /* tp_itemsize */ + Py_TPFLAGS_DEFAULT| + Py_TPFLAGS_HAVE_GC| + Py_TPFLAGS_BASETYPE, /* tp_flags */ + Variable_Type_slots /* slots */ }; -int import_variable() +bool Variable::Ready() { - return PyType_Ready( &Variable_Type ); + // The reference will be handled by the module to which we will add the type + TypeObject = pytype_cast( PyType_FromSpec( &TypeObject_Spec ) ); + if( !TypeObject ) + { + return false; + } + return true; } + +} // namespace kiwisolver diff --git a/contrib/python/kiwisolver/py3/ya.make b/contrib/python/kiwisolver/py3/ya.make index b98f8485dc..3ba8053ef6 100644 --- a/contrib/python/kiwisolver/py3/ya.make +++ b/contrib/python/kiwisolver/py3/ya.make @@ -2,15 +2,16 @@ PY3_LIBRARY() -VERSION(1.1.0) +VERSION(1.2.0) LICENSE(BSD-3-Clause) PEERDIR( - contrib/python/setuptools + contrib/python/cppy ) ADDINCL( + contrib/python/cppy/cppy/include contrib/python/kiwisolver/py3 ) |