[ccan] [PATCH 3/5] altstack: Use ptrint instead of bare casts
David Gibson
david at gibson.dropbear.id.au
Fri Jun 3 18:42:01 AEST 2016
Functions invoked with altstack take a void * parameter. However, the
test program wants to pass an integer, and so uses the trick of casting
the integer values to (void *) and back again.
The ptrint() module handles exactly this case in a more portable and
(somewhat) typesafe way, so use that instead.
Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
ccan/altstack/_info | 5 +++++
ccan/altstack/test/run.c | 25 +++++++++++++------------
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/ccan/altstack/_info b/ccan/altstack/_info
index 2713bd0..7accf86 100644
--- a/ccan/altstack/_info
+++ b/ccan/altstack/_info
@@ -122,6 +122,11 @@ int main(int argc, char *argv[])
if (strcmp(argv[1], "depends") == 0)
return 0;
+ if (strcmp(argv[1], "testdepends") == 0) {
+ printf("ccan/ptrint\n");
+ return 0;
+ }
+
if (strcmp(argv[1], "ported") == 0) {
#ifdef __x86_64__
printf("\n");
diff --git a/ccan/altstack/test/run.c b/ccan/altstack/test/run.c
index 23dd2e9..61710fd 100644
--- a/ccan/altstack/test/run.c
+++ b/ccan/altstack/test/run.c
@@ -8,6 +8,7 @@
#include <unistd.h>
#include <sys/mman.h>
#include <ccan/tap/tap.h>
+#include <ccan/ptrint/ptrint.h>
#include <ccan/altstack/altstack.h>
#include <stdio.h>
@@ -53,7 +54,7 @@ static void __attribute__((optimize("O0"))) dn(unsigned long i)
}
static void *wrap(void *i)
{
- dn((unsigned long) i);
+ dn(ptr2int(i));
return wrap;
}
@@ -86,43 +87,43 @@ int main(void)
plan_tests(50);
- chkfail(getrlimit_, altstack(8*MiB, wrap, 0, 0) == -1, e(getrlimit_),
+ chkfail(getrlimit_, altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(getrlimit_),
0,
0);
- chkfail(setrlimit_, altstack(8*MiB, wrap, 0, 0) == -1, e(setrlimit_),
+ chkfail(setrlimit_, altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(setrlimit_),
getrlimit_,
0);
- chkfail(mmap_, altstack(8*MiB, wrap, 0, 0) == -1, e(mmap_),
+ chkfail(mmap_, altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(mmap_),
getrlimit_|setrlimit_,
setrlimit_);
- chkfail(sigaltstack_, altstack(8*MiB, wrap, 0, 0) == -1, e(sigaltstack_),
+ chkfail(sigaltstack_, altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(sigaltstack_),
getrlimit_|setrlimit_|mmap_,
setrlimit_|munmap_);
- chkfail(sigaction_, altstack(8*MiB, wrap, 0, 0) == -1, e(sigaction_),
+ chkfail(sigaction_, altstack(8*MiB, wrap, int2ptr(0), 0) == -1, e(sigaction_),
getrlimit_|setrlimit_|mmap_|sigaltstack_,
setrlimit_|munmap_|sigaltstack_);
- chkfail(munmap_, altstack(8*MiB, wrap, 0, 0) == 1, e(munmap_),
+ chkfail(munmap_, altstack(8*MiB, wrap, int2ptr(0), 0) == 1, e(munmap_),
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|sigaltstack_|sigaction_);
if (fail = 0, munmap(m_, msz_) == -1)
err(1, "munmap");
- chkok( altstack(1*MiB, wrap, (void *) 1000000, 0) == -1, EOVERFLOW,
+ chkok( altstack(1*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
// be sure segv catch is repeatable (SA_NODEFER)
- chkok( altstack(1*MiB, wrap, (void *) 1000000, 0) == -1, EOVERFLOW,
+ chkok( altstack(1*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
used = 1;
- chkfail(munmap_, altstack(1*MiB, wrap, (void *) 1000000, 0) == -1, EOVERFLOW,
+ chkfail(munmap_, altstack(1*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|sigaltstack_|sigaction_);
if (fail = 0, munmap(m_, msz_) == -1)
@@ -149,7 +150,7 @@ int main(void)
ok1(strcmp(buf, estr "\n") == 0);
used = 1;
- chkok( altstack(8*MiB, wrap, (void *) 1000000, 0) == -1, EOVERFLOW,
+ chkok( altstack(8*MiB, wrap, int2ptr(1000000), 0) == -1, EOVERFLOW,
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
@@ -157,7 +158,7 @@ int main(void)
ok1(used >= 8*MiB - pgsz && used <= 8*MiB + pgsz);
used = 0;
- chkok( altstack(8*MiB, wrap, (void *) 100000, 0) == 0, 0,
+ chkok( altstack(8*MiB, wrap, int2ptr(100000), 0) == 0, 0,
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_|munmap_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
--
2.5.5
More information about the ccan
mailing list