Skip to contentSkip to conversation

QOM documentation updates

PATCH In review Eduardo Habkost 6 participants 32 messages Jul 29, 2021 – Aug 5, 2021

lore
Share & tools
lore
#0 lore raw

cover QOM documentation updates

This series includes a few fixes to the QOM documentation, and add some changes to avoid encouraging people from defining typecast macros manually.

Eduardo Habkost (10):
docs: qom: Replace old GTK-Doc #symbol syntax with symbol
docs: qom: Use Sphinx cross references more often
docs: qom: Fix autoptr expansion example
docs: qom: Fix "API Reference" heading level
docs: qom: Add subsection headings to declaration/definition macros
section
docs: qom: Remove unnecessary class typedefs from example
docs: qom: Fix OBJECT_DECLARE_SIMPLE_TYPE documentation
docs: qom: Show actual typecast functions in examples
docs: qom: Remove OBJECT_CHECK macro examples
MAINTAINERS: Add qom.rst to QOM section

 MAINTAINERS        |   1 +
 docs/devel/qom.rst | 147 ++++++++++++++++++++++++++++-----------------
 2 files changed, 94 insertions(+), 54 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/10 docs: qom: Replace old GTK-Doc #symbol syntax with `symbol`

Replace leftover of GTK-Doc #name syntax with name, and use default-role:: any, so we can add references to other functions, types, and macros.

There are 3 cases that required extra care:
- #TypeInfo.class_init: kernel-doc doesn't generate c:member::
directives, so references to C struct members are not possible yet. This was replaced with TypeInfo.class_init.
- #CPUClass.reset and #DeviceClass.realize: cpu.h and qdev docs are not rendered using Sphinx yet, so use ``code`` syntax for those.

---
 docs/devel/qom.rst | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
docs/devel/qom.rst +13 -12
index e5fe3597cd8..9c1be5d7fc2 100644
@@ -3,6 +3,7 @@ The QEMU Object Model (QOM)
 ===========================
 
 .. highlight:: c
+.. default-role:: any
 
 The QEMU Object Model provides a framework for registering user creatable
 types and instantiating objects from those types.  QOM provides the following
@@ -42,8 +43,8 @@ features:
 
    type_init(my_device_register_types)
 
-In the above example, we create a simple type that is described by #TypeInfo.
-#TypeInfo describes information about the type including what it inherits
+In the above example, we create a simple type that is described by `TypeInfo`.
+`TypeInfo` describes information about the type including what it inherits
 from, the instance and class size, and constructor/destructor hooks.
 
 Alternatively several static types could be registered using helper macro
@@ -66,13 +67,13 @@ DEFINE_TYPES()
 
    DEFINE_TYPES(device_types_info)
 
-Every type has an #ObjectClass associated with it.  #ObjectClass derivatives
+Every type has an `ObjectClass` associated with it.  `ObjectClass` derivatives
 are instantiated dynamically but there is only ever one instance for any
-given type.  The #ObjectClass typically holds a table of function pointers
+given type.  The `ObjectClass` typically holds a table of function pointers
 for the virtual methods implemented by this type.
 
-Using object_new(), a new #Object derivative will be instantiated.  You can
-cast an #Object to a subclass (or base-class) type using
+Using object_new(), a new `Object` derivative will be instantiated.  You can
+cast an `Object` to a subclass (or base-class) type using
 object_dynamic_cast().  You typically want to define macro wrappers around
 OBJECT_CHECK() and OBJECT_CLASS_CHECK() to make it easier to convert to a
 specific type:
@@ -111,7 +112,7 @@ The effect of this is that classes automatically inherit any virtual
 function pointers that the parent class has already initialized.  All
 other fields will be zero filled.
 
-Once all of the parent classes have been initialized, #TypeInfo::class_init
+Once all of the parent classes have been initialized, `TypeInfo`::class_init
 is called to let the class being instantiated provide default initialize for
 its virtual functions.  Here is how the above example might be modified
 to introduce an overridden virtual function:
@@ -135,7 +136,7 @@ to introduce an overridden virtual function:
    };
 
 Introducing new virtual methods requires a class to define its own
-struct and to add a .class_size member to the #TypeInfo.  Each method
+struct and to add a .class_size member to the `TypeInfo`.  Each method
 will also have a wrapper function to call it easily:
 
 .. code-block:: c
@@ -188,12 +189,12 @@ strongly-typed first argument.
 If it does not operate on an object instance, it is dubbed
 *class method*.
 
-Methods cannot be overloaded. That is, the #ObjectClass and method name
+Methods cannot be overloaded. That is, the `ObjectClass` and method name
 uniquely identity the function to be called; the signature does not vary
 except for trailing varargs.
 
 Methods are always *virtual*. Overriding a method in
-#TypeInfo.class_init of a subclass leads to any user of the class obtained
+`TypeInfo`.class_init of a subclass leads to any user of the class obtained
 via OBJECT_GET_CLASS() accessing the overridden function.
 The original function is not automatically invoked. It is the responsibility
 of the overriding class to determine whether and when to invoke the method
@@ -273,8 +274,8 @@ Alternatively, object_class_by_name() can be used to obtain the class and
 its non-overridden methods for a specific type. This would correspond to
 ``MyClass::method(...)`` in C++.
 
-The first example of such a QOM method was #CPUClass.reset,
-another example is #DeviceClass.realize.
+The first example of such a QOM method was ``CPUClass.reset``,
+another example is ``DeviceClass.realize``.
 
 Standard type declaration and definition macros
 ===============================================
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH for-6.2 01/10] docs: qom: Replace old GTK-Doc #symbol syntax with `symbol`

Quoted 30 lines · Eduardo Habkost

Replace leftover of GTK-Doc #name syntax with name, and use default-role:: any, so we can add references to other functions, types, and macros.

There are 3 cases that required extra care:
- #TypeInfo.class_init: kernel-doc doesn't generate c:member::
directives, so references to C struct members are not possible yet. This was replaced with TypeInfo.class_init.
- #CPUClass.reset and #DeviceClass.realize: cpu.h and qdev docs are not rendered using Sphinx yet, so use ``code`` syntax for those.

---
 docs/devel/qom.rst | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
docs/devel/qom.rst +1 -0
index e5fe3597cd8..9c1be5d7fc2 100644
@@ -3,6 +3,7 @@ The QEMU Object Model (QOM)
 ===========================
 
 .. highlight:: c
+.. default-role:: any
 
 The QEMU Object Model provides a framework for registering user creatable
 types and instantiating objects from those types.  QOM provides the following

docs/devel/qom.rst features: · line 47

Quoted 7 lines
docs/devel/qom.rst +2 -2
@@ -42,8 +43,8 @@ features:
 
    type_init(my_device_register_types)
 
-In the above example, we create a simple type that is described by #TypeInfo.
-#TypeInfo describes information about the type including what it inherits
+In the above example, we create a simple type that is described by `TypeInfo`.
+`TypeInfo` describes information about the type including what it inherits

I've just gone through all of docs/ finding the places where we had foo and probably meant ``foo``, so please don't add any new ones. I would suggest that you either use the ``double-backtick`` syntax to render as fixed-width font, or use an explicit role tag so readers of the rST source can tell that that's what you meant to use, ie avoid "default-role".

thanks
-- PMM

#3 lore raw

Re: [PATCH for-6.2 01/10] docs: qom: Replace old GTK-Doc #symbol syntax with `symbol`

Quoted 34 lines · Peter Maydell
Quoted 33 lines · Eduardo Habkost

Replace leftover of GTK-Doc #name syntax with name, and use default-role:: any, so we can add references to other functions, types, and macros.

There are 3 cases that required extra care:
- #TypeInfo.class_init: kernel-doc doesn't generate c:member::
directives, so references to C struct members are not possible yet. This was replaced with TypeInfo.class_init.
- #CPUClass.reset and #DeviceClass.realize: cpu.h and qdev docs are not rendered using Sphinx yet, so use ``code`` syntax for those.

---
 docs/devel/qom.rst | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
docs/devel/qom.rst +1 -0
index e5fe3597cd8..9c1be5d7fc2 100644
@@ -3,6 +3,7 @@ The QEMU Object Model (QOM)
 ===========================
 
 .. highlight:: c
+.. default-role:: any
 
 The QEMU Object Model provides a framework for registering user creatable
 types and instantiating objects from those types.  QOM provides the following
@@ -42,8 +43,8 @@ features:
 
    type_init(my_device_register_types)
 
Quoted 10 lines

docs/devel/qom.rst features: · line 47

Quoted 4 lines
docs/devel/qom.rst +2 -2
-In the above example, we create a simple type that is described by #TypeInfo.
-#TypeInfo describes information about the type including what it inherits
+In the above example, we create a simple type that is described by `TypeInfo`.
+`TypeInfo` describes information about the type including what it inherits

I've just gone through all of docs/ finding the places where we had foo and probably meant ``foo``, so please don't add any new ones. I would suggest that you either use the ``double-backtick`` syntax to render as fixed-width font, or use an explicit role tag so readers of the rST source can tell that that's what you meant to use, ie avoid "default-role".

I don't understand why that would be a reason to not use default-role. With default-role, we get an error when misusing foo. Without default-role, misuse won't be detected at all (except by manual inspection).

Signature · 1 line
Eduardo
#4 lore raw

Re: [PATCH for-6.2 01/10] docs: qom: Replace old GTK-Doc #symbol syntax with `symbol`

Quoted 30 lines · Eduardo Habkost
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Eduardo Habkost
docs/devel/qom.rst +1 -0
index e5fe3597cd8..9c1be5d7fc2 100644
@@ -3,6 +3,7 @@ The QEMU Object Model (QOM)
 ===========================
 
 .. highlight:: c
+.. default-role:: any
 
 The QEMU Object Model provides a framework for registering user creatable
 types and instantiating objects from those types.  QOM provides the following
@@ -42,8 +43,8 @@ features:
 
    type_init(my_device_register_types)
 
Quoted 10 lines

docs/devel/qom.rst features: · line 47

Quoted 4 lines
docs/devel/qom.rst +2 -2
-In the above example, we create a simple type that is described by #TypeInfo.
-#TypeInfo describes information about the type including what it inherits
+In the above example, we create a simple type that is described by `TypeInfo`.
+`TypeInfo` describes information about the type including what it inherits

I've just gone through all of docs/ finding the places where we had foo and probably meant ``foo``, so please don't add any new ones. I would suggest that you either use the ``double-backtick`` syntax to render as fixed-width font, or use an explicit role tag so readers of the rST source can tell that that's what you meant to use, ie avoid "default-role".

Quoted 4 lines

I don't understand why that would be a reason to not use default-role. With default-role, we get an error when misusing foo. Without default-role, misuse won't be detected at all (except by manual inspection).

Ah, I didn't realize that we got an error if we set the default-role to 'any'. That certainly makes it nicer than the default default of 'cite'.

Is there a sensible default-role we can use as the default for the whole manual, rather than only declaring it in individual .rst files ? One of the things I don't
like about the change here is that it means that thing in this individual .rst file is different from thing in every other .rst file in our docs.

Ccing John, who I have just remembered wrote something about Sphinx roles a few months back:
https://lore.kernel.org/qemu-devel/[email protected]/

-- PMM

#5 lore raw

Re: [PATCH for-6.2 01/10] docs: qom: Replace old GTK-Doc #symbol syntax with `symbol`

Quoted 40 lines · Peter Maydell
Quoted 30 lines · Eduardo Habkost
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Eduardo Habkost
docs/devel/qom.rst +1 -0
index e5fe3597cd8..9c1be5d7fc2 100644
@@ -3,6 +3,7 @@ The QEMU Object Model (QOM)
 ===========================
 
 .. highlight:: c
+.. default-role:: any
 
 The QEMU Object Model provides a framework for registering user creatable
 types and instantiating objects from those types.  QOM provides the following
@@ -42,8 +43,8 @@ features:
 
    type_init(my_device_register_types)
 
Quoted 10 lines

docs/devel/qom.rst features: · line 47

Quoted 4 lines
docs/devel/qom.rst +2 -2
-In the above example, we create a simple type that is described by #TypeInfo.
-#TypeInfo describes information about the type including what it inherits
+In the above example, we create a simple type that is described by `TypeInfo`.
+`TypeInfo` describes information about the type including what it inherits

