]> granicus.if.org Git - php/commitdiff
Streams now make more use of the memory manager, so tracking down
authorWez Furlong <wez@php.net>
Sun, 17 Mar 2002 22:50:59 +0000 (22:50 +0000)
committerWez Furlong <wez@php.net>
Sun, 17 Mar 2002 22:50:59 +0000 (22:50 +0000)
leaking streams should be easier.
# I hate these big commits

20 files changed:
ext/exif/exif.c
ext/ftp/php_ftp.c
ext/gd/gd.c
ext/mailparse/mailparse.c
ext/ming/ming.c
ext/pgsql/pgsql.c
ext/standard/basic_functions.c
ext/standard/ftp_fopen_wrapper.c
ext/standard/http_fopen_wrapper.c
ext/standard/image.c
ext/standard/php_fopen_wrapper.c
ext/standard/php_fopen_wrappers.h
ext/zlib/php_zlib.h
ext/zlib/zlib.c
ext/zlib/zlib_fopen_wrapper.c
main/main.c
main/network.c
main/php_network.h
main/php_streams.h
main/streams.c

index 37b60276cdb5252eda6347b5959af584c67876be..5cb796ee6cb290e5c5b86fa97d89b3dcb6abe1c6 100644 (file)
@@ -2960,7 +2960,7 @@ int exif_read_file(image_info_type *ImageInfo, char *FileName, int read_thumbnai
        ImageInfo->motorola_intel = 0;
 
        #ifdef HAVE_PHP_STREAM
-       ImageInfo->infile = php_stream_open_wrapper(FileName, "rb", IGNORE_PATH|ENFORCE_SAFE_MODE, NULL TSRMLS_CC);
+       ImageInfo->infile = php_stream_open_wrapper(FileName, "rb", IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
        #else
        ImageInfo->infile = VCWD_FOPEN(FileName, "rb"); /* Unix ignores 'b', windows needs it. */
        #endif
@@ -3264,7 +3264,7 @@ PHP_FUNCTION(exif_imagetype)
        if (zend_get_parameters_ex(1, &arg1) == FAILURE)
                WRONG_PARAM_COUNT;
 
-       stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb", IGNORE_PATH|ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL TSRMLS_CC);
+       stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb", IGNORE_PATH|ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL);
 
        if (stream == NULL)     {
                RETURN_FALSE;
index 1012698966a452b7a6ac1681c022ecce5da73daa..d3fd331bfab7ebf0cb82c7f3912cae20ad9aaf2e 100644 (file)
@@ -480,7 +480,7 @@ PHP_FUNCTION(ftp_get)
                RETURN_FALSE;
        }
 
-       outstream = php_stream_fopen(local, "wb", NULL TSRMLS_CC);
+       outstream = php_stream_fopen(local, "wb", NULL);
 
        if (outstream == NULL)  {
                php_stream_close(tmpstream);
@@ -547,7 +547,7 @@ PHP_FUNCTION(ftp_put)
        ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
        XTYPE(xtype, mode);
 
-       instream = php_stream_fopen(local, "rb", NULL TSRMLS_CC);
+       instream = php_stream_fopen(local, "rb", NULL);
 
        if (instream == NULL)   {
                RETURN_FALSE;
index 30ed56779245105a4777d444c3a3d4426c40d49d..93766aa1c245e9958359e7fec8fc8328dbe2d4b6 100644 (file)
@@ -449,7 +449,7 @@ PHP_FUNCTION(imageloadfont)
 
        convert_to_string_ex(file);
 
-       stream = php_stream_open_wrapper(Z_STRVAL_PP(file), "rb", IGNORE_PATH|IGNORE_URL_WIN|REPORT_ERRORS, NULL TSRMLS_CC);
+       stream = php_stream_open_wrapper(Z_STRVAL_PP(file), "rb", IGNORE_PATH|IGNORE_URL_WIN|REPORT_ERRORS, NULL);
        if (stream == NULL) {
                RETURN_FALSE;
        }
@@ -1150,7 +1150,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
        
        fn = Z_STRVAL_PP(file);
 
-       stream = php_stream_open_wrapper(fn, "rb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL TSRMLS_CC);
+       stream = php_stream_open_wrapper(fn, "rb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
        if (stream == NULL)     {
                RETURN_FALSE;
        }
index b86ee79aded47d52a818d69c70afb29a2b8149ff..3df3df56a0d0dd92bc332b48e547e97f084950b0 100755 (executable)
@@ -193,7 +193,7 @@ PHP_FUNCTION(mailparse_uudecode_all)
        instream = (php_stream*)zend_fetch_resource(&file TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream());
        ZEND_VERIFY_RESOURCE(instream);
 
-       outstream = php_stream_fopen_temporary_file(NULL, "mailparse", &outpath TSRMLS_CC);
+       outstream = php_stream_fopen_temporary_file(NULL, "mailparse", &outpath);
        if (outstream == NULL)  {
                zend_error(E_WARNING, "%s(): unable to open temp file", get_active_function_name(TSRMLS_C));
                RETURN_FALSE;
@@ -232,7 +232,7 @@ PHP_FUNCTION(mailparse_uudecode_all)
                        add_assoc_string(item, "origfilename", origfilename, 1);
 
                        /* create a temp file for the data */
-                       partstream = php_stream_fopen_temporary_file(NULL, "mailparse", &outpath TSRMLS_CC);
+                       partstream = php_stream_fopen_temporary_file(NULL, "mailparse", &outpath);
                        if (partstream) {
                                nparts++;
                                add_assoc_string(item, "filename", outpath, 0);
index 7233e3e4d24f838cc34280cb1e244fc1adb82a01..7cf91e00276869fa5f408e1de36c25b952fddf53 100644 (file)
@@ -1157,7 +1157,7 @@ PHP_FUNCTION(swffont_init)
     php_stream * stream;
        FILE * file;
        
-    stream = php_stream_open_wrapper(Z_STRVAL_PP(zfile), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL TSRMLS_CC);
+    stream = php_stream_open_wrapper(Z_STRVAL_PP(zfile), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
 
     if(stream == NULL) {
                RETURN_FALSE;
@@ -1602,7 +1602,7 @@ PHP_FUNCTION(swfmovie_save)
 
   convert_to_string_ex(x);
 
-  stream = php_stream_open_wrapper(Z_STRVAL_PP(x), "wb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL TSRMLS_CC);
+  stream = php_stream_open_wrapper(Z_STRVAL_PP(x), "wb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
 
   if (stream == NULL)
          RETURN_FALSE;
index 43eae5d0d4bf373a813690080b9eabd501f34685..e82379127e76cbf34224015e518926dfc69345e5 100644 (file)
@@ -1468,7 +1468,7 @@ PHP_FUNCTION(pg_trace)
     ZEND_FETCH_RESOURCE2(pgsql, PGconn *, z_pgsql_link, id, "PostgreSQL link", le_link, le_plink);
        convert_to_string_ex(z_filename);
 
-       stream = php_stream_open_wrapper(Z_STRVAL_PP(z_filename), mode, ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL TSRMLS_CC);
+       stream = php_stream_open_wrapper(Z_STRVAL_PP(z_filename), mode, ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL);
 
        if (!stream) {
                RETURN_FALSE;
index b0607df3eaebe4b5bb885768291e26c8a1343950..faec631bfba69ab0d748623b1c1943b586ace105 100644 (file)
@@ -1005,14 +1005,14 @@ PHP_MINIT_FUNCTION(basic)
 
 
        if (PG(allow_url_fopen)) {
-               if (FAILURE == php_register_url_stream_wrapper("http", &php_stream_http_wrapper TSRMLS_CC))
+               if (FAILURE == php_register_url_stream_wrapper("http", &php_stream_http_wrapper))
                        return FAILURE;
-               if (FAILURE == php_register_url_stream_wrapper("php", &php_stream_php_wrapper TSRMLS_CC))
+               if (FAILURE == php_register_url_stream_wrapper("php", &php_stream_php_wrapper))
                        return FAILURE;
-               if (FAILURE == php_register_url_stream_wrapper("ftp", &php_stream_ftp_wrapper TSRMLS_CC))
+               if (FAILURE == php_register_url_stream_wrapper("ftp", &php_stream_ftp_wrapper))
                        return FAILURE;
 # if HAVE_OPENSSL_EXT
-               if (FAILURE == php_register_url_stream_wrapper("https", &php_stream_http_wrapper TSRMLS_CC))
+               if (FAILURE == php_register_url_stream_wrapper("https", &php_stream_http_wrapper))
                        return FAILURE;
 # endif
        }
@@ -1030,11 +1030,11 @@ PHP_MSHUTDOWN_FUNCTION(basic)
 #endif
 
        if (PG(allow_url_fopen)) {
-               php_unregister_url_stream_wrapper("http" TSRMLS_CC);
-               php_unregister_url_stream_wrapper("ftp" TSRMLS_CC);
-               php_unregister_url_stream_wrapper("php" TSRMLS_CC);
+               php_unregister_url_stream_wrapper("http");
+               php_unregister_url_stream_wrapper("ftp");
+               php_unregister_url_stream_wrapper("php");
 # if HAVE_OPENSSL_EXT
-               php_unregister_url_stream_wrapper("https" TSRMLS_CC);
+               php_unregister_url_stream_wrapper("https");
 # endif
 
        }
@@ -1532,7 +1532,7 @@ PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers T
                        break;
 
                case 3:         /*save to a file */
-                       stream = php_stream_open_wrapper(opt, "a", IGNORE_URL | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL TSRMLS_CC);
+                       stream = php_stream_open_wrapper(opt, "a", IGNORE_URL | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL);
                        if (!stream)
                                return FAILURE;
                        php_stream_write(stream, message, strlen(message));
index ade1e86f362b0c0c24e07f5a1f4c00a27e7ea848..8cd85b30d2abbadbedcced6dc2f504f726036eef 100644 (file)
@@ -85,7 +85,7 @@ php_stream_wrapper php_stream_ftp_wrapper =   {
 
 /* {{{ php_fopen_url_wrap_ftp
  */
-php_stream * php_stream_url_wrap_ftp(char *path, char *mode, int options, char **opened_path TSRMLS_DC)
+php_stream * php_stream_url_wrap_ftp(char *path, char *mode, int options, char **opened_path STREAMS_DC)
 {
        php_stream *stream=NULL;
        php_url *resource=NULL;
index 9cada1fb52d7b709fb6a1033609e500e036e6375..c5e5e3c037a68e41199a04ad5e6ea28191180be5 100644 (file)
@@ -71,7 +71,7 @@
 #define HTTP_HEADER_BLOCK_SIZE         1024
 
 
-php_stream *php_stream_url_wrap_http(char *path, char *mode, int options, char **opened_path TSRMLS_DC)
+php_stream *php_stream_url_wrap_http(char *path, char *mode, int options, char **opened_path STREAMS_DC)
 {
        php_stream *stream = NULL;
        php_url *resource = NULL;
@@ -268,7 +268,7 @@ php_stream *php_stream_url_wrap_http(char *path, char *mode, int options, char *
                        else {
                                strlcpy(new_path, location, sizeof(new_path));
                        }
-                       stream = php_stream_url_wrap_http(new_path, mode, options, opened_path TSRMLS_CC);
+                       stream = php_stream_url_wrap_http(new_path, mode, options, opened_path STREAMS_CC);
                        if (stream->wrapperdata)        {
                                entryp = &entry;
                                MAKE_STD_ZVAL(entry);
index 9761fb18453ddb737c8be1103761eaeb588a2744..73baa53158dea180001419b85ceffdcd0d58b832 100644 (file)
@@ -717,7 +717,7 @@ PHP_FUNCTION(getimagesize)
                break;
        }
 
-       stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb", REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL TSRMLS_CC);
+       stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb", REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
 
        if (!stream) {
                RETURN_FALSE;
index 37b3b2b90fd86b4ca96d52d90eda3ffa6b8e9162..3a56bd6706aea21696ad5a899d84c969daccacca 100644 (file)
@@ -30,7 +30,7 @@
 #include "php_standard.h"
 #include "php_fopen_wrappers.h"
 
-php_stream * php_stream_url_wrap_php(char * path, char * mode, int options, char ** opened_path TSRMLS_DC)
+php_stream * php_stream_url_wrap_php(char * path, char * mode, int options, char ** opened_path STREAMS_DC)
 {
        FILE * fp = NULL;
        php_stream * stream = NULL;
index 0d235b945d3ef728dd0c3975dbbfa3d14a202d3c..d41d8cf4e67e30b1d751ed8b1166919dfbb73032 100644 (file)
@@ -23,8 +23,8 @@
 #ifndef PHP_FOPEN_WRAPPERS_H
 #define PHP_FOPEN_WRAPPERS_H
 
-php_stream *php_stream_url_wrap_http(char *path, char *mode, int options, char **opened_path TSRMLS_DC);
-php_stream *php_stream_url_wrap_ftp(char *path, char *mode, int options, char **opened_path TSRMLS_DC);
+php_stream *php_stream_url_wrap_http(char *path, char *mode, int options, char **opened_path STREAMS_DC);
+php_stream *php_stream_url_wrap_ftp(char *path, char *mode, int options, char **opened_path STREAMS_DC);
 php_stream_wrapper php_stream_http_wrapper;
 php_stream_wrapper php_stream_ftp_wrapper;
 php_stream_wrapper php_stream_php_wrapper;
index 10a40cd96a7c40cc48c304fffe53046359434ec0..2c603d3e763688aad5e30bed7988cfb10e54d3b0 100644 (file)
@@ -64,10 +64,9 @@ PHP_FUNCTION(gzinflate);
 PHP_FUNCTION(gzencode);
 PHP_FUNCTION(ob_gzhandler);
 
-FILE *zlib_fopen_wrapper(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path TSRMLS_DC);
 int php_enable_output_compression(int buffer_size TSRMLS_DC);
 
-php_stream *php_stream_gzopen(char *path, char *mode, int options, char **opened_path TSRMLS_DC);
+php_stream *php_stream_gzopen(char *path, char *mode, int options, char **opened_path STREAMS_DC);
 extern php_stream_ops php_stream_gzio_ops;
 extern php_stream_wrapper php_stream_gzip_wrapper;
 
index 44edcbdcd320a84addd8a709c5b1859225f2e9dd..35ef2a179dfed8e1d494498c30ae2b40f1aee81a 100644 (file)
@@ -188,7 +188,7 @@ PHP_MINIT_FUNCTION(zlib)
        le_zp = zend_register_list_destructors_ex(phpi_destructor_gzclose, NULL, "zlib", module_number);
 
        if(PG(allow_url_fopen)) {
-               php_register_url_stream_wrapper("zlib", &php_stream_gzip_wrapper TSRMLS_CC);
+               php_register_url_stream_wrapper("zlib", &php_stream_gzip_wrapper);
        }
 
        REGISTER_LONG_CONSTANT("FORCE_GZIP", CODING_GZIP, CONST_CS | CONST_PERSISTENT);
@@ -255,7 +255,7 @@ static gzFile php_gzopen_wrapper(char *path, char *mode, int options TSRMLS_DC)
        php_stream *stream = NULL;
        int fd;
 
-       stream = php_stream_open_wrapper(path, mode, options | REPORT_ERRORS, NULL TSRMLS_CC);
+       stream = php_stream_open_wrapper(path, mode, options | REPORT_ERRORS, NULL);
        if (stream)     {
                if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD|PHP_STREAM_CAST_TRY_HARD, (void**)&fd, 1))
                {
@@ -302,7 +302,7 @@ PHP_FUNCTION(gzfile)
        convert_to_string_ex(filename);
 
        /* using a stream here is a bit more efficient (resource wise) than php_gzopen_wrapper */
-       stream = php_stream_gzopen(Z_STRVAL_PP(filename), "rb", use_include_path|ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL TSRMLS_CC);
+       stream = php_stream_gzopen(Z_STRVAL_PP(filename), "rb", use_include_path|ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL STREAMS_CC);
        if (stream == NULL) {
                php_error(E_WARNING,"gzFile(\"%s\") - %s",Z_STRVAL_PP(filename),strerror(errno));
                RETURN_FALSE;
index 5d3129f8435a078fea646ef5c16ccf18df85d005..c28ab6a1e5afe32a96e36c6305f5adc977ff5140 100644 (file)
@@ -80,7 +80,7 @@ php_stream_ops php_stream_gzio_ops = {
        NULL, "ZLIB"
 };
 
-php_stream *php_stream_gzopen(char *path, char *mode, int options, char **opened_path TSRMLS_DC)
+php_stream *php_stream_gzopen(char *path, char *mode, int options, char **opened_path STREAMS_DC)
 {
        struct php_gz_stream_data_t *self;
        php_stream *stream = NULL;
@@ -90,7 +90,7 @@ php_stream *php_stream_gzopen(char *path, char *mode, int options, char **opened
        if (strncmp("zlib:", path, 5) == 0)
                path += 5;
        
-       self->stream = php_stream_open_wrapper(path, mode, options, opened_path TSRMLS_CC);
+       self->stream = php_stream_open_wrapper(path, mode, options, opened_path);
        
        if (self->stream) {
                int fd;
index 187286ad49d4c1c7f1d09f927b049197e5e09dbb..5e05ac0018a8b1551cc06a6b422b2b57c6f064dd 100644 (file)
@@ -565,9 +565,8 @@ static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path
 {
        FILE *retval = NULL;
        php_stream *stream;
-       TSRMLS_FETCH();
 
-       stream = php_stream_open_wrapper((char *)filename, "rb", USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS, opened_path TSRMLS_CC);
+       stream = php_stream_open_wrapper((char *)filename, "rb", USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS, opened_path);
        if (stream)     {
                /* no need for us to check the stream type here */
                php_stream_sock_set_chunk_size(stream, 1);
@@ -952,7 +951,7 @@ int php_module_startup(sapi_module_struct *sf)
        /* initialize stream wrappers registry
         * (this uses configuration parameters from php.ini)
         */
-       if (php_init_stream_wrappers(TSRMLS_C) == FAILURE)      {
+       if (php_init_stream_wrappers() == FAILURE)      {
                php_printf("PHP:  Unable to initialize stream url wrappers.\n");
                return FAILURE;
        }
@@ -1057,7 +1056,7 @@ void php_module_shutdown(TSRMLS_D)
 
        zend_shutdown(TSRMLS_C);
 
-       php_shutdown_stream_wrappers(TSRMLS_C);
+       php_shutdown_stream_wrappers();
 
        php_shutdown_info_logos();
        UNREGISTER_INI_ENTRIES();
index eff166634403eb47e00f8d9ed4f83b8549912893..3ae5861c7401f91bc745bb89fd836ad5ecd6e94e 100644 (file)
@@ -413,7 +413,7 @@ int php_sockaddr_size(php_sockaddr_storage *addr)
 }
 /* }}} */
 
-PHPAPI php_stream *php_stream_sock_open_from_socket(int socket, int persistent)
+PHPAPI php_stream *_php_stream_sock_open_from_socket(int socket, int persistent STREAMS_DC)
 {
        php_stream *stream;
        php_netstream_data_t *sock;
@@ -426,7 +426,7 @@ PHPAPI php_stream *php_stream_sock_open_from_socket(int socket, int persistent)
        sock->timeout.tv_sec = -1;
        sock->socket = socket;
 
-       stream = php_stream_alloc(&php_stream_socket_ops, sock, persistent, "r+");
+       stream = php_stream_alloc_rel(&php_stream_socket_ops, sock, persistent, "r+");
 
        if (stream == NULL)     
                pefree(sock, persistent);
@@ -434,8 +434,8 @@ PHPAPI php_stream *php_stream_sock_open_from_socket(int socket, int persistent)
        return stream;
 }
 
-PHPAPI php_stream *php_stream_sock_open_host(const char *host, unsigned short port,
-               int socktype, int timeout, int persistent)
+PHPAPI php_stream *_php_stream_sock_open_host(const char *host, unsigned short port,
+               int socktype, int timeout, int persistent STREAMS_DC)
 {
        int socket;
 
@@ -444,10 +444,11 @@ PHPAPI php_stream *php_stream_sock_open_host(const char *host, unsigned short po
        if (socket == -1)
                return NULL;
 
-       return php_stream_sock_open_from_socket(socket, persistent);
+       return php_stream_sock_open_from_socket_rel(socket, persistent);
 }
 
-PHPAPI php_stream *php_stream_sock_open_unix(const char *path, int pathlen, int persistent, struct timeval *timeout)
+PHPAPI php_stream *_php_stream_sock_open_unix(const char *path, int pathlen, int persistent,
+               struct timeval *timeout STREAMS_DC)
 {
 #if defined(AF_UNIX)
        int socketd;
@@ -476,7 +477,7 @@ PHPAPI php_stream *php_stream_sock_open_unix(const char *path, int pathlen, int
        if (php_connect_nonb(socketd, (struct sockaddr *) &unix_addr, sizeof(unix_addr), timeout) == SOCK_CONN_ERR) 
                return NULL;
 
-       return php_stream_sock_open_from_socket(socketd, persistent);
+       return php_stream_sock_open_from_socket_rel(socketd, persistent);
 #else
        return NULL;
 #endif
index b51177ceae3c2912988b11ad7a7ca1a23670a09c..caae0a97d351c309ef3715f4e408e8ab69d2ba69 100644 (file)
@@ -112,11 +112,23 @@ typedef struct _php_netstream_data_t php_netstream_data_t;
 extern php_stream_ops php_stream_socket_ops;
 #define PHP_STREAM_IS_SOCKET   (&php_stream_socket_ops)
 
-PHPAPI php_stream *php_stream_sock_open_from_socket(int socket, int persistent);
+PHPAPI php_stream *_php_stream_sock_open_from_socket(int socket, int persistent STREAMS_DC);
 /* open a connection to a host using php_hostconnect and return a stream */
-PHPAPI php_stream *php_stream_sock_open_host(const char *host, unsigned short port,
-               int socktype, int timeout, int persistent);
-PHPAPI php_stream *php_stream_sock_open_unix(const char *path, int pathlen, int persistent, struct timeval *timeout);
+PHPAPI php_stream *_php_stream_sock_open_host(const char *host, unsigned short port,
+               int socktype, int timeout, int persistent STREAMS_DC);
+PHPAPI php_stream *_php_stream_sock_open_unix(const char *path, int pathlen, int persistent,
+               struct timeval *timeout STREAMS_DC);
+
+#define php_stream_sock_open_from_socket(socket, persistent)   _php_stream_sock_open_from_socket((socket), (persistent) STREAMS_CC)
+#define php_stream_sock_open_host(host, port, socktype, timeout, persistent)   _php_stream_sock_open_host((host), (port), (socktype), (timeout), (persistent) STREAMS_CC)
+#define php_stream_sock_open_unix(path, pathlen, persistent, timeval)  _php_stream_sock_open_unix((path), (pathlen), (persistent), (timeval) STREAMS_CC)
+
+/* {{{ memory debug */
+#define php_stream_sock_open_from_socket_rel(socket, persistent)       _php_stream_sock_open_from_socket((socket), (persistent) STREAMS_REL_CC)
+#define php_stream_sock_open_host_rel(host, port, socktype, timeout, persistent)       _php_stream_sock_open_host((host), (port), (socktype), (timeout), (persistent) STREAMS_REL_CC)
+#define php_stream_sock_open_unix_rel(path, pathlen, persistent, timeval)      _php_stream_sock_open_unix((path), (pathlen), (persistent), (timeval) STREAMS_REL_CC)
+
+/* }}} */
 
 PHPAPI void php_stream_sock_set_timeout(php_stream *stream, struct timeval *timeout);
 PHPAPI int php_stream_sock_set_blocking(php_stream *stream, int mode);
index 402156c33508eb913f224ae47e09f65f145574cf..7141da21a112afa89be282f42d9e993530860530 100755 (executable)
 
 /* See README.STREAMS in php4 root dir for more info about this stuff */
 
+/* {{{ Streams memory debugging stuff */
+
+#if ZEND_DEBUG
+/* these have more of a dependency on the definitions of the zend macros than
+ * I would prefer, but doing it this way saves loads of idefs :-/ */
+# define STREAMS_D                     int __php_stream_call_depth ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC
+# define STREAMS_C                     0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC
+# define STREAMS_REL_C         __php_stream_call_depth + 1 ZEND_FILE_LINE_CC, \
+       __php_stream_call_depth ? __zend_orig_filename : __zend_filename, \
+       __php_stream_call_depth ? __zend_orig_lineno : __zend_lineno \
+       TSRMLS_CC
+
+# define STREAMS_DC            , STREAMS_D
+# define STREAMS_CC            , STREAMS_C
+# define STREAMS_REL_CC        , STREAMS_REL_C
+#else
+# define STREAMS_D             TSRMLS_D
+# define STREAMS_C             TSRMLS_C
+# define STREAMS_REL_C TSRMLS_C
+# define STREAMS_DC            TSRMLS_DC
+# define STREAMS_CC            TSRMLS_CC
+# define STREAMS_REL_CC        TSRMLS_CC
+#endif
+
+/* these functions relay the file/line number information. They are depth aware, so they will pass
+ * the ultimate ancestor, which is useful, because there can be several layers of calls */
+#define php_stream_alloc_rel(ops, thisptr, persistent, mode) _php_stream_alloc((ops), (thisptr), (persistent), (mode) STREAMS_REL_CC)
+
+#define php_stream_copy_to_mem_rel(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_REL_CC)
+       
+#define php_stream_fopen_rel(filename, mode, opened) _php_stream_fopen((filename), (mode), (opened) STREAMS_REL_CC)
+
+#define php_stream_fopen_with_path_rel(filename, mode, path, opened) _php_stream_fopen_with_path((filename), (mode), (path), (opened) STREAMS_REL_CC)
+
+#define php_stream_fopen_from_file_rel(file, mode)      _php_stream_fopen_from_file((file), (mode) STREAMS_REL_CC)
+       
+#define php_stream_fopen_from_pipe_rel(file, mode)      _php_stream_fopen_from_pipe((file), (mode) STREAMS_REL_CC)
+       
+#define php_stream_fopen_tmpfile_rel() _php_stream_fopen_tmpfile(STREAMS_REL_C)
+
+#define php_stream_fopen_temporary_file_rel(dir, pfx, opened_path)     _php_stream_fopen_temporary_file((dir), (pfx), (opened_path) STREAMS_REL_CC)
+       
+#define php_stream_open_wrapper_rel(path, mode, options, opened) _php_stream_open_wrapper((path), (mode), (options), (opened) STREAMS_REL_CC)
+
+#define php_stream_make_seekable_rel(origstream, newstream) _php_stream_make_seekable(origstream, newstream STREAMS_REL_CC)
+
+/* }}} */
+       
 /* The contents of the php_stream_ops and php_stream should only be accessed
  * using the functions/macros in this header.
  * If you need to get at something that doesn't have an API,
@@ -53,7 +101,7 @@ typedef struct _php_stream_ops  {
 } php_stream_ops;
 
 /* options uses the IGNORE_URL family of defines from fopen_wrappers.h */
-typedef php_stream *(*php_stream_factory_func_t)(char *filename, char *mode, int options, char **opened_path TSRMLS_DC);
+typedef php_stream *(*php_stream_factory_func_t)(char *filename, char *mode, int options, char **opened_path STREAMS_DC);
 typedef void (*php_stream_wrapper_dtor_func_t)(php_stream *stream);
 
 typedef struct _php_stream_wrapper     {
@@ -83,7 +131,9 @@ struct _php_stream  {
 
 
 /* allocate a new stream for a particular ops */
-PHPAPI php_stream *php_stream_alloc(php_stream_ops *ops, void *abstract, int persistent, const char *mode);
+PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract,
+               int persistent, const char *mode STREAMS_DC);
+#define php_stream_alloc(ops, thisptr, persistent, mode)       _php_stream_alloc((ops), (thisptr), (persistent), (mode) STREAMS_CC)
 
 PHPAPI int php_stream_free(php_stream *stream, int call_dtor);
 #define php_stream_close(stream)       php_stream_free(stream, 1)
@@ -107,7 +157,10 @@ PHPAPI int php_stream_puts(php_stream *stream, char *buf);
 PHPAPI size_t php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen);
 /* read all data from stream and put into a buffer. Caller must free buffer when done.
  * The copy will use mmap if available. */
-PHPAPI size_t php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent);
+PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen,
+               int persistent STREAMS_DC);
+#define php_stream_copy_to_mem(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_CC)
+
 
 /* maybe implement someday */
 #define php_stream_error(stream)       (0)
@@ -115,12 +168,23 @@ PHPAPI size_t php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen,
 /* operations for a stdio FILE; use the php_stream_fopen_XXX funcs below */
 extern php_stream_ops php_stream_stdio_ops;
 /* like fopen, but returns a stream */
-PHPAPI php_stream *php_stream_fopen(const char *filename, const char *mode, char **opened_path TSRMLS_DC);
-PHPAPI php_stream *php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path TSRMLS_DC);
-PHPAPI php_stream *php_stream_fopen_from_file(FILE *file, const char *mode);
-PHPAPI php_stream *php_stream_fopen_from_pipe(FILE *file, const char *mode);
-PHPAPI php_stream *php_stream_fopen_tmpfile(void);
-PHPAPI php_stream *php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path TSRMLS_DC);
+PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path STREAMS_DC);
+#define php_stream_fopen(filename, mode, opened)       _php_stream_fopen((filename), (mode), (opened) STREAMS_CC)
+
+PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path STREAMS_DC);
+#define php_stream_fopen_with_path(filename, mode, path, opened)       _php_stream_fopen_with_path((filename), (mode), (path), (opened) STREAMS_CC)
+
+PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC);
+#define php_stream_fopen_from_file(file, mode) _php_stream_fopen_from_file((file), (mode) STREAMS_CC)
+
+PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STREAMS_DC);
+#define php_stream_fopen_from_pipe(file, mode) _php_stream_fopen_from_pipe((file), (mode) STREAMS_CC)
+
+PHPAPI php_stream *_php_stream_fopen_tmpfile(STREAMS_D);
+#define php_stream_fopen_tmpfile()     _php_stream_fopen_tmpfile(STREAMS_C)
+
+PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path STREAMS_DC);
+#define php_stream_fopen_temporary_file(dir, pfx, opened_path) _php_stream_fopen_temporary_file((dir), (pfx), (opened_path) STREAMS_CC)
 
 /* coerce the stream into some other form */
 /* cast as a stdio FILE * */
@@ -163,18 +227,20 @@ PHPAPI int php_stream_cast(php_stream *stream, int castas, void **ret, int show_
 # define IGNORE_URL_WIN 0
 #endif
 
-int php_init_stream_wrappers(TSRMLS_D);
-int php_shutdown_stream_wrappers(TSRMLS_D);
-PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC);
-PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC);
-PHPAPI php_stream *php_stream_open_wrapper(char *path, char *mode, int options, char **opened_path TSRMLS_DC);
+int php_init_stream_wrappers(void);
+int php_shutdown_stream_wrappers(void);
+PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper);
+PHPAPI int php_unregister_url_stream_wrapper(char *protocol);
+PHPAPI php_stream *_php_stream_open_wrapper(char *path, char *mode, int options, char **opened_path STREAMS_DC);
+#define php_stream_open_wrapper(path, mode, options, opened)   _php_stream_open_wrapper((path), (mode), (options), (opened) STREAMS_CC)
 
 #define PHP_STREAM_UNCHANGED   0 /* orig stream was seekable anyway */
 #define PHP_STREAM_RELEASED            1 /* newstream should be used; origstream is no longer valid */
 #define PHP_STREAM_FAILED              2 /* an error occurred while attempting conversion */
 #define PHP_STREAM_CRITICAL            3 /* an error occurred; origstream is in an unknown state; you should close origstream */
 /* DO NOT call this on streams that are referenced by resources! */
-PHPAPI int php_stream_make_seekable(php_stream *origstream, php_stream **newstream);
+PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream STREAMS_DC);
+#define php_stream_make_seekable(origstream, newstream)        _php_stream_make_seekable(origstream, newstream STREAMS_CC)
 
 #endif
 
index b67bc837fe171c0503d07c1df22e0d0c32e7dedc..20cf6c0db52c185a914a8a4f413b4e49130dd992 100755 (executable)
 #include "build-defs.h"
 #endif
 
+#if ZEND_DEBUG
+/* some macros to help track leaks */
+#define emalloc_rel_orig(size) \
+               ( __php_stream_call_depth == 0 \
+               ? _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC) \
+               : _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC) )
+
+#define erealloc_rel_orig(ptr, size)   \
+               ( __php_stream_call_depth == 0 \
+               ? _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC) \
+               : _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC) )
+
+
+#define pemalloc_rel_orig(size, persistent)    ((persistent) ? malloc((size)) : emalloc_rel_orig((size)))
+#define perealloc_rel_orig(ptr, size, persistent)      ((persistent) ? realloc((ptr), (size)) : erealloc_rel_orig((ptr), (size)))
+#else
+# define pemalloc_rel_orig(size, persistent)                           pemalloc((size), (persistent))
+# define perealloc_rel_orig(ptr, size, persistent)                     perealloc((ptr), (size), (persistent))
+# define emalloc_rel_orig(size)                                                                emalloc((size))
+#endif
+
 static HashTable url_stream_wrappers_hash;
 
 /* allocate a new stream for a particular ops */
-PHPAPI php_stream *php_stream_alloc(php_stream_ops *ops, void *abstract, int persistent, const char *mode) /* {{{ */
+PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract, int persistent, const char *mode STREAMS_DC) /* {{{ */
 {
        php_stream *ret;
-
-       ret = (php_stream*) pemalloc(sizeof(php_stream), persistent);
+       
+       ret = (php_stream*) pemalloc_rel_orig(sizeof(php_stream), persistent);
 
        memset(ret, 0, sizeof(php_stream));
 
@@ -232,7 +253,7 @@ PHPAPI int php_stream_seek(php_stream *stream, off_t offset, int whence)
        return -1;
 }
 
-PHPAPI size_t php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent)
+PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC)
 {
        size_t ret = 0;
        char *ptr;
@@ -272,7 +293,7 @@ PHPAPI size_t php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen,
                        srcfile = mmap(NULL, maxlen, PROT_READ, MAP_SHARED, srcfd, 0);
                        if (srcfile != (void*)MAP_FAILED) {
 
-                               *buf = pemalloc(persistent, maxlen);
+                               *buf = pemalloc_rel_orig(persistent, maxlen);
 
                                if (*buf)       {
                                        memcpy(*buf, srcfile, maxlen);
@@ -287,19 +308,19 @@ PHPAPI size_t php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen,
        }
 #endif
 
-       ptr = *buf = pemalloc(persistent, step);
+       ptr = *buf = pemalloc_rel_orig(persistent, step);
        max_len = step;
 
        while((ret = php_stream_read(src, ptr, max_len - len))) {
                len += ret;
                if (len + min_room >= max_len) {
-                       *buf = perealloc(*buf, max_len + step, persistent);
+                       *buf = perealloc_rel_orig(*buf, max_len + step, persistent);
                        max_len += step;
                        ptr = *buf + len;
                }
        }
        if (len) {
-               *buf = perealloc(*buf, len, persistent);
+               *buf = perealloc_rel_orig(*buf, len, persistent);
        } else {
                pefree(*buf, persistent);
                *buf = NULL;
@@ -406,12 +427,12 @@ typedef struct {
 #endif
 } php_stdio_stream_data;
 
-PHPAPI php_stream *php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char **opened_path STREAMS_DC)
 {
        FILE *fp = php_open_temporary_file(dir, pfx, opened_path TSRMLS_CC);
 
        if (fp) {
-               php_stream *stream = php_stream_fopen_from_file(fp, "wb");
+               php_stream *stream = php_stream_fopen_from_file_rel(fp, "wb");
                if (stream) {
                        return stream;
                }
@@ -424,7 +445,7 @@ PHPAPI php_stream *php_stream_fopen_temporary_file(const char *dir, const char *
        return NULL;
 }
 
-PHPAPI php_stream *php_stream_fopen_tmpfile(void)
+PHPAPI php_stream *_php_stream_fopen_tmpfile(STREAMS_D)
 {
        FILE *fp;
        php_stream *stream;
@@ -434,7 +455,7 @@ PHPAPI php_stream *php_stream_fopen_tmpfile(void)
                zend_error(E_WARNING, "tmpfile(): %s", strerror(errno));
                return NULL;
        }
-       stream = php_stream_fopen_from_file(fp, "r+");
+       stream = php_stream_fopen_from_file_rel(fp, "r+");
        if (stream == NULL)     {
                zend_error(E_WARNING, "tmpfile(): %s", strerror(errno));
                fclose(fp);
@@ -445,24 +466,24 @@ PHPAPI php_stream *php_stream_fopen_tmpfile(void)
 
 
 
-PHPAPI php_stream *php_stream_fopen_from_file(FILE *file, const char *mode)
+PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC)
 {
        php_stdio_stream_data *self;
 
-       self = emalloc(sizeof(*self));
+       self = emalloc_rel_orig(sizeof(*self));
        self->file = file;
        self->is_pipe = 0;
-       return php_stream_alloc(&php_stream_stdio_ops, self, 0, mode);
+       return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
 }
 
-PHPAPI php_stream *php_stream_fopen_from_pipe(FILE *file, const char *mode)
+PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STREAMS_DC)
 {
        php_stdio_stream_data *self;
 
-       self = emalloc(sizeof(*self));
+       self = emalloc_rel_orig(sizeof(*self));
        self->file = file;
        self->is_pipe = 1;
-       return php_stream_alloc(&php_stream_stdio_ops, self, 0, mode);
+       return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
 }
 static size_t php_stdiop_write(php_stream *stream, const char *buf, size_t count)
 {
@@ -595,7 +616,7 @@ php_stream_ops      php_stream_stdio_ops = {
        "STDIO"
 };
 
-PHPAPI php_stream *php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path TSRMLS_DC) /* {{{ */
+PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char *path, char **opened_path STREAMS_DC) /* {{{ */
 {
        /* code ripped off from fopen_wrappers.c */
        char *pathbuf, *ptr, *end;
@@ -622,7 +643,7 @@ PHPAPI php_stream *php_stream_fopen_with_path(char *filename, char *mode, char *
                if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) {
                        return NULL;
                }
-               return php_stream_fopen(filename, mode, opened_path TSRMLS_CC);
+               return php_stream_fopen_rel(filename, mode, opened_path TSRMLS_CC);
        }
 
        /*
@@ -634,19 +655,19 @@ PHPAPI php_stream *php_stream_fopen_with_path(char *filename, char *mode, char *
        if (IS_ABSOLUTE_PATH(filename, filename_length)) {
                if ((php_check_safe_mode_include_dir(filename TSRMLS_CC)) == 0)
                        /* filename is in safe_mode_include_dir (or subdir) */
-                       return php_stream_fopen(filename, mode, opened_path TSRMLS_CC);
+                       return php_stream_fopen_rel(filename, mode, opened_path);
 
                if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM)))
                        return NULL;
 
-               return php_stream_fopen(filename, mode, opened_path TSRMLS_CC);
+               return php_stream_fopen_rel(filename, mode, opened_path);
        }
 
        if (!path || (path && !*path)) {
                if (PG(safe_mode) && (!php_checkuid(filename, mode, CHECKUID_CHECK_MODE_PARAM))) {
                        return NULL;
                }
-               return php_stream_fopen(filename, mode, opened_path TSRMLS_CC);
+               return php_stream_fopen_rel(filename, mode, opened_path);
        }
 
        /* check in provided path */
@@ -689,7 +710,7 @@ PHPAPI php_stream *php_stream_fopen_with_path(char *filename, char *mode, char *
                                if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC) == 0) ||
                                                php_checkuid(trypath, mode, CHECKUID_CHECK_MODE_PARAM)) {
                                        /* UID ok, or trypath is in safe_mode_include_dir */
-                                       stream = php_stream_fopen(trypath, mode, opened_path TSRMLS_CC);
+                                       stream = php_stream_fopen_rel(trypath, mode, opened_path);
                                } else {
                                        stream = NULL;
                                }
@@ -698,7 +719,7 @@ PHPAPI php_stream *php_stream_fopen_with_path(char *filename, char *mode, char *
                                return stream;
                        }
                }
-               stream = php_stream_fopen(trypath, mode, opened_path TSRMLS_CC);
+               stream = php_stream_fopen_rel(trypath, mode, opened_path);
                if (stream) {
                        efree(pathbuf);
                        return stream;
@@ -712,7 +733,7 @@ PHPAPI php_stream *php_stream_fopen_with_path(char *filename, char *mode, char *
 }
 /* }}} */
 
-PHPAPI php_stream *php_stream_fopen(const char *filename, const char *mode, char **opened_path TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, char **opened_path STREAMS_DC)
 {
        FILE *fp;
        char *realpath = NULL;
@@ -722,7 +743,7 @@ PHPAPI php_stream *php_stream_fopen(const char *filename, const char *mode, char
        fp = fopen(realpath, mode);
 
        if (fp) {
-               php_stream *ret = php_stream_fopen_from_file(fp, mode);
+               php_stream *ret = php_stream_fopen_from_file_rel(fp, mode);
 
                if (ret)        {
                        if (opened_path)        {
@@ -860,34 +881,34 @@ exit_success:
 
 } /* }}} */
 
-int php_init_stream_wrappers(TSRMLS_D)
+int php_init_stream_wrappers(void)
 {
        if (PG(allow_url_fopen))
                return zend_hash_init(&url_stream_wrappers_hash, 0, NULL, NULL, 1);
        return SUCCESS;
 }
 
-int php_shutdown_stream_wrappers(TSRMLS_D)
+int php_shutdown_stream_wrappers(void)
 {
        if (PG(allow_url_fopen))
                zend_hash_destroy(&url_stream_wrappers_hash);
        return SUCCESS;
 }
 
-PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC)
+PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper)
 {
        if (PG(allow_url_fopen))
                return zend_hash_add(&url_stream_wrappers_hash, protocol, strlen(protocol), wrapper, sizeof(*wrapper), NULL);
        return FAILURE;
 }
-PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC)
+PHPAPI int php_unregister_url_stream_wrapper(char *protocol)
 {
        if (PG(allow_url_fopen))
                return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol));
        return SUCCESS;
 }
 
-static php_stream *php_stream_open_url(char *path, char *mode, int options, char **opened_path TSRMLS_DC)
+static php_stream *php_stream_open_url(char *path, char *mode, int options, char **opened_path STREAMS_DC)
 {
        php_stream_wrapper *wrapper;
        const char *p, *protocol = NULL;
@@ -907,7 +928,7 @@ static php_stream *php_stream_open_url(char *path, char *mode, int options, char
                        protocol = NULL;
                }
                if (wrapper)    {
-                       php_stream *stream = wrapper->create(path, mode, options, opened_path TSRMLS_CC);
+                       php_stream *stream = wrapper->create(path, mode, options, opened_path STREAMS_REL_CC);
                        if (stream)
                                stream->wrapper = wrapper;
                        return stream;
@@ -923,15 +944,16 @@ static php_stream *php_stream_open_url(char *path, char *mode, int options, char
                        path += n + 1;
 
                /* fall back on regular file access */
-               return php_stream_open_wrapper(path, mode, (options & ~REPORT_ERRORS) | IGNORE_URL,
-                               opened_path TSRMLS_CC);
+               return php_stream_open_wrapper_rel(path, mode, (options & ~REPORT_ERRORS) | IGNORE_URL,
+                               opened_path);
        }
        return NULL;
 }
 
-PHPAPI php_stream *php_stream_open_wrapper(char *path, char *mode, int options, char **opened_path TSRMLS_DC)
+PHPAPI php_stream *_php_stream_open_wrapper(char *path, char *mode, int options, char **opened_path STREAMS_DC)
 {
        php_stream *stream = NULL;
+       TSRMLS_FETCH();
 
        if (opened_path)
                *opened_path = NULL;
@@ -940,24 +962,24 @@ PHPAPI php_stream *php_stream_open_wrapper(char *path, char *mode, int options,
                return NULL;
 
        if (PG(allow_url_fopen) && !(options & IGNORE_URL))     {
-               stream = php_stream_open_url(path, mode, options, opened_path TSRMLS_CC);
+               stream = php_stream_open_url(path, mode, options, opened_path STREAMS_REL_CC);
                goto out;
        }
 
        if ((options & USE_PATH) && PG(include_path) != NULL) {
-               stream = php_stream_fopen_with_path(path, mode, PG(include_path), opened_path TSRMLS_CC);
+               stream = php_stream_fopen_with_path_rel(path, mode, PG(include_path), opened_path);
                goto out;
        }
 
        if ((options & ENFORCE_SAFE_MODE) && PG(safe_mode) && (!php_checkuid(path, mode, CHECKUID_CHECK_MODE_PARAM)))
                return NULL;
 
-       stream = php_stream_fopen(path, mode, opened_path TSRMLS_CC);
+       stream = php_stream_fopen_rel(path, mode, opened_path);
 out:
        if (stream != NULL && (options & STREAM_MUST_SEEK)) {
                php_stream *newstream;
 
-               switch(php_stream_make_seekable(stream, &newstream)) {
+               switch(php_stream_make_seekable_rel(stream, &newstream)) {
                        case PHP_STREAM_UNCHANGED:
                                return stream;
                        case PHP_STREAM_RELEASED:
@@ -985,7 +1007,7 @@ out:
        return stream;
 }
 
-PHPAPI int php_stream_make_seekable(php_stream *origstream, php_stream **newstream)
+PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream STREAMS_DC)
 {
        assert(newstream != NULL);