Skip to content

Commit 92d27cc

Browse files
committed
Constify streams API and a few other calls down the rabbit hole.
(`char *` to `const char *` for parameters and few return values) In a few places int len moved to size_t len.
1 parent 5e1ac55 commit 92d27cc

38 files changed

+202
-189
lines changed

README.STREAMS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Opening Streams
4646
===============
4747
In most cases, you should use this API:
4848

49-
PHPAPI php_stream *php_stream_open_wrapper(char *path, char *mode,
49+
PHPAPI php_stream *php_stream_open_wrapper(const char *path, const char *mode,
5050
int options, char **opened_path TSRMLS_DC);
5151

5252
Where:

TSRM/tsrm_virtual_cwd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ CWD_API int virtual_creat(const char *path, mode_t mode TSRMLS_DC) /* {{{ */
16731673
}
16741674
/* }}} */
16751675

1676-
CWD_API int virtual_rename(char *oldname, char *newname TSRMLS_DC) /* {{{ */
1676+
CWD_API int virtual_rename(const char *oldname, const char *newname TSRMLS_DC) /* {{{ */
16771677
{
16781678
cwd_state old_state;
16791679
cwd_state new_state;

TSRM/tsrm_virtual_cwd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ CWD_API char *virtual_realpath(const char *path, char *real_path TSRMLS_DC);
161161
CWD_API FILE *virtual_fopen(const char *path, const char *mode TSRMLS_DC);
162162
CWD_API int virtual_open(const char *path TSRMLS_DC, int flags, ...);
163163
CWD_API int virtual_creat(const char *path, mode_t mode TSRMLS_DC);
164-
CWD_API int virtual_rename(char *oldname, char *newname TSRMLS_DC);
164+
CWD_API int virtual_rename(const char *oldname, const char *newname TSRMLS_DC);
165165
CWD_API int virtual_stat(const char *path, struct stat *buf TSRMLS_DC);
166166
CWD_API int virtual_lstat(const char *path, struct stat *buf TSRMLS_DC);
167167
CWD_API int virtual_unlink(const char *path TSRMLS_DC);

Zend/zend_operators.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ static inline zend_uchar is_numeric_string(const char *str, int length, long *lv
269269
return is_numeric_string_ex(str, length, lval, dval, allow_errors, NULL);
270270
}
271271

272-
static inline char *
273-
zend_memnstr(char *haystack, char *needle, int needle_len, char *end)
272+
static inline const char *
273+
zend_memnstr(const char *haystack, const char *needle, int needle_len, char *end)
274274
{
275-
char *p = haystack;
276-
char ne = needle[needle_len-1];
275+
const char *p = haystack;
276+
const char ne = needle[needle_len-1];
277277

278278
if (needle_len == 1) {
279279
return (char *)memchr(p, *needle, (end-p));

ext/bz2/bz2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ php_stream_ops php_stream_bz2io_ops = {
192192

193193
/* {{{ Bzip2 stream openers */
194194
PHP_BZ2_API php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz,
195-
char *mode, php_stream *innerstream STREAMS_DC TSRMLS_DC)
195+
const char *mode, php_stream *innerstream STREAMS_DC TSRMLS_DC)
196196
{
197197
struct php_bz2_stream_data_t *self;
198198

@@ -205,8 +205,8 @@ PHP_BZ2_API php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz,
205205
}
206206

207207
PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper,
208-
char *path,
209-
char *mode,
208+
const char *path,
209+
const char *mode,
210210
int options,
211211
char **opened_path,
212212
php_stream_context *context STREAMS_DC TSRMLS_DC)

ext/bz2/php_bz2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ extern zend_module_entry bz2_module_entry;
4747
# define PHP_BZ2_API
4848
#endif
4949

50-
PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
51-
PHP_BZ2_API php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz, char *mode, php_stream *innerstream STREAMS_DC TSRMLS_DC);
50+
PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
51+
PHP_BZ2_API php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz, const char *mode, php_stream *innerstream STREAMS_DC TSRMLS_DC);
5252

