Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions bindings/pyroot/cppyy/CPyCppyy/src/Converters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
#include <regex>
#include <utility>
#include <sstream>
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
#include <cstddef>
#include <string_view>
#endif

// codecvt does not exist for gcc4.8.5 and is in principle deprecated; it is
// only used in py2 for char -> wchar_t conversion for std::wstring; if not
// available, the conversion is done through Python (requires an extra copy)
Expand Down Expand Up @@ -1777,9 +1776,7 @@ bool CPyCppyy::name##ArrayConverter::ToMemory( \
CPPYY_IMPL_ARRAY_CONVERTER(Bool, c_bool, bool, '?', )
CPPYY_IMPL_ARRAY_CONVERTER(SChar, c_char, signed char, 'b', )
CPPYY_IMPL_ARRAY_CONVERTER(UChar, c_ubyte, unsigned char, 'B', )
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
CPPYY_IMPL_ARRAY_CONVERTER(Byte, c_ubyte, std::byte, 'B', )
#endif
CPPYY_IMPL_ARRAY_CONVERTER(Int8, c_byte, int8_t, 'b', _i8)
CPPYY_IMPL_ARRAY_CONVERTER(Int16, c_int16, int16_t, 'h', _i16)
CPPYY_IMPL_ARRAY_CONVERTER(Int32, c_int32, int32_t, 'i', _i32)
Expand Down Expand Up @@ -2032,7 +2029,6 @@ bool CPyCppyy::STLWStringConverter::ToMemory(PyObject* value, void* address, PyO
}


#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
CPyCppyy::STLStringViewConverter::STLStringViewConverter(bool keepControl) :
InstanceConverter(Cppyy::GetScope("std::string_view"), keepControl) {}

Expand Down Expand Up @@ -2112,7 +2108,6 @@ bool CPyCppyy::STLStringViewConverter::ToMemory(

return false;
}
#endif


