# HG changeset patch # User Markus Mützel # Date 1713010939 -7200 # Node ID f3ffee7cf47820a0857c26ed01e97f0e9264fbdf # Parent 0d1a3c2ad9c62c324996f0d09e1aaaffe2b7ba39 build: Run test for polymorphic allocators if possible. * m4/acinclude.m4 (OCTAVE_CHECK_STD_PMR_POLYMORPHIC_ALLOCATOR): On macOS, we need to run an executable to check if polymorphic allocators are actually working. Do that on all platforms (if possible). Fall back to a compilation-only test when cross-compiling. See: https://octave.discourse.group/t/5481/33 diff -r 0d1a3c2ad9c6 -r f3ffee7cf478 m4/acinclude.m4 --- a/m4/acinclude.m4 Sat Apr 13 12:13:34 2024 +0200 +++ b/m4/acinclude.m4 Sat Apr 13 14:22:19 2024 +0200 @@ -200,6 +200,47 @@ AC_CACHE_CHECK([whether std::pmr::polymorphic_allocator is available], [octave_cv_std_pmr_polymorphic_allocator], [AC_LANG_PUSH(C++) + AC_RUN_IFELSE([AC_LANG_PROGRAM([[ + #include + #include + #include + class mx_memory_resource : public std::pmr::memory_resource + { + private: + void * do_allocate (std::size_t bytes, size_t /*alignment*/) + { + void *ptr = std::malloc (bytes); + if (! ptr) + throw std::bad_alloc (); + return ptr; + } + void do_deallocate (void* ptr, std::size_t /*bytes*/, + std::size_t /*alignment*/) + { + std::free (ptr); + } + bool do_is_equal (const std::pmr::memory_resource& other) const noexcept + { + return this == dynamic_cast (&other); + return true; + } + }; + mx_memory_resource the_mx_memory_resource; + ]], [[ + std::pmr::vector my_int_vec { &the_mx_memory_resource }; + ]])], + octave_cv_std_pmr_polymorphic_allocator=yes, + octave_cv_std_pmr_polymorphic_allocator=no, + [## On macOS, we need to run an executable to check if polymorphic + ## allocators are working. + ## When cross-compiling to that target, the following test might succeed + ## even if polymorphic allocators are not actually implemented. In that + ## case, users would need to manually configure with + ## `--disable-std-pmr-polymorphic-allocator`. + ## When cross-compiling to any other target, the following test should be + ## giving accurate results. + + ## FIXME: Is there a way to not repeat the same code from above? AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include #include @@ -230,7 +271,7 @@ std::pmr::vector my_int_vec { &the_mx_memory_resource }; ]])], octave_cv_std_pmr_polymorphic_allocator=yes, - octave_cv_std_pmr_polymorphic_allocator=no) + octave_cv_std_pmr_polymorphic_allocator=no)]) AC_LANG_POP(C++) ]) if test $octave_cv_std_pmr_polymorphic_allocator = yes; then