Message ID | 20210729175554.686474-9-ehabkost@redhat.com |
---|---|
State | New |
Headers | show |
Series | QOM documentation updates | expand |
On Thu, 29 Jul 2021 at 19:03, Eduardo Habkost <ehabkost@redhat.com> wrote: > > For clarity and to avoid encouraging people to copy the examples, > show the actual typecast functions being defined by > OBJECT_DECLARE* macros in the examples. > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> > --- > docs/devel/qom.rst | 24 ++++++++++++++++-------- > 1 file changed, 16 insertions(+), 8 deletions(-) > > diff --git a/docs/devel/qom.rst b/docs/devel/qom.rst > index aa1f672efbe..3ae6f75a1a2 100644 > --- a/docs/devel/qom.rst > +++ b/docs/devel/qom.rst > @@ -303,8 +303,10 @@ This is equivalent to the following: > > typedef struct MyDevice MyDevice; > G_DEFINE_AUTOPTR_CLEANUP_FUNC(MyDevice, object_unref) > - #define MY_DEVICE(void *obj) > - OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE) > + static inline MyDevice *MY_DEVICE(void *obj) > + { > + return OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE); > + } > > The 'struct MyDevice' needs to be declared separately. > > @@ -327,12 +329,18 @@ This is equivalent to the following: > > G_DEFINE_AUTOPTR_CLEANUP_FUNC(MyDevice, object_unref) > > - #define MY_DEVICE_GET_CLASS(void *obj) \ > - OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE) > - #define MY_DEVICE_CLASS(void *klass) \ > - OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE) > - #define MY_DEVICE(void *obj) > - OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE) > + static inline MyDeviceClass *MY_DEVICE_GET_CLASS(void *obj) > + { > + return OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE); > + } > + static inline MyDeviceClass *MY_DEVICE_CLASS(void *klass) > + { > + return OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE); > + } > + static inline MyDevice *MY_DEVICE(void *obj) > + { > + return OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE); > + } ...aha, you can ignore my remark on the previous patch :-) Reviewed-by: Peter Maydell <peter.maydell@linaro.org> thanks -- PMM
diff --git a/docs/devel/qom.rst b/docs/devel/qom.rst index aa1f672efbe..3ae6f75a1a2 100644 --- a/docs/devel/qom.rst +++ b/docs/devel/qom.rst @@ -303,8 +303,10 @@ This is equivalent to the following: typedef struct MyDevice MyDevice; G_DEFINE_AUTOPTR_CLEANUP_FUNC(MyDevice, object_unref) - #define MY_DEVICE(void *obj) - OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE) + static inline MyDevice *MY_DEVICE(void *obj) + { + return OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE); + } The 'struct MyDevice' needs to be declared separately. @@ -327,12 +329,18 @@ This is equivalent to the following: G_DEFINE_AUTOPTR_CLEANUP_FUNC(MyDevice, object_unref) - #define MY_DEVICE_GET_CLASS(void *obj) \ - OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE) - #define MY_DEVICE_CLASS(void *klass) \ - OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE) - #define MY_DEVICE(void *obj) - OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE) + static inline MyDeviceClass *MY_DEVICE_GET_CLASS(void *obj) + { + return OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE); + } + static inline MyDeviceClass *MY_DEVICE_CLASS(void *klass) + { + return OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE); + } + static inline MyDevice *MY_DEVICE(void *obj) + { + return OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE); + } Type definition macros ----------------------
For clarity and to avoid encouraging people to copy the examples, show the actual typecast functions being defined by OBJECT_DECLARE* macros in the examples. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- docs/devel/qom.rst | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)