From f273558b634fac1022cdcc8fbb9893665d247ca3 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Mon, 2 Mar 2026 14:21:01 +1300 Subject: [PATCH 1/3] New version. --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index 453a6881f..db334406c 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.20260226.0 +0.20260302.0 From f5ddf390f54f3ff41946e15014b58af676496db5 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Mon, 2 Mar 2026 14:51:12 +1300 Subject: [PATCH 2/3] nanobind: upgraded to version 2.12.0. --- extern/nanobind/cmake/nanobind-config.cmake | 7 +- extern/nanobind/docs/api_core.rst | 13 +- extern/nanobind/docs/bazel.rst | 4 +- extern/nanobind/docs/changelog.rst | 33 ++- extern/nanobind/docs/faq.rst | 6 + extern/nanobind/docs/requirements.txt | 2 +- extern/nanobind/docs/why.rst | 5 +- extern/nanobind/include/nanobind/nanobind.h | 8 +- extern/nanobind/include/nanobind/nb_attr.h | 2 +- extern/nanobind/include/nanobind/nb_defs.h | 8 +- extern/nanobind/include/nanobind/nb_func.h | 21 +- extern/nanobind/include/nanobind/nb_lib.h | 5 +- extern/nanobind/include/nanobind/nb_types.h | 6 + extern/nanobind/pyproject.toml | 2 +- extern/nanobind/src/__init__.py | 2 +- extern/nanobind/src/common.cpp | 7 + extern/nanobind/src/nb_abi.h | 2 +- extern/nanobind/src/nb_func.cpp | 3 + extern/nanobind/src/nb_internals.cpp | 206 ++++++++++-------- extern/nanobind/src/nb_internals.h | 26 ++- extern/nanobind/src/nb_ndarray.cpp | 4 +- extern/nanobind/src/nb_static_property.cpp | 2 +- extern/nanobind/src/nb_type.cpp | 7 + extern/nanobind/tests/test_callbacks.cpp | 3 +- extern/nanobind/tests/test_classes.cpp | 13 ++ .../nanobind/tests/test_classes_ext.pyi.ref | 5 + extern/nanobind/tests/test_functions.cpp | 5 +- extern/nanobind/tests/test_functions.py | 7 + .../nanobind/tests/test_functions_ext.pyi.ref | 4 + extern/nanobind/tests/test_stl.cpp | 6 + extern/nanobind/tests/test_stl.py | 7 + extern/nanobind/tests/test_stl_bind_map.cpp | 3 +- extern/nanobind/tests/test_stl_ext.pyi.ref | 2 + 33 files changed, 311 insertions(+), 125 deletions(-) diff --git a/extern/nanobind/cmake/nanobind-config.cmake b/extern/nanobind/cmake/nanobind-config.cmake index 4baa3b7f9..768403572 100644 --- a/extern/nanobind/cmake/nanobind-config.cmake +++ b/extern/nanobind/cmake/nanobind-config.cmake @@ -500,7 +500,7 @@ function(nanobind_sanitizer_preload_env env_var) get_target_property(options ${tgt} ${prop}) if(options) foreach(opt ${options}) - if(opt MATCHES "-fsanitize=([^ ]+)") + if(opt MATCHES "-fsanitize=([^ >]+)") list(APPEND san_flags "${CMAKE_MATCH_1}") endif() endforeach() @@ -508,6 +508,8 @@ function(nanobind_sanitizer_preload_env env_var) endforeach() endforeach() + list(REMOVE_DUPLICATES san_flags) + # Parse sanitizer flags foreach(flag ${san_flags}) string(REPLACE "\"" "" flag "${flag}") @@ -517,6 +519,8 @@ function(nanobind_sanitizer_preload_env env_var) list(APPEND detected_san "asan") elseif(san MATCHES "^(thread|tsan)$") list(APPEND detected_san "tsan") + elseif(san MATCHES "^(realtime)$") + list(APPEND detected_san "rtsan") elseif(san MATCHES "^(undefined|ubsan)$") list(APPEND detected_san "ubsan") endif() @@ -525,7 +529,6 @@ function(nanobind_sanitizer_preload_env env_var) endforeach() if (detected_san) - list(REMOVE_DUPLICATES detected_san) set(libs "") foreach(san ${detected_san}) diff --git a/extern/nanobind/docs/api_core.rst b/extern/nanobind/docs/api_core.rst index 3b1850644..232db2b6a 100644 --- a/extern/nanobind/docs/api_core.rst +++ b/extern/nanobind/docs/api_core.rst @@ -1268,6 +1268,15 @@ Wrapper classes // Now do something ... }); +.. cpp:class:: memoryview: public object + + Wrapper class representing Python ``memoryview`` instances. + + .. cpp:function:: memoryview(handle h) + + Attempt to create a ``memoryview`` Python object from an object. Analogous + to the expression ``memoryview(h)`` in Python. + .. cpp:class:: ellipsis: public object Wrapper class representing a Python ellipsis (``...``) object. @@ -2641,8 +2650,8 @@ Class binding Bind the enumeration of type `T` to the identifier `name` within the scope `scope`. The variable length `extra` parameter can be used to pass - a docstring and other :ref:`enum binding annotations - ` (currently, only :cpp:class:`is_arithmetic` is supported). + a docstring and + :ref:`enum binding annotations `. .. cpp:function:: enum_ &value(const char * name, T value, const char * doc = nullptr) diff --git a/extern/nanobind/docs/bazel.rst b/extern/nanobind/docs/bazel.rst index d820b360e..33467deb8 100644 --- a/extern/nanobind/docs/bazel.rst +++ b/extern/nanobind/docs/bazel.rst @@ -27,8 +27,8 @@ in your MODULE.bazel file: # Place this in your MODULE.bazel file. # The major version of nanobind-bazel is equal to the version # of the internally used nanobind. - # In this case, we are building bindings with nanobind v2.11.0. - bazel_dep(name = "nanobind_bazel", version = "2.11.0") + # In this case, we are building bindings with nanobind v2.12.0. + bazel_dep(name = "nanobind_bazel", version = "2.12.0") To instead use a development version from GitHub, you can declare the dependency as a ``git_override()`` in your MODULE.bazel: diff --git a/extern/nanobind/docs/changelog.rst b/extern/nanobind/docs/changelog.rst index 44bdd8531..6fc09d35d 100644 --- a/extern/nanobind/docs/changelog.rst +++ b/extern/nanobind/docs/changelog.rst @@ -15,6 +15,35 @@ case, both modules must use the same nanobind ABI version, or they will be isolated from each other. Releases that don't explicitly mention an ABI version below inherit that of the preceding release. +Version 2.12.0 (Feb 25, 2025) +----------------------------- + +- Added :cpp:class:`nb::memoryview` that wraps the Python ``memoryview`` type. + (PR `#1291 `__). + +- Made stub generation compatible with the Realtime Sanitizer (RTSan) + from Clang 20. + (PR `#1285 `__). + +- Fixed a use-after-free when calling functions after their module has been + deleted. The internals state is now reference-counted with references held by + modules, functions, and types. This also fixes memory leaks reported in issue + `#957 `__. + (PR `#1287 `__). + +- Fixed two regressions from v2.11.0 related to the implicit ``std::optional`` + :cpp:func:`.none() ` annotation: an off-by-one error that applied + the annotation to the wrong argument for methods, and a missing ``convert`` + flag that silently disabled implicit type conversions. + (issues `#1281 `__, + `#1293 `__, + commits `ed7ab31 + `__, + `1f96278 + `__). + +- ABI version 19. + Version 2.11.0 (Jan 29, 2026) ----------------------------- @@ -92,7 +121,7 @@ Version 2.11.0 (Jan 29, 2026) (PR `#1255 `__). Version 2.10.2 (Dec 10, 2025) ----------------------------- +----------------------------- - Fixes a regression that broke compilation on 32-bit architectures. (PR `#1239 `__). @@ -564,7 +593,7 @@ Version 2.3.0 There is no version 2.3.0 due to a deployment mishap. -- Added casters for `Eigen::Map` types from the `Eigen library +- Added casters for ``Eigen::Map>`` types from the `Eigen library `__. (PR `#782 `_). diff --git a/extern/nanobind/docs/faq.rst b/extern/nanobind/docs/faq.rst index e37c807bf..c6ff01046 100644 --- a/extern/nanobind/docs/faq.rst +++ b/extern/nanobind/docs/faq.rst @@ -369,6 +369,12 @@ build system compatible with another tool that is sufficiently feature-complete, then please file an issue and I am happy to reference it in the documentation. +Is there a way to pass ``JSON`` objects between Python and C++? +------------------------------------------------- +Yes, an unofficial, currently maintained, package supporting that can be found `here +`_. It is based on a similar package for +``pybind11`` called ``pybind11_json``. + Are there tools to generate nanobind bindings automatically? ------------------------------------------------------------ diff --git a/extern/nanobind/docs/requirements.txt b/extern/nanobind/docs/requirements.txt index 601bd4d88..1d37ee928 100644 --- a/extern/nanobind/docs/requirements.txt +++ b/extern/nanobind/docs/requirements.txt @@ -1,5 +1,5 @@ furo sphinx==6.1.3 sphinx-copybutton==0.5.1 -sphinxcontrib-moderncmakedomain==3.25.0 +sphinxcontrib-moderncmakedomain==3.29.0 sphinxcontrib-svg2pdfconverter==1.2.2 diff --git a/extern/nanobind/docs/why.rst b/extern/nanobind/docs/why.rst index 79e955c75..996f2c6e7 100644 --- a/extern/nanobind/docs/why.rst +++ b/extern/nanobind/docs/why.rst @@ -247,7 +247,6 @@ would require a substantial redesign and years of careful work by a team of C++ metaprogramming experts. At the same time, changing anything in pybind11 is extremely hard because of the large number of downstream users and their requirements on API/ABI stability. I personally don't have the time and energy -to fix pybind11 and have moved my focus to this project. The `testimonials -section -` lists +to fix pybind11 and have moved my focus to this project. The `testimonials section +`__ lists the experience of a number of large projects that made the switch. diff --git a/extern/nanobind/include/nanobind/nanobind.h b/extern/nanobind/include/nanobind/nanobind.h index 12807690f..30ed86fc4 100644 --- a/extern/nanobind/include/nanobind/nanobind.h +++ b/extern/nanobind/include/nanobind/nanobind.h @@ -22,10 +22,15 @@ #endif #define NB_VERSION_MAJOR 2 -#define NB_VERSION_MINOR 11 +#define NB_VERSION_MINOR 12 #define NB_VERSION_PATCH 0 #define NB_VERSION_DEV 0 // A value > 0 indicates a development release +// nb_python.h includes Python.h, which according to +// https://docs.python.org/3/c-api/intro.html#include-files, must be included +// before standard headers because it overrides feature test macros +#include "nb_python.h" + // Core C++ headers that nanobind depends on #include #include @@ -39,7 +44,6 @@ // Implementation. The nb_*.h files should only be included through nanobind.h // IWYU pragma: begin_exports -#include "nb_python.h" #include "nb_defs.h" #include "nb_enums.h" #include "nb_traits.h" diff --git a/extern/nanobind/include/nanobind/nb_attr.h b/extern/nanobind/include/nanobind/nb_attr.h index 5ff5b706c..48064b888 100644 --- a/extern/nanobind/include/nanobind/nb_attr.h +++ b/extern/nanobind/include/nanobind/nb_attr.h @@ -328,7 +328,7 @@ NB_INLINE void func_extra_apply(F &f, const arg &a, size_t &index) { flag |= (uint8_t) cast_flags::convert; arg_data &arg = f.args[index]; - arg.flag |= flag; + arg.flag = flag; arg.name = a.name_; arg.signature = a.signature_; arg.value = nullptr; diff --git a/extern/nanobind/include/nanobind/nb_defs.h b/extern/nanobind/include/nanobind/nb_defs.h index d3b50712a..4bde051de 100644 --- a/extern/nanobind/include/nanobind/nb_defs.h +++ b/extern/nanobind/include/nanobind/nb_defs.h @@ -169,8 +169,6 @@ X(const X &) = delete; \ X &operator=(const X &) = delete; -#define NB_MOD_STATE_SIZE (12 * sizeof(PyObject*)) - // Helper macros to ensure macro arguments are expanded before token pasting/stringification #define NB_MODULE_IMPL(name, variable) NB_MODULE_IMPL2(name, variable) #define NB_MODULE_IMPL2(name, variable) \ @@ -196,9 +194,9 @@ NB_MODULE_SLOTS_2 \ }; \ static struct PyModuleDef nanobind_##name##_module = { \ - PyModuleDef_HEAD_INIT, #name, nullptr, NB_MOD_STATE_SIZE, nullptr, \ - nanobind_##name##_slots, nanobind::detail::nb_module_traverse, \ - nanobind::detail::nb_module_clear, nanobind::detail::nb_module_free \ + PyModuleDef_HEAD_INIT, #name, nullptr, 0, nullptr, \ + nanobind_##name##_slots, nullptr, nullptr, \ + nanobind::detail::nb_module_free \ }; \ extern "C" [[maybe_unused]] NB_EXPORT PyObject *PyInit_##name(void); \ extern "C" PyObject *PyInit_##name(void) { \ diff --git a/extern/nanobind/include/nanobind/nb_func.h b/extern/nanobind/include/nanobind/nb_func.h index 5daab0dc2..364f3cdd8 100644 --- a/extern/nanobind/include/nanobind/nb_func.h +++ b/extern/nanobind/include/nanobind/nb_func.h @@ -190,15 +190,14 @@ NB_INLINE PyObject *func_create(Func &&func, Return (*)(Args...), }; // The following temporary record will describe the function in detail - func_data_prelim f; + func_data_prelim f; - // Initialize argument flags. The first branch turns std::optional<> types - // into implicit nb::none() anotations. + // Pre-initialize argument flags with 'convert'. The 'accepts_none' flag + // for std::optional<> args is applied after func_extra_apply (see below). if constexpr (has_arg_defaults) { - size_t i = 0; - ((f.args[i++] = { nullptr, nullptr, nullptr, nullptr, - has_arg_defaults_v ? (uint8_t) cast_flags::accepts_none - : (uint8_t) 0 }), ...); + ((void)(Is < (size_t)is_method_det || + (f.args[Is - is_method_det] = { nullptr, nullptr, nullptr, nullptr, + (uint8_t) cast_flags::convert }, true)), ...); } else if constexpr (nargs_provided > 0) { for (size_t i = 0; i < nargs_provided; ++i) f.args[i].flag = 0; @@ -326,6 +325,14 @@ NB_INLINE PyObject *func_create(Func &&func, Return (*)(Args...), (void) arg_index; + // Apply implicit accepts_none for std::optional<> typed arguments + // after func_extra_apply, so that explicit nb::arg().noconvert() works. + if constexpr (has_arg_defaults) { + ((void)(Is >= (size_t)is_method_det && has_arg_defaults_v && + (f.args[Is - is_method_det].flag |= + (uint8_t) cast_flags::accepts_none, true)), ...); + } + return nb_func_new(&f); } diff --git a/extern/nanobind/include/nanobind/nb_lib.h b/extern/nanobind/include/nanobind/nb_lib.h index 8fd35a1a2..fc3e6d39e 100644 --- a/extern/nanobind/include/nanobind/nb_lib.h +++ b/extern/nanobind/include/nanobind/nb_lib.h @@ -117,8 +117,6 @@ NB_CORE void raise_next_overload_if_null(void *p); // ======================================================================== NB_CORE void nb_module_exec(const char *domain, PyObject *m); -NB_CORE int nb_module_traverse(PyObject *m, visitproc visit, void *arg); -NB_CORE int nb_module_clear(PyObject *m); NB_CORE void nb_module_free(void *m); // ======================================================================== @@ -176,6 +174,9 @@ NB_CORE PyObject *set_from_obj(PyObject *o); /// Convert a Python object into a Python frozenset NB_CORE PyObject *frozenset_from_obj(PyObject *o); +/// Convert a Python object into a Python memoryview +NB_CORE PyObject *memoryview_from_obj(PyObject *o); + // ======================================================================== /// Get an object attribute or raise an exception diff --git a/extern/nanobind/include/nanobind/nb_types.h b/extern/nanobind/include/nanobind/nb_types.h index a0e303ae8..cf487844a 100644 --- a/extern/nanobind/include/nanobind/nb_types.h +++ b/extern/nanobind/include/nanobind/nb_types.h @@ -753,6 +753,12 @@ class slice : public object { } }; +class memoryview : public object { + NB_OBJECT(memoryview, object, "memoryview", PyMemoryView_Check) + explicit memoryview(handle h) + : object(detail::memoryview_from_obj(h.ptr()), detail::steal_t{}) { } +}; + class ellipsis : public object { static bool is_ellipsis(PyObject *obj) { return obj == Py_Ellipsis; } diff --git a/extern/nanobind/pyproject.toml b/extern/nanobind/pyproject.toml index d711cbaf1..4bdf3ba91 100644 --- a/extern/nanobind/pyproject.toml +++ b/extern/nanobind/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build" [project] name = "nanobind" -version = "2.11.0" +version = "2.12.0" description = "nanobind: tiny and efficient C++/Python bindings" readme.content-type = "text/markdown" readme.text = """ diff --git a/extern/nanobind/src/__init__.py b/extern/nanobind/src/__init__.py index 0b2c021e7..b8249f441 100644 --- a/extern/nanobind/src/__init__.py +++ b/extern/nanobind/src/__init__.py @@ -16,7 +16,7 @@ def cmake_dir() -> str: "Return the path to the nanobind CMake module directory." return os.path.join(os.path.abspath(os.path.dirname(__file__)), "cmake") -__version__ = "2.11.0" +__version__ = "2.12.0" __all__ = ( "__version__", diff --git a/extern/nanobind/src/common.cpp b/extern/nanobind/src/common.cpp index 1a33cedcb..f2d3faee9 100644 --- a/extern/nanobind/src/common.cpp +++ b/extern/nanobind/src/common.cpp @@ -673,6 +673,13 @@ PyObject *frozenset_from_obj(PyObject *o) { return result; } +PyObject *memoryview_from_obj(PyObject *o) { + PyObject *result = PyMemoryView_FromObject(o); + if (!result) + raise_python_error(); + return result; +} + // ======================================================================== PyObject **seq_get(PyObject *seq, size_t *size_out, PyObject **temp_out) noexcept { diff --git a/extern/nanobind/src/nb_abi.h b/extern/nanobind/src/nb_abi.h index 8eccefa59..9848915bc 100644 --- a/extern/nanobind/src/nb_abi.h +++ b/extern/nanobind/src/nb_abi.h @@ -14,7 +14,7 @@ /// Tracks the version of nanobind's internal data structures #ifndef NB_INTERNALS_VERSION -# define NB_INTERNALS_VERSION 18 +# define NB_INTERNALS_VERSION 19 #endif #if defined(__MINGW32__) diff --git a/extern/nanobind/src/nb_func.cpp b/extern/nanobind/src/nb_func.cpp index 4d39f3ef5..838a1e313 100644 --- a/extern/nanobind/src/nb_func.cpp +++ b/extern/nanobind/src/nb_func.cpp @@ -121,6 +121,8 @@ void nb_func_dealloc(PyObject *self) { } PyObject_GC_Del(self); + + internals_dec_ref(); } int nb_bound_method_traverse(PyObject *self, visitproc visit, void *arg) { @@ -296,6 +298,7 @@ PyObject *nb_func_new(const func_data_prelim_base *f) noexcept { name_cstr); make_immortal((PyObject *) func); + internals_inc_ref(); // Check if the complex dispatch loop is needed bool complex_call = can_mutate_args || has_var_kwargs || has_var_args || diff --git a/extern/nanobind/src/nb_internals.cpp b/extern/nanobind/src/nb_internals.cpp index 497d4410f..8e756565e 100644 --- a/extern/nanobind/src/nb_internals.cpp +++ b/extern/nanobind/src/nb_internals.cpp @@ -176,58 +176,128 @@ static const char* interned_c_strs[pyobj_name::string_count] { "dl_device", }; -PyObject **static_pyobjects = nullptr; +PyObject *static_pyobjects[pyobj_name::total_count] = {}; -static bool init_pyobjects(PyObject* m) { - PyObject** pyobjects = (PyObject**) PyModule_GetState(m); - if (!pyobjects) - return false; +static void new_constant(nb_internals *p, int index, PyObject *o) { + static_pyobjects[index] = o; + new_object(p, o); +} + +/// Populate this library's static_pyobjects[] +static void init_pyobjects(nb_internals *p) { + if (static_pyobjects[0]) + return; NB_NOUNROLL for (int i = 0; i < pyobj_name::string_count; ++i) - pyobjects[i] = PyUnicode_InternFromString(interned_c_strs[i]); + new_constant(p, i, PyUnicode_InternFromString(interned_c_strs[i])); - pyobjects[pyobj_name::copy_tpl] = - PyTuple_Pack(1, pyobjects[pyobj_name::copy_str]); - pyobjects[pyobj_name::max_version_tpl] = - PyTuple_Pack(1, pyobjects[pyobj_name::max_version_str]); + new_constant(p, pyobj_name::copy_tpl, + PyTuple_Pack(1, static_pyobjects[pyobj_name::copy_str])); + new_constant(p, pyobj_name::max_version_tpl, + PyTuple_Pack(1, static_pyobjects[pyobj_name::max_version_str])); - PyObject* one = PyLong_FromLong(1); - PyObject* zero = PyLong_FromLong(0); - pyobjects[pyobj_name::dl_cpu_tpl] = PyTuple_Pack(2, one, zero); + PyObject *one = PyLong_FromLong(1), *zero = PyLong_FromLong(0); + new_constant(p, pyobj_name::dl_cpu_tpl, PyTuple_Pack(2, one, zero)); Py_DECREF(zero); Py_DECREF(one); - PyObject* major = PyLong_FromLong(dlpack::major_version); - PyObject* minor = PyLong_FromLong(dlpack::minor_version); - pyobjects[pyobj_name::dl_version_tpl] = PyTuple_Pack(2, major, minor); + PyObject *major = PyLong_FromLong(dlpack::major_version), + *minor = PyLong_FromLong(dlpack::minor_version); + new_constant(p, pyobj_name::dl_version_tpl, PyTuple_Pack(2, major, minor)); Py_DECREF(minor); Py_DECREF(major); +} + +/// Create lifeline + internal types if needed +static void init_internals(nb_internals *p) { + if (p->lifeline) + return; + + p->lifeline = PyList_New(0); + check(p->lifeline, "nanobind::detail::nb_module_exec(): " + "could not create lifeline list!"); + + str nb_name("nanobind"); + p->nb_module = PyModule_NewObject(nb_name.ptr()); + new_object(p, p->nb_module); + + nb_meta_slots[0].pfunc = (PyObject *) &PyType_Type; + p->nb_meta = new_type(p, &nb_meta_spec); + + p->nb_type_dict = PyDict_New(); + new_object(p, p->nb_type_dict); + + p->nb_func = new_type(p, &nb_func_spec); + p->nb_method = new_type(p, &nb_method_spec); + p->nb_bound_method = new_type(p, &nb_bound_method_spec); + + check(p->nb_module && p->nb_meta && p->nb_type_dict && p->nb_func && + p->nb_method && p->nb_bound_method, + "nanobind::detail::nb_module_exec(): initialization failed!"); + +#if defined(Py_LIMITED_API) + p->PyType_Type_tp_free = (freefunc) PyType_GetSlot(&PyType_Type, Py_tp_free); + p->PyType_Type_tp_init = (initproc) PyType_GetSlot(&PyType_Type, Py_tp_init); + p->PyType_Type_tp_dealloc = + (destructor) PyType_GetSlot(&PyType_Type, Py_tp_dealloc); + p->PyType_Type_tp_setattro = + (setattrofunc) PyType_GetSlot(&PyType_Type, Py_tp_setattro); + p->PyProperty_Type_tp_descr_get = + (descrgetfunc) PyType_GetSlot(&PyProperty_Type, Py_tp_descr_get); + p->PyProperty_Type_tp_descr_set = + (descrsetfunc) PyType_GetSlot(&PyProperty_Type, Py_tp_descr_set); - static_pyobjects = pyobjects; + PyType_Slot dummy_slots[] = { + { Py_tp_base, &PyType_Type }, + { 0, nullptr } + }; - return true; + PyType_Spec dummy_spec = { + /* .name = */ "nanobind.dummy", + /* .basicsize = */ - (int) sizeof(void*), + /* .itemsize = */ 0, + /* .flags = */ Py_TPFLAGS_DEFAULT, + /* .slots = */ dummy_slots + }; + + PyObject *dummy = PyType_FromMetaclass( + p->nb_meta, p->nb_module, &dummy_spec, nullptr); + p->type_data_offset = + (uint8_t *) PyObject_GetTypeData(dummy, p->nb_meta) - (uint8_t *) dummy; + Py_DECREF(dummy); +#endif } -NB_NOINLINE int nb_module_traverse(PyObject *m, visitproc visit, void *arg) { - PyObject** pyobjects = (PyObject**) PyModule_GetState(m); - NB_NOUNROLL - for (int i = 0; i < pyobj_name::total_count; ++i) - Py_VISIT(pyobjects[i]); - return 0; +void internals_inc_ref() { + internals->shared_ref_count.value++; } -NB_NOINLINE int nb_module_clear(PyObject *m) { - PyObject** pyobjects = (PyObject**) PyModule_GetState(m); - NB_NOUNROLL +void internals_dec_ref() { + nb_internals *p = internals; + auto value = --p->shared_ref_count.value; + if (value != 0) + return; + + Py_CLEAR(p->lifeline); + + p->nb_module = nullptr; + p->nb_meta = nullptr; + p->nb_type_dict = nullptr; + p->nb_func = nullptr; + p->nb_method = nullptr; + p->nb_bound_method = nullptr; + p->nb_static_property.store_release(nullptr); + p->nb_ndarray.store_release(nullptr); + + nb_meta_cache = nullptr; + for (int i = 0; i < pyobj_name::total_count; ++i) - Py_CLEAR(pyobjects[i]); - return 0; + static_pyobjects[i] = nullptr; } -void nb_module_free(void *m) { - // Allow nanobind_##name##_exec to omit calling nb_module_clear on error. - (void) nb_module_clear((PyObject *) m); +void nb_module_free(void *) { + internals_dec_ref(); } @@ -384,12 +454,14 @@ static void internals_cleanup() { #endif } -NB_NOINLINE void nb_module_exec(const char *name, PyObject *m) { - if (internals) +NB_NOINLINE void nb_module_exec(const char *name, PyObject *) { + if (internals) { + init_internals(internals); + init_pyobjects(internals); + nb_meta_cache = internals->nb_meta; + internals_inc_ref(); return; - - check(init_pyobjects(m), "nanobind::detail::nb_module_exec(): " - "could not initialize module state!"); + } #if defined(PYPY_VERSION) PyObject *dict = PyEval_GetBuiltins(); @@ -410,8 +482,13 @@ NB_NOINLINE void nb_module_exec(const char *name, PyObject *m) { internals = (nb_internals *) PyCapsule_GetPointer(capsule, "nb_internals"); check(internals, "nanobind::detail::nb_module_exec(): " "capsule pointer is NULL!"); - nb_meta_cache = internals->nb_meta; is_alive_ptr = internals->is_alive_ptr; + + init_internals(internals); + init_pyobjects(internals); + nb_meta_cache = internals->nb_meta; + internals_inc_ref(); + Py_DECREF(capsule); return; } @@ -429,65 +506,25 @@ NB_NOINLINE void nb_module_exec(const char *name, PyObject *m) { #endif p->shard_count = shard_count; - str nb_name("nanobind"); - p->nb_module = PyModule_NewObject(nb_name.ptr()); + internals = p; - nb_meta_slots[0].pfunc = (PyObject *) &PyType_Type; - nb_meta_cache = p->nb_meta = (PyTypeObject *) PyType_FromSpec(&nb_meta_spec); - p->nb_type_dict = PyDict_New(); - p->nb_func = (PyTypeObject *) PyType_FromSpec(&nb_func_spec); - p->nb_method = (PyTypeObject *) PyType_FromSpec(&nb_method_spec); - p->nb_bound_method = (PyTypeObject *) PyType_FromSpec(&nb_bound_method_spec); + init_internals(p); + init_pyobjects(p); + nb_meta_cache = p->nb_meta; #if defined(NB_FREE_THREADED) p->nb_static_property_disabled = PyThread_tss_alloc(); PyThread_tss_create(p->nb_static_property_disabled); #endif - check(p->nb_module && p->nb_meta && p->nb_type_dict && p->nb_func && - p->nb_method && p->nb_bound_method, - "nanobind::detail::nb_module_exec(): initialization failed!"); - -#if defined(Py_LIMITED_API) - // Cache important functions from PyType_Type and PyProperty_Type - p->PyType_Type_tp_free = (freefunc) PyType_GetSlot(&PyType_Type, Py_tp_free); - p->PyType_Type_tp_init = (initproc) PyType_GetSlot(&PyType_Type, Py_tp_init); - p->PyType_Type_tp_dealloc = - (destructor) PyType_GetSlot(&PyType_Type, Py_tp_dealloc); - p->PyType_Type_tp_setattro = - (setattrofunc) PyType_GetSlot(&PyType_Type, Py_tp_setattro); - p->PyProperty_Type_tp_descr_get = - (descrgetfunc) PyType_GetSlot(&PyProperty_Type, Py_tp_descr_get); - p->PyProperty_Type_tp_descr_set = - (descrsetfunc) PyType_GetSlot(&PyProperty_Type, Py_tp_descr_set); - - PyType_Slot dummy_slots[] = { - { Py_tp_base, &PyType_Type }, - { 0, nullptr } - }; - - PyType_Spec dummy_spec = { - /* .name = */ "nanobind.dummy", - /* .basicsize = */ - (int) sizeof(void*), - /* .itemsize = */ 0, - /* .flags = */ Py_TPFLAGS_DEFAULT, - /* .slots = */ dummy_slots - }; - - // Determine the offset, at which types defined by nanobind begin - PyObject *dummy = PyType_FromMetaclass( - p->nb_meta, p->nb_module, &dummy_spec, nullptr); - p->type_data_offset = - (uint8_t *) PyObject_GetTypeData(dummy, p->nb_meta) - (uint8_t *) dummy; - Py_DECREF(dummy); -#endif - p->translators = { default_exception_translator, nullptr, nullptr }; is_alive_value = true; is_alive_ptr = &is_alive_value; p->is_alive_ptr = is_alive_ptr; + internals_inc_ref(); + #if PY_VERSION_HEX < 0x030C0000 && !defined(PYPY_VERSION) /* The implementation of typing.py on CPython <3.12 tends to introduce spurious reference leaks that upset nanobind's leak checker. The @@ -536,7 +573,6 @@ NB_NOINLINE void nb_module_exec(const char *name, PyObject *m) { "nanobind::detail::nb_module_exec(): capsule creation failed!"); Py_DECREF(capsule); Py_DECREF(key); - internals = p; } #if defined(NB_COMPACT_ASSERTIONS) diff --git a/extern/nanobind/src/nb_internals.h b/extern/nanobind/src/nb_internals.h index a0f45f630..cb15de869 100644 --- a/extern/nanobind/src/nb_internals.h +++ b/extern/nanobind/src/nb_internals.h @@ -426,6 +426,13 @@ struct nb_internals { // Size of the 'shards' data structure. Only rarely accessed, hence at the end size_t shard_count = 1; + + /// Reference count tracking modules + types + functions using shared state + nb_maybe_atomic shared_ref_count = 0; + + /// PyList keeping managed PyObjects alive. Cleared when shared_ref_count + /// reaches 0. + PyObject *lifeline = nullptr; }; // Names for the PyObject* entries in the per-module state array. @@ -450,9 +457,24 @@ struct pyobj_name { }; }; -static_assert(pyobj_name::total_count * sizeof(PyObject*) == NB_MOD_STATE_SIZE); +extern PyObject *static_pyobjects[]; + +extern void internals_inc_ref(); +extern void internals_dec_ref(); -extern PyObject **static_pyobjects; +/// Append 'o' to the lifeline and transfer ownership to it +inline void new_object(nb_internals *p, PyObject *o) { + PyList_Append(p->lifeline, o); + Py_DECREF(o); +} + +/// Create a type via PyType_FromSpec and transfer ownership to the lifeline +inline PyTypeObject *new_type(nb_internals *p, PyType_Spec *spec) { + PyTypeObject *tp = (PyTypeObject *) PyType_FromSpec(spec); + if (tp) + new_object(p, (PyObject *) tp); + return tp; +} /// Convenience macro to potentially access cached functions #if defined(Py_LIMITED_API) diff --git a/extern/nanobind/src/nb_ndarray.cpp b/extern/nanobind/src/nb_ndarray.cpp index 2f6d93a55..9af525302 100644 --- a/extern/nanobind/src/nb_ndarray.cpp +++ b/extern/nanobind/src/nb_ndarray.cpp @@ -271,7 +271,7 @@ static PyObject *nb_ndarray_dlpack(PyObject *self, PyObject *const *args, ndarray_handle *th = ((nb_ndarray *) self)->th; PyObject *capsule; - if (max_major_version >= dlpack::major_version) + if (max_major_version >= (long)dlpack::major_version) capsule = th->make_capsule_versioned(); else capsule = th->make_capsule_unversioned(); @@ -338,7 +338,7 @@ static PyTypeObject *nb_ndarray_tp() noexcept { /* .slots = */ slots }; - tp = (PyTypeObject *) PyType_FromSpec(&spec); + tp = new_type(internals_, &spec); check(tp, "nb_ndarray type creation failed!"); internals_->nb_ndarray.store_release(tp); diff --git a/extern/nanobind/src/nb_static_property.cpp b/extern/nanobind/src/nb_static_property.cpp index 51be66101..a7784c5ad 100644 --- a/extern/nanobind/src/nb_static_property.cpp +++ b/extern/nanobind/src/nb_static_property.cpp @@ -62,7 +62,7 @@ PyTypeObject *nb_static_property_tp() noexcept { /* .slots = */ slots }; - tp = (PyTypeObject *) PyType_FromSpec(&spec); + tp = new_type(internals_, &spec); check(tp, "nb_static_property type creation failed!"); internals_->nb_static_property_descr_set = nb_static_property_descr_set; diff --git a/extern/nanobind/src/nb_type.cpp b/extern/nanobind/src/nb_type.cpp index cf1c8a056..7ae75321d 100644 --- a/extern/nanobind/src/nb_type.cpp +++ b/extern/nanobind/src/nb_type.cpp @@ -437,8 +437,12 @@ static void nb_type_dealloc(PyObject *o) { PyMem_Free(t->implicit.py); } + bool initialized = t->name != nullptr; free((char *) t->name); NB_SLOT(PyType_Type, tp_dealloc)(o); + + if (initialized) + internals_dec_ref(); } /// Called when a C++ type is extended from within Python @@ -493,6 +497,8 @@ static int nb_type_init(PyObject *self, PyObject *args, PyObject *kwds) { ((PyTypeObject *) self)->tp_vectorcall = nullptr; #endif + internals_inc_ref(); + return 0; } @@ -1319,6 +1325,7 @@ PyObject *nb_type_new(const type_init_data *t) noexcept { Py_DECREF(metaclass); make_immortal(result); + internals_inc_ref(); type_data *to = nb_type_data((PyTypeObject *) result); diff --git a/extern/nanobind/tests/test_callbacks.cpp b/extern/nanobind/tests/test_callbacks.cpp index f178baedd..1c71f2d58 100644 --- a/extern/nanobind/tests/test_callbacks.cpp +++ b/extern/nanobind/tests/test_callbacks.cpp @@ -3,11 +3,12 @@ // directly keep a Python object alive (they're trivially copyable), we // maintain a sideband structure to manage the lifetimes. +#include + #include #include #include -#include #include namespace nb = nanobind; diff --git a/extern/nanobind/tests/test_classes.cpp b/extern/nanobind/tests/test_classes.cpp index 51986cf53..6235471ff 100644 --- a/extern/nanobind/tests/test_classes.cpp +++ b/extern/nanobind/tests/test_classes.cpp @@ -60,6 +60,13 @@ struct PairStruct { Struct s2; }; +// Test case for issue #1280 +struct OptionalNoneTest { + int compute(int i, std::optional j, int k) const { + return i + j.value_or(0) + k; + } +}; + struct Big { char data[1024]; Big() { memset(data, 0xff, 1024); } @@ -187,6 +194,12 @@ NB_MODULE(test_classes_ext, m) { .def_rw("s1", &PairStruct::s1, "A documented property") .def_rw("s2", &PairStruct::s2); + // Test case for issue #1280 + nb::class_(m, "OptionalNoneTest") + .def(nb::init<>()) + .def("compute", &OptionalNoneTest::compute, + "i"_a, "j"_a = nb::none(), "k"_a = 0); + m.def("stats", []{ nb::dict d; d["default_constructed"] = default_constructed; diff --git a/extern/nanobind/tests/test_classes_ext.pyi.ref b/extern/nanobind/tests/test_classes_ext.pyi.ref index e816904fc..8abf48140 100644 --- a/extern/nanobind/tests/test_classes_ext.pyi.ref +++ b/extern/nanobind/tests/test_classes_ext.pyi.ref @@ -60,6 +60,11 @@ class PairStruct: @s2.setter def s2(self, arg: Struct, /) -> None: ... +class OptionalNoneTest: + def __init__(self) -> None: ... + + def compute(self, i: int, j: int | None = None, k: int = 0) -> int: ... + def stats() -> dict: ... def reset() -> None: ... diff --git a/extern/nanobind/tests/test_functions.cpp b/extern/nanobind/tests/test_functions.cpp index 3c2010dfc..b38a9e078 100644 --- a/extern/nanobind/tests/test_functions.cpp +++ b/extern/nanobind/tests/test_functions.cpp @@ -1,6 +1,7 @@ +#include + #include -#include #include #include #include @@ -367,6 +368,8 @@ NB_MODULE(test_functions_ext, m) { return s.contains(h); }); + m.def("test_memoryview", []() { return nb::memoryview(nb::bytes("123456")); }); + m.def("test_bad_memview", []() { return nb::memoryview(nb::int_(0)); }); m.def("test_del_list", [](nb::list l) { nb::del(l[2]); }); m.def("test_del_dict", [](nb::dict l) { nb::del(l["a"]); }); diff --git a/extern/nanobind/tests/test_functions.py b/extern/nanobind/tests/test_functions.py index aa779b892..267709907 100644 --- a/extern/nanobind/tests/test_functions.py +++ b/extern/nanobind/tests/test_functions.py @@ -783,3 +783,10 @@ def test53_fallback(): def test54_dict_default(): assert t.test_get_dict_default({'key': 100}) == 100 assert t.test_get_dict_default({'key2': 100}) == 123 + +def test_55_memoryview(): + memview = t.test_memoryview() + assert isinstance(memview, memoryview) + assert bytes(memview[0:3]) == b'123' + with pytest.raises(TypeError): + t.test_bad_memview() diff --git a/extern/nanobind/tests/test_functions_ext.pyi.ref b/extern/nanobind/tests/test_functions_ext.pyi.ref index 8809c5f6c..54659e3ee 100644 --- a/extern/nanobind/tests/test_functions_ext.pyi.ref +++ b/extern/nanobind/tests/test_functions_ext.pyi.ref @@ -187,6 +187,10 @@ def test_frozenset() -> frozenset: ... def test_frozenset_contains(arg0: frozenset, arg1: object, /) -> bool: ... +def test_memoryview() -> memoryview: ... + +def test_bad_memview() -> memoryview: ... + def test_del_list(arg: list, /) -> None: ... def test_del_dict(arg: dict, /) -> None: ... diff --git a/extern/nanobind/tests/test_stl.cpp b/extern/nanobind/tests/test_stl.cpp index 48edaed50..40a92b703 100644 --- a/extern/nanobind/tests/test_stl.cpp +++ b/extern/nanobind/tests/test_stl.cpp @@ -284,6 +284,12 @@ NB_MODULE(test_stl_ext, m) { m.def("optional_unbound_type_with_nullopt_as_default", [](std::optional &x) { return x; }, nb::arg("x") = std::nullopt); m.def("optional_non_assignable", [](std::optional &x) { return x; }); + // Regression test: std::optional<> with lossy implicit conversion on a + // sibling argument and no explicit nb::arg annotations (issue #1293) + m.def("optional_implicit_convert", [](float f, std::optional o) { + return (double) f + o.value_or(0); + }); + // ----- test43-test50 ------ m.def("variant_copyable", [](std::variant &) {}); m.def("variant_copyable_none", [](std::variant &) {}, nb::arg("x").none()); diff --git a/extern/nanobind/tests/test_stl.py b/extern/nanobind/tests/test_stl.py index 9c227e64c..a3f390578 100644 --- a/extern/nanobind/tests/test_stl.py +++ b/extern/nanobind/tests/test_stl.py @@ -388,6 +388,13 @@ def test38_std_optional_none(): assert t.optional_non_assignable(None) == None +def test38b_std_optional_implicit_convert(): + # Regression test: std::optional<> with lossy implicit conversion on a + # sibling argument and no explicit nb::arg annotations (issue #1293) + assert t.optional_implicit_convert(16777217, 10) == 16777216.0 + 10 + assert t.optional_implicit_convert(16777217, None) == 16777216.0 + + def test39_std_optional_ret_opt_movable(clean): assert t.optional_ret_opt_movable().value == 5 opt_movable = optional("test_stl_ext.Movable") diff --git a/extern/nanobind/tests/test_stl_bind_map.cpp b/extern/nanobind/tests/test_stl_bind_map.cpp index 6c933ab9e..09585c2ac 100644 --- a/extern/nanobind/tests/test_stl_bind_map.cpp +++ b/extern/nanobind/tests/test_stl_bind_map.cpp @@ -1,9 +1,10 @@ +#include + #include #include #include #include -#include #include #include diff --git a/extern/nanobind/tests/test_stl_ext.pyi.ref b/extern/nanobind/tests/test_stl_ext.pyi.ref index eb197bf1e..3db01917c 100644 --- a/extern/nanobind/tests/test_stl_ext.pyi.ref +++ b/extern/nanobind/tests/test_stl_ext.pyi.ref @@ -169,6 +169,8 @@ def optional_unbound_type_with_nullopt_as_default(x: int | None = None) -> int | def optional_non_assignable(arg: NonAssignable | None) -> NonAssignable | None: ... +def optional_implicit_convert(arg0: float, arg1: int | None) -> float: ... + def variant_copyable(arg: Copyable | int, /) -> None: ... def variant_copyable_none(x: int | Copyable | None) -> None: ... From 1314c58e38c556a7428cdac901da34461e157910 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Mon, 2 Mar 2026 14:09:01 +1300 Subject: [PATCH 3/3] libCellML: upgraded to commit 387274c. --- cmake/packages.cmake | 2 +- src/3rdparty/libCellML/CMakeLists.txt | 20 +++--- src/sed/sedinstancetask.cpp | 40 +++++------ src/sed/sedinstancetask_p.h | 2 +- src/solver/solvercvode.cpp | 6 +- src/solver/solvercvode_p.h | 2 +- src/solver/solverforwardeuler.cpp | 4 +- src/solver/solverforwardeuler_p.h | 2 +- src/solver/solverfourthorderrungekutta.cpp | 4 +- src/solver/solverfourthorderrungekutta_p.h | 2 +- src/solver/solverheun.cpp | 4 +- src/solver/solverheun_p.h | 2 +- src/solver/solverode.cpp | 10 +-- src/solver/solverode_p.h | 4 +- src/solver/solverodefixedstep.cpp | 4 +- src/solver/solverodefixedstep_p.h | 2 +- src/solver/solversecondorderrungekutta.cpp | 4 +- src/solver/solversecondorderrungekutta_p.h | 2 +- src/support/cellml/cellmlfileruntime.cpp | 84 +++++++++++----------- src/support/cellml/cellmlfileruntime.h | 28 ++++---- src/support/cellml/cellmlfileruntime_p.h | 14 ++-- 21 files changed, 121 insertions(+), 121 deletions(-) diff --git a/cmake/packages.cmake b/cmake/packages.cmake index 53777a7f7..e48256b49 100644 --- a/cmake/packages.cmake +++ b/cmake/packages.cmake @@ -195,7 +195,7 @@ function(retrieve_package PACKAGE_NAME PACKAGE_VERSION PACKAGE_REPOSITORY RELEAS if("${PACKAGE_NAME}" STREQUAL "libCellML") #---GRY--- USE THIS VERSION OF libCellML WHICH CORRESPONDS TO PR #1256 UNTIL IT GETS MERGED IN. - set(PACKAGE_URL "https://github.com/agarny/${PACKAGE_REPOSITORY}/releases/download/7cc5bea/${PACKAGE_FILE}") + set(PACKAGE_URL "https://github.com/agarny/${PACKAGE_REPOSITORY}/releases/download/387274c/${PACKAGE_FILE}") endif() set(ATTEMPT 1) diff --git a/src/3rdparty/libCellML/CMakeLists.txt b/src/3rdparty/libCellML/CMakeLists.txt index 73f1343bb..4add0272e 100644 --- a/src/3rdparty/libCellML/CMakeLists.txt +++ b/src/3rdparty/libCellML/CMakeLists.txt @@ -34,49 +34,49 @@ if(LIBOPENCOR_PREBUILT_LIBCELLML) if(EMSCRIPTEN) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 5bee3b3c508fb274e084468243b43d9f83647beb) + 12e968703dfeeabe5539ecfc1ccb0b21b67ed4eb) else() if(WIN32) if(RELEASE_MODE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - d277ce028be3806aa2514ba27ec4bed352faf069) + c3561f24cbb652ec9d063f0d401823d06a9ea9ea) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 388a936417a5681fbcf835bdda20e8ed0fbf3382) + b0e7d01738dd41823ccbda87e597366400ceab2b) endif() else() if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - c768d8c59db5ee4a07baa0fc61d7a8ccac4ea6db) + cd4360fbf0ac7bf899aab34993b38be3a40c164e) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 2fd521abaf83b480e5b07c746ae310be529faa7e) + c4b2f37b0e980fe28c1924a1469a4ff779abb53b) endif() endif() elseif(APPLE) if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 055181384ac2e4e942603c6b1f3d0c20f439b523) + 1e93b2949c2abd64018427527bf9964a086b6ce8) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 847c024d893e3a1f73172e8f6d2e55136e46dd86) + 7df5020452a434a983ab3163b69a22437a024c1f) endif() else() if(INTEL_MODE) retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - f8d847dffd74264a3074e742149dca0ab4c57653) + 04f59b936b23c1a2f618c414462f6ae829c1dfb2) else() retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION} ${PACKAGE_REPOSITORY} ${RELEASE_TAG} - 674bb536a67cc7e7d4afef553c843ac38d44d43f) + 78d9b000ccaa76fa60ea9c07238bb5dc33e2ef9d) endif() endif() endif() @@ -86,7 +86,7 @@ elseif(NOT ONLY_BUILD_JAVASCRIPT_THIRD_PARTY_LIBRARIES) build_package(${PACKAGE_NAME} URL # https://github.com/opencor/${PACKAGE_REPOSITORY}/archive/refs/tags/${RELEASE_TAG}.tar.gz - https://github.com/agarny/${PACKAGE_REPOSITORY}/archive/refs/tags/7cc5bea.tar.gz + https://github.com/agarny/${PACKAGE_REPOSITORY}/archive/refs/tags/387274c.tar.gz DOWNLOAD_NO_PROGRESS ON CMAKE_ARGS -DBINDINGS_PYTHON=OFF diff --git a/src/sed/sedinstancetask.cpp b/src/sed/sedinstancetask.cpp index 9ba421118..2e7d632de 100644 --- a/src/sed/sedinstancetask.cpp +++ b/src/sed/sedinstancetask.cpp @@ -112,7 +112,7 @@ SedInstanceTask::Impl::Impl(const SedAbstractTaskPtr &pTask) mConstants = mConstantDoubles.data(); mComputedConstants = mComputedConstantDoubles.data(); - mAlgebraic = mAlgebraicDoubles.data(); + mAlgebraicVariables = mAlgebraicDoubles.data(); mResults.constants.resize(mAnalyserModel->constantCount(), {}); mResults.computedConstants.resize(mAnalyserModel->computedConstantCount(), {}); @@ -137,7 +137,7 @@ void SedInstanceTask::Impl::trackResults(size_t pIndex) } for (size_t i {0}; i < mAnalyserModel->algebraicVariableCount(); ++i) { - mResults.algebraic[i][pIndex] = mAlgebraic[i]; // NOLINT + mResults.algebraic[i][pIndex] = mAlgebraicVariables[i]; // NOLINT } } @@ -169,15 +169,15 @@ void SedInstanceTask::Impl::initialise() mVoi = mSedUniformTimeCourse->pimpl()->mOutputStartTime; #ifdef __EMSCRIPTEN__ - mRuntime->initialiseArraysForDifferentialModel(mStates, mRates, mConstants, mComputedConstants, mAlgebraic); + mRuntime->initialiseArraysForDifferentialModel(mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); #else - mRuntime->initialiseArraysForDifferentialModel()(mStates, mRates, mConstants, mComputedConstants, mAlgebraic); + mRuntime->initialiseArraysForDifferentialModel()(mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); #endif } else { #ifdef __EMSCRIPTEN__ - mRuntime->initialiseArraysForAlgebraicModel(mConstants, mComputedConstants, mAlgebraic); + mRuntime->initialiseArraysForAlgebraicModel(mConstants, mComputedConstants, mAlgebraicVariables); #else - mRuntime->initialiseArraysForAlgebraicModel()(mConstants, mComputedConstants, mAlgebraic); + mRuntime->initialiseArraysForAlgebraicModel()(mConstants, mComputedConstants, mAlgebraicVariables); #endif } @@ -185,21 +185,21 @@ void SedInstanceTask::Impl::initialise() if (mSedUniformTimeCourse != nullptr) { #ifdef __EMSCRIPTEN__ - mRuntime->computeComputedConstantsForDifferentialModel(mStates, mRates, mConstants, mComputedConstants, mAlgebraic); - mRuntime->computeRates(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraic); - mRuntime->computeVariablesForDifferentialModel(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraic); + mRuntime->computeComputedConstantsForDifferentialModel(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); + mRuntime->computeRates(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); + mRuntime->computeVariablesForDifferentialModel(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); #else - mRuntime->computeComputedConstantsForDifferentialModel()(mStates, mRates, mConstants, mComputedConstants, mAlgebraic); - mRuntime->computeRates()(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraic); - mRuntime->computeVariablesForDifferentialModel()(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraic); + mRuntime->computeComputedConstantsForDifferentialModel()(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); + mRuntime->computeRates()(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); + mRuntime->computeVariablesForDifferentialModel()(mVoi, mStates, mRates, mConstants, mComputedConstants, mAlgebraicVariables); #endif } else { #ifdef __EMSCRIPTEN__ - mRuntime->computeComputedConstantsForAlgebraicModel(mConstants, mComputedConstants, mAlgebraic); - mRuntime->computeVariablesForAlgebraicModel(mConstants, mComputedConstants, mAlgebraic); + mRuntime->computeComputedConstantsForAlgebraicModel(mConstants, mComputedConstants, mAlgebraicVariables); + mRuntime->computeVariablesForAlgebraicModel(mConstants, mComputedConstants, mAlgebraicVariables); #else - mRuntime->computeComputedConstantsForAlgebraicModel()(mConstants, mComputedConstants, mAlgebraic); - mRuntime->computeVariablesForAlgebraicModel()(mConstants, mComputedConstants, mAlgebraic); + mRuntime->computeComputedConstantsForAlgebraicModel()(mConstants, mComputedConstants, mAlgebraicVariables); + mRuntime->computeVariablesForAlgebraicModel()(mConstants, mComputedConstants, mAlgebraicVariables); #endif } @@ -215,7 +215,7 @@ void SedInstanceTask::Impl::initialise() if (mDifferentialModel) { if (!mOdeSolver->pimpl()->initialise(mVoi, mAnalyserModel->stateCount(), mStates, mRates, - mConstants, mComputedConstants, mAlgebraic, + mConstants, mComputedConstants, mAlgebraicVariables, mRuntime)) { addIssues(mOdeSolver, mOdeSolver->name()); @@ -283,10 +283,10 @@ double SedInstanceTask::Impl::run() #ifdef __EMSCRIPTEN__ mRuntime->computeVariablesForDifferentialModel(mVoi, mStates, mRates, - mConstants, mComputedConstants, mAlgebraic); + mConstants, mComputedConstants, mAlgebraicVariables); #else mRuntime->computeVariablesForDifferentialModel()(mVoi, mStates, mRates, - mConstants, mComputedConstants, mAlgebraic); + mConstants, mComputedConstants, mAlgebraicVariables); #endif //---GRY--- WE NEED TO CHECK FOR POSSIBLE NLA ISSUES, BUT FOR CODE COVERAGE WE NEED A MODEL THAT WOULD @@ -315,7 +315,7 @@ double SedInstanceTask::Impl::run() } for (size_t i {0}; i < mAnalyserModel->algebraicVariableCount(); ++i) { - mResults.algebraic[i].resize(1, mAlgebraic[i]); // NOLINT + mResults.algebraic[i].resize(1, mAlgebraicVariables[i]); // NOLINT } } diff --git a/src/sed/sedinstancetask_p.h b/src/sed/sedinstancetask_p.h index f20c085cc..7ee992ba0 100644 --- a/src/sed/sedinstancetask_p.h +++ b/src/sed/sedinstancetask_p.h @@ -55,7 +55,7 @@ class SedInstanceTask::Impl: public Logger::Impl double *mRates {nullptr}; double *mConstants {nullptr}; double *mComputedConstants {nullptr}; - double *mAlgebraic {nullptr}; + double *mAlgebraicVariables {nullptr}; Doubles mStateDoubles; Doubles mRateDoubles; diff --git a/src/solver/solvercvode.cpp b/src/solver/solvercvode.cpp index 2978de459..5ed0cb63a 100644 --- a/src/solver/solvercvode.cpp +++ b/src/solver/solvercvode.cpp @@ -304,7 +304,7 @@ StringStringMap SolverCvode::Impl::properties() const } bool SolverCvode::Impl::initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) { resetInternals(); @@ -313,7 +313,7 @@ bool SolverCvode::Impl::initialise(double pVoi, size_t pSize, double *pStates, d // Initialise the ODE solver itself. SolverOde::Impl::initialise(pVoi, pSize, pStates, pRates, - pConstants, pComputedConstants, pAlgebraic, + pConstants, pComputedConstants, pAlgebraicVariables, pRuntime); // Check the solver's properties. @@ -398,7 +398,7 @@ bool SolverCvode::Impl::initialise(double pVoi, size_t pSize, double *pStates, d mUserData.constants = pConstants; mUserData.computedConstants = pComputedConstants; - mUserData.algebraic = pAlgebraic; + mUserData.algebraic = pAlgebraicVariables; mUserData.runtime = pRuntime; ASSERT_EQ(CVodeSetUserData(mSolver, &mUserData), CV_SUCCESS); diff --git a/src/solver/solvercvode_p.h b/src/solver/solvercvode_p.h index fc64ab4fa..6f0d18d4b 100644 --- a/src/solver/solvercvode_p.h +++ b/src/solver/solvercvode_p.h @@ -89,7 +89,7 @@ class SolverCvode::Impl: public SolverOde::Impl StringStringMap properties() const override; bool initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) override; /*---GRY--- TO BE UNCOMMENTED ONCE WE ACTUALLY NEED IT. bool reinitialise(double pVoi) override; diff --git a/src/solver/solverforwardeuler.cpp b/src/solver/solverforwardeuler.cpp index 9ce3bcd23..fab0a0e9b 100644 --- a/src/solver/solverforwardeuler.cpp +++ b/src/solver/solverforwardeuler.cpp @@ -31,7 +31,7 @@ SolverPtr SolverForwardEuler::Impl::duplicate() } bool SolverForwardEuler::Impl::initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) { removeAllIssues(); @@ -39,7 +39,7 @@ bool SolverForwardEuler::Impl::initialise(double pVoi, size_t pSize, double *pSt // Initialise the ODE solver itself. return SolverOdeFixedStep::Impl::initialise(pVoi, pSize, pStates, pRates, - pConstants, pComputedConstants, pAlgebraic, + pConstants, pComputedConstants, pAlgebraicVariables, pRuntime); } diff --git a/src/solver/solverforwardeuler_p.h b/src/solver/solverforwardeuler_p.h index bf34215de..7a02e3661 100644 --- a/src/solver/solverforwardeuler_p.h +++ b/src/solver/solverforwardeuler_p.h @@ -30,7 +30,7 @@ class SolverForwardEuler::Impl: public SolverOdeFixedStep::Impl SolverPtr duplicate() override; bool initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) override; bool solve(double &pVoi, double pVoiEnd) override; diff --git a/src/solver/solverfourthorderrungekutta.cpp b/src/solver/solverfourthorderrungekutta.cpp index 8fbbdfdbc..d3da36676 100644 --- a/src/solver/solverfourthorderrungekutta.cpp +++ b/src/solver/solverfourthorderrungekutta.cpp @@ -31,7 +31,7 @@ SolverPtr SolverFourthOrderRungeKutta::Impl::duplicate() } bool SolverFourthOrderRungeKutta::Impl::initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) { removeAllIssues(); @@ -39,7 +39,7 @@ bool SolverFourthOrderRungeKutta::Impl::initialise(double pVoi, size_t pSize, do // Initialise the ODE solver itself. if (!SolverOdeFixedStep::Impl::initialise(pVoi, pSize, pStates, pRates, - pConstants, pComputedConstants, pAlgebraic, + pConstants, pComputedConstants, pAlgebraicVariables, pRuntime)) { return false; } diff --git a/src/solver/solverfourthorderrungekutta_p.h b/src/solver/solverfourthorderrungekutta_p.h index dcfbbfee5..847fc754d 100644 --- a/src/solver/solverfourthorderrungekutta_p.h +++ b/src/solver/solverfourthorderrungekutta_p.h @@ -40,7 +40,7 @@ class SolverFourthOrderRungeKutta::Impl: public SolverOdeFixedStep::Impl SolverPtr duplicate() override; bool initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) override; bool solve(double &pVoi, double pVoiEnd) override; diff --git a/src/solver/solverheun.cpp b/src/solver/solverheun.cpp index 54a3f3a13..6deb2ef7e 100644 --- a/src/solver/solverheun.cpp +++ b/src/solver/solverheun.cpp @@ -31,7 +31,7 @@ SolverPtr SolverHeun::Impl::duplicate() } bool SolverHeun::Impl::initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) { removeAllIssues(); @@ -39,7 +39,7 @@ bool SolverHeun::Impl::initialise(double pVoi, size_t pSize, double *pStates, do // Initialise the ODE solver itself. if (!SolverOdeFixedStep::Impl::initialise(pVoi, pSize, pStates, pRates, - pConstants, pComputedConstants, pAlgebraic, + pConstants, pComputedConstants, pAlgebraicVariables, pRuntime)) { return false; } diff --git a/src/solver/solverheun_p.h b/src/solver/solverheun_p.h index 2a424a369..60457dfbd 100644 --- a/src/solver/solverheun_p.h +++ b/src/solver/solverheun_p.h @@ -36,7 +36,7 @@ class SolverHeun::Impl: public SolverOdeFixedStep::Impl SolverPtr duplicate() override; bool initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) override; bool solve(double &pVoi, double pVoiEnd) override; diff --git a/src/solver/solverode.cpp b/src/solver/solverode.cpp index dec2d15d5..1e1acecfb 100644 --- a/src/solver/solverode.cpp +++ b/src/solver/solverode.cpp @@ -24,7 +24,7 @@ SolverOde::Impl::Impl(const std::string &pId, const std::string &pName) } bool SolverOde::Impl::initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) { (void)pVoi; @@ -35,7 +35,7 @@ bool SolverOde::Impl::initialise(double pVoi, size_t pSize, double *pStates, dou mRates = pRates; mConstants = pConstants; mComputedConstants = pComputedConstants; - mAlgebraic = pAlgebraic; + mAlgebraic = pAlgebraicVariables; mRuntime = pRuntime; @@ -52,12 +52,12 @@ bool SolverOde::Impl::reinitialise(double pVoi) */ void SolverOde::Impl::computeRates(double pVoi, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic) const + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { #ifdef __EMSCRIPTEN__ - mRuntime->computeRates(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraic); + mRuntime->computeRates(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); #else - mRuntime->computeRates()(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraic); + mRuntime->computeRates()(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); #endif } diff --git a/src/solver/solverode_p.h b/src/solver/solverode_p.h index 6363723a4..5c3792819 100644 --- a/src/solver/solverode_p.h +++ b/src/solver/solverode_p.h @@ -40,7 +40,7 @@ class SolverOde::Impl: public Solver::Impl explicit Impl(const std::string &pId, const std::string &pName); virtual bool initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) = 0; /*---GRY--- TO BE UNCOMMENTED ONCE WE ACTUALLY NEED IT. virtual bool reinitialise(double pVoi); @@ -49,7 +49,7 @@ class SolverOde::Impl: public Solver::Impl virtual bool solve(double &pVoi, double pVoiEnd) = 0; void computeRates(double pVoi, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic) const; + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; }; } // namespace libOpenCOR diff --git a/src/solver/solverodefixedstep.cpp b/src/solver/solverodefixedstep.cpp index 2539f44fd..6013bcb33 100644 --- a/src/solver/solverodefixedstep.cpp +++ b/src/solver/solverodefixedstep.cpp @@ -69,13 +69,13 @@ StringStringMap SolverOdeFixedStep::Impl::properties() const } bool SolverOdeFixedStep::Impl::initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) { // Initialise the ODE solver itself. SolverOde::Impl::initialise(pVoi, pSize, pStates, pRates, - pConstants, pComputedConstants, pAlgebraic, + pConstants, pComputedConstants, pAlgebraicVariables, pRuntime); // Check the solver's properties. diff --git a/src/solver/solverodefixedstep_p.h b/src/solver/solverodefixedstep_p.h index 470099163..e84b47b9d 100644 --- a/src/solver/solverodefixedstep_p.h +++ b/src/solver/solverodefixedstep_p.h @@ -40,7 +40,7 @@ class SolverOdeFixedStep::Impl: public SolverOde::Impl StringStringMap properties() const override; bool initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) override; double step() const; diff --git a/src/solver/solversecondorderrungekutta.cpp b/src/solver/solversecondorderrungekutta.cpp index cf80bfd87..efde86723 100644 --- a/src/solver/solversecondorderrungekutta.cpp +++ b/src/solver/solversecondorderrungekutta.cpp @@ -31,7 +31,7 @@ SolverPtr SolverSecondOrderRungeKutta::Impl::duplicate() } bool SolverSecondOrderRungeKutta::Impl::initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) { removeAllIssues(); @@ -39,7 +39,7 @@ bool SolverSecondOrderRungeKutta::Impl::initialise(double pVoi, size_t pSize, do // Initialise the ODE solver itself. if (!SolverOdeFixedStep::Impl::initialise(pVoi, pSize, pStates, pRates, - pConstants, pComputedConstants, pAlgebraic, + pConstants, pComputedConstants, pAlgebraicVariables, pRuntime)) { return false; } diff --git a/src/solver/solversecondorderrungekutta_p.h b/src/solver/solversecondorderrungekutta_p.h index 7a2570fa1..cb2801e10 100644 --- a/src/solver/solversecondorderrungekutta_p.h +++ b/src/solver/solversecondorderrungekutta_p.h @@ -34,7 +34,7 @@ class SolverSecondOrderRungeKutta::Impl: public SolverOdeFixedStep::Impl SolverPtr duplicate() override; bool initialise(double pVoi, size_t pSize, double *pStates, double *pRates, - double *pConstants, double *pComputedConstants, double *pAlgebraic, + double *pConstants, double *pComputedConstants, double *pAlgebraicVariables, const CellmlFileRuntimePtr &pRuntime) override; bool solve(double &pVoi, double pVoiEnd) override; diff --git a/src/support/cellml/cellmlfileruntime.cpp b/src/support/cellml/cellmlfileruntime.cpp index dc0ecbfa1..8fc4e98b1 100644 --- a/src/support/cellml/cellmlfileruntime.cpp +++ b/src/support/cellml/cellmlfileruntime.cpp @@ -432,67 +432,67 @@ extern void nlaSolve(uintptr_t nlaSolverAddress, void (*objectiveFunction)(doubl } #ifdef __EMSCRIPTEN__ -EM_JS(void, jsInitialiseArraysForAlgebraicModel, (intptr_t pWasmInstanceFunctionsId, double *pConstants, double *pComputedConstants, double *pAlgebraic), { - Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).initialiseArrays(pConstants, pComputedConstants, pAlgebraic); +EM_JS(void, jsInitialiseArraysForAlgebraicModel, (intptr_t pWasmInstanceFunctionsId, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables), { + Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).initialiseArrays(pConstants, pComputedConstants, pAlgebraicVariables); }); -void CellmlFileRuntime::Impl::initialiseArraysForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::Impl::initialiseArraysForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - jsInitialiseArraysForAlgebraicModel(mWasmInstanceFunctionsId, pConstants, pComputedConstants, pAlgebraic); + jsInitialiseArraysForAlgebraicModel(mWasmInstanceFunctionsId, pConstants, pComputedConstants, pAlgebraicVariables); } -EM_JS(void, jsInitialiseArraysForDifferentialModel, (intptr_t pWasmInstanceFunctionsId, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic), { - Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).initialiseArrays(pStates, pRates, pConstants, pComputedConstants, pAlgebraic); +EM_JS(void, jsInitialiseArraysForDifferentialModel, (intptr_t pWasmInstanceFunctionsId, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables), { + Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).initialiseArrays(pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); }); -void CellmlFileRuntime::Impl::initialiseArraysForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::Impl::initialiseArraysForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - jsInitialiseArraysForDifferentialModel(mWasmInstanceFunctionsId, pStates, pRates, pConstants, pComputedConstants, pAlgebraic); + jsInitialiseArraysForDifferentialModel(mWasmInstanceFunctionsId, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); } -EM_JS(void, jsComputeComputedConstantsForAlgebraicModel, (intptr_t pWasmInstanceFunctionsId, double *pConstants, double *pComputedConstants, double *pAlgebraic), { - Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).computeComputedConstants(pConstants, pComputedConstants, pAlgebraic); +EM_JS(void, jsComputeComputedConstantsForAlgebraicModel, (intptr_t pWasmInstanceFunctionsId, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables), { + Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).computeComputedConstants(pConstants, pComputedConstants, pAlgebraicVariables); }); -void CellmlFileRuntime::Impl::computeComputedConstantsForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::Impl::computeComputedConstantsForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - jsComputeComputedConstantsForAlgebraicModel(mWasmInstanceFunctionsId, pConstants, pComputedConstants, pAlgebraic); + jsComputeComputedConstantsForAlgebraicModel(mWasmInstanceFunctionsId, pConstants, pComputedConstants, pAlgebraicVariables); } -EM_JS(void, jsComputeComputedConstantsForDifferentialModel, (intptr_t pWasmInstanceFunctionsId, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic), { - Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).computeComputedConstants(pStates, pRates, pConstants, pComputedConstants, pAlgebraic); +EM_JS(void, jsComputeComputedConstantsForDifferentialModel, (intptr_t pWasmInstanceFunctionsId, double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables), { + Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).computeComputedConstants(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); }); -void CellmlFileRuntime::Impl::computeComputedConstantsForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::Impl::computeComputedConstantsForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - jsComputeComputedConstantsForDifferentialModel(mWasmInstanceFunctionsId, pStates, pRates, pConstants, pComputedConstants, pAlgebraic); + jsComputeComputedConstantsForDifferentialModel(mWasmInstanceFunctionsId, pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); } -EM_JS(void, jsComputeRates, (intptr_t pWasmInstanceFunctionsId, double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic), { - Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).computeRates(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraic); +EM_JS(void, jsComputeRates, (intptr_t pWasmInstanceFunctionsId, double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables), { + Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).computeRates(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); }); -void CellmlFileRuntime::Impl::computeRates(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::Impl::computeRates(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - jsComputeRates(mWasmInstanceFunctionsId, pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraic); + jsComputeRates(mWasmInstanceFunctionsId, pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); } -EM_JS(void, jsComputeVariablesForAlgebraicModel, (intptr_t pWasmInstanceFunctionsId, double *pConstants, double *pComputedConstants, double *pAlgebraic), { - Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).computeVariables(pConstants, pComputedConstants, pAlgebraic); +EM_JS(void, jsComputeVariablesForAlgebraicModel, (intptr_t pWasmInstanceFunctionsId, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables), { + Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).computeVariables(pConstants, pComputedConstants, pAlgebraicVariables); }); -void CellmlFileRuntime::Impl::computeVariablesForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::Impl::computeVariablesForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - jsComputeVariablesForAlgebraicModel(mWasmInstanceFunctionsId, pConstants, pComputedConstants, pAlgebraic); + jsComputeVariablesForAlgebraicModel(mWasmInstanceFunctionsId, pConstants, pComputedConstants, pAlgebraicVariables); } -EM_JS(void, jsComputeVariablesForDifferentialModel, (intptr_t pWasmInstanceFunctionsId, double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic), { - Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).computeVariables(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraic); +EM_JS(void, jsComputeVariablesForDifferentialModel, (intptr_t pWasmInstanceFunctionsId, double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables), { + Module.wasmInstanceFunctions.get(pWasmInstanceFunctionsId).computeVariables(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); }); -void CellmlFileRuntime::Impl::computeVariablesForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::Impl::computeVariablesForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - jsComputeVariablesForDifferentialModel(mWasmInstanceFunctionsId, pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraic); + jsComputeVariablesForDifferentialModel(mWasmInstanceFunctionsId, pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); } #else CellmlFileRuntime::InitialiseArraysForAlgebraicModel CellmlFileRuntime::Impl::initialiseArraysForAlgebraicModel() const @@ -557,39 +557,39 @@ CellmlFileRuntimePtr CellmlFileRuntime::create(const CellmlFilePtr &pCellmlFile, } #ifdef __EMSCRIPTEN__ -void CellmlFileRuntime::initialiseArraysForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::initialiseArraysForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - pimpl()->initialiseArraysForAlgebraicModel(pConstants, pComputedConstants, pAlgebraic); + pimpl()->initialiseArraysForAlgebraicModel(pConstants, pComputedConstants, pAlgebraicVariables); } -void CellmlFileRuntime::initialiseArraysForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::initialiseArraysForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - pimpl()->initialiseArraysForDifferentialModel(pStates, pRates, pConstants, pComputedConstants, pAlgebraic); + pimpl()->initialiseArraysForDifferentialModel(pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); } -void CellmlFileRuntime::computeComputedConstantsForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::computeComputedConstantsForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - pimpl()->computeComputedConstantsForAlgebraicModel(pConstants, pComputedConstants, pAlgebraic); + pimpl()->computeComputedConstantsForAlgebraicModel(pConstants, pComputedConstants, pAlgebraicVariables); } -void CellmlFileRuntime::computeComputedConstantsForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::computeComputedConstantsForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - pimpl()->computeComputedConstantsForDifferentialModel(pStates, pRates, pConstants, pComputedConstants, pAlgebraic); + pimpl()->computeComputedConstantsForDifferentialModel(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); } -void CellmlFileRuntime::computeRates(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::computeRates(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - pimpl()->computeRates(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraic); + pimpl()->computeRates(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); } -void CellmlFileRuntime::computeVariablesForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::computeVariablesForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - pimpl()->computeVariablesForAlgebraicModel(pConstants, pComputedConstants, pAlgebraic); + pimpl()->computeVariablesForAlgebraicModel(pConstants, pComputedConstants, pAlgebraicVariables); } -void CellmlFileRuntime::computeVariablesForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const +void CellmlFileRuntime::computeVariablesForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const { - pimpl()->computeVariablesForDifferentialModel(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraic); + pimpl()->computeVariablesForDifferentialModel(pVoi, pStates, pRates, pConstants, pComputedConstants, pAlgebraicVariables); } #else CellmlFileRuntime::InitialiseArraysForAlgebraicModel CellmlFileRuntime::initialiseArraysForAlgebraicModel() const diff --git a/src/support/cellml/cellmlfileruntime.h b/src/support/cellml/cellmlfileruntime.h index ef020c73b..c5acc81dc 100644 --- a/src/support/cellml/cellmlfileruntime.h +++ b/src/support/cellml/cellmlfileruntime.h @@ -32,13 +32,13 @@ class CellmlFileRuntime: public Logger { public: #ifndef __EMSCRIPTEN__ - using InitialiseArraysForAlgebraicModel = void (*)(double *pConstants, double *pComputedConstants, double *pAlgebraic); - using InitialiseArraysForDifferentialModel = void (*)(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic); - using ComputeComputedConstantsForAlgebraicModel = void (*)(double *pConstants, double *pComputedConstants, double *pAlgebraic); - using ComputeComputedConstantsForDifferentialModel = void (*)(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic); - using ComputeRates = void (*)(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic); - using ComputeVariablesForAlgebraicModel = void (*)(double *pConstants, double *pComputedConstants, double *pAlgebraic); - using ComputeVariablesForDifferentialModel = void (*)(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic); + using InitialiseArraysForAlgebraicModel = void (*)(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables); + using InitialiseArraysForDifferentialModel = void (*)(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables); + using ComputeComputedConstantsForAlgebraicModel = void (*)(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables); + using ComputeComputedConstantsForDifferentialModel = void (*)(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables); + using ComputeRates = void (*)(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables); + using ComputeVariablesForAlgebraicModel = void (*)(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables); + using ComputeVariablesForDifferentialModel = void (*)(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables); #endif CellmlFileRuntime() = delete; @@ -53,13 +53,13 @@ class CellmlFileRuntime: public Logger static CellmlFileRuntimePtr create(const CellmlFilePtr &pCellmlFile, const SolverNlaPtr &pNlaSolver); #ifdef __EMSCRIPTEN__ - void initialiseArraysForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void initialiseArraysForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void computeComputedConstantsForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void computeComputedConstantsForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void computeRates(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void computeVariablesForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void computeVariablesForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const; + void initialiseArraysForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void initialiseArraysForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void computeComputedConstantsForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void computeComputedConstantsForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void computeRates(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void computeVariablesForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void computeVariablesForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; #else InitialiseArraysForAlgebraicModel initialiseArraysForAlgebraicModel() const; InitialiseArraysForDifferentialModel initialiseArraysForDifferentialModel() const; diff --git a/src/support/cellml/cellmlfileruntime_p.h b/src/support/cellml/cellmlfileruntime_p.h index e417924b1..ba916cdac 100644 --- a/src/support/cellml/cellmlfileruntime_p.h +++ b/src/support/cellml/cellmlfileruntime_p.h @@ -46,13 +46,13 @@ class CellmlFileRuntime::Impl: public Logger::Impl explicit Impl(const CellmlFilePtr &pCellmlFile, const SolverNlaPtr &pNlaSolver); #ifdef __EMSCRIPTEN__ - void initialiseArraysForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void initialiseArraysForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void computeComputedConstantsForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void computeComputedConstantsForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void computeRates(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void computeVariablesForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraic) const; - void computeVariablesForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraic) const; + void initialiseArraysForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void initialiseArraysForDifferentialModel(double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void computeComputedConstantsForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void computeComputedConstantsForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void computeRates(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void computeVariablesForAlgebraicModel(double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; + void computeVariablesForDifferentialModel(double pVoi, double *pStates, double *pRates, double *pConstants, double *pComputedConstants, double *pAlgebraicVariables) const; #else CellmlFileRuntime::InitialiseArraysForAlgebraicModel initialiseArraysForAlgebraicModel() const; CellmlFileRuntime::InitialiseArraysForDifferentialModel initialiseArraysForDifferentialModel() const;