From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C93CF1F93C for ; Tue, 15 Nov 2022 19:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1668540821; bh=KFFUkxvs0zxo+ErumnUqT0fed7e03z055/6w2YDVFuk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wIka+1bP6nsK6Rr1gF4gJBgN8vngM/Neg3+xKjYlx5+F22KW7KMPUVGdU0BUpp/MC sqcsUOXUxf03k/etBTz+Kr+DSiWJGFMkLls3EUaerMZYsWf1ETXRfqRMZ4DkVew5qp SLIujVbxdMVxVENZ4anW3T9Ky6YJq9PhRZrBs8mU= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH 1/6] test cfree and aligned_alloc aliases Date: Tue, 15 Nov 2022 19:33:36 +0000 Message-Id: <20221115193341.3948245-2-e@80x24.org> In-Reply-To: <20221115193341.3948245-1-e@80x24.org> References: <20221115193341.3948245-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: These aliases aren't necessary for modern glibc, at least, but they also don't hurt. This quiets an old warning about cfree. --- .gitignore | 1 + Mwrap.xs | 4 +++- t/mwrap.t | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) 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 +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 {