Hi Oliver,
On 11 November 2016 at 13:14, Oliver Wang <
pyth...@gmail.com> wrote:
> /* client.c */
> #include "attr.h"
> #define INODES_64bit
I think the "#define" must be before the "#include", otherwise it
can't have an effect.
> So yes, I think you are right that there must be someplace in the library
> that did exactly what you wrote:
>
> #ifdef INODES_64bit
> # define attr_t attr64_t
> # define read_attr read_attr64
> #endif
No, I meant these lines must be inside "attr.h". If they were inside
some .c source file, they wouldn't have the effect that you want.
If you want to dig more, I'd recommend that you read more about
#define and #ifdef in C first. But:
> However, how do I give such a "#define INODES_64bit" knob to Python users?
This is a compilation switch. If you call set_source() and compile()
only once, then you can only get one of the two behaviors, compiled
inside the produced .so. This is because this .so is produced from
auto-generated C code, which will itself either use the #define or
not. There is no reasonable way to have both behaviors inside one
.so.
You could build two .so's, but what I think you should try to do
instead: just forget about the whole #define issue and expose both
read_attr and read_attr64 and both attr_t and attr64_t. Then, write
regular Python functions that will use one variant or the other,
depending on some Python switch. Something like:
def read_attr(args):
if use_inodes_64:
p = ffi.new("attr64_t")
lib.read_attr64(p, args)
return p.ino
else:
p = ffi.new("attr_t")
lib.read_attr(p, args)
return p.ino
A bientôt,
Armin.