Skip to content

Commit ef960ef

Browse files
committed
Merge pull request php#6 from weltling/string_size_refactor_take_2
String size refactor take 2 ext/standard last wave
2 parents dc29937 + bfb0e87 commit ef960ef

File tree

91 files changed

+1500
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1500
-371
lines changed

Zend/tests/bug64979.phpt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #64578 (Closures with static variables can be generators)
3+
--XFAIL--
4+
Bug #64979 not fixed yet.
5+
--FILE--
6+
<?php
7+
8+
function new_closure_gen() {
9+
return function() {
10+
static $foo = 0;
11+
yield ++$foo;
12+
};
13+
}
14+
15+
$closure1 = new_closure_gen();
16+
$closure2 = new_closure_gen();
17+
18+
$gen1 = $closure1();
19+
$gen2 = $closure1();
20+
$gen3 = $closure2();
21+
22+
foreach (array($gen1, $gen2, $gen3) as $gen) {
23+
foreach ($gen as $val) {
24+
print "$val\n";
25+
}
26+
}
27+
28+
?>
29+
--EXPECT--
30+
int(1)
31+
int(2)
32+
int(1)

Zend/tests/closure_047.phpt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Closure 047: Use in preg_replace_callback() using variables by reference
3+
--FILE--
4+
<?php
5+
6+
function replace_variables($text, $params) {
7+
8+
preg_replace_callback( '/(\?)/', function($matches) use (&$params, &$text) {
9+
10+
$text = preg_replace( '/(\?)/', array_shift( $params ), $text, 1 );
11+
12+
}, $text );
13+
14+
return $text;
15+
}
16+
17+
echo replace_variables('a=?', array('0')) . "\n";
18+
echo replace_variables('a=?, b=?', array('0', '1')) . "\n";
19+
echo replace_variables('a=?, b=?, c=?', array('0', '1', '2')) . "\n";
20+
echo "Done\n";
21+
?>
22+
--EXPECT--
23+
a=0
24+
a=0, b=1
25+
a=0, b=1, c=2
26+
Done

Zend/tests/closure_048.phpt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Closure 048: Use in preg_replace_callback() using variables by reference
3+
--FILE--
4+
<?php
5+
6+
function replace_variables($text, $params) {
7+
8+
$c = function($matches) use (&$params, &$text) {
9+
$text = preg_replace( '/(\?)/', array_shift( $params ), $text, 1 );
10+
};
11+
12+
preg_replace_callback( '/(\?)/', $c, $text );
13+
14+
return $text;
15+
}
16+
17+
echo replace_variables('a=?', array('0')) . "\n";
18+
echo replace_variables('a=?, b=?', array('0', '1')) . "\n";
19+
echo replace_variables('a=?, b=?, c=?', array('0', '1', '2')) . "\n";
20+
echo "Done\n";
21+
?>
22+
--EXPECT--
23+
a=0
24+
a=0, b=1
25+
a=0, b=1, c=2
26+
Done

Zend/zend.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1092,17 +1092,19 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
10921092
error_filename = "Unknown";
10931093
}
10941094

1095-
va_start(args, format);
1096-
10971095
#ifdef HAVE_DTRACE
10981096
if(DTRACE_ERROR_ENABLED()) {
10991097
char *dtrace_error_buffer;
1098+
va_start(args, format);
11001099
zend_vspprintf(&dtrace_error_buffer, 0, format, args);
11011100
DTRACE_ERROR(dtrace_error_buffer, (char *)error_filename, error_lineno);
11021101
efree(dtrace_error_buffer);
1102+
va_end(args);
11031103
}
11041104
#endif /* HAVE_DTRACE */
11051105

1106+
va_start(args, format);
1107+
11061108
/* if we don't have a user defined error handler */
11071109
if (!EG(user_error_handler)
11081110
|| !(EG(user_error_handler_error_reporting) & type)

Zend/zend_constants.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void clean_non_persistent_constants(TSRMLS_D)
145145
}
146146
}
147147