I've just gone through all of docs/ finding the places where we had foo and probably meant ``foo``, so please don't add any new ones. I would suggest that you either use the ``double-backtick`` syntax to render as fixed-width font, or use an explicit role tag so readers of the rST source can tell that that's what you meant to use, ie avoid "default-role".

Quoted 4 lines

I don't understand why that would be a reason to not use default-role. With default-role, we get an error when misusing foo. Without default-role, misuse won't be detected at all (except by manual inspection).

Ah, I didn't realize that we got an error if we set the default-role to 'any'. That certainly makes it nicer than the default default of 'cite'.

Quoted 5 lines

Is there a sensible default-role we can use as the default for the whole manual, rather than only declaring it in individual .rst files ? One of the things I don't
like about the change here is that it means that thing in this individual .rst file is different from thing in every other .rst file in our docs.

I believe "any" would be a very sensible default role for all documents, but I don't know how to set default-role globally. I'll try to find out.

Signature · 1 line
Eduardo
#6 lore raw

Re: [PATCH for-6.2 01/10] docs: qom: Replace old GTK-Doc #symbol syntax with `symbol`

Quoted 59 lines · Eduardo Habkost
Quoted 1 line · Peter Maydell

On Wed, 4 Aug 2021 at 21:31, Eduardo Habkost <[email protected]>

Quoted 3 lines · wrote:
Quoted 3 lines · Peter Maydell
Quoted 1 line

On Thu, 29 Jul 2021 at 19:00, Eduardo Habkost <[email protected]>

Quoted 11 lines · wrote:
Quoted 11 lines
Quoted 11 lines

docs/devel/qom.rst The QEMU Object Model (QOM) · line 8

Quoted 11 lines
docs/devel/qom.rst +1 -0
index e5fe3597cd8..9c1be5d7fc2 100644
@@ -3,6 +3,7 @@ The QEMU Object Model (QOM)
 ===========================
 
 .. highlight:: c
+.. default-role:: any
 
 The QEMU Object Model provides a framework for registering user

creatable

Quoted 1 line
Quoted 1 line
Quoted 1 line

docs/devel/qom.rst The QEMU Object Model (QOM) · line 9

Quoted 1 line
docs/devel/qom.rst +0 -0
 types and instantiating objects from those types.  QOM provides

the following

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

docs/devel/qom.rst features: · line 45

Quoted 5 lines
docs/devel/qom.rst +0 -1
@@ -42,8 +43,8 @@ features:
 
    type_init(my_device_register_types)
 
-In the above example, we create a simple type that is described

by #TypeInfo.

Quoted 1 line
Quoted 1 line
Quoted 1 line

docs/devel/qom.rst features: · line 46

Quoted 1 line
docs/devel/qom.rst +0 -1
-#TypeInfo describes information about the type including what it

inherits

Quoted 1 line
Quoted 1 line
Quoted 1 line

docs/devel/qom.rst features: · line 46

Quoted 1 line
docs/devel/qom.rst +1 -0
+In the above example, we create a simple type that is described

by TypeInfo.

Quoted 1 line
Quoted 1 line
Quoted 1 line

docs/devel/qom.rst features: · line 47

Quoted 1 line
docs/devel/qom.rst +1 -0
+`TypeInfo` describes information about the type including what it

inherits

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I've just gone through all of docs/ finding the places where we had

foo and

Quoted 1 line
Quoted 1 line
Quoted 1 line

probably meant ``foo``, so please don't add any new ones. I would

suggest

Quoted 1 line
Quoted 1 line
Quoted 1 line

that you either use the ``double-backtick`` syntax to render as

fixed-width

Quoted 1 line
Quoted 1 line
Quoted 1 line

font, or use an explicit role tag so readers of the rST source can

tell that

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

that's what you meant to use, ie avoid "default-role".

I don't understand why that would be a reason to not use default-role. With default-role, we get an error when misusing foo. Without default-role, misuse won't be detected at all (except by manual inspection).

Quoted 5 lines

Ah, I didn't realize that we got an error if we set the default-role to 'any'. That certainly makes it nicer than the default default of 'cite'.

Is there a sensible default-role we can use as the default for the whole

manual,

Quoted 3 lines

rather than only declaring it in individual .rst files ? One of the things I don't
like about the change here is that it means that thing in this

individual .rst

Quoted 9 lines
Quoted 1 line

file is different from thing in every other .rst file in our docs.

I believe "any" would be a very sensible default role for all documents, but I don't know how to set default-role globally. I'll try to find out.

--
Eduardo

Oh, I actually fixed that issue I referenced there back in May -- I keep a patchset up to date whenever I work on modernizing the QAPI python code that actually DOES switch our default role to "any" ... I updated it just today, in fact. I will send it to the list if there's an appetite for it now.

--js

#7 lore raw

Re: [PATCH for-6.2 01/10] docs: qom: Replace old GTK-Doc #symbol syntax with `symbol`

Quoted 15 lines · John Snow
Quoted 6 lines · Eduardo Habkost
Quoted 1 line · Peter Maydell

Is there a sensible default-role we can use as the default for the whole

manual,

Quoted 3 lines

rather than only declaring it in individual .rst files ? One of the things I don't
like about the change here is that it means that thing in this

Quoted 6 lines

individual .rst

Quoted 1 line

file is different from thing in every other .rst file in our docs.

I believe "any" would be a very sensible default role for all documents, but I don't know how to set default-role globally. I'll try to find out.

Quoted 5 lines

Oh, I actually fixed that issue I referenced there back in May -- I keep a patchset up to date whenever I work on modernizing the QAPI python code that actually DOES switch our default role to "any" ... I updated it just today, in fact. I will send it to the list if there's an appetite for it now.

If you already have a patch that makes it possible to change the default role to "any" globally, I'd be glad to include it in v2 of this series.

Signature · 1 line
Eduardo
#8 lore raw

Re: [PATCH for-6.2 01/10] docs: qom: Replace old GTK-Doc #symbol syntax with `symbol`

Quoted 22 lines · Eduardo Habkost
Quoted 15 lines · John Snow
Quoted 6 lines · Eduardo Habkost
Quoted 1 line · Peter Maydell

Is there a sensible default-role we can use as the default for the whole

