datatype: return const pointer from datatype_get()
PATCH 1/1 datatype: return const pointer from datatype_get()
"struct datatype" is for the most part immutable, and most callers deal with const pointers. That's why datatype_get() accepts a const pointer to increase the reference count (mutating the refcnt field).
It should also return a const pointer. In fact, all callers are fine with that already.
Signed-off-by Thomas Haller <[email protected]>
--- include/datatype.h | 2 +- src/datatype.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/datatype.h +1 -1
@@ -174,7 +174,7 @@ struct datatype {extern const struct datatype *datatype_lookup (enum datatypes type);extern const struct datatype *datatype_lookup_byname (const char *name); -extern struct datatype *datatype_get (const struct datatype *dtype); +extern const struct datatype *datatype_get (const struct datatype *dtype);extern void datatype_set (struct expr *expr,const struct datatype *dtype);extern void __datatype_set (struct expr *expr,const struct datatype *dtype);extern void datatype_free (const struct datatype *dtype);
src/datatype.c +1 -1
@@ -1211,7 +1211,7 @@ static struct datatype *datatype_alloc(void)return dtype; } -struct datatype *datatype_get (const struct datatype *ptr) +const struct datatype *datatype_get (const struct datatype *ptr) {struct datatype *dtype = (struct datatype *)ptr;
Signature · 1 line
2.41.0
Quoted 6 lines · Thomas Haller
"struct datatype" is for the most part immutable, and most callers deal with const pointers. That's why
datatype_get()accepts a const pointer to increase the reference count (mutating the refcnt field).It should also return a const pointer. In fact, all callers are fine with that already.
Applied, thanks Thomas