Archived

This forum has been archived. Please start a new discussion on GitHub.

OpenSSLPluginI.cpp problem on FreeBSD-CURRENT

Hi,

I am using:
FreeBSD-CURRENT
gcc version 3.2.2 [FreeBSD] 20030205 (release)

On FreeBSD, pthread_t is a typedef for "struct pthread *"

When compiling IceSSL, I get this error:
OpenSSLPluginI.cpp: In function `long unsigned int idFunction()':
OpenSSLPluginI.cpp:151: invalid static_cast from type `pthread*' to type `long
unsigned int'

Why is a static_cast necessary for this code? If I change to a C-style cast,
the problem goes away:

--- OpenSSLPluginI.cpp.orig Wed May 28 17:58:00 2003
+++ OpenSSLPluginI.cpp Thu May 29 22:34:13 2003

#ifdef _WIN32
return static_cast<unsigned long>(GetCurrentThreadId());
#else
- return static_cast<unsigned long>(pthread_self());
+ return (unsigned long)pthread_self();
#endif
}
}

Comments

  • bernard
    bernard Jupiter, FL
    Hi Craig,

    This code should use a conditional for each platform: pthread_t is an opaque type, and any "automatic" convertion to an integer is somewhat dangerous, as it could yield the same id for different threads on some platform.

    On FreeBSD since pthread_t is a pointer to a per-thread structure, you can safely use reinterpret_cast<unsigned long>(pthread_self()).

    On Tru64, for example, the correct code would be pthread_getsequence_np(pthread_self()).

    Cheers,
    Bernard
  • OK, then I submit this patch.

    --- OpenSSLPluginI.cpp.orig Wed May 28 17:58:00 2003
    +++ OpenSSLPluginI.cpp Fri May 30 08:51:42 2003

    {
    #ifdef _WIN32
    return static_cast<unsigned long>(GetCurrentThreadId());
    +#elif defined(__FreeBSD__)
    + return reinterpret_cast<unsigned long>(pthread_self());
    #else
    return static_cast<unsigned long>(pthread_self());
    #endif