Skip to content

Commit

Permalink
Cast via VALUE function pointer between object pointer (#150)
Browse files Browse the repository at this point in the history
With gcc 13 and -pedantic:

```
../../../src/ext/fiddle/function.c: In function ‘function_call’:
../../../src/ext/fiddle/function.c:374:15: error: ISO C forbids conversion of object pointer to function pointer type [-Wpedantic]
  374 |     args.fn = (void(*)(void))NUM2PTR(cfunc);
      |               ^
../../../src/ext/fiddle/pointer.c: In function ‘rb_fiddle_ptr_inspect’:
../../../src/ext/fiddle/pointer.c:573:84: error: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
  573 |                       RB_OBJ_CLASSNAME(self), (void *)data, data->ptr, data->size, (void *)data->free);
      |                                                                                    ^
```
  • Loading branch information
nobu authored Oct 10, 2024
1 parent d76c87b commit 6421e31
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext/fiddle/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ function_call(int argc, VALUE argv[], VALUE self)
args.values[i_call] = (void *)&generic_args[i_call];
}
args.values[i_call] = NULL;
args.fn = (void(*)(void))NUM2PTR(cfunc);
args.fn = (void(*)(void))(VALUE)NUM2PTR(cfunc);

if (RTEST(need_gvl)) {
ffi_call(args.cif, args.fn, &(args.retval), args.values);
Expand Down
2 changes: 1 addition & 1 deletion ext/fiddle/pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ rb_fiddle_ptr_inspect(VALUE self)

TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
return rb_sprintf("#<%"PRIsVALUE":%p ptr=%p size=%ld free=%p>",
RB_OBJ_CLASSNAME(self), (void *)data, data->ptr, data->size, (void *)data->free);
RB_OBJ_CLASSNAME(self), (void *)data, data->ptr, data->size, (void *)(VALUE)data->free);
}

/*
Expand Down

0 comments on commit 6421e31

Please sign in to comment.