Re: sdl2 and ffi

new topic     » goto parent     » topic index » view thread      » older message » newer message
ghaberek said...
ChrisB said...

At the risk of sounding like a troll (seriously not my intention, Andy has always done great work on all the libraries he has created, and wrapping all those functions must be some sort of tedium), but I think you've missed my point Gregg.

I don't think you're trolling. This is a very complex topic and sometimes it's hard to tell who's understanding what and by how much. I'm happy to iterate over this until we're all in understanding.

ChrisB said...

My point is that all sdl functions need pointers to structures, as far as I can tell, and passing a type, created using allocate structure, does not contain the pointer to that allocated memory

It looks like Andy misunderstood how to use the types created by FFI, but I hadn't realized that yet so you and I were talking about slightly different things. Sorry about that. Once Andy corrects the wrapper to use C_POINTER wherever there are types like SDL_Event *event (mind the asterisk!) then we should all be on the same conceptual page again.

ChrisB said...

I don't doubt that ffi will make it easier to manipulate structures, it already has done so for me, and I know I'm a pest, but the SDL library as Andy has presented just doesn't work. Now, correct me if I'm wrong, and I'm misunderstanding something here, but is passing a type the same as passing pointer?

No, passing a type is not the same as passing a pointer. Internally it's much different. Each combination of platform, architecture, and calling convention presents a new way of handling values and they all involve registers and stack space. The Wikipedia x86 calling conventions page helps explain this but it's all very messy. This is why I opted to use libffi instead of trying to extend Euphoria's "legacy" backend functions. I'd only be reinventing the wheel and likely creating all sorts of issues due to the many-to-many-to-many complexity involved, and libffi has already spent decades addressing and correcting these issues.

ChrisB said...

ps - see the code above - peek_struct isn't returning the correct values - is C_UINT in euphoria 1 byte, 8 bits only, as that's what SDL_GetVersion returns, and that's why the peek version returns the correct values. Change the SDL_version type C_UINTs to C_UINT8s, and it works.

C_UINT is an unsigned int which is "at least 16 bits" which is weird, right? C types are loosely defined and weren't really intended for use outside the compiler. C99 created "fixed width" types which is what gives us things like uint8_t which is an unsigned int that is always 8-bits like you would expect. Effectively unsigned int would be the same as uint32_t but since it's loosely defined that makes figuring these things out very challenging. The Wikipedia C data types page helps explain this, and at least it seems more straight-forward than the calling conventions concept.

-Greg

I've fixed the SDL_events.e file. I've changed the SDL_Event to a C_POINTER.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu