On 04/08/2011 03:58 AM, Simon Josefsson wrote: > Paul Eggert <egg...@cs.ucla.edu> writes: > >> But that raises another problem. For Emacs, I'd like a variant of >> vasnprintf that uses Emacs's allocators rather than malloc/realloc/free. >> I could instead attack the problem by blocking interrupts while >> calling vasnprintf, but I'd rather not add these extra system calls >> for every call to vasnprintf. >> >> I expect that I can do that by creating a new module (vcasnprintf, say), >> which defines a function that acts like vasnprintf but allocates >> storage as specified by a struct allocator parameter. The best way >> to do that, I expect, would be to refactor vasnprintf.c, and I am >> thinking of proposing something along those lines. > > Couldn't you just call the existing *printf functions and reallocate the > output using Emacs' strdup or similar? There will be a slight > performance hit, but I wonder if it matters compared to the cost if > maintaining *printf functions that differs even more from glibc.
Not really, because even glibc's snprintf calls malloc() internally for certain cases, even when you pass in a size of 0. If the whole point of this exercise is to completely avoid malloc() in favor of a safer allocater, then you'd have to lock every call to snprintf. -- Eric Blake ebl...@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature