On Wed, Dec 24, 2014, Carsten Haitzler wrote:
> On Tue, 23 Dec 2014 18:35:20 +0100 (CET) Michelle Legrand
> <michelle.legr...@openwide.fr> said:
> 
> > So if I understood correctly, I should replace in 
> > src/lib/eina/eina_thread.h:
> > typedef unsigned long int Eina_Thread; 
> > by :
> > typedef uintptr_t Eina_Thread; 
> > 
> > like Nash suggested ?
> 
> or just unsigned long long - which in any sane world will always be 64bit.

It's still completely wrong. It might work, including on Windows with
winpthreads (but not pthreads-win32) but it's wrong.

As I've mentioned, pthread_t can be anything and the whole issue is
about assuming a specific ABI for pthread_t. The proper approach would
be to remove this typedef and avoid casts between types which aren't
guaranteed to be compatible (i.e. Eina_Thread and pthread_t).

It's obviously more work however and the platforms with a non-integer
pthread_t are quite uncommon. I've given the example of pthreads-win32
on Windows but it's not that much used nowadays and winpthreads which
usually comes with GCC on/for Windows has been created specifically for
the applications which violate the specification by assuming an ABI for
pthread_t.

Realistically I don't see this fixed properly anytime soon and would
definitely rather go for the half-fix rather than keeping the
win32-based implentation since it probably has many more bugs that are
yet to be found and solved. I'd like a check to be added however. Not
very long ago I had another ABI issue with libarchive and wrote the
following to make compilation fail if the ABIs wouldn't match. It uses
C11/C++11's static assert (or that sufficient GCC and LLVM handle it no
matter the standard).

Code can be seen outside of mail at
http://cgit.notk.org/adrien/yypkg/slackware64-current.git/tree/l/libarchive/use-static-asserts-to-guarantee-abi-compatibility.patch

/* Take advantage of static_assert/_Static_assert to make sure libarchive is
 * not built and is not used with a "struct stat" that isn't 64bits.
 * On Windows I had "stat" #define'd to "stat64" but libarchive #undef'ed it in
 * its private headers; I then built a program that used libarchive and didn't
 * have that #undef and got ABI issues: libarchive was storing a 32bit offset
 * in a "struct stat" but the caller was expecting a 64bit one.
 * This is a best effort check but which should cover most uses. */
#ifdef __cplusplus
#if (__cplusplus >= 201103L)
static_assert(sizeof(struct stat) == sizeof(struct stat64), "Not using 
largefile support");
#endif
#else
#if ((defined(__STDC_VERSION) && __STDC_VERSION >= 201112L) \
    || (defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 6)) \
    || (defined(__clang__) && (__clang_major__ >= 3) && (__clang_minor__ >= 4)))
_Static_assert(sizeof(struct stat) == sizeof(struct stat64), "Not using 
largefile support");
#endif
#endif

-- 
Adrien Nader

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to