* printf() less __assert_fail()
@ 2014-10-01 14:45 Daniel Cegiełka
2014-10-01 14:54 ` Rich Felker
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Cegiełka @ 2014-10-01 14:45 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 81 bytes --]
It makes no sense to use printf() in this function. Is this a good idea?
Daniel
[-- Attachment #2: assert.c --]
[-- Type: text/x-csrc, Size: 635 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
static void print(const char *s)
{
write(2, s, strlen(s));
}
static unsigned int fmt_uint(char *s, int n)
{
unsigned int l = 1, q = n;
while (q > 9) { ++l; q /= 10; }
if (s) {
s += l;
do { *--s = '0' + (n % 10); n /= 10; } while (n);
}
return l;
}
void __assert_fail(const char *expr, const char *file, int line, const char *func)
{
char buf[10];
print("Assertion failed: ");
print(expr);
print(" (");
print(file);
print(": ");
print(func);
print(": ");
write(2, buf, fmt_uint(buf, line));
print(")\n");
fflush(NULL);
abort();
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: printf() less __assert_fail()
2014-10-01 14:45 printf() less __assert_fail() Daniel Cegiełka
@ 2014-10-01 14:54 ` Rich Felker
2014-10-01 15:13 ` Daniel Cegiełka
0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2014-10-01 14:54 UTC (permalink / raw)
To: musl
On Wed, Oct 01, 2014 at 04:45:44PM +0200, Daniel Cegiełka wrote:
> It makes no sense to use printf() in this function. Is this a good idea?
I'm not sure why it "makes no sense". There are a few minor
differences in behavior with your version, the main ones I see being
that yours is non-atomic but async-signal-safe. Are there major
reasons you want to change it?
Rich
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: printf() less __assert_fail()
2014-10-01 14:54 ` Rich Felker
@ 2014-10-01 15:13 ` Daniel Cegiełka
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Cegiełka @ 2014-10-01 15:13 UTC (permalink / raw)
To: musl
2014-10-01 16:54 GMT+02:00 Rich Felker <dalias@libc.org>:
> On Wed, Oct 01, 2014 at 04:45:44PM +0200, Daniel Cegiełka wrote:
>> It makes no sense to use printf() in this function. Is this a good idea?
>
> I'm not sure why it "makes no sense". There are a few minor
> differences in behavior with your version, the main ones I see being
> that yours is non-atomic but async-signal-safe. Are there major
> reasons you want to change it?
Atomic version, yes, I thought about it. It's just an idea. This
version gives a much smaller binary. Similar solutions (WSTR macro)
you use in noxcuse for a small size.
Daniel
> Rich
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-10-01 15:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-01 14:45 printf() less __assert_fail() Daniel Cegiełka
2014-10-01 14:54 ` Rich Felker
2014-10-01 15:13 ` Daniel Cegiełka
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).