manual,

Quoted 3 lines

rather than only declaring it in individual .rst files ? One of the things I don't
like about the change here is that it means that thing in this

Quoted 6 lines

individual .rst

Quoted 1 line

file is different from thing in every other .rst file in our docs.

I believe "any" would be a very sensible default role for all documents, but I don't know how to set default-role globally. I'll try to find out.

Quoted 5 lines

Oh, I actually fixed that issue I referenced there back in May -- I keep a patchset up to date whenever I work on modernizing the QAPI python code that actually DOES switch our default role to "any" ... I updated it just today, in fact. I will send it to the list if there's an appetite for it now.

Quoted 3 lines

If you already have a patch that makes it possible to change the default role to "any" globally, I'd be glad to include it in v2 of this series.

John had submitted the patches at:
https://lore.kernel.org/qemu-devel/[email protected]/
(Thanks!)

If John's patches are merged, the only change needed in this series is the removal of the "default-role" line in patch 01/10.

Instead of submitting v2 for a one-line change, I'm hoping I can just get Reviewed-by lines for this version. (the reviews can be conditional on the removal of the "default-role" line in patch 01/10)

Signature · 1 line
Eduardo
#9 lore raw

PATCH 2/10 docs: qom: Use Sphinx cross references more often

In reply to Eduardo Habkost

To make the document easier to navigate, use reference syntax more often when mentioning other types, functions, and macros.

---
 docs/devel/qom.rst | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
docs/devel/qom.rst +14 -14
index 9c1be5d7fc2..3499a8ca3b6 100644
@@ -48,7 +48,7 @@ In the above example, we create a simple type that is described by `TypeInfo`.
 from, the instance and class size, and constructor/destructor hooks.
 
 Alternatively several static types could be registered using helper macro
-DEFINE_TYPES()
+`DEFINE_TYPES()`:
 
 .. code-block:: c
 
@@ -72,10 +72,10 @@ are instantiated dynamically but there is only ever one instance for any
 given type.  The `ObjectClass` typically holds a table of function pointers
 for the virtual methods implemented by this type.
 
-Using object_new(), a new `Object` derivative will be instantiated.  You can
+Using `object_new()`, a new `Object` derivative will be instantiated.  You can
 cast an `Object` to a subclass (or base-class) type using
-object_dynamic_cast().  You typically want to define macro wrappers around
-OBJECT_CHECK() and OBJECT_CLASS_CHECK() to make it easier to convert to a
+`object_dynamic_cast()`.  You typically want to define macro wrappers around
+`OBJECT_CHECK()` and `OBJECT_CLASS_CHECK()` to make it easier to convert to a
 specific type:
 
 .. code-block:: c
@@ -195,7 +195,7 @@ except for trailing varargs.
 
 Methods are always *virtual*. Overriding a method in
 `TypeInfo`.class_init of a subclass leads to any user of the class obtained
-via OBJECT_GET_CLASS() accessing the overridden function.
+via `OBJECT_GET_CLASS()` accessing the overridden function.
 The original function is not automatically invoked. It is the responsibility
 of the overriding class to determine whether and when to invoke the method
 being overridden.
@@ -270,7 +270,7 @@ class, which someone might choose to change at some point.
        .class_init = derived_class_init,
    };
 
-Alternatively, object_class_by_name() can be used to obtain the class and
+Alternatively, `object_class_by_name()` can be used to obtain the class and
 its non-overridden methods for a specific type. This would correspond to
 ``MyClass::method(...)`` in C++.
 
@@ -285,9 +285,9 @@ convention. To reduce the amount of boilerplate code that needs to be
 written for a new type there are two sets of macros to generate the
 common parts in a standard format.
 
-A type is declared using the OBJECT_DECLARE macro family. In types
+A type is declared using the ``OBJECT_DECLARE`` macro family. In types
 which do not require any virtual functions in the class, the
-OBJECT_DECLARE_SIMPLE_TYPE macro is suitable, and is commonly placed
+`OBJECT_DECLARE_SIMPLE_TYPE` macro is suitable, and is commonly placed
 in the header file:
 
 .. code-block:: c
@@ -319,12 +319,12 @@ This is equivalent to the following:
 
 The 'struct MyDevice' needs to be declared separately.
 If the type requires virtual functions to be declared in the class
-struct, then the alternative OBJECT_DECLARE_TYPE() macro can be
-used. This does the same as OBJECT_DECLARE_SIMPLE_TYPE(), but without
+struct, then the alternative `OBJECT_DECLARE_TYPE()` macro can be
+used. This does the same as `OBJECT_DECLARE_SIMPLE_TYPE()`, but without
 the 'struct MyDeviceClass' definition.
 
-To implement the type, the OBJECT_DEFINE macro family is available.
-In the simple case the OBJECT_DEFINE_TYPE macro is suitable:
+To implement the type, the ``OBJECT_DEFINE`` macro family is available.
+In the simple case the `OBJECT_DEFINE_TYPE()` macro is suitable:
 
 .. code-block:: c
    :caption: Defining a simple type
@@ -362,7 +362,7 @@ system, and the three standard methods now need to be implemented
 along with any other logic required for the type.
 
 If the type needs to implement one or more interfaces, then the
-OBJECT_DEFINE_TYPE_WITH_INTERFACES() macro can be used instead.
+`OBJECT_DEFINE_TYPE_WITH_INTERFACES()` macro can be used instead.
 This accepts an array of interface type names.
 
 .. code-block:: c
@@ -374,7 +374,7 @@ This accepts an array of interface type names.
                                       { NULL })
 
 If the type is not intended to be instantiated, then then
-the OBJECT_DEFINE_ABSTRACT_TYPE() macro can be used instead:
+the `OBJECT_DEFINE_ABSTRACT_TYPE()` macro can be used instead:
 
 .. code-block:: c
    :caption: Defining a simple abstract type
Signature · 1 line
2.31.1
#10 lore raw

PATCH 3/10 docs: qom: Fix autoptr expansion example

In reply to Eduardo Habkost

The wrong type name was being used. The autoptr cleanup function will be declared for the instance type, not the class type.

---
 docs/devel/qom.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
