From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45845 invoked by alias); 5 Jun 2019 22:33:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 45837 invoked by uid 89); 5 Jun 2019 22:33:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-5.6 required=5.0 tests=AWL,BAYES_00,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.144.97) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Jun 2019 22:33:48 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway31.websitewelcome.com (Postfix) with ESMTP id B39B97BFB for ; Wed, 5 Jun 2019 17:33:47 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id YeTbhi5OS2PzOYeTbh2P6D; Wed, 05 Jun 2019 17:33:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=FqHKO/TUDzcUByJeWNQPu8GpeSxGEOiUlCNQ72kH0uA=; b=AyGc5MnJC/admHb0G1EXLhyyv+ nBD4RW7PoVB//hSQwlEV9R/yLS7Tg/CFa+rtXpFkwAxJ530KCykXje1srzhI5jPQVJ8i6aUHg4h0s BLUx94lLf316wlcDyUlJwT3jW; Received: from 174-29-48-168.hlrn.qwest.net ([174.29.48.168]:47408 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hYeTb-002aDh-FY; Wed, 05 Jun 2019 17:33:47 -0500 From: Tom Tromey To: Pedro Alves Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [RFC 2/2] Move gdb's xmalloc and friends to new file References: <20190530213046.20542-1-tom@tromey.com> <20190530213046.20542-3-tom@tromey.com> Date: Wed, 05 Jun 2019 22:33:00 -0000 In-Reply-To: (Pedro Alves's message of "Wed, 5 Jun 2019 10:40:49 +0100") Message-ID: <87ef47br1x.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2019-06/txt/msg00135.txt.bz2 >>>>> "Pedro" == Pedro Alves writes: Pedro> This will be the first case of gdbserver building a file Pedro> from gdb/ . I suppose we could preserve the gdb/common/ Pedro> directory for such files. But I guess moving it out of the Pedro> way until gdb/common/ moves to top level helps. Yeah. We can shuffle it around again later if we want. >> + Copyright (C) 2019 Free Software Foundation, Inc. Pedro> The file is new, but the contents aren't, and it's the contents Pedro> that matter wrt to copyright years. Fixed. Pedro> There should be some comment here about why this is in a separate file Pedro> instead of living in the common library, to help people that read Pedro> the code from the tree without having this commit in context. Also fixed. >> +#include "common/common-defs.h" Pedro> There should also be a comment explaining why this includes common-defs.h Pedro> instead of defs.h. Fixed. >> +#include "libiberty.h" >> +#include Pedro> Including looks strange, given common-defs.h includes stdlib.h. Pedro> Why did you need this? Removed. I've appended the new file. I'll probably push these patches sometime soon. Tom /* Shared allocation functions for GDB, the GNU debugger. Copyright (C) 1986-2019 Free Software Foundation, Inc. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* This file is unusual. Because both libiberty and readline define xmalloc and friends, the functions in this file can't appear in a library -- that will cause link errors. And, because we want to turn the common code into a library, this file can't live there. So, it lives in gdb and is built separately by gdb and gdbserver. Please be aware of this when modifying it. This also explains why this file includes common-defs.h and not defs.h or server.h -- we'd prefer to avoid depending on the GDBSERVER define when possible, and for this file it seemed simple to do so. */ #include "common/common-defs.h" #include "libiberty.h" #include "common/errors.h" /* The xmalloc() (libiberty.h) family of memory management routines. These are like the ISO-C malloc() family except that they implement consistent semantics and guard against typical memory management problems. */ /* NOTE: These are declared using PTR to ensure consistency with "libiberty.h". xfree() is GDB local. */ PTR /* ARI: PTR */ xmalloc (size_t size) { void *val; /* See libiberty/xmalloc.c. This function need's to match that's semantics. It never returns NULL. */ if (size == 0) size = 1; val = malloc (size); /* ARI: malloc */ if (val == NULL) malloc_failure (size); return val; } PTR /* ARI: PTR */ xrealloc (PTR ptr, size_t size) /* ARI: PTR */ { void *val; /* See libiberty/xmalloc.c. This function need's to match that's semantics. It never returns NULL. */ if (size == 0) size = 1; if (ptr != NULL) val = realloc (ptr, size); /* ARI: realloc */ else val = malloc (size); /* ARI: malloc */ if (val == NULL) malloc_failure (size); return val; } PTR /* ARI: PTR */ xcalloc (size_t number, size_t size) { void *mem; /* See libiberty/xmalloc.c. This function need's to match that's semantics. It never returns NULL. */ if (number == 0 || size == 0) { number = 1; size = 1; } mem = calloc (number, size); /* ARI: xcalloc */ if (mem == NULL) malloc_failure (number * size); return mem; } void xmalloc_failed (size_t size) { malloc_failure (size); }