148-
ZEND_API void zend_register_null_constant(const char *name, uint name_len, int flags, int module_number TSRMLS_DC)
148+
ZEND_API void zend_register_null_constant(const char *name, zend_str_size_uint name_len, int flags, int module_number TSRMLS_DC)
149149
{
150150
zend_constant c;
151151

@@ -157,7 +157,7 @@ ZEND_API void zend_register_null_constant(const char *name, uint name_len, int f
157157
zend_register_constant(&c TSRMLS_CC);
158158
}
159159

160-
ZEND_API void zend_register_bool_constant(const char *name, uint name_len, zend_bool bval, int flags, int module_number TSRMLS_DC)
160+
ZEND_API void zend_register_bool_constant(const char *name, zend_str_size_uint name_len, zend_bool bval, int flags, int module_number TSRMLS_DC)
161161
{
162162
zend_constant c;
163163

acinclude.m4

+38-4
Original file line numberDiff line numberDiff line change
@@ -2925,17 +2925,17 @@ dnl providerdesc
29252925
dnl header-file
29262926
ac_hdrobj=$2
29272927
2928-
dnl Add providerdesc.o into global objects when needed
2928+
dnl Add providerdesc.o or .lo into global objects when needed
29292929
case $host_alias in
29302930
*freebsd*)
29312931
PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.o"
29322932
PHP_LDFLAGS="$PHP_LDFLAGS -lelf"
29332933
;;
29342934
*solaris*)
2935-
PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.o"
2935+
PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.lo"
29362936
;;
29372937
*linux*)
2938-
PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.o"
2938+
PHP_GLOBAL_OBJS="[$]PHP_GLOBAL_OBJS [$]ac_bdir[$]ac_provsrc.lo"
29392939
;;
29402940
esac
29412941
@@ -2969,14 +2969,48 @@ dnl in GNU Make which causes the .d file to be overwritten (Bug 61268)
29692969
$abs_srcdir/$ac_provsrc:;
29702970
29712971
$ac_bdir[$]ac_hdrobj: $abs_srcdir/$ac_provsrc
2972-
CFLAGS="\$(CFLAGS_CLEAN)" dtrace -h -C -s $ac_srcdir[$]ac_provsrc -o \$[]@.bak && \$(SED) 's,PHP_,DTRACE_,g' \$[]@.bak > \$[]@
2972+
CFLAGS="\$(CFLAGS_CLEAN)" dtrace -h -C -s $ac_srcdir[$]ac_provsrc -o \$[]@.bak && \$(SED) -e 's,PHP_,DTRACE_,g' \$[]@.bak > \$[]@
29732973
29742974
\$(PHP_DTRACE_OBJS): $ac_bdir[$]ac_hdrobj
29752975
2976+
EOF
2977+
2978+
case $host_alias in
2979+
*solaris*|*linux*)
2980+
dtrace_prov_name="`echo $ac_provsrc | $SED -e 's#\(.*\)\/##'`.o"
2981+
dtrace_lib_dir="`echo $ac_bdir[$]ac_provsrc | $SED -e 's#\(.*\)/[^/]*#\1#'`/.libs"
2982+
dtrace_d_obj="`echo $ac_bdir[$]ac_provsrc | $SED -e 's#\(.*\)/\([^/]*\)#\1/.libs/\2#'`.o"
2983+
dtrace_nolib_objs='$(PHP_DTRACE_OBJS:.lo=.o)'
2984+
for ac_lo in $PHP_DTRACE_OBJS; do
2985+
dtrace_lib_objs="[$]dtrace_lib_objs `echo $ac_lo | $SED -e 's,\.lo$,.o,' -e 's#\(.*\)\/#\1\/.libs\/#'`"
2986+
done;
2987+
dnl Always attempt to create both PIC and non-PIC DTrace objects (Bug 63692)
2988+
cat>>Makefile.objects<<EOF
2989+
$ac_bdir[$]ac_provsrc.lo: \$(PHP_DTRACE_OBJS)
2990+
echo "[#] Generated by Makefile for libtool" > \$[]@
2991+
@test -d "$dtrace_lib_dir" || mkdir $dtrace_lib_dir
2992+
if CFLAGS="\$(CFLAGS_CLEAN)" dtrace -G -o $dtrace_d_obj -s $abs_srcdir/$ac_provsrc $dtrace_lib_objs 2> /dev/null && test -f "$dtrace_d_obj"; then [\\]
2993+
echo "pic_object=['].libs/$dtrace_prov_name[']" >> \$[]@ [;\\]
2994+
else [\\]
2995+
echo "pic_object='none'" >> \$[]@ [;\\]
2996+
fi
2997+
if CFLAGS="\$(CFLAGS_CLEAN)" dtrace -G -o $ac_bdir[$]ac_provsrc.o -s $abs_srcdir/$ac_provsrc $dtrace_nolib_objs 2> /dev/null && test -f "$ac_bdir[$]ac_provsrc.o"; then [\\]
2998+
echo "non_pic_object=[']$dtrace_prov_name[']" >> \$[]@ [;\\]
2999+
else [\\]
3000+
echo "non_pic_object='none'" >> \$[]@ [;\\]
3001+
fi
3002+
3003+
EOF
3004+
3005+
;;
3006+
*)
3007+
cat>>Makefile.objects<<EOF
29763008
$ac_bdir[$]ac_provsrc.o: \$(PHP_DTRACE_OBJS)
29773009
CFLAGS="\$(CFLAGS_CLEAN)" dtrace -G -o \$[]@ -s $abs_srcdir/$ac_provsrc $dtrace_objs
29783010
29793011
EOF
3012+
;;
3013+
esac
29803014
])
29813015

