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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: larry at garfieldtech dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 00:01:30 2024 UTC