bool CPyCppyy::STLStringMoveConverter::SetArg(
Expand Down Expand Up @@ -3563,9 +3558,7 @@ static struct InitConvFactories_t {
gf["SCharAsInt[]"] = gf["signed char ptr"];
gf["UCharAsInt*"] = gf["unsigned char ptr"];
gf["UCharAsInt[]"] = gf["unsigned char ptr"];
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
gf["std::byte ptr"] = (cf_t)+[](cdims_t d) { return new ByteArrayConverter{d}; };
#endif
gf["int8_t ptr"] = (cf_t)+[](cdims_t d) { return new Int8ArrayConverter{d}; };
gf["int16_t ptr"] = (cf_t)+[](cdims_t d) { return new Int16ArrayConverter{d}; };
gf["int32_t ptr"] = (cf_t)+[](cdims_t d) { return new Int32ArrayConverter{d}; };
Expand All @@ -3590,14 +3583,12 @@ static struct InitConvFactories_t {
// aliases
gf["signed char"] = gf["char"];
gf["const signed char&"] = gf["const char&"];
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
gf["std::byte"] = gf["uint8_t"];
gf["byte"] = gf["uint8_t"];
gf["const std::byte&"] = gf["const uint8_t&"];
gf["const byte&"] = gf["const uint8_t&"];
gf["std::byte&"] = gf["uint8_t&"];
gf["byte&"] = gf["uint8_t&"];
#endif
gf["std::int8_t"] = gf["int8_t"];
gf["const std::int8_t&"] = gf["const int8_t&"];
gf["std::int8_t&"] = gf["int8_t&"];
Expand Down Expand Up @@ -3651,13 +3642,11 @@ static struct InitConvFactories_t {
gf["const string&"] = gf["std::string"];
gf["std::string&&"] = (cf_t)+[](cdims_t) { return new STLStringMoveConverter{}; };
gf["string&&"] = gf["std::string&&"];
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
gf["std::string_view"] = (cf_t)+[](cdims_t) { return new STLStringViewConverter{}; };
gf[STRINGVIEW] = gf["std::string_view"];
gf["std::string_view&"] = gf["std::string_view"];
gf["const std::string_view&"] = gf["std::string_view"];
gf["const " STRINGVIEW "&"] = gf["std::string_view"];
#endif
gf["std::wstring"] = (cf_t)+[](cdims_t) { return new STLWStringConverter{}; };
gf[WSTRING1] = gf["std::wstring"];
gf[WSTRING2] = gf["std::wstring"];
Expand Down
4 changes: 0 additions & 4 deletions bindings/pyroot/cppyy/CPyCppyy/src/DeclareConverters.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ class CString32Converter : public Converter {
CPPYY_DECLARE_ARRAY_CONVERTER(Bool);
CPPYY_DECLARE_ARRAY_CONVERTER(SChar);
CPPYY_DECLARE_ARRAY_CONVERTER(UChar);
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
CPPYY_DECLARE_ARRAY_CONVERTER(Byte);
#endif
CPPYY_DECLARE_ARRAY_CONVERTER(Int8);
CPPYY_DECLARE_ARRAY_CONVERTER(Int16);
CPPYY_DECLARE_ARRAY_CONVERTER(Int32);
Expand Down Expand Up @@ -384,9 +382,7 @@ protected: \

CPPYY_DECLARE_STRING_CONVERTER(STLString, std::string);
CPPYY_DECLARE_STRING_CONVERTER(STLWString, std::wstring);
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
CPPYY_DECLARE_STRING_CONVERTER(STLStringView, std::string_view);
#endif

class STLStringMoveConverter : public STLStringConverter {
public:
Expand Down
4 changes: 0 additions & 4 deletions bindings/pyroot/cppyy/CPyCppyy/src/DeclareExecutors.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#include "Dimensions.h"

// Standard
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
#include <cstddef>
#endif


namespace CPyCppyy {
Expand Down Expand Up @@ -65,9 +63,7 @@ CPPYY_ARRAY_DECL_EXEC(Void);
CPPYY_ARRAY_DECL_EXEC(Bool);
CPPYY_ARRAY_DECL_EXEC(SChar);
CPPYY_ARRAY_DECL_EXEC(UChar);
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
CPPYY_ARRAY_DECL_EXEC(Byte);
#endif
CPPYY_ARRAY_DECL_EXEC(Int8);
CPPYY_ARRAY_DECL_EXEC(UInt8);
CPPYY_ARRAY_DECL_EXEC(Short);
Expand Down
6 changes: 0 additions & 6 deletions bindings/pyroot/cppyy/CPyCppyy/src/Executors.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,7 @@ PyObject* CPyCppyy::name##ArrayExecutor::Execute( \
CPPYY_IMPL_ARRAY_EXEC(Bool, bool, )
CPPYY_IMPL_ARRAY_EXEC(SChar, signed char, )
CPPYY_IMPL_ARRAY_EXEC(UChar, unsigned char, )
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
CPPYY_IMPL_ARRAY_EXEC(Byte, std::byte, )
#endif
CPPYY_IMPL_ARRAY_EXEC(Int8, int8_t, _i8)
CPPYY_IMPL_ARRAY_EXEC(UInt8, uint8_t, _i8)
CPPYY_IMPL_ARRAY_EXEC(Short, short, )
Expand Down Expand Up @@ -1019,12 +1017,10 @@ struct InitExecFactories_t {
gf["bool ptr"] = (ef_t)+[](cdims_t d) { return new BoolArrayExecutor{d}; };
gf["unsigned char ptr"] = (ef_t)+[](cdims_t d) { return new UCharArrayExecutor{d}; };
gf["const unsigned char ptr"] = gf["unsigned char ptr"];
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
gf["std::byte ptr"] = (ef_t)+[](cdims_t d) { return new ByteArrayExecutor{d}; };
gf["const std::byte ptr"] = gf["std::byte ptr"];
gf["byte ptr"] = gf["std::byte ptr"];
gf["const byte ptr"] = gf["std::byte ptr"];
#endif
gf["int8_t ptr"] = (ef_t)+[](cdims_t d) { return new Int8ArrayExecutor{d}; };
gf["uint8_t ptr"] = (ef_t)+[](cdims_t d) { return new UInt8ArrayExecutor{d}; };
gf["short ptr"] = (ef_t)+[](cdims_t d) { return new ShortArrayExecutor{d}; };
Expand All @@ -1046,14 +1042,12 @@ struct InitExecFactories_t {
gf["internal_enum_type_t"] = gf["int"];
gf["internal_enum_type_t&"] = gf["int&"];
gf["internal_enum_type_t ptr"] = gf["int ptr"];
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
gf["std::byte"] = gf["uint8_t"];
gf["byte"] = gf["uint8_t"];
gf["std::byte&"] = gf["uint8_t&"];
gf["byte&"] = gf["uint8_t&"];
gf["const std::byte&"] = gf["const uint8_t&"];
gf["const byte&"] = gf["const uint8_t&"];
#endif
gf["std::int8_t"] = gf["int8_t"];
gf["std::int8_t&"] = gf["int8_t&"];
gf["const std::int8_t&"] = gf["const int8_t&"];
Expand Down
4 changes: 0 additions & 4 deletions bindings/pyroot/cppyy/CPyCppyy/src/LowLevelViews.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1001,10 +1001,8 @@ template<> struct typecode_traits<signed char> {
static constexpr const char* format = "b"; static constexpr const char* name = "SCharAsInt"; };
template<> struct typecode_traits<unsigned char> {
static constexpr const char* format = "B"; static constexpr const char* name = "UCharAsInt"; };
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
template<> struct typecode_traits<std::byte> {
static constexpr const char* format = "B"; static constexpr const char* name = "UCharAsInt"; };
#endif
template<> struct typecode_traits<char*> {
static constexpr const char* format = "b"; static constexpr const char* name = "char*"; };
template<> struct typecode_traits<const char*> {
Expand Down Expand Up @@ -1142,9 +1140,7 @@ PyObject* CPyCppyy::CreateLowLevelView(type** address, cdims_t shape) { \
CPPYY_IMPL_VIEW_CREATOR(bool);
CPPYY_IMPL_VIEW_CREATOR(signed char);
CPPYY_IMPL_VIEW_CREATOR(unsigned char);
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
CPPYY_IMPL_VIEW_CREATOR(std::byte);
#endif
CPPYY_IMPL_VIEW_CREATOR(short);
CPPYY_IMPL_VIEW_CREATOR(unsigned short);
CPPYY_IMPL_VIEW_CREATOR(int);
Expand Down
4 changes: 0 additions & 4 deletions bindings/pyroot/cppyy/CPyCppyy/src/LowLevelViews.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
// Standard
#include <complex>
#include <stddef.h>
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
#include <cstddef>
#endif


namespace CPyCppyy {
Expand Down Expand Up @@ -49,9 +47,7 @@ CPPYY_DECL_VIEW_CREATOR(bool);
CPPYY_DECL_VIEW_CREATOR(char);
CPPYY_DECL_VIEW_CREATOR(signed char);
CPPYY_DECL_VIEW_CREATOR(unsigned char);
#if (__cplusplus > 201402L) || (defined(_MSC_VER) && _MSVC_LANG > 201402L)
CPPYY_DECL_VIEW_CREATOR(std::byte);
#endif
PyObject* CreateLowLevelView_i8(int8_t*, cdims_t shape);
PyObject* CreateLowLevelView_i8(int8_t**, cdims_t shape);
PyObject* CreateLowLevelView_i8(uint8_t*, cdims_t shape);
Expand Down
3 changes: 3 additions & 0 deletions bindings/pyroot/cppyy/CPyCppyy/src/PyStrings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
PyObject* CPyCppyy::PyStrings::gAssign = nullptr;
PyObject* CPyCppyy::PyStrings::gBases = nullptr;
PyObject* CPyCppyy::PyStrings::gBase = nullptr;
PyObject* CPyCppyy::PyStrings::gContains = nullptr;
PyObject* CPyCppyy::PyStrings::gCopy = nullptr;
PyObject* CPyCppyy::PyStrings::gCppBool = nullptr;
PyObject* CPyCppyy::PyStrings::gCppName = nullptr;
Expand Down Expand Up @@ -88,6 +89,7 @@ bool CPyCppyy::CreatePyStrings() {
CPPYY_INITIALIZE_STRING(gAssign, __assign__);
CPPYY_INITIALIZE_STRING(gBases, __bases__);
CPPYY_INITIALIZE_STRING(gBase, __base__);
CPPYY_INITIALIZE_STRING(gContains, contains);
CPPYY_INITIALIZE_STRING(gCopy, copy);
#if PY_VERSION_HEX < 0x03000000
CPPYY_INITIALIZE_STRING(gCppBool, __cpp_nonzero__);
Expand Down Expand Up @@ -171,6 +173,7 @@ PyObject* CPyCppyy::DestroyPyStrings() {
// Remove all cached python strings.
Py_DECREF(PyStrings::gBases); PyStrings::gBases = nullptr;
Py_DECREF(PyStrings::gBase); PyStrings::gBase = nullptr;
Py_DECREF(PyStrings::gContains); PyStrings::gContains = nullptr;
Py_DECREF(PyStrings::gCopy); PyStrings::gCopy = nullptr;
Py_DECREF(PyStrings::gCppBool); PyStrings::gCppBool = nullptr;
Py_DECREF(PyStrings::gCppName); PyStrings::gCppName = nullptr;
Expand Down
1 change: 1 addition & 0 deletions bindings/pyroot/cppyy/CPyCppyy/src/PyStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace PyStrings {
extern PyObject* gAssign;
extern PyObject* gBases;
extern PyObject* gBase;
extern PyObject* gContains;
extern PyObject* gCopy;
extern PyObject* gCppBool;
extern PyObject* gCppName;
Expand Down
18 changes: 17 additions & 1 deletion bindings/pyroot/cppyy/CPyCppyy/src/Pythonize.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ PyObject* MapInit(PyObject* self, PyObject* args, PyObject* /* kwds */)
return nullptr;
}

#if __cplusplus <= 202002L
PyObject* STLContainsWithFind(PyObject* self, PyObject* obj)
{
// Implement python's __contains__ for std::map/std::set
Expand All @@ -924,6 +925,7 @@ PyObject* STLContainsWithFind(PyObject* self, PyObject* obj)

return result;
}
#endif


//- set behavior as primitives ------------------------------------------------
Expand Down Expand Up @@ -1266,6 +1268,7 @@ PyObject* STLStringDecode(CPPInstance* self, PyObject* args, PyObject* kwds)
return PyUnicode_Decode(obj->data(), obj->size(), encoding, errors);
}

#if __cplusplus <= 202302L
PyObject* STLStringContains(CPPInstance* self, PyObject* pyobj)
{
std::string* obj = GetSTLString(self);
Expand All @@ -1282,6 +1285,7 @@ PyObject* STLStringContains(CPPInstance* self, PyObject* pyobj)

Py_RETURN_FALSE;
}
#endif

PyObject* STLStringReplace(CPPInstance* self, PyObject* args, PyObject* /*kwds*/)
{
Expand Down Expand Up @@ -1654,6 +1658,10 @@ bool CPyCppyy::Pythonize(PyObject* pyclass, const std::string& name)
Utility::AddToClass(pyclass, "__len__", "size");
}

if (HasAttrDirect(pyclass, PyStrings::gContains)) {
Utility::AddToClass(pyclass, "__contains__", "contains");
}

if (!IsTemplatedSTLClass(name, "vector") && // vector is dealt with below
!((PyTypeObject*)pyclass)->tp_iter) {
if (HasAttrDirect(pyclass, PyStrings::gBegin) && HasAttrDirect(pyclass, PyStrings::gEnd)) {
Expand Down Expand Up @@ -1885,16 +1893,21 @@ bool CPyCppyy::Pythonize(PyObject* pyclass, const std::string& name)
// constructor that takes python associative collections
Utility::AddToClass(pyclass, "__real_init", "__init__");
Utility::AddToClass(pyclass, "__init__", (PyCFunction)MapInit, METH_VARARGS | METH_KEYWORDS);

#if __cplusplus <= 202002L
// From C++20, std::map and std::unordered_map already implement a contains() method.
Utility::AddToClass(pyclass, "__contains__", (PyCFunction)STLContainsWithFind, METH_O);
#endif
}

else if (IsTemplatedSTLClass(name, "set")) {
// constructor that takes python associative collections
Utility::AddToClass(pyclass, "__real_init", "__init__");
Utility::AddToClass(pyclass, "__init__", (PyCFunction)SetInit, METH_VARARGS | METH_KEYWORDS);

#if __cplusplus <= 202002L
// From C++20, std::set already implements a contains() method.
Utility::AddToClass(pyclass, "__contains__", (PyCFunction)STLContainsWithFind, METH_O);
#endif
}

else if (IsTemplatedSTLClass(name, "pair")) {
Expand Down Expand Up @@ -1922,7 +1935,10 @@ bool CPyCppyy::Pythonize(PyObject* pyclass, const std::string& name)
Utility::AddToClass(pyclass, "__cmp__", (PyCFunction)STLStringCompare, METH_O);
Utility::AddToClass(pyclass, "__eq__", (PyCFunction)STLStringIsEqual, METH_O);
Utility::AddToClass(pyclass, "__ne__", (PyCFunction)STLStringIsNotEqual, METH_O);
#if __cplusplus <= 202302L
// From C++23, std::sting already implements a contains() method.
Utility::AddToClass(pyclass, "__contains__", (PyCFunction)STLStringContains, METH_O);
#endif
Utility::AddToClass(pyclass, "decode", (PyCFunction)STLStringDecode, METH_VARARGS | METH_KEYWORDS);
Utility::AddToClass(pyclass, "__cpp_find", "find");
Utility::AddToClass(pyclass, "find", (PyCFunction)STLStringFind, METH_VARARGS | METH_KEYWORDS);
Expand Down
4 changes: 0 additions & 4 deletions bindings/pyroot/cppyy/cppyy/test/cpp11features.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if __cplusplus >= 201103L

#include "cpp11features.h"


Expand Down Expand Up @@ -57,5 +55,3 @@ void implicit_converion_move(TestMoving2&&) {
// for std::function testing
std::function<int(const FNTestStruct& t)> FNCreateTestStructFunc() { return [](const FNTestStruct& t) { return t.t; }; }
std::function<int(const FunctionNS::FNTestStruct& t)> FunctionNS::FNCreateTestStructFunc() { return [](const FNTestStruct& t) { return t.t; }; }

#endif // c++11 and later
4 changes: 0 additions & 4 deletions bindings/pyroot/cppyy/cppyy/test/cpp11features.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if __cplusplus >= 201103L

#include <functional>
#include <memory>
#include <vector>
Expand Down Expand Up @@ -120,5 +118,3 @@ namespace std {
size_t operator()(const StructWithHash&) const { return 17; }
};
} // namespace std

#endif // c++11 and later
Loading
Loading