Skip to content

Commit 88daf87

Browse files
author
Kasper Peeters
committed
Merge branch 'master' of git:cadabra2
2 parents c6de10a + b6d3279 commit 88daf87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1241
-365
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
2-
set(CADABRA_CMAKE_VERSION 3.1)
2+
set(CADABRA_CMAKE_VERSION 3.5)
33

44
# Policy settings for CMake to resolve ambiguities.
55

@@ -332,6 +332,8 @@ else()
332332
set(PYTHON_MOD_SUFFIX "${PYTHON_SOABI}.so")
333333
endif()
334334

335+
message(STATUS "Python module extension ${PYTHON_MOD_SUFFIX}")
336+
335337

336338
#---------------------------------------------------------------------------
337339
# Add subdirectories to project.

client_server/ComputeThread.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ void ComputeThread::try_spawn_server()
203203

204204
char buffer[100];
205205
FILE *f = fdopen(server_stdout, "r");
206-
if(fscanf(f, "%100s", buffer)!=1) {
206+
if(fscanf(f, "%99s", buffer)!=1) {
207207
throw std::logic_error("Failed to read port from server.");
208208
}
209209
port = atoi(buffer);
210-
if(fscanf(f, "%100s", buffer)!=1) {
210+
if(fscanf(f, "%99s", buffer)!=1) {
211211
throw std::logic_error("Failed to read authentication token from server.");
212212
}
213213
authentication_token=std::string(buffer);

cmake/version.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(CADABRA_VERSION_MAJOR 2)
22
set(CADABRA_VERSION_MINOR 4)
3-
set(CADABRA_VERSION_PATCH 3)
4-
set(CADABRA_VERSION_TWEAK 5)
3+
set(CADABRA_VERSION_PATCH 4)
4+
set(CADABRA_VERSION_TWEAK 0)
55
set(COPYRIGHT_YEARS "2001-2023")
66
math(EXPR SYSTEM_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
77
find_program(GIT git PATHS ${GIT_DIR})

config/install_script.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
33

44
#define MyAppName "Cadabra2"
5-
#define MyAppVersion "2.4.3"
5+
#define MyAppVersion "2.4.4"
66
#define MyAppPublisher "Kasper Peeters"
77
#define MyAppURL "https://www.cadabra.science/"
88
#define MyAppExeName "cadabra2-gtk.exe"

core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.1) # Required for various macros
1+
cmake_minimum_required(VERSION ${CADABRA_CMAKE_VERSION}) # Required for various macros
22
project(Cadabra)
33

44

core/packages/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.1)
1+
cmake_minimum_required(VERSION ${CADABRA_CMAKE_VERSION})
22
project(Cadabra)
33

44

libs/pybind11/CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
# All rights reserved. Use of this source code is governed by a
66
# BSD-style license that can be found in the LICENSE file.
77

8-
cmake_minimum_required(VERSION 3.4)
8+
cmake_minimum_required(VERSION 3.5)
99

10-
# The `cmake_minimum_required(VERSION 3.4...3.22)` syntax does not work with
10+
# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
1111
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
1212
# the behavior using the following workaround:
13-
if(${CMAKE_VERSION} VERSION_LESS 3.22)
13+
if(${CMAKE_VERSION} VERSION_LESS 3.26)
1414
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
1515
else()
16-
cmake_policy(VERSION 3.22)
16+
cmake_policy(VERSION 3.26)
1717
endif()
1818

1919
# Avoid infinite recursion if tests include this as a subdirectory
@@ -126,6 +126,7 @@ set(PYBIND11_HEADERS
126126
include/pybind11/complex.h
127127
include/pybind11/options.h
128128
include/pybind11/eigen.h
129+
include/pybind11/eigen/common.h
129130
include/pybind11/eigen/matrix.h
130131
include/pybind11/eigen/tensor.h
131132
include/pybind11/embed.h
@@ -139,7 +140,9 @@ set(PYBIND11_HEADERS
139140
include/pybind11/pytypes.h
140141
include/pybind11/stl.h
141142
include/pybind11/stl_bind.h
142-
include/pybind11/stl/filesystem.h)
143+
include/pybind11/stl/filesystem.h
144+
include/pybind11/type_caster_pyobject_ptr.h
145+
include/pybind11/typing.h)
143146

144147
# Compare with grep and warn if mismatched
145148
if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)

