April 08, 2014 [Issue 12548] New: Safer malloc/calloc/realloc wrappers in Phobos | ||||
---|---|---|---|---|
| ||||
https://d.puremagic.com/issues/show_bug.cgi?id=12548 Summary: Safer malloc/calloc/realloc wrappers in Phobos Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2014-04-08 12:42:05 PDT --- In my D code for various reasons I sometimes need or wants to use C memory allocating functions, the malloc/calloc/realloc. But in D they force the usage of a cast(), that I prefer to avoid. And often you need to specify the type two times, like this (such code is not DRY, and this leads to bugs): cast(T*)malloc(typeof(T).sizeof * 10); So I suggest to add to Phobos three little wrappers around those functions that allow remove those casts (this can't be done with the "alloca" function), that are safer than the C functions: cMalloc!T(n) cCalloc!T(n) cRealloc(ptr, n) cRealloc doesn't need the type because it's inferred from the given pointer. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation