X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftypesafe_cb%2Ftest%2Frun.c;h=79863db84128c85a3079f5faad769e9db039bbf3;hp=5afbb91877d0f505ca32d23dc4219a272f825d91;hb=b0fa019adb998c20a8740f5696b61ae87d2a77a6;hpb=076877c266706ba432987195422a1e8653bd0c3b diff --git a/ccan/typesafe_cb/test/run.c b/ccan/typesafe_cb/test/run.c index 5afbb918..79863db8 100644 --- a/ccan/typesafe_cb/test/run.c +++ b/ccan/typesafe_cb/test/run.c @@ -12,7 +12,7 @@ static void _set_some_value(void *val) } #define set_some_value(expr) \ - _set_some_value(cast_if_type(void *, (expr), (expr), unsigned long)) + _set_some_value(typesafe_cb_cast(void *, unsigned long, (expr))) static void _callback_onearg(void (*fn)(void *arg), void *arg) { @@ -30,30 +30,19 @@ static void _callback_postargs(void (*fn)(void *arg, int a, int b), void *arg) } #define callback_onearg(cb, arg) \ - _callback_onearg(typesafe_cb(void, (cb), (arg)), (arg)) + _callback_onearg(typesafe_cb(void, void *, (cb), (arg)), (arg)) #define callback_preargs(cb, arg) \ - _callback_preargs(typesafe_cb_preargs(void, (cb), (arg), int, int), (arg)) + _callback_preargs(typesafe_cb_preargs(void, void *, (cb), (arg), int, int), (arg)) #define callback_postargs(cb, arg) \ - _callback_postargs(typesafe_cb_postargs(void, (cb), (arg), int, int), (arg)) + _callback_postargs(typesafe_cb_postargs(void, void *, (cb), (arg), int, int), (arg)) static void my_callback_onearg(char *p) { ok1(strcmp(p, "hello world") == 0); } -static void my_callback_onearg_const(const char *p) -{ - ok1(strcmp(p, "hello world") == 0); -} - -static void my_callback_onearg_volatile(volatile char *p) -{ - /* Double cast avoids warning on gcc's -Wcast-qual */ - ok1(strcmp((char *)(intptr_t)p, "hello world") == 0); -} - static void my_callback_preargs(int a, int b, char *p) { ok1(a == 1); @@ -61,22 +50,6 @@ static void my_callback_preargs(int a, int b, char *p) ok1(strcmp(p, "hello world") == 0); } -#if 0 /* FIXME */ -static void my_callback_preargs_const(int a, int b, const char *p) -{ - ok1(a == 1); - ok1(b == 2); - ok1(strcmp(p, "hello world") == 0); -} - -static void my_callback_preargs_volatile(int a, int b, volatile char *p) -{ - ok1(a == 1); - ok1(b == 2); - ok1(strcmp((char *)p, "hello world") == 0); -} -#endif - static void my_callback_postargs(char *p, int a, int b) { ok1(a == 1); @@ -84,23 +57,7 @@ static void my_callback_postargs(char *p, int a, int b) ok1(strcmp(p, "hello world") == 0); } -#if 0 /* FIXME */ -static void my_callback_postargs_const(const char *p, int a, int b) -{ - ok1(a == 1); - ok1(b == 2); - ok1(strcmp(p, "hello world") == 0); -} - -static void my_callback_postargs_volatile(volatile char *p, int a, int b) -{ - ok1(a == 1); - ok1(b == 2); - ok1(strcmp((char *)p, "hello world") == 0); -} -#endif - -/* This is simply a compile test; we promised cast_if_type can be in a +/* This is simply a compile test; we promised typesafe_cb_cast can be in a * static initializer. */ struct callback_onearg { @@ -109,7 +66,7 @@ struct callback_onearg }; struct callback_onearg cb_onearg -= { typesafe_cb(void, my_callback_onearg, (char *)(intptr_t)"hello world"), += { typesafe_cb(void, void *, my_callback_onearg, (char *)(intptr_t)"hello world"), "hello world" }; struct callback_preargs @@ -119,7 +76,7 @@ struct callback_preargs }; struct callback_preargs cb_preargs -= { typesafe_cb_preargs(void, my_callback_preargs, += { typesafe_cb_preargs(void, void *, my_callback_preargs, (char *)(intptr_t)"hi", int, int), "hi" }; struct callback_postargs @@ -129,7 +86,7 @@ struct callback_postargs }; struct callback_postargs cb_postargs -= { typesafe_cb_postargs(void, my_callback_postargs, += { typesafe_cb_postargs(void, void *, my_callback_postargs, (char *)(intptr_t)"hi", int, int), "hi" }; int main(int argc, char *argv[]) @@ -138,25 +95,15 @@ int main(int argc, char *argv[]) unsigned long l = (unsigned long)p; char str[] = "hello world"; - plan_tests(2 + 3 + 3 + 3); + plan_tests(2 + 1 + 3 + 3); set_some_value(p); set_some_value(l); callback_onearg(my_callback_onearg, str); - callback_onearg(my_callback_onearg_const, str); - callback_onearg(my_callback_onearg_volatile, str); callback_preargs(my_callback_preargs, str); -#if 0 /* FIXME */ - callback_preargs(my_callback_preargs_const, str); - callback_preargs(my_callback_preargs_volatile, str); -#endif callback_postargs(my_callback_postargs, str); -#if 0 /* FIXME */ - callback_postargs(my_callback_postargs_const, str); - callback_postargs(my_callback_postargs_volatile, str); -#endif return exit_status(); }