about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-11-15 19:33:36 +0000
committerEric Wong <e@80x24.org>2022-11-16 09:25:10 +0000
commitf9f30aad253c6a5d44830a25d82b275a696da3e5 (patch)
treee326b8aeb5bccae5aeeca5912d47a1c62217643a
parentad099a42014469ed4369613f9f179f433e6b61b2 (diff)
downloadmwrap-f9f30aad253c6a5d44830a25d82b275a696da3e5.tar.gz
These aliases aren't necessary for modern glibc, at least,
but they also don't hurt.  This quiets an old warning about
cfree.
-rw-r--r--.gitignore1
-rw-r--r--Mwrap.xs4
-rw-r--r--t/mwrap.t31
3 files changed, 35 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 10623de..c228ee1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@
 /blib
 /pm_to_blib
 /config.mak
+/_Inline
diff --git a/Mwrap.xs b/Mwrap.xs
index 31e9394..518edb1 100644
--- a/Mwrap.xs
+++ b/Mwrap.xs
@@ -542,8 +542,10 @@ int posix_memalign(void **p, size_t alignment, size_t size)
         return internal_memalign(p, alignment, size, RETURN_ADDRESS(0));
 }
 
+/* these aliases aren't needed for glibc, not sure about other libcs... */
 void *aligned_alloc(size_t, size_t) __attribute__((alias("memalign")));
-void cfree(void *) __attribute__((alias("free")));
+void cfree(void *) __attribute__((__nothrow__))
+                __attribute__((__leaf__)) __attribute__((alias("free")));
 
 void *valloc(size_t size)
 {
diff --git a/t/mwrap.t b/t/mwrap.t
index c6e589c..0bb3ea8 100644
--- a/t/mwrap.t
+++ b/t/mwrap.t
@@ -141,6 +141,37 @@ diag slurp($out);
 is(Devel::Mwrap::quiet(1), 0, 'was not quiet, before');
 is(Devel::Mwrap::quiet(0), 1, 'was quiet, before');
 
+SKIP: {
+        eval { require Inline::C } or skip 'Inline::C not available', 1;
+        $ENV{TEST_ALIASES} or skip 'TEST_ALIASES unset', 1;
+        my $c_src = <<'EOM';
+#include <stdlib.h>
+void cfree(void *); /* lold glibc version */
+int test_aliases()
+{
+        size_t i;
+        void *p;
+        for (i = 0; i < 100; i++) {
+                if (i % 3 == 0)
+                        p = aligned_alloc(64, i);
+                else
+                        p = malloc(i);
+                if (i % 2 == 0)
+                        cfree(p);
+                else
+                        free(p);
+        }
+        return 3;
+}
+EOM
+        eval <<'EOM';
+use Inline C => $c_src, BUILD_NOISY => 1
+EOM
+        BAIL_OUT "cannot build $@" if $@;
+        is(test_aliases(), 3,
+                'aligned_alloc + cfree function ran w/o crashing');
+};
+
 done_testing();
 
 sub slurp {