docs/devel/qom.rst +1 -1
index 3499a8ca3b6..7ef16d92ca6 100644
@@ -304,7 +304,7 @@ This is equivalent to the following:
    typedef struct MyDevice MyDevice;
    typedef struct MyDeviceClass MyDeviceClass;
 
-   G_DEFINE_AUTOPTR_CLEANUP_FUNC(MyDeviceClass, object_unref)
+   G_DEFINE_AUTOPTR_CLEANUP_FUNC(MyDevice, object_unref)
 
    #define MY_DEVICE_GET_CLASS(void *obj) \
            OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE)
Signature · 1 line
2.31.1
Reviewed-by on v1 3/10
#11 lore raw

Re: [PATCH for-6.2 03/10] docs: qom: Fix autoptr expansion example

Quoted 8 lines · Eduardo Habkost

The wrong type name was being used. The autoptr cleanup function will be declared for the instance type, not the class type.

---
 docs/devel/qom.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

thanks
-- PMM

#12 lore raw

PATCH 4/10 docs: qom: Fix "API Reference" heading level

In reply to Eduardo Habkost

The API reference section was being rendered as a subsection of the "Standard type declaration and definition macros" subsection. Fix that.

---
 docs/devel/qom.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
docs/devel/qom.rst +1 -1
index 7ef16d92ca6..3f48016aa8f 100644
@@ -385,6 +385,6 @@ the `OBJECT_DEFINE_ABSTRACT_TYPE()` macro can be used instead:
 
 
 API Reference
--------------
+=============
 
 .. kernel-doc:: include/qom/object.h
Signature · 1 line
2.31.1
Reviewed-by on v1 4/10
#13 lore raw

Re: [PATCH for-6.2 04/10] docs: qom: Fix "API Reference" heading level

Quoted 9 lines · Eduardo Habkost

The API reference section was being rendered as a subsection of the "Standard type declaration and definition macros" subsection. Fix that.

---
 docs/devel/qom.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

thanks
-- PMM

#14 lore raw

PATCH 5/10 docs: qom: Add subsection headings to declaration/definition macros section

In reply to Eduardo Habkost

Add two new subsection headings to make the separation between "declaration macros" and "definition macros" more visible.

---
 docs/devel/qom.rst | 6 ++++++
 1 file changed, 6 insertions(+)
docs/devel/qom.rst +6 -0
index 3f48016aa8f..05d045bf570 100644
@@ -285,6 +285,9 @@ convention. To reduce the amount of boilerplate code that needs to be
 written for a new type there are two sets of macros to generate the
 common parts in a standard format.
 
+Type declaration macros
+-----------------------
+
 A type is declared using the ``OBJECT_DECLARE`` macro family. In types
 which do not require any virtual functions in the class, the
 `OBJECT_DECLARE_SIMPLE_TYPE` macro is suitable, and is commonly placed
@@ -323,6 +326,9 @@ struct, then the alternative `OBJECT_DECLARE_TYPE()` macro can be
 used. This does the same as `OBJECT_DECLARE_SIMPLE_TYPE()`, but without
 the 'struct MyDeviceClass' definition.
 
+Type definition macros
+----------------------
+
 To implement the type, the ``OBJECT_DEFINE`` macro family is available.
 In the simple case the `OBJECT_DEFINE_TYPE()` macro is suitable:
 
Signature · 1 line
2.31.1
Reviewed-by on v1 5/10
#15 lore raw

Re: [PATCH for-6.2 05/10] docs: qom: Add subsection headings to declaration/definition macros section

Quoted 7 lines · Eduardo Habkost

Add two new subsection headings to make the separation between "declaration macros" and "definition macros" more visible.

---
 docs/devel/qom.rst | 6 ++++++
 1 file changed, 6 insertions(+)
Reviewed-by on v1 5/10
#16 lore raw

Re: [PATCH for-6.2 05/10] docs: qom: Add subsection headings to declaration/definition macros section

In reply to Eduardo Habkost
Quoted 8 lines · Eduardo Habkost

Add two new subsection headings to make the separation between "declaration macros" and "definition macros" more visible.

---
 docs/devel/qom.rst | 6 ++++++
 1 file changed, 6 insertions(+)

thanks
-- PMM

#17 lore raw

PATCH 6/10 docs: qom: Remove unnecessary class typedefs from example

In reply to Eduardo Habkost

When there's no specific class struct used for a QOM type, we normally don't define a typedef for it. Remove the typedef from the minimal example, as it is unnecessary.

---
 docs/devel/qom.rst | 3 ---
 1 file changed, 3 deletions(-)
docs/devel/qom.rst +0 -3
index 05d045bf570..dee60a64c0a 100644
@@ -20,9 +20,6 @@ features:
 
    #define TYPE_MY_DEVICE "my-device"
 
