Bug 2005 – dynamic va_arg looping/ align info in TypeInfo

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-04-18T10:24:00Z
Last change time
2017-07-02T14:09:56Z
Keywords
spec
Assigned to
nobody
Creator
fawzi

Comments

Comment #0 by fawzi — 2008-04-18T10:24:36Z
Looping over va_arg that span a set of types that is unknown is error prone. In dmd this seem to work because va_list is a void* and one can simply add the size of the actual type to go to the next. Actually such a method does not keep into account alignment issues, and no alignment information is present in TypeInfo. A clean way to solve this would be to add a function like void *dyn_va_arg(TypeInfo, inout va_list) that returns a pointer to the actual argument and updates va_list. If one wants to allow even more flexibility in the implementation of va_list then the function should be void *dyn_va_arg_tmp(TypeInfo, inout va_list, out bool); and the pointer returned by this functions would be invalided at the next call of va_arg if bool says so. Such functions could be readily implemented for dmd if typeinfo would give access to the alignment information of its type (.talign?). Also for gdc it should be possible to implement this function (at least the second one), and it would solve or at least alleviate the much more serious issues that gdc has in that department, something that I proposed in http://d.puremagic.com/issues/show_bug.cgi?id=2004 Another possibility would be to change _args to a void*[] in D2, this would also solve all the issues, but would add some overhead that the actual implementation does not have.
Comment #1 by dlang-bugzilla — 2017-07-02T14:09:56Z
As I understand, C-style variadics are provided in D only as a low-level interoperability feature with existing C code. Today, variadic IFTI template functions should be used instead in D code. (In reply to Fawzi Mohamed from comment #0) > Such functions could be readily implemented for dmd if typeinfo would give > access to the alignment information of its type (.talign?). TypeInfo.talign was added in https://github.com/dlang/druntime/commit/cbd538f34f8082cc512a05eae3ab23039d8fe1d7.