5353
#define php_stream_bz2open_from_BZFILE(bz, mode, innerstream) _php_stream_bz2open_from_BZFILE((bz), (mode), (innerstream) STREAMS_CC TSRMLS_CC)
5454
#define php_stream_bz2open(wrapper, path, mode, options, opened_path) _php_stream_bz2open((wrapper), (path), (mode), (options), (opened_path), NULL STREAMS_CC TSRMLS_CC)

ext/fileinfo/fileinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
497497
case FILEINFO_MODE_FILE:
498498
{
499499
/* determine if the file is a local file or remote URL */
500-
char *tmp2;
500+
const char *tmp2;
501501
php_stream_wrapper *wrap;
502502
php_stream_statbuf ssb;
503503

ext/libxml/libxml.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char
292292
php_stream_statbuf ssbuf;
293293
php_stream_context *context = NULL;
294294
php_stream_wrapper *wrapper = NULL;
295-
char *resolved_path, *path_to_open = NULL;
295+
char *resolved_path;
296+
const char *path_to_open = NULL;
296297
void *ret_val = NULL;
297298
int isescaped=0;
298299
xmlURI *uri;

ext/openssl/xp_ssl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static inline int php_openssl_setup_crypto(php_stream *stream,
309309
php_stream_xport_crypto_param *cparam
310310
TSRMLS_DC)
311311
{
312-
SSL_METHOD *method;
312+
const SSL_METHOD *method;
313313
long ssl_ctx_options = SSL_OP_ALL;
314314

315315
if (sslsock->ssl_handle) {
@@ -853,7 +853,7 @@ php_stream_ops php_openssl_socket_ops = {
853853
php_openssl_sockop_set_option,
854854
};
855855

856-
static char * get_sni(php_stream_context *ctx, char *resourcename, long resourcenamelen, int is_persistent TSRMLS_DC) {
856+
static char * get_sni(php_stream_context *ctx, const char *resourcename, size_t resourcenamelen, int is_persistent TSRMLS_DC) {
857857

858858
php_url *url;
859859

@@ -900,8 +900,8 @@ static char * get_sni(php_stream_context *ctx, char *resourcename, long resource
900900
return NULL;
901901
}
902902

903-
php_stream *php_openssl_ssl_socket_factory(const char *proto, long protolen,
904-
char *resourcename, long resourcenamelen,
903+
php_stream *php_openssl_ssl_socket_factory(const char *proto, size_t protolen,
904+
const char *resourcename, size_t resourcenamelen,
905905
const char *persistent_id, int options, int flags,
906906
struct timeval *timeout,
907907
php_stream_context *context STREAMS_DC TSRMLS_DC)

ext/phar/dirstream.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
319319
/**
320320
* Open a directory handle within a phar archive
321321
*/
322-
php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
322+
php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
323323
{
324324
php_url *resource = NULL;
325325
php_stream *ret;
@@ -432,7 +432,7 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, char *path, char
432432
/**
433433
* Make a new directory within a phar archive
434434
*/
435-
int phar_wrapper_mkdir(php_stream_wrapper *wrapper, char *url_from, int mode, int options, php_stream_context *context TSRMLS_DC) /* {{{ */
435+
int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mode, int options, php_stream_context *context TSRMLS_DC) /* {{{ */
436436
{
437437
phar_entry_info entry, *e;
438438
phar_archive_data *phar = NULL;
@@ -564,7 +564,7 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, char *url_from, int mode, in
564564
/**
565565
* Remove a directory within a phar archive
566566
*/
567-
int phar_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) /* {{{ */
567+
int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC) /* {{{ */
568568
{
569569
phar_entry_info *entry;
570570
phar_archive_data *phar = NULL;

0 commit comments

Comments
 (0)