rpav / c2ffi

Clang-based FFI wrapper generator
GNU Lesser General Public License v2.1
234 stars 38 forks source link

How to recognize `uint8_t` ? #90

Closed kojix2 closed 3 years ago

kojix2 commented 3 years ago

Hello.

I'm trying to use c2ffi. When I run c2ffi on the following file, I get the following error. From the error message, it is assumed that c2ffi is unable to recognize uint8_t. Maybe I am missing something basic. I would appreciate it if you could tell me how to make it work.

foo.c

#include <stdio.h>
#include <stdint.h>

int foo(uint8_t bar){
  printf("%d\n", bar);
  return 0;
}

int main(void){
  uint8_t x = 10;
  foo(x);
  return 0;
}

Run c2ffi

c2ffi foo.c -o foo.json 2> foo.log

Error

foo.c:4:9: error: unknown type name 'uint8_t'
int foo(uint8_t bar){
        ^
Skipping invalid Decl:
FunctionDecl 0x5648fe4e0d40 <foo.c:4:1, line:7:1> line:4:5 invalid foo 'int (int)'
|-ParmVarDecl 0x5648fe4e0ca8 <col:9, col:17> col:17 invalid bar 'int'
`-CompoundStmt 0x5648fe4e0e58 <col:21, line:7:1>
  `-ReturnStmt 0x5648fe4e0e48 <line:6:3, col:10>
    `-IntegerLiteral 0x5648fe4e0e28 <col:10> 'int' 0
foo.c:10:10: error: expected ';' after expression
  uint8_t x = 10;
         ^
         ;
foo.c:10:3: error: use of undeclared identifier 'uint8_t'
  uint8_t x = 10;
  ^
foo.c:10:11: error: use of undeclared identifier 'x'
  uint8_t x = 10;
          ^
foo.c:11:7: error: use of undeclared identifier 'x'
  foo(x);
      ^

Thank you.

rpav commented 3 years ago

Probably this is not the first error... rather, c2ffi isn't finding a platform-specific header that stdint.h requires. Currently only some guesswork is done about header locations; #89 is doing work to fix this, but I haven't had a chance to swing back around (hopefully this week). You can manually specify system header locations with -i (or try that PR!).

kojix2 commented 3 years ago

Thanks for your reply. I tried the pull request #89. It works fine on my computer.

c2ffi foo.c -o foo.json 2> foo.log

tail of foo.json

{ "tag": "function", "name": "foo", "ns": 0, "location": "foo.c:4:5", "variadic": false, "inline": false, "storage-class": "none", "parameters": [{ "tag": "parameter", "name": "bar", "type": { "tag": "uint8_t" } }], "return-type": { "tag": ":int", "bit-size": 32, "bit-alignment": 32 } },
{ "tag": "function", "name": "main", "ns": 0, "location": "foo.c:9:5", "variadic": false, "inline": false, "storage-class": "none", "parameters": [], "return-type": { "tag": ":int", "bit-size": 32, "bit-alignment": 32 } }
]

No error.

This issue has been resolved.

If I have any questions, please let me ask you again. Have a nice day.