Skip to content

Commit aba4673

Browse files
committed
Merge branch 'main' into beta
2 parents 53aa44f + 6e1f857 commit aba4673

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ opcache.enable_cli=1
5252
ffi.enable="true"
5353

5454
; List of headers files to preload, wildcard patterns allowed. `ffi.preload` has no effect on Windows.
55-
; see headers directory `your-php-version`
56-
;ffi.preload=path/to/vendor/symplely/zend-ffi/headers/ze(your-php-version)_generated.h
55+
; See headers directory for `your-php-version`, this feature is untested, since not enabled for Windows.
56+
;ffi.preload=path/to/vendor/symplely/zend-ffi/headers/ze(your-php-version).h
5757

58+
;This feature is untested.
5859
;opcache.preload==path/to/vendor/symplely/zend-ffi/preload.php
5960
```
6061

preload.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,17 +357,26 @@ function is_cdata($ptr): bool
357357
}
358358

359359
/**
360-
* Checks whether the given object is `FFI\CData`, and has the given `field`.
360+
* Checks whether the given _c struct_ object is `FFI\CData`, and has the given member `field`.
361361
*
362362
* @param object $ptr
363-
* @param string $field
363+
* @param string $field member depth, up three levels *c_field0->c_field1->c_field2*
364364
* @return boolean
365365
*/
366-
function is_cdata_valid(object $ptr, string $field)
366+
function is_cdata_valid(object $ptr, string $field): bool
367367
{
368368
try {
369-
$isValid = \ffi_object($ptr)->{$field};
370-
return \is_null($isValid) || !\is_null($isValid);
369+
if (\strpos($field, '->') !== false) {
370+
$fields = \explode('->', $field);
371+
if (\count($fields) == 3)
372+
\ffi_object($ptr)->{$fields[0]}->{$fields[1]}->{$fields[2]};
373+
elseif (\count($fields) == 2)
374+
\ffi_object($ptr)->{$fields[0]}->{$fields[1]};
375+
} else {
376+
\ffi_object($ptr)->{$field};
377+
}
378+
379+
return true;
371380
} catch (\Throwable $e) {
372381
return false;
373382
}
@@ -639,7 +648,7 @@ function zend_preloader(): void
639648
if (\IS_WINDOWS) {
640649
$mmap_header = __DIR__ . '\\headers\\windows_mman.h';
641650
if (\file_exists('vendor\\symplely\\zend-ffi')) {
642-
$vendor_code = \str_replace('.h', '_vendor.h', $mmap_header);
651+
$vendor_code = \str_replace('.h', '_generated.h', $mmap_header);
643652
if (!\file_exists($vendor_code)) {
644653
$file = \str_replace(
645654
'FFI_LIB ".',

tests/900-misc_general_c.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ $cs = c_struct_type('_php_socket', 'ze', [
2525
'std' => ZendObject::init($ci)()[0]
2626
]);
2727
var_dump(is_cdata_valid($cs, 'blocking'));
28+
var_dump(is_cdata_valid($cs, 'block'));
29+
var_dump(is_cdata_valid($cs, 'zstream->value'));
30+
var_dump(is_cdata_valid($cs, 'zstream->value->lval'));
2831
var_dump($cs->sizeof());
2932
var_dump($cs->alignof());
3033
var_dump($cs->char());
@@ -57,6 +60,9 @@ object(CStruct)#%d (2) {
5760
int(1477705728)
5861
}
5962
bool(true)
63+
bool(false)
64+
bool(true)
65+
bool(true)
6066
int(88)
6167
int(8)
6268
object(FFI\CData:char*)#%d (1) {

0 commit comments

Comments
 (0)