From:             dev at pp3345 dot net
Operating system: Linux
PHP version:      5.5.0RC2
Package:          *Compile Issues
Bug Type:         Feature/Change Request
Bug description:Make life for extension developers just a little bit easier

Description:
------------
This is not quite a bug, rather a little annoyance for extension
developers. See 
the following struct, defined in /main/SAPI.h on line 
118:

typedef struct _sapi_globals_struct {
        void *server_context;
        sapi_request_info request_info;
        sapi_headers_struct sapi_headers;
        int read_post_bytes;
        unsigned char headers_sent;
        struct stat global_stat;
        char *default_mimetype;
        char *default_charset;
        HashTable *rfc1867_uploaded_files;
        long post_max_size;
        int options;
        zend_bool sapi_started;
        double global_request_time;
        HashTable known_post_content_types;
        zval *callback_func;
        zend_fcall_info_cache fci_cache;
        zend_bool callback_run;
} sapi_globals_struct;

used for sapi_globals. All elements except global_stat will have the same
size 
across different systems. When an extension tries to 
access elements that lie behind global_stat this can lead to problems (like

segfaults) due to different compiled offsets. This is not a 
problem as long as the extension is compiled on the same system as PHP,
however, 
for example closed-source extensions are distributed as 
precompiled binaries.

In order to avoid problems due to different compiled offsets when trying to

access sapi_globals I'd suggest placing global_stat at the 
end of the struct instead of the middle. This should not lead to any
problems 
but will make life for extension developers easier since 
they don't have to invent ugly and probably buggy workarounds. For BC with

already existing extensions I'd recommend patching this for 
PHP 5.5, but not for PHP 5.4. Extensions will have to be recompiled for 5.5

anyway.

I know that some fancy compiler options for memory alignment will mess up
the 
offsets within the struct too, but I think it's safe to 
assume that these are not common, especially since Zend itself seems to
assume 
specific offsets in some places too.


-- 
Edit bug report at https://bugs.php.net/bug.php?id=64950&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64950&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64950&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64950&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64950&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64950&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64950&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64950&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64950&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64950&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64950&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64950&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64950&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64950&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64950&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64950&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64950&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64950&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64950&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64950&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64950&r=mysqlcfg

Reply via email to