PATCH ssize_t without messing with fcgi source

php.internals

Steph

22 years ago
Works with everything. (phew!) Wez?? - Steph

Ard Biesheuvel

22 years ago
> Works with everything. (phew!) >
You might wanna use long instead of int here, as sizeof(ssize_t) is supposed to match the native pointer size.
-- Ard

Steph

22 years ago
Ard, hi - ssize_t was originally defined as ptrdiff_t in config.w32.h, which is itself defined as int in win32 (in stddef.h). It was then redefined as int in the fcgi configuration. It was also redefined in gd_jpeg.c (one of the few win32-affecting places that uses it) prior to any includes: #if PHP_WIN32 && !defined(ssize_t) typedef int ssize_t; #endif - this was originally preventing some of the gd functions from working, because ssize_t WAS defined already (in config.w32.h) - as ptrdiff_t, which there was no definition for that gd_jpeg.c knew of. From to the Single Unix Specification (http://www.opengroup.org/onlinepubs/007908799/xsh/systypes.h.html): "ssize_t Used for a count of bytes or an error indication. <snip/> ssize_t is a signed integral type .. capable of storing values at least in the range [-1, SSIZE_MAX]." Windows - uniquely - uses the definition SSIZE_T (type: INT_PTR) - note that ssize_t isn't the same thing as SSIZE_T, anywhere - but if I go that route for ssize_t definition (as I already tried to do) we end up with the fcgi redefinition to int anyway. Basically all I'm doing here is going back to the original, just saying it in a less obfuscated and more generic way :) so if it breaks on 64-bit architectures (which it shouldn't), it's not going to break in a way that it wouldn't have broken if I'd never been born. If you follow. Steph

Ard Biesheuvel

22 years ago
Steph,
> Windows - uniquely - uses the definition SSIZE_T (type: INT_PTR) - note > that ssize_t isn't the same thing as SSIZE_T, anywhere - but if I go that > route for ssize_t definition (as I already tried to do) we end up with the > fcgi redefinition to int anyway. > > Basically all I'm doing here is going back to the original, just saying it > in a less obfuscated and more generic way :) so if it breaks on 64-bit > architectures (which it shouldn't), it's not going to break in a way that it > wouldn't have broken if I'd never been born. If you follow.
... except that INT_PTR is 64-bit on Win64, and int is not.
-- Ard

Steph

22 years ago
> ... except that INT_PTR is 64-bit on Win64, and int is not. >
yeah, I just found that too :) This means that php-src is currently correct for all architectures but fcgi src is not. So what's the best line of attack here? #ifdef _WIN64 + # define ssize_t SSIZE_T # define SIZEOF_SIZE_T 8 # define SIZEOF_PTRDIFF_T 8 #else + # define ssize_t int # define SIZEOF_SIZE_T 4 # define SIZEOF_PTRDIFF_T 4 #endif ?

Ard Biesheuvel

22 years ago
Steph wrote:
>>... except that INT_PTR is 64-bit on Win64, and int is not. >> > > yeah, I just found that too :) > > This means that php-src is currently correct for all architectures but fcgi > src is not. So what's the best line of attack here?
What about #define ssize_t INT_PTR for Win{32|64} ??
-- Ard

Steph

22 years ago
> What about > > #define ssize_t INT_PTR > > for Win{32|64} ?? > > -- > Ard
SSIZE_T is already an INT_PTR in both architectures. Calling it INT_PTR directly, doesn't actually change anything from the current php-src (the patch Edin put in for me yesterday). The objection Wez made to that was that it involves either altering fcgi source or living with the subsequent redefinition (to int). All I want for Christmas is to get the number of PHP5 win32 warnings down to a sane level, if fcgi configuration is b0rked on win64 currently there's not a great deal we can do about it (exceptions: Sascha, Shane, Frank). int works for win32, and is the most frequently used definition of ssize_t I've come across for systems without sys/types.h. It would be nicer if fcgi's win32|64 configuration used SSIZE_T, but it doesn't...

Ard Biesheuvel

22 years ago
Steph wrote:
> Works with everything. (phew!)
Are you sure this will work on Win64 ? I think sizeof(ssize_t) is supposed to match the native pointer size.
-- Ard