-   // No new virtual functions: we can reuse the typedef for the
-   // superclass.
-   typedef DeviceClass MyDeviceClass;
    typedef struct MyDevice
    {
        DeviceState parent;
Signature · 1 line
2.31.1
#18 lore raw

Re: [PATCH for-6.2 06/10] docs: qom: Remove unnecessary class typedefs from example

Quoted 14 lines · Eduardo Habkost

When there's no specific class struct used for a QOM type, we normally don't define a typedef for it. Remove the typedef from the minimal example, as it is unnecessary.

---
 docs/devel/qom.rst | 3 ---
 1 file changed, 3 deletions(-)
docs/devel/qom.rst +0 -0
index 05d045bf570..dee60a64c0a 100644

docs/devel/qom.rst features: · line 25

Quoted 9 lines
docs/devel/qom.rst +0 -3
@@ -20,9 +20,6 @@ features:
 
    #define TYPE_MY_DEVICE "my-device"
 
-   // No new virtual functions: we can reuse the typedef for the
-   // superclass.
-   typedef DeviceClass MyDeviceClass;
    typedef struct MyDevice
    {
        DeviceState parent;

Documenting existing practice makes sense, but I'm not sure the existing practice to elide this typedef makes sense.

#19 lore raw

Re: [PATCH for-6.2 06/10] docs: qom: Remove unnecessary class typedefs from example

Quoted 20 lines · Markus Armbruster
Quoted 17 lines · Eduardo Habkost

When there's no specific class struct used for a QOM type, we normally don't define a typedef for it. Remove the typedef from the minimal example, as it is unnecessary.

---
 docs/devel/qom.rst | 3 ---
 1 file changed, 3 deletions(-)
docs/devel/qom.rst +0 -0
index 05d045bf570..dee60a64c0a 100644
@@ -20,9 +20,6 @@ features:
 
    #define TYPE_MY_DEVICE "my-device"
 
Quoted 9 lines

docs/devel/qom.rst features: · line 25

Quoted 6 lines
docs/devel/qom.rst +0 -3
-   // No new virtual functions: we can reuse the typedef for the
-   // superclass.
-   typedef DeviceClass MyDeviceClass;
    typedef struct MyDevice
    {
        DeviceState parent;

Documenting existing practice makes sense, but I'm not sure the existing practice to elide this typedef makes sense.

The QOMConventions page on the wiki
https://wiki.qemu.org/Documentation/QOMConventions
makes what I think is a reasonable distinction:

# If your class (a) will be subclassed or (b) has member fields it needs

# to put in its class struct then you should write all of:
#
# a FOO_CLASS macro
# a FOO_GET_CLASS macro
# a FooClass structure definition containing at least the parent class field
#
# and your TypeInfo for this class should set the .class_size field to
sizeof(FooClass).
#
# These ensure that nothing in future should need changing if new fields are
# added to your class struct, and that any subclasses have the correct typenames
# available so they won't need to change either even if your
implementation changes.
#
# If your class meets neither of the above requirements (ie it is a
simple leaf class) then:
#
# don't provide FOO_CLASS or FOO_GET_CLASS
# don't provide a FooClass structure
# leave the TypeInfo's .class_size field unset.
#
# If a change means a class which didn't provide these macros/types now needs to
# provide them, then your change should add all of them (ie move the class from
# the latter category to the former).

By those principles, we should never do "typedef DeviceClass MyDeviceClass" -- either we have a real MyDeviceClass which contains at least the parent class field (ie is not a mere typedef), or we don't provide MyDeviceClass at all.

I would say the rationale for the wiki's distinction is that we don't want to require unnecessary boilerplate for leaf classes without methods (which are by far the most common kind of class), but we don't want a free-for-all regarding how you write things either. So we define a standard pattern for leaves and a standard pattern for everything else.

-- PMM

#20 lore raw

Re: [PATCH for-6.2 06/10] docs: qom: Remove unnecessary class typedefs from example

Quoted 66 lines · Peter Maydell
Quoted 20 lines · Markus Armbruster
Quoted 17 lines · Eduardo Habkost

When there's no specific class struct used for a QOM type, we normally don't define a typedef for it. Remove the typedef from the minimal example, as it is unnecessary.

---
 docs/devel/qom.rst | 3 ---
 1 file changed, 3 deletions(-)
docs/devel/qom.rst +0 -0
index 05d045bf570..dee60a64c0a 100644
@@ -20,9 +20,6 @@ features:
 
    #define TYPE_MY_DEVICE "my-device"
 
Quoted 9 lines

docs/devel/qom.rst features: · line 25

Quoted 6 lines
docs/devel/qom.rst +0 -3
-   // No new virtual functions: we can reuse the typedef for the
-   // superclass.
-   typedef DeviceClass MyDeviceClass;
    typedef struct MyDevice
    {
        DeviceState parent;

Documenting existing practice makes sense, but I'm not sure the existing practice to elide this typedef makes sense.

The QOMConventions page on the wiki
https://wiki.qemu.org/Documentation/QOMConventions
makes what I think is a reasonable distinction:

# If your class (a) will be subclassed or (b) has member fields it needs

# to put in its class struct then you should write all of:
#
# a FOO_CLASS macro
# a FOO_GET_CLASS macro
# a FooClass structure definition containing at least the parent class field
#
# and your TypeInfo for this class should set the .class_size field to
sizeof(FooClass).
#
# These ensure that nothing in future should need changing if new fields are
# added to your class struct, and that any subclasses have the correct typenames
# available so they won't need to change either even if your
implementation changes.
#
# If your class meets neither of the above requirements (ie it is a
simple leaf class) then:
#
# don't provide FOO_CLASS or FOO_GET_CLASS
# don't provide a FooClass structure
# leave the TypeInfo's .class_size field unset.
#
# If a change means a class which didn't provide these macros/types now needs to
# provide them, then your change should add all of them (ie move the class from
# the latter category to the former).

By those principles, we should never do "typedef DeviceClass MyDeviceClass" -- either we have a real MyDeviceClass which contains at least the parent class field (ie is not a mere typedef), or we don't provide MyDeviceClass at all.

Quoted 5 lines

I would say the rationale for the wiki's distinction is that we don't want to require unnecessary boilerplate for leaf classes without methods (which are by far the most common kind of class), but we don't want a free-for-all regarding how you write things either. So we define a standard pattern for leaves and a standard pattern for everything else.

Neither the wiki page above nor this part of the docs is really showing best practice. The best practice is much later in this doc where it shows the macros that eliminate all of tedious boilerplate code:

https://qemu-project.gitlab.io/qemu/devel/qom.html#standard-type-declaration-and-definition-macros

Personally I'd suggest we reverse the documentation order, so that the first thing we tell people about at the simple macros for declaring types, and strongly recomend that they are used. Only document the manual boilerplate at the end, merely as reference material, and recommend against its use.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 6/10
#21 lore raw

Re: [PATCH for-6.2 06/10] docs: qom: Remove unnecessary class typedefs from example

In reply to Eduardo Habkost
Quoted 15 lines · Eduardo Habkost

When there's no specific class struct used for a QOM type, we normally don't define a typedef for it. Remove the typedef from the minimal example, as it is unnecessary.

---
 docs/devel/qom.rst | 3 ---
 1 file changed, 3 deletions(-)
docs/devel/qom.rst +0 -0
index 05d045bf570..dee60a64c0a 100644

docs/devel/qom.rst features: · line 25

Quoted 9 lines
docs/devel/qom.rst +0 -3
@@ -20,9 +20,6 @@ features:
 
    #define TYPE_MY_DEVICE "my-device"
 
-   // No new virtual functions: we can reuse the typedef for the
-   // superclass.
-   typedef DeviceClass MyDeviceClass;
    typedef struct MyDevice
    {
        DeviceState parent;

though I agree with Daniel that in the long-term we should reverse the structure of the documents so the recommended macros go first and the behind-the-scenes boilerplate last.

thanks
-- PMM

#22 lore raw

Re: [PATCH for-6.2 06/10] docs: qom: Remove unnecessary class typedefs from example

Quoted 28 lines · Peter Maydell
Quoted 15 lines · Eduardo Habkost

When there's no specific class struct used for a QOM type, we normally don't define a typedef for it. Remove the typedef from the minimal example, as it is unnecessary.

---
 docs/devel/qom.rst | 3 ---
 1 file changed, 3 deletions(-)
docs/devel/qom.rst +0 -0
index 05d045bf570..dee60a64c0a 100644

docs/devel/qom.rst features: · line 25

Quoted 9 lines
docs/devel/qom.rst +0 -3
@@ -20,9 +20,6 @@ features:
 
    #define TYPE_MY_DEVICE "my-device"
 
-   // No new virtual functions: we can reuse the typedef for the
-   // superclass.
-   typedef DeviceClass MyDeviceClass;
    typedef struct MyDevice
    {
        DeviceState parent;
Quoted 3 lines

though I agree with Daniel that in the long-term we should reverse the structure of the documents so the recommended macros go first and the behind-the-scenes boilerplate last.

I agree 100%, and maybe I will give it a try later.

My immediate goal was to just remove the examples in the docs where type checking macros were defined manually. Since we introduced the new QOM helper macros, the number of OBJECT_CHECK macros in the QEMU tree almost doubled (from 40 in commit 8110fa1d94f2 to 75 in commit bccabb3a5d60).

Signature · 1 line
Eduardo
#23 lore raw

Re: [PATCH for-6.2 06/10] docs: qom: Remove unnecessary class typedefs from example

Quoted 14 lines · Eduardo Habkost
Quoted 11 lines · Peter Maydell
Quoted 4 lines · Eduardo Habkost

When there's no specific class struct used for a QOM type, we normally don't define a typedef for it. Remove the typedef from the minimal example, as it is unnecessary.

though I agree with Daniel that in the long-term we should reverse the structure of the documents so the recommended macros go first and the behind-the-scenes boilerplate last.

Quoted 7 lines

I agree 100%, and maybe I will give it a try later.

My immediate goal was to just remove the examples in the docs where type checking macros were defined manually. Since we introduced the new QOM helper macros, the number of OBJECT_CHECK macros in the QEMU tree almost doubled (from 40 in commit 8110fa1d94f2 to 75 in commit bccabb3a5d60).

Yeah, to be clear, I'm all in favour of changes like this patchset and don't think we should hold them up because we have a theoretical larger restructuring of the documentation we might one day (or never) get round to.

-- PMM

#24 lore raw

PATCH 7/10 docs: qom: Fix OBJECT_DECLARE_SIMPLE_TYPE documentation

In reply to Eduardo Habkost

The OBJECT_DECLARE_SIMPLE_TYPE documentation was inaccurate: it doesn't define a class struct or class type checking helpers.

OBJECT_DECLARE_TYPE expansion looks very similar to the existing example, though. Rewrite that section to show both both OBJECT_DECLARE_SIMPLE_TYPE and OBJECT_DECLARE_TYPE.

---
 docs/devel/qom.rst | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)
docs/devel/qom.rst +21 -10
index dee60a64c0a..aa1f672efbe 100644
@@ -301,6 +301,27 @@ This is equivalent to the following:
 .. code-block:: c
    :caption: Expansion from declaring a simple type
 
+   typedef struct MyDevice MyDevice;
+   G_DEFINE_AUTOPTR_CLEANUP_FUNC(MyDevice, object_unref)
+   #define MY_DEVICE(void *obj)
+           OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE)
+
+The 'struct MyDevice' needs to be declared separately.
+
+If the type requires virtual functions to be declared in a class
+struct, then the alternative `OBJECT_DECLARE_TYPE()` macro can be
+used:
+
+.. code-block:: c
+   :caption: Declaring a type with custom class struct
+
+   OBJECT_DECLARE_TYPE(MyDevice, my_device, MY_DEVICE, DEVICE)
+
+This is equivalent to the following:
+
+.. code-block:: c
+   :caption: Expansion from declaring a type with custom class struct
+
    typedef struct MyDevice MyDevice;
    typedef struct MyDeviceClass MyDeviceClass;
 
@@ -313,16 +334,6 @@ This is equivalent to the following:
    #define MY_DEVICE(void *obj)
            OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE)
 
-   struct MyDeviceClass {
-       DeviceClass parent_class;
-   };
-
-The 'struct MyDevice' needs to be declared separately.
-If the type requires virtual functions to be declared in the class
-struct, then the alternative `OBJECT_DECLARE_TYPE()` macro can be
-used. This does the same as `OBJECT_DECLARE_SIMPLE_TYPE()`, but without
-the 'struct MyDeviceClass' definition.
-
 Type definition macros
 ----------------------
 
Signature · 1 line
2.31.1
Reviewed-by on v1 7/10
#25 lore raw

Re: [PATCH for-6.2 07/10] docs: qom: Fix OBJECT_DECLARE_SIMPLE_TYPE documentation

Quoted 18 lines · Eduardo Habkost

The OBJECT_DECLARE_SIMPLE_TYPE documentation was inaccurate: it doesn't define a class struct or class type checking helpers.

OBJECT_DECLARE_TYPE expansion looks very similar to the existing example, though. Rewrite that section to show both both OBJECT_DECLARE_SIMPLE_TYPE and OBJECT_DECLARE_TYPE.

---
 docs/devel/qom.rst | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)
