On Monday, 5 January 2015 at 17:44:31 UTC, Daniel Murphy wrote:
I think I've got a handle on this, sort of. I've moved the declaration of __va_argsave into the glue layer, and added intrinsic detection for va_start/va_end/va_arg (the two-arg form).

I've implemented them in the backend for win32 and they have passed a simple test!

I'd suggest you have a look at Posix x86_64 first before finalizing the "easy" x86 implementation. The former comes with two extra niceties compared to the simple "pointer to stack-allocated arguments" model:

1) You need to copy the registers to the stack on function entry (in case the arguments are later accessed using va_arg, they are just regular functions on the caller side), and then be able to access the address of this area in va_start. This is what va_argsave is currently used for in DMD.

2) The issue with passing va_list as a parameter (especially regarding C ABI compatibility) vs. allocating the struct storage allocation. If you simply make it a pointer on x86_64, it's hard to implement va_copy correctly. The DMD implementation of the latter is currently broken, which is the reason for some of the vararg-related version(X86_64) blocks.

Do you think we can change _all_ the druntime and phobos code to just use va_arg directly? It would be nice to have it all portable like that.

Yes. Some parts might need a bit of rework, though. This job would be quite a bit easier if we could finally ditch the old vararg-based std.format stuff before.

Be sure to let me know if you have any specific questions.

David

Reply via email to