From owner-freebsd-hackers Wed Dec 20 11:33:22 2000 From owner-freebsd-hackers@FreeBSD.ORG Wed Dec 20 11:33:20 2000 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from assaris.sics.se (h122n4fls32o892.telia.com [213.64.47.122]) by hub.freebsd.org (Postfix) with ESMTP id 08FA337B400 for ; Wed, 20 Dec 2000 11:33:19 -0800 (PST) Received: (from assar@localhost) by assaris.sics.se (8.9.3/8.9.3) id UAA89020; Wed, 20 Dec 2000 20:33:09 +0100 (CET) (envelope-from assar) Sender: assar@assaris.sics.se To: seebs@plethora.net (Peter Seebach) Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Why not another style thread? (was Re: cvs commit: src/lib/libc/gen .. References: <200012201541.JAA15236@guild.plethora.net> From: Assar Westerlund Date: 20 Dec 2000 20:33:08 +0100 In-Reply-To: seebs@plethora.net's message of "Wed, 20 Dec 2000 09:41:11 -0600" Message-ID: <5l3dfiyjkb.fsf@assaris.sics.se> Lines: 30 User-Agent: Gnus/5.070098 (Pterodactyl Gnus v0.98) Emacs/20.6 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG seebs@plethora.net (Peter Seebach) writes: > Okay, from a style standpoint, the basic problem is that this function > is a mistake. No, I use a function like that (called emalloc) all the time, when I know there's nothing better to do than exit. > Programs may have temp files open, they may have stty > settings to reset, there are tons of things you may need to do *BEFORE > EXITING*. atexit > At a bare minimum, the Correct Thing would be > #define safe_malloc(x) safe_malloc_internal((x), __FILE__, __LINE__) > > void *safe_malloc(size_t bytes, char *file, int line) > { > void *p = malloc(bytes); > if (p == NULL) { > fprintf(stderr, "can't allocate %lu bites at file %s, line %d.", > (unsigned long) x, __FILE__, __LINE__); s/__FILE__/file/, s/__LINE__/line/ > (In an ideal world, you'd have the program name in here.) err(3) ? /assar To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message