[Git][ghc/ghc][master] rts: Fix platform-dependent pointer casts

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Sat Nov 16 21:25:00 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
d9dff93a by Ben Gamari at 2024-11-16T16:23:58-05:00
rts: Fix platform-dependent pointer casts

Previously we had unnecessary (and incorrect) platform-dependent casts
to turn `OSThreadIds`s into a integer. We now just uniformly cast first
to a `uintptr_t` (which is always safe, regardless of whether
`OSThreadId` is a pointer), and then cast to the desired integral type.

This fixes a warning on musl platforms.

- - - - -


1 changed file:

- rts/Task.h


Changes:

=====================================
rts/Task.h
=====================================
@@ -314,18 +314,12 @@ typedef StgWord64 TaskId;
 //
 #if defined(THREADED_RTS)
 INLINE_HEADER TaskId serialiseTaskId (OSThreadId taskID) {
-#if defined(freebsd_HOST_OS) || defined(darwin_HOST_OS)
-    // Here OSThreadId is a pthread_t and pthread_t is a pointer, but within
+    // Here OSThreadId may be a pthread_t and pthread_t is a pointer, but within
     // the process we can still use that pointer value as a unique id.
-    return (TaskId) (size_t) taskID;
-#else
-    // On Windows, Linux and others it's an integral type to start with.
-    return (TaskId) taskID;
-#endif
+    return (TaskId) (uintptr_t) taskID;
 }
 #endif
 
-//
 // Get a serialisable Id for the Task's OS thread
 // Needed mainly for logging since the OSThreadId is an opaque type
 INLINE_HEADER TaskId
@@ -334,7 +328,7 @@ serialisableTaskId (Task *task)
 #if defined(THREADED_RTS)
     return serialiseTaskId(task->id);
 #else
-    return (TaskId) (size_t) task;
+    return (TaskId) (uintptr_t) task;
 #endif
 }
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d9dff93a3c902cead782b35e8f4003fb766cb4b7

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d9dff93a3c902cead782b35e8f4003fb766cb4b7
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241116/f1b573aa/attachment-0001.html>


More information about the ghc-commits mailing list