Skip to content

Commit

Permalink
Merge branch 'main' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Feb 14, 2023
2 parents b85d2fd + 5c33b5c commit 2d1cff1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ _To setup a skeleton for FFI integration._
composer create-project symplely/zend-ffi .
```

`FFI` is enabled by default in `php.ini` since `PHP 7.4`, as to `OpCache`, they should not be changed unless already manually disabled.
Only the `preload` section might need setting up if better performance is desired.

It seems all the `php.ini` setting **files** on Windows does not have them enabled.
Minimum `php.ini` setting:

```ini
extension=ffi
Expand All @@ -52,14 +49,12 @@ opcache.enable_cli=1
; "preload" - enabled in CLI scripts and preloaded files (default)
; "false" - always disabled
; "true" - always enabled
ffi.enable="preload"
ffi.enable="true"

; List of headers files to preload, wildcard patterns allowed. `ffi.preload` has no effect on Windows.
ffi.preload=path/to/vendor/symplely/zend-ffi/headers/ze{%php version%}.h
ffi.preload=path/to/vendor/symplely/zend-ffi/headers/ze{%php version%}_vendor.h

opcache.preload==path/to/.cdef/ffi_preloader.php ; For simple integration with other FFI extensions
; Or
opcache.preload==path/to/vendor/symplely/zend-ffi/preload.php ; For standalone usage
opcache.preload==path/to/vendor/symplely/zend-ffi/preload.php
```

For a simple FFI integration process **create/edit**:
Expand Down
22 changes: 16 additions & 6 deletions zend/Types/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,20 @@ class Resource extends \ZE

public function __destruct()
{
$this->extra = null;
if (!\is_null($this->extra)) {
$object = $this->extra;
$this->extra = null;
\zval_del_ref($object);
}

$this->free();
}

public function update(CData $ptr, bool $isOther = false): self
{
if ($isOther) {
\FFI::free($this->ze_other_ptr);
$this->ze_other_ptr = null;
$this->ze_other = null;
}

Expand All @@ -157,7 +163,7 @@ public function update(CData $ptr, bool $isOther = false): self

public function free(): void
{
if (!\is_null($this->ze_other_ptr) && \count($this->fd) === 0) {
if (!\is_null($this->ze_other_ptr)) {
if (\is_typeof($this->ze_other_ptr, 'struct _php_stream*'))
\ze_ffi()->_php_stream_free($this->ze_other_ptr, self::PHP_STREAM_FREE_CLOSE);
else
Expand Down Expand Up @@ -209,11 +215,15 @@ public function add_pair(Zval $zval, int $fd1, int $resource1, int $fd0 = null,
{
$this->zval = $zval;
$this->index = $fd1;
$this->fd[$fd1] = $this->fd[$resource1] = [$fd1, $resource1];
static::$instances[$fd1] = static::$instances[$resource1] = $this;
$this->fd[$fd1] = [$fd1, $resource1];
$this->fd[$resource1] = [$fd1, $resource1];
static::$instances[$fd1] = $this;
static::$instances[$resource1] = $this;
if (!\is_null($fd0) && !\is_null($resource0)) {
$this->fd[$fd0] = $this->fd[$resource0] = [$fd0, $resource0];
static::$instances[$fd0] = static::$instances[$resource0] = $this;
$this->fd[$fd0] = [$fd0, $resource0];
$this->fd[$resource0] = [$fd0, $resource0];
static::$instances[$fd0] = $this;
static::$instances[$resource0] = $this;
}

return $this;
Expand Down

0 comments on commit 2d1cff1

Please sign in to comment.