libs/pybind11/include/pybind11/attr.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ struct is_method {
2626
explicit is_method(const handle &c) : class_(c) {}
2727
};
2828

29+
/// Annotation for setters
30+
struct is_setter {};
31+
2932
/// Annotation for operators
3033
struct is_operator {};
3134

@@ -188,8 +191,8 @@ struct argument_record {
188191
struct function_record {
189192
function_record()
190193
: is_constructor(false), is_new_style_constructor(false), is_stateless(false),
191-
is_operator(false), is_method(false), has_args(false), has_kwargs(false),
192-
prepend(false) {}
194+
is_operator(false), is_method(false), is_setter(false), has_args(false),
195+
has_kwargs(false), prepend(false) {}
193196

194197
/// Function name
195198
char *name = nullptr; /* why no C++ strings? They generate heavier code.. */
@@ -230,6 +233,9 @@ struct function_record {
230233
/// True if this is a method
231234
bool is_method : 1;
232235

236+
/// True if this is a setter
237+
bool is_setter : 1;
238+
233239
/// True if the function has a '*args' argument
234240
bool has_args : 1;
235241

@@ -399,7 +405,7 @@ struct process_attribute<doc> : process_attribute_default<doc> {
399405
template <>
400406
struct process_attribute<const char *> : process_attribute_default<const char *> {
401407
static void init(const char *d, function_record *r) { r->doc = const_cast<char *>(d); }
402-
static void init(const char *d, type_record *r) { r->doc = const_cast<char *>(d); }
408+
static void init(const char *d, type_record *r) { r->doc = d; }
403409
};
404410
template <>
405411
struct process_attribute<char *> : process_attribute<const char *> {};
@@ -426,6 +432,12 @@ struct process_attribute<is_method> : process_attribute_default<is_method> {
426432
}
427433
};
428434

435+
/// Process an attribute which indicates that this function is a setter
436+
template <>
437+
struct process_attribute<is_setter> : process_attribute_default<is_setter> {
438+
static void init(const is_setter &, function_record *r) { r->is_setter = true; }
439+
};
440+
429441
/// Process an attribute which indicates the parent scope of a method
430442
template <>
431443
struct process_attribute<scope> : process_attribute_default<scope> {

libs/pybind11/include/pybind11/buffer_info.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ inline std::vector<ssize_t> f_strides(const std::vector<ssize_t> &shape, ssize_t
3737
return strides;
3838
}
3939

40+
template <typename T, typename SFINAE = void>
41+
struct compare_buffer_info;
42+
4043
PYBIND11_NAMESPACE_END(detail)
4144

4245
/// Information record describing a Python buffer object
@@ -150,6 +153,17 @@ struct buffer_info {
150153
Py_buffer *view() const { return m_view; }
151154
Py_buffer *&view() { return m_view; }
152155

156+
/* True if the buffer item type is equivalent to `T`. */
157+
// To define "equivalent" by example:
158+
// `buffer_info::item_type_is_equivalent_to<int>(b)` and
159+
// `buffer_info::item_type_is_equivalent_to<long>(b)` may both be true
160+
// on some platforms, but `int` and `unsigned` will never be equivalent.
161+
// For the ground truth, please inspect `detail::compare_buffer_info<>`.
162+
template <typename T>
163+
bool item_type_is_equivalent_to() const {
164+
return detail::compare_buffer_info<T>::compare(*this);
165+
}
166+
153167
private:
154168
struct private_ctr_tag {};
155169

@@ -170,9 +184,10 @@ struct buffer_info {
170184

171185
PYBIND11_NAMESPACE_BEGIN(detail)
172186

173-
template <typename T, typename SFINAE = void>
187+
template <typename T, typename SFINAE>
174188
struct compare_buffer_info {
175189
static bool compare(const buffer_info &b) {
190+
// NOLINTNEXTLINE(bugprone-sizeof-expression) Needed for `PyObject *`
176191
return b.format == format_descriptor<T>::format() && b.itemsize == (ssize_t) sizeof(T);
177192
}
178193
};

libs/pybind11/include/pybind11/cast.h

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public:
9191
template <typename T_, \
9292
::pybind11::detail::enable_if_t< \
9393
std::is_same<type, ::pybind11::detail::remove_cv_t<T_>>::value, \
94-
int> = 0> \
94+
int> \
95+
= 0> \
9596
static ::pybind11::handle cast( \
9697
T_ *src, ::pybind11::return_value_policy policy, ::pybind11::handle parent) { \
9798
if (!src) \
@@ -897,6 +898,10 @@ struct handle_type_name<float_> {
897898
static constexpr auto name = const_name("float");
898899
};
899900
template <>
901+
struct handle_type_name<function> {
902+
static constexpr auto name = const_name("Callable");
903+
};
904+
template <>
900905
struct handle_type_name<none> {
901906
static constexpr auto name = const_name("None");
902907
};
@@ -963,7 +968,7 @@ struct move_always<
963968
enable_if_t<
964969
all_of<move_is_plain_type<T>,
965970
negation<is_copy_constructible<T>>,
966-
std::is_move_constructible<T>,
971+
is_move_constructible<T>,
967972
std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>::value>>
968973
: std::true_type {};
969974
template <typename T, typename SFINAE = void>
@@ -974,7 +979,7 @@ struct move_if_unreferenced<
974979
enable_if_t<
975980
all_of<move_is_plain_type<T>,
976981
negation<move_always<T>>,
977-
std::is_move_constructible<T>,
982+
is_move_constructible<T>,
978983
std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>::value>>
979984
: std::true_type {};
980985
template <typename T>
@@ -1016,11 +1021,14 @@ type_caster<T, SFINAE> &load_type(type_caster<T, SFINAE> &conv, const handle &ha
10161021
"Internal error: type_caster should only be used for C++ types");
10171022
if (!conv.load(handle, true)) {
10181023
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1019-
throw cast_error("Unable to cast Python instance to C++ type (#define "
1020-
"PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1024+
throw cast_error(
1025+
"Unable to cast Python instance of type "
1026+
+ str(type::handle_of(handle)).cast<std::string>()
1027+
+ " to C++ type '?' (#define "
1028+
"PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
10211029
#else
10221030
throw cast_error("Unable to cast Python instance of type "
1023-
+ (std::string) str(type::handle_of(handle)) + " to C++ type '"
1031+
+ str(type::handle_of(handle)).cast<std::string>() + " to C++ type '"
10241032
+ type_id<T>() + "'");
10251033
#endif
10261034
}
@@ -1037,7 +1045,11 @@ make_caster<T> load_type(const handle &handle) {
10371045
PYBIND11_NAMESPACE_END(detail)
10381046

10391047
// pytype -> C++ type
1040-
template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0>
1048+
template <typename T,
1049+
detail::enable_if_t<!detail::is_pyobject<T>::value
1050+
&& !detail::is_same_ignoring_cvref<T, PyObject *>::value,
1051+
int>
1052+
= 0>
10411053
T cast(const handle &handle) {
10421054
using namespace detail;
10431055
static_assert(!cast_is_temporary_value_reference<T>::value,
@@ -1051,6 +1063,34 @@ T cast(const handle &handle) {
10511063
return T(reinterpret_borrow<object>(handle));
10521064
}
10531065

1066+
// Note that `cast<PyObject *>(obj)` increments the reference count of `obj`.
1067+
// This is necessary for the case that `obj` is a temporary, and could
1068+
// not possibly be different, given
1069+
// 1. the established convention that the passed `handle` is borrowed, and
1070+
// 2. we don't want to force all generic code using `cast<T>()` to special-case
1071+
// handling of `T` = `PyObject *` (to increment the reference count there).
1072+
// It is the responsibility of the caller to ensure that the reference count
1073+
// is decremented.
1074+
template <typename T,
1075+
typename Handle,
1076+
detail::enable_if_t<detail::is_same_ignoring_cvref<T, PyObject *>::value
1077+
&& detail::is_same_ignoring_cvref<Handle, handle>::value,
1078+
int>
1079+
= 0>
1080+
T cast(Handle &&handle) {
1081+
return handle.inc_ref().ptr();
1082+
}
1083+
// To optimize way an inc_ref/dec_ref cycle:
1084+
template <typename T,
1085+
typename Object,
1086+
detail::enable_if_t<detail::is_same_ignoring_cvref<T, PyObject *>::value
1087+
&& detail::is_same_ignoring_cvref<Object, object>::value,
1088+
int>
1089+
= 0>
1090+
T cast(Object &&obj) {
1091+
return obj.release().ptr();
1092+
}
1093+
10541094
// C++ type -> py::object
10551095
template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0>
10561096
object cast(T &&value,
@@ -1084,12 +1124,13 @@ detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
10841124
if (obj.ref_count() > 1) {
10851125
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
10861126
throw cast_error(
1087-
"Unable to cast Python instance to C++ rvalue: instance has multiple references"
1088-
" (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1127+
"Unable to cast Python " + str(type::handle_of(obj)).cast<std::string>()
1128+
+ " instance to C++ rvalue: instance has multiple references"
1129+
" (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
10891130
#else
1090-
throw cast_error("Unable to move from Python " + (std::string) str(type::handle_of(obj))
1091-
+ " instance to C++ " + type_id<T>()
1092-
+ " instance: instance has multiple references");
1131+
throw cast_error("Unable to move from Python "
1132+
+ str(type::handle_of(obj)).cast<std::string>() + " instance to C++ "
1133+
+ type_id<T>() + " instance: instance has multiple references");
10931134
#endif
10941135
}
10951136

@@ -1194,9 +1235,10 @@ PYBIND11_NAMESPACE_END(detail)
11941235
// The overloads could coexist, i.e. the #if is not strictly speaking needed,
11951236
// but it is an easy minor optimization.
11961237
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1197-
inline cast_error cast_error_unable_to_convert_call_arg() {
1198-
return cast_error("Unable to convert call argument to Python object (#define "
1199-
"PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1238+
inline cast_error cast_error_unable_to_convert_call_arg(const std::string &name) {
1239+
return cast_error("Unable to convert call argument '" + name
1240+
+ "' to Python object (#define "
1241+
"PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
12001242
}
12011243
#else
12021244
inline cast_error cast_error_unable_to_convert_call_arg(const std::string &name,
@@ -1219,7 +1261,7 @@ tuple make_tuple(Args &&...args_) {
12191261
for (size_t i = 0; i < args.size(); i++) {
12201262
if (!args[i]) {
12211263
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1222-
throw cast_error_unable_to_convert_call_arg();
1264+
throw cast_error_unable_to_convert_call_arg(std::to_string(i));
12231265
#else
12241266
std::array<std::string, size> argtypes{{type_id<Args>()...}};
12251267
throw cast_error_unable_to_convert_call_arg(std::to_string(i), argtypes[i]);
@@ -1339,7 +1381,15 @@ inline namespace literals {
13391381
/** \rst
13401382
String literal version of `arg`
13411383
\endrst */
1342-
constexpr arg operator"" _a(const char *name, size_t) { return arg(name); }
1384+
constexpr arg
1385+
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5
1386+
operator"" _a // gcc 4.8.5 insists on having a space (hard error).
1387+
#else
1388+
operator""_a // clang 17 generates a deprecation warning if there is a space.
1389+
#endif
1390+
(const char *name, size_t) {
1391+
return arg(name);
1392+
}
13431393
} // namespace literals
13441394

13451395
PYBIND11_NAMESPACE_BEGIN(detail)
@@ -1509,7 +1559,7 @@ class unpacking_collector {
15091559
detail::make_caster<T>::cast(std::forward<T>(x), policy, {}));
15101560
if (!o) {
15111561
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1512-
throw cast_error_unable_to_convert_call_arg();
1562+
throw cast_error_unable_to_convert_call_arg(std::to_string(args_list.size()));
15131563
#else
15141564
throw cast_error_unable_to_convert_call_arg(std::to_string(args_list.size()),
15151565
type_id<T>());
@@ -1541,7 +1591,7 @@ class unpacking_collector {
15411591
}
15421592
if (!a.value) {
15431593
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1544-
throw cast_error_unable_to_convert_call_arg();
1594+
throw cast_error_unable_to_convert_call_arg(a.name);
15451595
#else
15461596
throw cast_error_unable_to_convert_call_arg(a.name, a.type);
15471597
#endif

0 commit comments

Comments
 (0)