Bug #78474 [Nab]: FFI::scope does not work in CLI SAPI

From: Date: Thu, 29 Aug 2019 21:29:16 +0000
Subject: Bug #78474 [Nab]: FFI::scope does not work in CLI SAPI
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222487@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78474&edit=1

 ID:                 78474
 User updated by:    ojrask at gmail dot com
 Reported by:        ojrask at gmail dot com
 Summary:            FFI::scope does not work in CLI SAPI
 Status:             Not a bug
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Ubuntu 18.04
 PHP Version:        7.4.0beta4
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Okay, is there a specific reason why scopes cannot be used outside the preloading state?


Previous Comments:
------------------------------------------------------------------------
[2019-08-29 08:15:48] cmb@php.net

[1] <https://www.php.net/manual/en/ffi.scope.php>

------------------------------------------------------------------------
[2019-08-29 08:15:28] cmb@php.net

From the docs[1]:

| Instantiates an FFI object with C declarations parsed during
| preloading.

------------------------------------------------------------------------
[2019-08-29 08:00:20] ojrask at gmail dot com

Description:
------------
When I attempt to use \FFI::scope() in CLI scripts (no preloading and all that jazz), I
get an error saying

    PHP Fatal error:  Uncaught FFI\Exception: Failed loading scope 'FOO' in ...

The stack trace reveals no reasons. I would presume scopes are OK to be used in CLI SAPI, or then
there is some documentation missing as to why it is not possible.

Test script:
---------------
<?php declare(strict_types = 1);

$header = <<<'HEA'
    #define FFI_SCOPE "FOO"
    #define FFI_LIB "libc.so.6"

    void printf(char *const str, ...);
    'HEA';

file_put_contents(__DIR__ . '/header.h', $header);

\FFI::load(__DIR__ . '/header.h');

$ffi = \FFI::scope('FOO');

$ffi->printf('Hello %s!', 'world');

Expected result:
----------------
Output should be

    Hello world!

Actual result:
--------------
Output is

    PHP Fatal error:  Uncaught FFI\Exception: Failed loading scope 'FOO' in
.../hello-world.php:14
    Stack trace:
    #0 .../hello-world.php(14): FFI::scope()
    #1 {main}
      thrown in .../hello-world.php on line 14


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78474&edit=1


Thread (5 messages)

« previous php.bugs (#222487) next »