From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by sourceware.org (Postfix) with ESMTPS id 147483861017 for ; Tue, 30 Jun 2020 23:34:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 147483861017 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 05UNWKim049504 for ; Tue, 30 Jun 2020 23:34:04 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 31xx1dv815-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 30 Jun 2020 23:34:04 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 05UNNl9J068642 for ; Tue, 30 Jun 2020 23:32:03 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 31xg1xgarp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 30 Jun 2020 23:32:03 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05UNW2Jt005794 for ; Tue, 30 Jun 2020 23:32:02 GMT Received: from loom.srvr.nix (/81.187.191.129) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 30 Jun 2020 23:32:02 +0000 From: Nick Alcock To: binutils@sourceware.org Subject: [PATCH 15/59] libctf: add ctf_type_name_raw Date: Wed, 1 Jul 2020 00:31:02 +0100 Message-Id: <20200630233146.338613-16-nick.alcock@oracle.com> X-Mailer: git-send-email 2.27.0.247.g3dff7de930 In-Reply-To: <20200630233146.338613-1-nick.alcock@oracle.com> References: <20200630233146.338613-1-nick.alcock@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9668 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006300162 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9668 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 adultscore=0 suspectscore=1 mlxlogscore=999 cotscore=-2147483648 lowpriorityscore=0 malwarescore=0 phishscore=0 impostorscore=0 mlxscore=0 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006300163 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Jun 2020 23:34:06 -0000 We already have a function ctf_type_aname_raw, which returns the raw name of a type with no decoration for structures or arrays or anything like that: just the underlying name of whatever it is that's being ultimately pointed at. But this can be inconvenient to use, becauswe it always allocates new storage for the string and copies it in, so it can potentially fail. Add ctf_type_name_raw, which just returns the string directly out of libctf's guts: it will live until the ctf_file_t is closed (if we later gain the ability to remove types from writable dicts, it will live as long as the type lives). Reimplement ctf_type_aname_raw in terms of it. include/ * ctf-api.c (ctf_type_name_raw): New. libctf/ * ctf-types.c (ctf_type_name_raw): New. (ctf_type_aname_raw): Reimplement accordingly. --- include/ctf-api.h | 1 + libctf/ctf-types.c | 23 +++++++++++++++++------ libctf/libctf.ver | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/ctf-api.h b/include/ctf-api.h index 2e3e28b840c..363b5c258ca 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -324,6 +324,7 @@ extern char *ctf_type_aname (ctf_file_t *, ctf_id_t); extern char *ctf_type_aname_raw (ctf_file_t *, ctf_id_t); extern ssize_t ctf_type_lname (ctf_file_t *, ctf_id_t, char *, size_t); extern char *ctf_type_name (ctf_file_t *, ctf_id_t, char *, size_t); +extern const char *ctf_type_name_raw (ctf_file_t *, ctf_id_t); extern ssize_t ctf_type_size (ctf_file_t *, ctf_id_t); extern ssize_t ctf_type_align (ctf_file_t *, ctf_id_t); extern int ctf_type_kind (ctf_file_t *, ctf_id_t); diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c index db42b9e8a90..ce3890c33a6 100644 --- a/libctf/ctf-types.c +++ b/libctf/ctf-types.c @@ -472,19 +472,30 @@ ctf_type_name (ctf_file_t *fp, ctf_id_t type, char *buf, size_t len) return (rv >= 0 && (size_t) rv < len ? buf : NULL); } -/* Lookup the given type ID and return its raw, unadorned, undecorated name as a - new dynamcally-allocated string. */ +/* Lookup the given type ID and return its raw, unadorned, undecorated name. + The name will live as long as its ctf_file_t does. */ -char * -ctf_type_aname_raw (ctf_file_t *fp, ctf_id_t type) +const char * +ctf_type_name_raw (ctf_file_t *fp, ctf_id_t type) { const ctf_type_t *tp; if ((tp = ctf_lookup_by_id (&fp, type)) == NULL) return NULL; /* errno is set for us. */ - if (ctf_strraw (fp, tp->ctt_name) != NULL) - return strdup (ctf_strraw (fp, tp->ctt_name)); + return ctf_strraw (fp, tp->ctt_name); +} + +/* Lookup the given type ID and return its raw, unadorned, undecorated name as a + new dynamically-allocated string. */ + +char * +ctf_type_aname_raw (ctf_file_t *fp, ctf_id_t type) +{ + const char *name = ctf_type_name_raw (fp, type); + + if (name != NULL) + return strdup (name); return NULL; } diff --git a/libctf/libctf.ver b/libctf/libctf.ver index aad304bc0d9..30a0b087bd6 100644 --- a/libctf/libctf.ver +++ b/libctf/libctf.ver @@ -57,6 +57,7 @@ LIBCTF_1.0 { ctf_type_resolve; ctf_type_lname; ctf_type_name; + ctf_type_name_raw; ctf_type_aname; ctf_type_aname_raw; ctf_type_size; -- 2.27.0.247.g3dff7de930