diff mbox series

[Valgrind-developers] tests: Make pthread_detatch call portable across platforms

Message ID 20200128012321.578096-1-raj.khem@gmail.com
State New
Headers show
Series [Valgrind-developers] tests: Make pthread_detatch call portable across platforms | expand

Commit Message

Khem Raj Jan. 28, 2020, 1:23 a.m. UTC
pthread_t is opaque type therefore we can not apply simple arithmetic to variables of pthread_t type
this test needs to pass a invalid pthread_t handle, typcasting (long)thread works too and is portable
across glibc and musl

Fixes
| pth_detached3.c:24:25: error: invalid use of undefined type 'struct __pthread'
|    24 |   pthread_detach(thread + 8);
|       |                         ^

Signed-off-by: Khem Raj <raj.khem@gmail.com>

---
 drd/tests/pth_detached3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.25.0



_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Comments

Bart Van Assche Jan. 28, 2020, 3:16 a.m. UTC | #1
On 2020-01-27 17:23, Khem Raj wrote:
> pthread_t is opaque type therefore we can not apply simple arithmetic to variables of pthread_t type

> this test needs to pass a invalid pthread_t handle, typcasting (long)thread works too and is portable

> across glibc and musl

> 

> Fixes

> | pth_detached3.c:24:25: error: invalid use of undefined type 'struct __pthread'

> |    24 |   pthread_detach(thread + 8);

> |       |                         ^

> 

> Signed-off-by: Khem Raj <raj.khem@gmail.com>

> ---

>  drd/tests/pth_detached3.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/drd/tests/pth_detached3.c b/drd/tests/pth_detached3.c

> index c02eef11a..341193ba1 100644

> --- a/drd/tests/pth_detached3.c

> +++ b/drd/tests/pth_detached3.c

> @@ -21,7 +21,7 @@ int main(int argc, char** argv)

>    pthread_detach(thread);

>  

>    /* Invoke pthread_detach() with an invalid thread ID. */

> -  pthread_detach(thread + 8);

> +  pthread_detach((pthread_t)((long)thread + 8));

>  

>    fprintf(stderr, "Finished.\n");


Is sizeof(long) always identical to sizeof(pthread_t)? How about casting
to uintptr_t instead of to long?

Thanks,

Bart.



_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers
Khem Raj Jan. 28, 2020, 3:51 a.m. UTC | #2
On Mon, Jan 27, 2020 at 7:16 PM Bart Van Assche <bvanassche@acm.org> wrote:
>

> On 2020-01-27 17:23, Khem Raj wrote:

> > pthread_t is opaque type therefore we can not apply simple arithmetic to variables of pthread_t type

> > this test needs to pass a invalid pthread_t handle, typcasting (long)thread works too and is portable

> > across glibc and musl

> >

> > Fixes

> > | pth_detached3.c:24:25: error: invalid use of undefined type 'struct __pthread'

> > |    24 |   pthread_detach(thread + 8);

> > |       |                         ^

> >

> > Signed-off-by: Khem Raj <raj.khem@gmail.com>

> > ---

> >  drd/tests/pth_detached3.c | 2 +-

> >  1 file changed, 1 insertion(+), 1 deletion(-)

> >

> > diff --git a/drd/tests/pth_detached3.c b/drd/tests/pth_detached3.c

> > index c02eef11a..341193ba1 100644

> > --- a/drd/tests/pth_detached3.c

> > +++ b/drd/tests/pth_detached3.c

> > @@ -21,7 +21,7 @@ int main(int argc, char** argv)

> >    pthread_detach(thread);

> >

> >    /* Invoke pthread_detach() with an invalid thread ID. */

> > -  pthread_detach(thread + 8);

> > +  pthread_detach((pthread_t)((long)thread + 8));

> >

> >    fprintf(stderr, "Finished.\n");

>

> Is sizeof(long) always identical to sizeof(pthread_t)? How about casting

> to uintptr_t instead of to long?


Thanks for your review.
I agree using uintptr_t would be better, I have sent a v2

>

> Thanks,

>

> Bart.

>



_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers
diff mbox series

Patch

diff --git a/drd/tests/pth_detached3.c b/drd/tests/pth_detached3.c
index c02eef11a..341193ba1 100644
--- a/drd/tests/pth_detached3.c
+++ b/drd/tests/pth_detached3.c
@@ -21,7 +21,7 @@  int main(int argc, char** argv)
   pthread_detach(thread);
 
   /* Invoke pthread_detach() with an invalid thread ID. */
-  pthread_detach(thread + 8);
+  pthread_detach((pthread_t)((long)thread + 8));
 
   fprintf(stderr, "Finished.\n");