Skip to content

Commit 87e9d63

Browse files
committed
Merge branch 'master' into refactor_bcmath_str2num
2 parents fc7f7cb + 0dfd2a9 commit 87e9d63

26 files changed

+246
-194
lines changed

.github/workflows/nightly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ jobs:
824824
with:
825825
key: "${{github.job}}-${{hashFiles('php/main/php_version.h')}}"
826826
append-timestamp: false
827+
save: ${{ github.event_name != 'pull_request' }}
827828
- name: build PHP
828829
run: |
829830
cd php

.github/workflows/push.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ jobs:
116116
# job id, not the job name)
117117
key: "LINUX_X64_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}${{ matrix.asan && '_ASAN' || '' }}-${{hashFiles('main/php_version.h')}}"
118118
append-timestamp: false
119+
save: ${{ github.event_name != 'pull_request' }}
119120
- name: ./configure
120121
uses: ./.github/actions/configure-x64
121122
with:
@@ -170,6 +171,7 @@ jobs:
170171
with:
171172
key: "${{github.job}}-${{matrix.os}}-${{hashFiles('main/php_version.h')}}"
172173
append-timestamp: false
174+
save: ${{ github.event_name != 'pull_request' }}
173175
- name: ./configure
174176
uses: ./.github/actions/configure-macos
175177
with:
@@ -246,6 +248,7 @@ jobs:
246248
with:
247249
key: "${{github.job}}-${{hashFiles('main/php_version.h')}}"
248250
append-timestamp: false
251+
save: ${{ github.event_name != 'pull_request' }}
249252
- name: ./configure
250253
run: |
251254
set -x

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Makefile
7878
Makefile.fragments
7979
Makefile.objects
8080

81-
# Directories for shared object files and headers generated by `./configure`
81+
# Directories for shared object files generated by `./configure`
8282
libs/
8383
modules/
8484

@@ -166,11 +166,6 @@ php
166166
# Extensions files
167167
# ------------------------------------------------------------------------------
168168

169-
# Miscellaneous extensions files
170-
/ext/opcache/jit/zend_jit_x86.c
171-
/ext/opcache/jit/zend_jit_arm64.c
172-
/ext/opcache/minilua
173-
174169
# Generated by `cd ext/name && phpize && ./configure`
175170
/ext/*/build/
176171
/ext/*/configure.ac

CODING_STANDARDS.md

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -152,62 +152,74 @@ rewritten to comply with these rules.
152152
1. Method names follow the *studlyCaps* (also referred to as *bumpy case* or
153153
*camel caps*) naming convention, with care taken to minimize the letter
154154
count. The initial letter of the name is lowercase, and each letter that
155-
starts a new `word` is capitalized:
155+
starts a new "word" is capitalized.
156156

157-
Good:
157+
1. Class names should be descriptive nouns in *PascalCase* and as short as
158+
possible. Each word in the class name should start with a capital letter,
159+
without underscore delimiters. The class name should be prefixed with the
160+
name of the "parent set" (e.g. the name of the extension) if no namespaces
161+
are used.
162+
163+
1. Abbreviations and acronyms as well as initialisms should be avoided wherever
164+
possible, unless they are much more widely used than the long form (e.g. HTTP
165+
or URL). Abbreviations, acronyms, and initialisms should be treated like
166+
regular words, thus they should be written with an uppercase first character,
167+
followed by lowercase characters.
168+
169+
1. Diverging from this policy is allowed to keep internal consistency within a
170+
single extension, if the name follows an established, language-agnostic
171+
standard, or for other reasons, if those reasons are properly justified
172+
and voted on as part of the RFC process.
173+
174+
175+
Good method names:
158176

159177
```php
160178
connect()
161179
getData()
162180
buildSomeWidget()
181+
performHttpRequest()
163182
```
164183

165-
Bad:
184+
Bad method names:
166185

167186
```php
168187
get_Data()
169188
buildsomewidget()
170189
getI()
190+
performHTTPRequest()
171191
```
172192

173-
1. Class names should be descriptive nouns in *PascalCase* and as short as
174-
possible. Each word in the class name should start with a capital letter,
175-
without underscore delimiters. The class name should be prefixed with the
176-
name of the "parent set" (e.g. the name of the extension) if no namespaces
177-
are used. Abbreviations and acronyms as well as initialisms should be
178-
avoided wherever possible, unless they are much more widely used than the
179-
long form (e.g. HTTP or URL). Abbreviations start with a capital letter
180-
followed by lowercase letters, whereas acronyms and initialisms are written
181-
according to their standard notation. Usage of acronyms and initialisms is
182-
not allowed if they are not widely adopted and recognized as such.
183-
184-
Good:
193+
Good class names:
185194

186195
```php
187196
Curl
188197
CurlResponse
189-
HTTPStatusCode
190-
URL
191-
BTreeMap // B-tree Map
192-
Id // Identifier
193-
ID // Identity Document
198+
HttpStatusCode
199+
Url
200+
BtreeMap // B-tree Map
201+
UserId // User Identifier
194202
Char // Character
195203
Intl // Internationalization
196-
Radar // Radio Detecting and Ranging
204+
Ssl\Certificate
205+
Ssl\Crl // Certificate Revocation List
206+
Ssl\CrlUrl
197207
```
198208