docs/devel/qom.rst +0 -0
index dee60a64c0a..aa1f672efbe 100644

docs/devel/qom.rst This is equivalent to the following: · line 308

Quoted 8 lines
docs/devel/qom.rst +4 -0
@@ -301,6 +301,27 @@ This is equivalent to the following:
 .. code-block:: c
    :caption: Expansion from declaring a simple type
 
+   typedef struct MyDevice MyDevice;
+   G_DEFINE_AUTOPTR_CLEANUP_FUNC(MyDevice, object_unref)
+   #define MY_DEVICE(void *obj)
+           OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE)
 

though I note that the macro doesn't actually create a MY_DEVICE #define any more -- you get a function named MY_DEVICE(). I guess "equivalent to" covers that.

thanks
-- PMM

#26 lore raw

PATCH 8/10 docs: qom: Show actual typecast functions in examples

In reply to Eduardo Habkost

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.

---
 docs/devel/qom.rst | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
docs/devel/qom.rst +16 -8
index aa1f672efbe..3ae6f75a1a2 100644
@@ -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
 ----------------------
Signature · 1 line
2.31.1
Reviewed-by on v1 8/10
#27 lore raw

Re: [PATCH for-6.2 08/10] docs: qom: Show actual typecast functions in examples

Quoted 39 lines · Eduardo Habkost

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.

