Skip to content

Commit 3967b7a

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix FFI Parsing of Pointer Declaration Lists (#17794)
2 parents 6ccb35e + ddde315 commit 3967b7a

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

ext/ffi/ffi.g

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,14 @@ struct_contents(zend_ffi_dcl *dcl):
264264

265265
struct_declaration(zend_ffi_dcl *struct_dcl):
266266
{zend_ffi_dcl common_field_dcl = ZEND_FFI_ATTR_INIT;}
267+
{zend_ffi_dcl base_field_dcl = ZEND_FFI_ATTR_INIT;}
267268
specifier_qualifier_list(&common_field_dcl)
269+
{base_field_dcl = common_field_dcl;}
268270
( /* empty */
269271
{zend_ffi_add_anonymous_field(struct_dcl, &common_field_dcl);}
270272
| struct_declarator(struct_dcl, &common_field_dcl)
271273
( ","
272-
{zend_ffi_dcl field_dcl = common_field_dcl;}
274+
{zend_ffi_dcl field_dcl = base_field_dcl;}
273275
attributes(&field_dcl)?
274276
struct_declarator(struct_dcl, &field_dcl)
275277
)*

ext/ffi/ffi_parser.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2472,14 +2472,16 @@ static int parse_struct_contents(int sym, zend_ffi_dcl *dcl) {
24722472

24732473
static int parse_struct_declaration(int sym, zend_ffi_dcl *struct_dcl) {
24742474
zend_ffi_dcl common_field_dcl = ZEND_FFI_ATTR_INIT;
2475+
zend_ffi_dcl base_field_dcl = ZEND_FFI_ATTR_INIT;
24752476
sym = parse_specifier_qualifier_list(sym, &common_field_dcl);
2477+
base_field_dcl = common_field_dcl;
24762478
if (sym == YY__SEMICOLON || sym == YY__RBRACE) {
24772479
zend_ffi_add_anonymous_field(struct_dcl, &common_field_dcl);
24782480
} else if (sym == YY__STAR || sym == YY_ID || sym == YY__LPAREN || sym == YY__COLON) {
24792481
sym = parse_struct_declarator(sym, struct_dcl, &common_field_dcl);
24802482
while (sym == YY__COMMA) {
24812483
sym = get_sym();
2482-
zend_ffi_dcl field_dcl = common_field_dcl;
2484+
zend_ffi_dcl field_dcl = base_field_dcl;
24832485
if (YY_IN_SET(sym, (YY___ATTRIBUTE,YY___ATTRIBUTE__,YY___DECLSPEC,YY___CDECL,YY___STDCALL,YY___FASTCALL,YY___THISCALL,YY___VECTORCALL), "\000\000\000\000\000\000\360\017\000\000\000\000\000")) {
24842486
sym = parse_attributes(sym, &field_dcl);
24852487
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Declaration Lists with Pointers
3+
--EXTENSIONS--
4+
ffi
5+
--SKIPIF--
6+
--FILE--
7+
<?php
8+
$ffi = FFI::cdef(<<<EOF
9+
struct MyStruct {
10+
uint8_t** a, *b, c;
11+
};
12+
EOF);
13+
14+
$test_struct = $ffi->new('struct MyStruct');
15+
$one = $ffi->new("uint8_t");
16+
$oneptr = $ffi->new("uint8_t*");
17+
$oneptrptr = $ffi->new("uint8_t**");
18+
$one->cdata = 1;
19+
$oneptr = FFI::addr($one);
20+
$oneptrptr = FFI::addr($oneptr);
21+
22+
$test_struct->a = $oneptrptr;
23+
$test_struct->b = $oneptr;
24+
$test_struct->c = $one;
25+
26+
var_dump($test_struct->a[0][0]);
27+
var_dump($test_struct->b[0]);
28+
var_dump($test_struct->c);
29+
?>
30+
--EXPECT--
31+
int(1)
32+
int(1)
33+
int(1)

0 commit comments

Comments
 (0)