xref: /PHP-8.1/ext/ffi/tests/bug80847.phpt (revision 1440d15e)
1--TEST--
2Bug #80847 (Nested structs)
3--EXTENSIONS--
4ffi
5zend_test
6--SKIPIF--
7<?php
8if (PHP_OS_FAMILY == 'Windows' && ((1 << 31) > 0)) die('xfail libffi doesn\'t properly support passing big structures by value on Windows/64');
9?>
10--FILE--
11<?php
12require_once('utils.inc');
13$header = <<<HEADER
14    typedef struct bug80847_01 {
15        uint64_t b;
16        double c;
17    } bug80847_01;
18
19    typedef struct bug80847_02 {
20        bug80847_01 a;
21    } bug80847_02;
22
23	bug80847_02 ffi_bug80847(bug80847_02 s);
24HEADER;
25
26if (PHP_OS_FAMILY !== 'Windows') {
27    $ffi = FFI::cdef($header);
28} else {
29    try {
30        $ffi = FFI::cdef($header, 'php_zend_test.dll');
31    } catch (FFI\Exception $ex) {
32        $ffi = FFI::cdef($header, ffi_get_php_dll_name());
33    }
34}
35$x = $ffi->new('bug80847_02');
36$x->a->b = 42;
37$x->a->c = 42.5;
38var_dump($x);
39$y = $ffi->ffi_bug80847($x);
40var_dump($x, $y);
41?>
42--EXPECTF--
43object(FFI\CData:struct bug80847_02)#%d (1) {
44  ["a"]=>
45  object(FFI\CData:struct bug80847_01)#%d (2) {
46    ["b"]=>
47    int(42)
48    ["c"]=>
49    float(42.5)
50  }
51}
52object(FFI\CData:struct bug80847_02)#%d (1) {
53  ["a"]=>
54  object(FFI\CData:struct bug80847_01)#%d (2) {
55    ["b"]=>
56    int(42)
57    ["c"]=>
58    float(42.5)
59  }
60}
61object(FFI\CData:struct bug80847_02)#%d (1) {
62  ["a"]=>
63  object(FFI\CData:struct bug80847_01)#%d (2) {
64    ["b"]=>
65    int(52)
66    ["c"]=>
67    float(32.5)
68  }
69}
70