---
 docs/devel/qom.rst | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
docs/devel/qom.rst +6 -8
index aa1f672efbe..3ae6f75a1a2 100644
@@ -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)
+   {

docs/devel/qom.rst This is equivalent to the following: · line 343

Quoted 10 lines
docs/devel/qom.rst +10 -0
+       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 :-)

thanks
-- PMM

#28 lore raw

PATCH 9/10 docs: qom: Remove OBJECT_CHECK macro examples

In reply to Eduardo Habkost

We shouldn't encourage people to keep defining typecast macros manually, when we have the OBJECT_DECLARE* macros. Remove the section showing how to define them, and replace with a section explaining how typecasting works.

---
 docs/devel/qom.rst | 46 +++++++++++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 15 deletions(-)
docs/devel/qom.rst +31 -15
index 3ae6f75a1a2..0f222555019 100644
@@ -69,21 +69,10 @@ are instantiated dynamically but there is only ever one instance for any
 given type.  The `ObjectClass` typically holds a table of function pointers
 for the virtual methods implemented by this type.
 
-Using `object_new()`, a new `Object` derivative will be instantiated.  You can
-cast an `Object` to a subclass (or base-class) type using
-`object_dynamic_cast()`.  You typically want to define macro wrappers around
-`OBJECT_CHECK()` and `OBJECT_CLASS_CHECK()` to make it easier to convert to a
-specific type:
-
-.. code-block:: c
-   :caption: Typecasting macros
-
-   #define MY_DEVICE_GET_CLASS(obj) \
-      OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE)
-   #define MY_DEVICE_CLASS(klass) \
-      OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE)
-   #define MY_DEVICE(obj) \
-      OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE)
+Using `object_new()`, a new `Object` derivative will be
+instantiated.  You can cast an `Object` to a subclass (or
+base-class) type using `object_dynamic_cast()` or :ref:`typecast
+wrappers <typecasting>`.
 
 In case the ObjectClass implementation can be built as module a
 module_obj() line must be added to make sure qemu loads the module
@@ -93,6 +82,31 @@ when the object is needed.
 
    module_obj(TYPE_MY_DEVICE);
 
+.. _typecasting:
+
+Typecasting
+===========
+
+The `OBJECT_DECLARE macros <OBJECT_DECLARE>` automatically define
+typecasting functions having signatures like these:
+
+.. code-block:: c
+
+   static inline MyDevice *MY_DEVICE(const void *obj);
+   static inline MyDeviceClass *MY_DEVICE_GET_CLASS(const void *obj);
+   static inline MyDeviceClass *MY_DEVICE_CLASS(const void *klass);
+
+These typecasting functions are wrappers around `OBJECT_CHECK`,
+`OBJECT_GET_CLASS`, and `OBJECT_CLASS_CHECK`.  Example usage:
+
+.. code-block:: c
+
+    Object *obj = object_new("my-device");
+    MyDevice *my_dev = MY_DEVICE(obj);
+    DeviceState *dev = DEVICE(my_dev);
+    MyDeviceClass *mdc = MY_DEVICE_GET_CLASS(my_dev);
+    DeviceClass *dc = DEVICE_CLASS(mdc);
+
 Class Initialization
 ====================
 
@@ -282,6 +296,8 @@ convention. To reduce the amount of boilerplate code that needs to be
 written for a new type there are two sets of macros to generate the
 common parts in a standard format.
 
+.. _OBJECT_DECLARE:
+
 Type declaration macros
 -----------------------
 
Signature · 1 line
2.31.1
Reviewed-by on v1 9/10
#29 lore raw

Re: [PATCH for-6.2 09/10] docs: qom: Remove OBJECT_CHECK macro examples

Quoted 7 lines · Eduardo Habkost

We shouldn't encourage people to keep defining typecast macros manually, when we have the OBJECT_DECLARE* macros. Remove the section showing how to define them, and replace with a section explaining how typecasting works.

other than all the ... (cf patch 1):

thanks
-- PMM

#30 lore raw

PATCH 10/10 MAINTAINERS: Add qom.rst to QOM section

In reply to Eduardo Habkost

Add qom.rst to the QOM section of MAINTAINERS.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 42ac45c3e50..dc3f04242eb 100644
@@ -2651,6 +2651,7 @@ M: Paolo Bonzini <[email protected]>
 R: Daniel P. Berrange <[email protected]>
 R: Eduardo Habkost <[email protected]>
 S: Supported
+F: docs/devel/qom.rst
 F: docs/qdev-device-use.txt
 F: hw/core/qdev*
 F: hw/core/bus.c
Signature · 1 line
2.31.1
Reviewed-by on v1 10/10
#31 lore raw

Re: [PATCH for-6.2 10/10] MAINTAINERS: Add qom.rst to QOM section

Quoted 13 lines · Eduardo Habkost

Add qom.rst to the QOM section of MAINTAINERS.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +0 -0
index 42ac45c3e50..dc3f04242eb 100644

MAINTAINERS M: Paolo Bonzini <[email protected]>

Quoted 8 lines
MAINTAINERS +1 -1
@@ -2651,6 +2651,7 @@ M: Paolo Bonzini <[email protected]>
 R: Daniel P. Berrange <[email protected]>
 R: Eduardo Habkost <[email protected]>
 S: Supported
+F: docs/devel/qom.rst
 F: docs/qdev-device-use.txt
 F: hw/core/qdev*
 F: hw/core/bus.c
--

thanks
-- PMM