199-
Bad:
209+
Bad class names:
200210

201211
```php
202212
curl
203213
curl_response
204-
HttpStatusCode
205-
Url
206-
BtreeMap
207-
ID // Identifier
214+
HTTPStatusCode
215+
URL
216+
BTreeMap
217+
UserID // User Identifier
208218
CHAR
209219
INTL
210-
RADAR // Radio Detecting and Ranging
220+
SSL\Certificate
221+
SSL\CRL
222+
SSL\CRLURL
211223
```
212224

213225
## Internal function naming conventions

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ PHP 8.4 UPGRADE NOTES
142142
. SoapClient::$sdl is now a Soap\Sdl object rather than a resource.
143143
Checks using is_resource() (i.e. is_resource($client->sdl)) should be
144144
replaced with checks for null (i.e. $client->sdl !== null).
145+
. SoapClient::$typemap is now an array rather than a resource.
146+
Checks using is_resource() (i.e. is_resource($client->typemap)) should be
147+
replaced with checks for null (i.e. $client->typemap !== null).
145148

146149
- SPL:
147150
. Out of bounds accesses in SplFixedArray now throw an exception of type

ext/bcmath/bcmath.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
#include "php_bcmath.h"
3030
#include "libbcmath/src/bcmath.h"
3131

32+
/* Always pair SETUP with TEARDOWN, and do so in the outer scope!
33+
* Should not be used when data can escape the function. */
34+
#define BC_ARENA_SETUP \
35+
char bc_arena[BC_ARENA_SIZE]; \
36+
BCG(arena) = bc_arena;
37+
38+
#define BC_ARENA_TEARDOWN \
39+
BCG(arena) = NULL; \
40+
BCG(arena_offset) = 0;
41+
3242
ZEND_DECLARE_MODULE_GLOBALS(bcmath)
3343
static PHP_GINIT_FUNCTION(bcmath);
3444
static PHP_GSHUTDOWN_FUNCTION(bcmath);
@@ -89,6 +99,8 @@ static PHP_GINIT_FUNCTION(bcmath)
8999
ZEND_TSRMLS_CACHE_UPDATE();
90100
#endif
91101
bcmath_globals->bc_precision = 0;
102+
bcmath_globals->arena = NULL;
103+
bcmath_globals->arena_offset = 0;
92104
bc_init_numbers();
93105
}
94106
/* }}} */
@@ -99,6 +111,8 @@ static PHP_GSHUTDOWN_FUNCTION(bcmath)
99111
_bc_free_num_ex(&bcmath_globals->_zero_, 1);
100112
_bc_free_num_ex(&bcmath_globals->_one_, 1);
101113
_bc_free_num_ex(&bcmath_globals->_two_, 1);
114+
bcmath_globals->arena = NULL;
115+
bcmath_globals->arena_offset = 0;
102116
}
103117
/* }}} */
104118

@@ -167,6 +181,8 @@ PHP_FUNCTION(bcadd)
167181
scale = (int) scale_param;
168182
}
169183

184+
BC_ARENA_SETUP;
185+
170186
if (php_str2num(&first, left) == FAILURE) {
171187
zend_argument_value_error(1, "is not well-formed");
172188
goto cleanup;
@@ -185,6 +201,7 @@ PHP_FUNCTION(bcadd)
185201
bc_free_num(&first);
186202
bc_free_num(&second);
187203
bc_free_num(&result);
204+
BC_ARENA_TEARDOWN;
188205
};
189206
}
190207
/* }}} */
@@ -214,6 +231,8 @@ PHP_FUNCTION(bcsub)
214231
scale = (int) scale_param;
215232
}
216233

234+
BC_ARENA_SETUP;
235+
217236
if (php_str2num(&first, left) == FAILURE) {
218237
zend_argument_value_error(1, "is not well-formed");
219238
goto cleanup;
@@ -232,6 +251,7 @@ PHP_FUNCTION(bcsub)
232251
bc_free_num(&first);
233252
bc_free_num(&second);
234253
bc_free_num(&result);
254+
BC_ARENA_TEARDOWN;
235255
};
236256
}
237257
/* }}} */
@@ -261,6 +281,8 @@ PHP_FUNCTION(bcmul)
261281
scale = (int) scale_param;
262282
}
263283

284+
BC_ARENA_SETUP;
285+
264286
if (php_str2num(&first, left) == FAILURE) {
265287
zend_argument_value_error(1, "is not well-formed");
266288
goto cleanup;
@@ -279,6 +301,7 @@ PHP_FUNCTION(bcmul)
279301
bc_free_num(&first);
280302
bc_free_num(&second);
281303
bc_free_num(&result);
304+
BC_ARENA_TEARDOWN;
282305
};
283306
}
284307
/* }}} */
@@ -308,6 +331,8 @@ PHP_FUNCTION(bcdiv)
308331
scale = (int) scale_param;
309332
}
310333

