From owner-freebsd-arch Fri Jul 27 10:16: 9 2001 Delivered-To: freebsd-arch@freebsd.org Received: from dragon.nuxi.com (trang.nuxi.com [206.40.252.115]) by hub.freebsd.org (Postfix) with ESMTP id 96EDA37B403 for ; Fri, 27 Jul 2001 10:16:06 -0700 (PDT) (envelope-from obrien@NUXI.com) Received: (from obrien@localhost) by dragon.nuxi.com (8.11.3/8.11.1) id f6RHFYo44335; Fri, 27 Jul 2001 10:15:34 -0700 (PDT) (envelope-from obrien) Date: Fri, 27 Jul 2001 10:15:29 -0700 From: "David O'Brien" To: Kris Kennaway Cc: arch@FreeBSD.org Subject: Re: Nuking all malloc wrappers (Re: cvs commit: src/usr.bin/nm nm.c) Message-ID: <20010727101529.B43542@dragon.nuxi.com> Reply-To: obrien@FreeBSD.org References: <200107241408.f6OE83j65583@freefall.freebsd.org> <20010724130418.A34051@xor.obsecurity.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010724130418.A34051@xor.obsecurity.org>; from kris@obsecurity.org on Tue, Jul 24, 2001 at 01:04:18PM -0700 X-Operating-System: FreeBSD 5.0-CURRENT Organization: The NUXI BSD group X-Pgp-Rsa-Fingerprint: B7 4D 3E E9 11 39 5F A3 90 76 5D 69 58 D9 98 7A X-Pgp-Rsa-Keyid: 1024/34F9F9D5 Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, Jul 24, 2001 at 01:04:18PM -0700, Kris Kennaway wrote: > I don't understand why you're doing this. Increasing code duplication > by expanding out a local function seems like a pessimization to me. Check the diffs. Two programs wrote "emalloc" as: void * emalloc(size_t s) { void * p; if ((p = malloc(s)) == NULL) errx(1, NULL); bzero(p, s); (or memset(p, 0, s)) return p; } ie, they rolled their own calloc(). That is a pestimazation as your libc may easily have a platform-specific optimized one. And the name emalloc implies malloc, not calloc semantics. So it is misleading to the reader. Which leads to the issue of someone not knowing emalloc is used in a particular program (or estrdup), so they use straight malloc or strdup -- breaking coherence w/in the program. (yes I found cases of this) Another case of "optimized" wrapper was the realloc one that didn't trust that our libc was ANSI compliant, so it tested `p' for NULL and called malloc if it was, else it went ahead and called realloc. Since ANSI says that is exactly how realloc must function, effectively we were testing for a NULL `p' twice. Again in this case, my change wasn't a pessimization. But rather it lead to easier to read and audit code. Also, in all but the xlint case, I there were only a hand full of "emalloc" uses. So they were only saving a hand full of testing malloc's return value, while adding the code overhead of another function call. -- -- David (obrien@FreeBSD.org) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message