29823016
dnl

ext/bz2/bz2_filter.c

-2
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,13 @@ static php_stream_filter_status_t php_bz2_compress_filter(
215215
size_t consumed = 0;
216216
int status;
217217
php_stream_filter_status_t exit_status = PSFS_FEED_ME;
218-
bz_stream *streamp;
219218

220219
if (!thisfilter || !thisfilter->abstract) {
221220
/* Should never happen */
222221
return PSFS_ERR_FATAL;
223222
}
224223

225224
data = (php_bz2_filter_data *)(thisfilter->abstract);
226-
streamp = &(data->strm);
227225

228226
while (buckets_in->head) {
229227
size_t bin = 0, desired;

ext/curl/interface.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -1717,9 +1717,9 @@ static void curl_free_post(void **post)
17171717

17181718
/* {{{ curl_free_slist
17191719
*/
1720-
static void curl_free_slist(void **slist)
1720+
static void curl_free_slist(void *slist)
17211721
{
1722-
curl_slist_free_all((struct curl_slist *) *slist);
1722+
curl_slist_free_all(*((struct curl_slist **) slist));
17231723
}
17241724
/* }}} */
17251725

@@ -1790,9 +1790,11 @@ static void alloc_curl_handle(php_curl **ch)
17901790
(*ch)->handlers->read->stream = NULL;
17911791

17921792
zend_llist_init(&(*ch)->to_free->str, sizeof(char *), (llist_dtor_func_t) curl_free_string, 0);
1793-
zend_llist_init(&(*ch)->to_free->slist, sizeof(struct curl_slist), (llist_dtor_func_t) curl_free_slist, 0);
17941793
zend_llist_init(&(*ch)->to_free->post, sizeof(struct HttpPost), (llist_dtor_func_t) curl_free_post, 0);
17951794
(*ch)->safe_upload = 1; /* for now, for BC reason we allow unsafe API */
1795+
1796+
(*ch)->to_free->slist = emalloc(sizeof(HashTable));
1797+
zend_hash_init((*ch)->to_free->slist, 4, NULL, curl_free_slist, 0);
17961798
}
17971799
/* }}} */
17981800

@@ -2043,6 +2045,7 @@ PHP_FUNCTION(curl_copy_handle)
20432045
}
20442046
#endif
20452047

2048+
efree(dupch->to_free->slist);
20462049
efree(dupch->to_free);
20472050
dupch->to_free = ch->to_free;
20482051

@@ -2438,7 +2441,7 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
24382441

24392442
ph = HASH_OF(*zvalue);
24402443
if (!ph) {
2441-
char *name;
2444+
char *name = NULL;
24422445
switch (option) {
24432446
case CURLOPT_HTTPHEADER:
24442447
name = "CURLOPT_HTTPHEADER";
@@ -2488,7 +2491,7 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
24882491
return 1;
24892492
}
24902493
}
2491-
zend_llist_add_element(&ch->to_free->slist, &slist);
2494+
zend_hash_index_update(ch->to_free->slist, (ulong) option, &slist, sizeof(struct curl_slist *), NULL);
24922495

24932496
error = curl_easy_setopt(ch->cp, option, slist);
24942497