334+
BC_ARENA_SETUP;
335+
311336
bc_init_num(&result);
312337

313338
if (php_str2num(&first, left) == FAILURE) {
@@ -331,6 +356,7 @@ PHP_FUNCTION(bcdiv)
331356
bc_free_num(&first);
332357
bc_free_num(&second);
333358
bc_free_num(&result);
359+
BC_ARENA_TEARDOWN;
334360
};
335361
}
336362
/* }}} */
@@ -360,6 +386,8 @@ PHP_FUNCTION(bcmod)
360386
scale = (int) scale_param;
361387
}
362388

389+
BC_ARENA_SETUP;
390+
363391
bc_init_num(&result);
364392

365393
if (php_str2num(&first, left) == FAILURE) {
@@ -383,6 +411,7 @@ PHP_FUNCTION(bcmod)
383411
bc_free_num(&first);
384412
bc_free_num(&second);
385413
bc_free_num(&result);
414+
BC_ARENA_TEARDOWN;
386415
};
387416
}
388417
/* }}} */
@@ -413,6 +442,8 @@ PHP_FUNCTION(bcpowmod)
413442
scale = (int) scale_param;
414443
}
415444

445+
BC_ARENA_SETUP;
446+
416447
bc_init_num(&result);
417448

418449
if (php_str2num(&bc_base, base_str) == FAILURE) {
@@ -458,6 +489,7 @@ PHP_FUNCTION(bcpowmod)
458489
bc_free_num(&bc_expo);
459490
bc_free_num(&bc_modulus);
460491
bc_free_num(&result);
492+
BC_ARENA_TEARDOWN;
461493
};
462494
}
463495
/* }}} */
@@ -487,6 +519,8 @@ PHP_FUNCTION(bcpow)
487519
scale = (int) scale_param;
488520
}
489521

522+
BC_ARENA_SETUP;
523+
490524
bc_init_num(&result);
491525

492526
if (php_str2num(&first, base_str) == FAILURE) {
@@ -518,6 +552,7 @@ PHP_FUNCTION(bcpow)
518552
bc_free_num(&first);
519553
bc_free_num(&bc_exponent);
520554
bc_free_num(&result);
555+
BC_ARENA_TEARDOWN;
521556
};
522557
}
523558
/* }}} */
@@ -546,6 +581,8 @@ PHP_FUNCTION(bcsqrt)
546581
scale = (int) scale_param;
547582
}
548583

584+
BC_ARENA_SETUP;
585+
549586
if (php_str2num(&result, left) == FAILURE) {
550587
zend_argument_value_error(1, "is not well-formed");
551588
goto cleanup;
@@ -559,6 +596,7 @@ PHP_FUNCTION(bcsqrt)
559596

560597
cleanup: {
561598
bc_free_num(&result);
599+
BC_ARENA_TEARDOWN;
562600
};
563601
}
564602
/* }}} */
@@ -588,6 +626,8 @@ PHP_FUNCTION(bccomp)
588626
scale = (int) scale_param;
589627
}
590628

629+
BC_ARENA_SETUP;
630+
591631
if (!bc_str2num(&first, ZSTR_VAL(left), ZSTR_VAL(left) + ZSTR_LEN(left), scale, false)) {
592632
zend_argument_value_error(1, "is not well-formed");
593633
goto cleanup;
@@ -603,6 +643,7 @@ PHP_FUNCTION(bccomp)
603643
cleanup: {
604644
bc_free_num(&first);
605645
bc_free_num(&second);
646+
BC_ARENA_TEARDOWN;
606647
};
607648
}
608649
/* }}} */
@@ -617,6 +658,8 @@ static void bcfloor_or_bcceil(INTERNAL_FUNCTION_PARAMETERS, bool is_floor)
617658
Z_PARAM_STR(numstr)
618659
ZEND_PARSE_PARAMETERS_END();
619660

661+
BC_ARENA_SETUP;
662+
620663
if (php_str2num(&num, numstr) == FAILURE) {
621664
zend_argument_value_error(1, "is not well-formed");
622665
goto cleanup;
@@ -628,6 +671,7 @@ static void bcfloor_or_bcceil(INTERNAL_FUNCTION_PARAMETERS, bool is_floor)
628671
cleanup: {
629672
bc_free_num(&num);
630673
bc_free_num(&result);
674+
BC_ARENA_TEARDOWN;
631675
};
632676
}
633677
/* }}} */
@@ -676,6 +720,8 @@ PHP_FUNCTION(bcround)
676720
return;
677721
}
678722

723+
BC_ARENA_SETUP;
724+
679725
bc_init_num(&result);
680726

681727
if (php_str2num(&num, numstr) == FAILURE) {
@@ -689,6 +735,7 @@ PHP_FUNCTION(bcround)
689735
cleanup: {
690736
bc_free_num(&num);
691737
bc_free_num(&result);
738+
BC_ARENA_TEARDOWN;
692739
};
693740
}
694741
/* }}} */

0 commit comments

Comments
 (0)