php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79075 FFI header parser chokes on comments
Submitted: 2020-01-07 21:45 UTC Modified: -
From: larry at garfieldtech dot com Assigned:
Status: Open Package: Unknown/Other Function
PHP Version: 7.4.1 OS: Ubuntu 19.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
48 - 8 = ?
Subscribe to this entry?

 
 [2020-01-07 21:45 UTC] larry at garfieldtech dot com
Description:
------------
(I couldn't find an FFI section in the packages affected section; feel free to relocate this ticket to the right location.)

When using FFI, If the .h file contains a comment that comes before a #define then the FFI::load() will fail with a Warning: cannot resolve C function.

This does not seem to happen if the same .h file is used in FFI::cdef().

That is, the following header file works fine:

```
#define FFI_SCOPE "POINTS"
#define FFI_LIB "./points.so"

struct point {
    int     x;
    int     y;
};

// Foo

double distance(struct point first, struct point second);
```

But this version fails in FFI::load(), and works in FFI::cdef():

```
#define FFI_SCOPE "POINTS"
// Foo
#define FFI_LIB "./points.so"

struct point {
    int     x;
    int     y;
};

double distance(struct point first, struct point second);
```

I have verified the same behavior regardless of whether // or /* */ comments are used.

Test script:
---------------
See: https://github.com/Crell/ffi-test/tree/476610f469aff116f41131948e58b0e27f9b9a57

That commit has a directory "points" with sample code.  (It's fixed in more recent comments.)  To demonstrate, change into that directory and run "make inline".  That will work.  Then run "make preload", which uses the preload-with-load() approach.  It will fail.  Then modify the points.h file to remove the comment between the #define statements.  It will now work.

(At least that's what I experienced.)


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 16:01:31 2024 UTC