Message ID | 20200813222625.243136-31-ehabkost@redhat.com |
---|---|
State | New |
Headers | show |
Series | qom: Automated conversion of type checking boilerplate | expand |
On 8/14/20 12:26 AM, Eduardo Habkost wrote: > The existing type check macros all unconditionally drop const > qualifiers from their arguments. Keep this behavior in the > macros generated by DECLARE_*CHECKER* by now. > > In the future, we might use _Generic to preserve const-ness of > the cast function arguments. > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > include/qom/object.h | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/include/qom/object.h b/include/qom/object.h > index 4cd84998c2..1d6a520d35 100644 > --- a/include/qom/object.h > +++ b/include/qom/object.h > @@ -567,7 +567,7 @@ struct Object > */ > #define DECLARE_INSTANCE_CHECKER(InstanceType, OBJ_NAME, TYPENAME) \ > static inline G_GNUC_UNUSED InstanceType * \ > - OBJ_NAME(void *obj) \ > + OBJ_NAME(const void *obj) \ > { return OBJECT_CHECK(InstanceType, obj, TYPENAME); } > > /** > @@ -581,14 +581,16 @@ struct Object > * > * This macro will provide the three standard type cast functions for a > * QOM type. > + * > + *FIXME: Use _Generic to make this const-safe > */ > #define DECLARE_CLASS_CHECKERS(ClassType, OBJ_NAME, TYPENAME) \ > static inline G_GNUC_UNUSED ClassType * \ > - OBJ_NAME##_GET_CLASS(void *obj) \ > + OBJ_NAME##_GET_CLASS(const void *obj) \ > { return OBJECT_GET_CLASS(ClassType, obj, TYPENAME); } \ > \ > static inline G_GNUC_UNUSED ClassType * \ > - OBJ_NAME##_CLASS(void *klass) \ > + OBJ_NAME##_CLASS(const void *klass) \ > { return OBJECT_CLASS_CHECK(ClassType, klass, TYPENAME); } > > /** >
On Thu, Aug 13, 2020 at 06:26:14PM -0400, Eduardo Habkost wrote: > The existing type check macros all unconditionally drop const > qualifiers from their arguments. Keep this behavior in the > macros generated by DECLARE_*CHECKER* by now. > > In the future, we might use _Generic to preserve const-ness of > the cast function arguments. I'm not sure what you mean by "use _Generic" ? > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > --- > include/qom/object.h | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> > > diff --git a/include/qom/object.h b/include/qom/object.h > index 4cd84998c2..1d6a520d35 100644 > --- a/include/qom/object.h > +++ b/include/qom/object.h > @@ -567,7 +567,7 @@ struct Object > */ > #define DECLARE_INSTANCE_CHECKER(InstanceType, OBJ_NAME, TYPENAME) \ > static inline G_GNUC_UNUSED InstanceType * \ > - OBJ_NAME(void *obj) \ > + OBJ_NAME(const void *obj) \ > { return OBJECT_CHECK(InstanceType, obj, TYPENAME); } > > /** > @@ -581,14 +581,16 @@ struct Object > * > * This macro will provide the three standard type cast functions for a > * QOM type. > + * > + *FIXME: Use _Generic to make this const-safe > */ > #define DECLARE_CLASS_CHECKERS(ClassType, OBJ_NAME, TYPENAME) \ > static inline G_GNUC_UNUSED ClassType * \ > - OBJ_NAME##_GET_CLASS(void *obj) \ > + OBJ_NAME##_GET_CLASS(const void *obj) \ > { return OBJECT_GET_CLASS(ClassType, obj, TYPENAME); } \ > \ > static inline G_GNUC_UNUSED ClassType * \ > - OBJ_NAME##_CLASS(void *klass) \ > + OBJ_NAME##_CLASS(const void *klass) \ > { return OBJECT_CLASS_CHECK(ClassType, klass, TYPENAME); } > > /** > -- > 2.26.2 > Regards, Daniel
On Mon, Aug 17, 2020 at 05:08:41PM +0100, Daniel P. Berrangé wrote: > On Thu, Aug 13, 2020 at 06:26:14PM -0400, Eduardo Habkost wrote: > > The existing type check macros all unconditionally drop const > > qualifiers from their arguments. Keep this behavior in the > > macros generated by DECLARE_*CHECKER* by now. > > > > In the future, we might use _Generic to preserve const-ness of > > the cast function arguments. > > I'm not sure what you mean by "use _Generic" ? I meant something like: #define OBJECT_CHECK(Type, obj, ...) \ _Generic((obj), void *: (Type *)object_dynamic_cast_assert(obj, ...), const void *: (const Type *)object_dynamic_cast_assert(obj, ...)) However, now we'll generate type checking functions instead of type checking macros, so making (for example) DEVICE((Object*)x) and DEVICE((const Object*)x) return a different type would be impossible.
diff --git a/include/qom/object.h b/include/qom/object.h index 4cd84998c2..1d6a520d35 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -567,7 +567,7 @@ struct Object */ #define DECLARE_INSTANCE_CHECKER(InstanceType, OBJ_NAME, TYPENAME) \ static inline G_GNUC_UNUSED InstanceType * \ - OBJ_NAME(void *obj) \ + OBJ_NAME(const void *obj) \ { return OBJECT_CHECK(InstanceType, obj, TYPENAME); } /** @@ -581,14 +581,16 @@ struct Object * * This macro will provide the three standard type cast functions for a * QOM type. + * + *FIXME: Use _Generic to make this const-safe */ #define DECLARE_CLASS_CHECKERS(ClassType, OBJ_NAME, TYPENAME) \ static inline G_GNUC_UNUSED ClassType * \ - OBJ_NAME##_GET_CLASS(void *obj) \ + OBJ_NAME##_GET_CLASS(const void *obj) \ { return OBJECT_GET_CLASS(ClassType, obj, TYPENAME); } \ \ static inline G_GNUC_UNUSED ClassType * \ - OBJ_NAME##_CLASS(void *klass) \ + OBJ_NAME##_CLASS(const void *klass) \ { return OBJECT_CLASS_CHECK(ClassType, klass, TYPENAME); } /**
The existing type check macros all unconditionally drop const qualifiers from their arguments. Keep this behavior in the macros generated by DECLARE_*CHECKER* by now. In the future, we might use _Generic to preserve const-ness of the cast function arguments. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- include/qom/object.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)