@@ -3266,8 +3269,9 @@ static void _php_curl_close_ex(php_curl *ch TSRMLS_DC)
32663269
/* cURL destructors should be invoked only by last curl handle */
32673270
if (Z_REFCOUNT_P(ch->clone) <= 1) {
32683271
zend_llist_clean(&ch->to_free->str);
3269-
zend_llist_clean(&ch->to_free->slist);
32703272
zend_llist_clean(&ch->to_free->post);
3273+
zend_hash_destroy(ch->to_free->slist);
3274+
efree(ch->to_free->slist);
32713275
efree(ch->to_free);
32723276
FREE_ZVAL(ch->clone);
32733277
} else {

ext/curl/php_curl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct _php_curl_send_headers {
168168
struct _php_curl_free {
169169
zend_llist str;
170170
zend_llist post;
171-
zend_llist slist;
171+
HashTable *slist;
172172
};
173173

174174
typedef struct {

ext/curl/tests/bug65458.phpt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #65458 (curl memory leak)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('curl')) exit("skip curl extension not loaded");
6+
?>
7+
--FILE--
8+
<?php
9+
$ch = curl_init();
10+
$init = memory_get_usage();
11+
for ($i = 0; $i < 10000; $i++) {
12+
curl_setopt($ch, CURLOPT_HTTPHEADER, [ "SOAPAction: getItems" ]);
13+
}
14+
15+
$preclose = memory_get_usage();
16+
curl_close($ch);
17+
18+
// This is a slightly tricky heuristic, but basically, we want to ensure
19+
// $preclose - $init has a delta in the order of bytes, not megabytes. Given
20+
// the number of iterations in the loop, if we're wasting memory here, we
21+
// should have megs and megs of extra allocations.
22+
var_dump(($preclose - $init) < 10000);
23+
?>
24+
--EXPECT--
25+
bool(true)

ext/dom/php_dom.c

+4
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,11 @@ void dom_xpath_objects_free_storage(void *object TSRMLS_DC)
10891089
void dom_objects_free_storage(void *object TSRMLS_DC)
10901090
{
10911091
dom_object *intern = (dom_object *)object;
1092+
#if defined(__GNUC__) && __GNUC__ >= 3
1093+
int retcount __attribute__((unused)); /* keep compiler quiet */
1094+
#else
10921095
int retcount;
1096+
#endif
10931097

10941098
zend_object_std_dtor(&intern->std TSRMLS_CC);
10951099

ext/ftp/ftp.c

-5
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ int
790790
ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, long resumepos TSRMLS_DC)
791791
{
792792
databuf_t *data = NULL;
793-
int lastch;
794793
size_t rcvd;
795794
char arg[11];
796795

@@ -828,7 +827,6 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type,
828827
goto bail;
829828
}
830829

831-
lastch = 0;
832830
while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) {
833831
if (rcvd == -1) {
834832
goto bail;
@@ -1187,12 +1185,9 @@ ftp_readline(ftpbuf_t *ftp)
11871185
int
11881186
ftp_getresp(ftpbuf_t *ftp)
11891187
{
1190-
char *buf;
1191-
11921188
if (ftp == NULL) {
11931189
return 0;
11941190
}
1195-
buf = ftp->inbuf;
11961191
ftp->resp = 0;
11971192

11981193
while (1) {

ext/intl/breakiterator/breakiterator_iterators.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ U_CFUNC zend_object_iterator *_breakiterator_get_iterator(
3939
zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC);
4040
U_CFUNC void breakiterator_register_IntlPartsIterator_class(TSRMLS_D);
4141

42-
#endif
42+
#endif

ext/intl/breakiterator/breakiterator_methods.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ PHP_FUNCTION(breakiter_get_error_code);
6161

6262
PHP_FUNCTION(breakiter_get_error_message);
6363

64-
#endif
64+
#endif

ext/intl/breakiterator/codepointiterator_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ namespace PHP {
9595
};
9696
}
9797

98-
#endif
98+
#endif

ext/intl/breakiterator/codepointiterator_methods.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ U_CFUNC PHP_FUNCTION(cpbi_get_last_code_point)
4141
BREAKITER_METHOD_FETCH_OBJECT;
4242

4343
RETURN_LONG(fetch_cpbi(bio)->getLastCodePoint());
44-
}
44+
}

ext/intl/breakiterator/codepointiterator_methods.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121

2222
PHP_FUNCTION(cpbi_get_last_code_point);
2323

24-
#endif
24+
#endif

ext/intl/breakiterator/rulebasedbreakiterator_methods.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ PHP_FUNCTION(rbbi_get_rule_status_vec);
2929

3030
PHP_FUNCTION(rbbi_get_binary_rules);
3131

32-
#endif
32+
#endif

0 commit comments

Comments
 (0)