summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
5ec7465)
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.
+2020-07-22 Nick Alcock <nick.alcock@oracle.com>
+
+ * ctf-api.c (ctf_type_name_raw): New.
+
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
* ctf-api.h (ECTF_*): Improve comments.
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
* ctf-api.h (ECTF_*): Improve comments.
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 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);
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);
+2020-07-22 Nick Alcock <nick.alcock@oracle.com>
+
+ * ctf-types.c (ctf_type_name_raw): New.
+ (ctf_type_aname_raw): Reimplement accordingly.
+
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
* ctf-subr.c (ctf_dprintf): _libctf_debug is unlikely to be set.
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
* ctf-subr.c (ctf_dprintf): _libctf_debug is unlikely to be set.
return (rv >= 0 && (size_t) rv < len ? buf : NULL);
}
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. */
{
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);
ctf_type_resolve;
ctf_type_lname;
ctf_type_name;
ctf_type_resolve;
ctf_type_lname;
ctf_type_name;
ctf_type_aname;
ctf_type_aname_raw;
ctf_type_size;
ctf_type_aname;
ctf_type_aname_raw;
ctf_type_size;