leaking streams should be easier.
# I hate these big commits
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
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;
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);
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;
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;
}
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;
}
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;
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);
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;
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;
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;
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
}
#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
}
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));
/* {{{ 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;
#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;
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);
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;
#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;
#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;
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;
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);
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))
{
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;
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;
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;
{
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);
/* 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;
}
zend_shutdown(TSRMLS_C);
- php_shutdown_stream_wrappers(TSRMLS_C);
+ php_shutdown_stream_wrappers();
php_shutdown_info_logos();
UNREGISTER_INI_ENTRIES();
}
/* }}} */
-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;
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);
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;
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;
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
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);
/* 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,
} 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 {
/* 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)
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)
/* 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 * */
# 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
#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));
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;
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);
}
#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;
#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;
}
return NULL;
}
-PHPAPI php_stream *php_stream_fopen_tmpfile(void)
+PHPAPI php_stream *_php_stream_fopen_tmpfile(STREAMS_D)
{
FILE *fp;
php_stream *stream;
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);
-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)
{
"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;
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);
}
/*
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 */
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;
}
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;
}
/* }}} */
-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;
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) {
} /* }}} */
-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;
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;
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;
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:
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);