From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id C83E5396D838 for ; Thu, 2 Jun 2022 13:36:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C83E5396D838 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 252Cmt6H030698; Thu, 2 Jun 2022 13:36:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gew0h1k42-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Jun 2022 13:36:01 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 252DNXWT038993; Thu, 2 Jun 2022 13:36:01 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gew0h1k3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Jun 2022 13:36:01 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 252DZcbQ002317; Thu, 2 Jun 2022 13:35:59 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 3gbcae73yf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Jun 2022 13:35:58 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 252DZpf022675790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Jun 2022 13:35:51 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B955AA4040; Thu, 2 Jun 2022 13:35:55 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 611F0A4051; Thu, 2 Jun 2022 13:35:55 +0000 (GMT) Received: from heavy.ibmuc.com (unknown [9.171.42.87]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 2 Jun 2022 13:35:55 +0000 (GMT) From: Ilya Leoshkevich To: Tom Tromey , Andrew Burgess , Pedro Alves Cc: Andreas Arnez , gdb-patches@sourceware.org, Ilya Leoshkevich Subject: [PATCH 1/5] gdbsupport: Introduce obstack_newvec Date: Thu, 2 Jun 2022 15:35:42 +0200 Message-Id: <20220602133546.2948282-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220602133546.2948282-1-iii@linux.ibm.com> References: <20220602133546.2948282-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: sQvn7ThVgWIF43nA9nFx01MROTgUz16v X-Proofpoint-ORIG-GUID: m514Q2AHGqtycOzpg1larbKqfVNKm6Zw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-02_03,2022-06-02_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 mlxscore=0 suspectscore=0 bulkscore=0 clxscore=1015 phishscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206020059 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Jun 2022 13:36:29 -0000 obstack_calloc() allocates multiple objects, but doesn't call their constructors. obstack_new() allocates a single object and calls its constructor. Introduce a new function that does both. --- gdbsupport/gdb_obstack.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gdbsupport/gdb_obstack.h b/gdbsupport/gdb_obstack.h index 5e870cb7981..201ed99216f 100644 --- a/gdbsupport/gdb_obstack.h +++ b/gdbsupport/gdb_obstack.h @@ -59,6 +59,32 @@ obstack_new (struct obstack *ob, Args&&... args) return object; } +/* Allocate NUMBER objects on OB and call their default constructors. Note + that obstack_free() won't call their destructors: this has to be done + manually. */ + +template +static inline T * +obstack_newvec (obstack *ob, size_t number) +{ + T *objects = static_cast (obstack_alloc (ob, number * sizeof (T))); + for (size_t i = 0; i < number; i++) + { + try + { + new (objects + i) T (); + } + catch (...) + { + for (size_t j = 0; j < i; j++) + (objects + j)->~T (); + obstack_free (ob, objects); + throw; + }; + } + return objects; +} + /* Unless explicitly specified, GDB obstacks always use xmalloc() and xfree(). */ /* Note: ezannoni 2004-02-09: One could also specify the allocation -- 2.35.3