All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Markus Armbruster" <armbru@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
	"Philippe Mathieu-Daudé" <philmd@mailo.com>,
	"Eric Blake" <eblake@redhat.com>
Subject: [PATCH v3 73/74] qapi: expose integer signedness and width in introspection
Date: Tue, 18 Aug 2026 17:29:39 +0400	[thread overview]
Message-ID: <20260818-qom-qapi-v3-73-24b8bbbe3d86@redhat.com> (raw)
In-Reply-To: <20260818-qom-qapi-v3-0-24b8bbbe3d86@redhat.com>

Integer built-in types are currently canonicalized to "int" in
query-qmp-schema. Consequently, clients cannot distinguish types such
as int8, uint64, and size, even though they accept different ranges.

Preserve the individual integer types during schema analysis and add an
optional "integer" member to SchemaInfoBuiltin. It reports whether the
type is signed and its width in bits. This also preserves the actual
element type for arrays of integers.

Teach the introspection generator to emit integer values and update the
documentation to describe the extended schema information.

For example for introspection, for all kind of int, before:
{"name": "int", "json-type": "int", "meta-type": "builtin"}

After, there are various int types such as:
{"name": "int64", "integer": {"bits": 64, "signed": true}, "json-type":
"int", "meta-type": "builtin"}

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 docs/devel/qapi-code-gen.rst    | 24 ++++++++++++++----------
 qapi/introspect.json            | 20 +++++++++++++++++++-
 scripts/qapi/introspect.py      | 29 ++++++++++++++++++++++++++---
 scripts/qapi/schema_analysis.py | 16 ----------------
 4 files changed, 59 insertions(+), 30 deletions(-)

diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
index d176238fc2ef..a158f017d9a7 100644
--- a/docs/devel/qapi-code-gen.rst
+++ b/docs/devel/qapi-code-gen.rst
@@ -1400,14 +1400,19 @@ Example: the SchemaInfo for str ::
 
     { "name": "str", "meta-type": "builtin", "json-type": "string" }
 
-The QAPI schema supports a number of integer types that only differ in
-how they map to C.  They are identical as far as SchemaInfo is
-concerned.  Therefore, they get all mapped to a single type "int" in
-SchemaInfo.
+The QAPI schema supports a number of integer types with different widths
+and signedness.  Each has its own SchemaInfo with "json-type" "int" and
+variant member "integer" specifying its "signed" flag and width in
+"bits".
+
+Example: the SchemaInfo for uint8 ::
+
+    { "name": "uint8", "meta-type": "builtin", "json-type": "int",
+      "integer": { "signed": false, "bits": 8 } }
 
 As explained above, type names are not part of the wire ABI.  Not even
-the names of built-in types.  Clients should examine member
-"json-type" instead of hard-coding names of built-in types.
+the names of built-in types.  Clients should examine members "json-type"
+and "integer" instead of hard-coding names of built-in types.
 
 
 Compatibility considerations
@@ -2130,10 +2135,9 @@ Each ``QAPITypeInfo`` struct has the following fields:
 ``masked_name``
     For user-defined types, the masked name used in
     ``query-qmp-schema`` output. For array types, the corresponding
-    bracketed introspection name. Built-in types use their QAPI name;
-    note that introspection canonicalizes the integer built-in types
-    to ``int``. Internal types not present in introspection use
-    ``NULL``.
+    bracketed introspection name. Built-in types, including the distinct
+    integer types, use their QAPI name. Internal types not present in
+    introspection use ``NULL``.
 
 ``lookup``
     For enum types, a pointer to the corresponding ``QEnumLookup``
diff --git a/qapi/introspect.json b/qapi/introspect.json
index c8432c8ed8ec..8b5848862c4e 100644
--- a/qapi/introspect.json
+++ b/qapi/introspect.json
@@ -117,10 +117,28 @@
 #
 # @json-type: the JSON type used for this type on the wire.
 #
+# @integer: the integer type's representation.  Present exactly when
+#     @json-type is 'int'.  (since 11.2)
+#
 # Since: 2.5
 ##
 { 'struct': 'SchemaInfoBuiltin',
-  'data': { 'json-type': 'JSONType' } }
+  'data': { 'json-type': 'JSONType',
+            '*integer': 'SchemaInfoBuiltinInteger' } }
+
+##
+# @SchemaInfoBuiltinInteger:
+#
+# Representation of an integer built-in type.
+#
+# @signed: whether the integer is signed.
+#
+# @bits: the integer's width in bits.
+#
+# Since: 11.2
+##
+{ 'struct': 'SchemaInfoBuiltinInteger',
+  'data': { 'signed': 'bool', 'bits': 'int' } }
 
 ##
 # @JSONType:
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index ce37ce787567..e3749d38ced5 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -49,7 +49,7 @@
 # A complexity over JSON is that our values may or may not be annotated.
 #
 # Un-annotated values may be:
-#     Scalar: str, bool, None.
+#     Scalar: str, bool, int, None.
 #     Non-scalar: List, Dict
 # _value = Union[str, bool, None, Dict[str, JSONValue], List[JSONValue]]
 #
@@ -59,11 +59,25 @@
 # Sadly, mypy does not support recursive types; so the _Stub alias is used to
 # mark the imprecision in the type model where we'd otherwise use JSONValue.
 _Stub = Any  # pylint: disable=invalid-name
-_Scalar = Union[str, bool, None]
+_Scalar = Union[str, bool, int, None]
 _NonScalar = Union[Dict[str, _Stub], List[_Stub]]
 _Value = Union[_Scalar, _NonScalar]
 JSONValue = Union[_Value, 'Annotated[_Value]']
 
+
+_INTEGER_TYPE_INFO = {
+    'int': (True, 64),
+    'int8': (True, 8),
+    'int16': (True, 16),
+    'int32': (True, 32),
+    'int64': (True, 64),
+    'uint8': (False, 8),
+    'uint16': (False, 16),
+    'uint32': (False, 32),
+    'uint64': (False, 64),
+    'size': (False, 64),
+}
+
 # These types are based on structures defined in QEMU's schema, so we
 # lack precise types for them here. Python 3.6 does not offer
 # TypedDict constructs, so they are broadly typed here as simple
@@ -135,6 +149,8 @@ def indent(level: int) -> str:
         ret += f"QLIT_QSTR({to_c_string(obj)})"
     elif isinstance(obj, bool):
         ret += f"QLIT_QBOOL({str(obj).lower()})"
+    elif isinstance(obj, int):
+        ret += f"QLIT_QNUM({obj})"
 
     # Non-scalars:
     elif isinstance(obj, list):
@@ -271,7 +287,14 @@ def _gen_variant(self, variant: QAPISchemaVariant
 
     def visit_builtin_type(self, name: str, info: Optional[QAPISourceInfo],
                            json_type: str) -> None:
-        self._gen_tree(name, 'builtin', {'json-type': json_type})
+        obj: Dict[str, object] = {'json-type': json_type}
+        if json_type == 'int':
+            signed, bits = _INTEGER_TYPE_INFO[name]
+            obj['integer'] = {
+                'signed': signed,
+                'bits': bits,
+            }
+        self._gen_tree(name, 'builtin', obj)
 
     def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo],
                         ifcond: QAPISchemaIfCond,
diff --git a/scripts/qapi/schema_analysis.py b/scripts/qapi/schema_analysis.py
index 1d12306f61e2..1aad2dc80380 100644
--- a/scripts/qapi/schema_analysis.py
+++ b/scripts/qapi/schema_analysis.py
@@ -123,27 +123,12 @@ def visit_alternate_type(
 
     def _register_type(self, typ: QAPISchemaType) -> None:
         """Record a type for introspection (idempotent)."""
-        typ = self._canonicalize_type(typ)
         if typ not in self._types_set:
             self._types.append(typ)
             self._types_set.add(typ)
             if isinstance(typ, QAPISchemaArrayType):
                 self._register_type(typ.element_type)
 
-    def _canonicalize_type(self, typ: QAPISchemaType) -> QAPISchemaType:
-        """Canonicalize integer types to plain int."""
-        assert self._schema is not None
-        if typ.json_type() == 'int':
-            type_int = self._schema.lookup_type('int')
-            assert type_int
-            return type_int
-        if (isinstance(typ, QAPISchemaArrayType) and
-                typ.element_type.json_type() == 'int'):
-            type_intlist = self._schema.lookup_type('intList')
-            assert type_intlist
-            return type_intlist
-        return typ
-
     def masked_name(self, name: str) -> str:
         """Return the masked name for a non-builtin, non-array type."""
         assert name in self._name_map, \
@@ -152,7 +137,6 @@ def masked_name(self, name: str) -> str:
 
     def introspection_name(self, typ: QAPISchemaType) -> str:
         """Return the introspection name for a type."""
-        typ = self._canonicalize_type(typ)
         if isinstance(typ, QAPISchemaBuiltinType):
             return typ.name
         if isinstance(typ, QAPISchemaArrayType):

-- 
2.55.0.543.g5ebe2ebe4ea8



  parent reply	other threads:[~2026-08-18 13:38 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 11:10 [PATCH v3 00/74] qom/qdev: associate properties with QAPI schema types Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 01/74] qapi: add QAPITypeInfo struct definition Marc-André Lureau
2026-08-21 13:40   ` Markus Armbruster
2026-08-21 15:33     ` Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 02/74] qapi/gen: fix _module_basename for multi-dash 'what' parameters Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 03/74] qapi: factor out QAPISchemaUsedTypes from introspect visitor Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 04/74] qapi: register all introspectable types, not just QMP-reachable ones Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 05/74] qapi: add type-infos generator Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 06/74] meson: add qapi-type-infos-*.c/h to build Marc-André Lureau
2026-08-18 11:41   ` Kostiantyn Kostiuk
2026-08-18 11:10 ` [PATCH v3 07/74] qom: add qapi_type field to ObjectProperty Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 08/74] qapi/qom: add qapi-type field to ObjectPropertyInfo Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 09/74] qom/qmp: populate qapi-type in QMP handlers Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 10/74] qom: add object_property_set_default_enum() Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 11/74] qom: add object_{class_}property_add_qapi Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 12/74] qom: add object_{class_}property_add_qapi_enum Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 13/74] tests: update check-qom-proplist for QAPI-aware property registration Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 14/74] qom: convert enum properties to QAPI-aware registration Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 15/74] qom: remove old enum property registration API Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 16/74] qom: convert struct properties to QAPI-aware registration Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 17/74] x86: convert OnOffAuto " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 18/74] microvm: " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 19/74] pc: convert OnOffAuto vmport property " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 20/74] arm/virt: convert OnOffAuto acpi " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 21/74] riscv/virt: convert OnOffAuto properties " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 22/74] loongarch/virt: " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 23/74] hostmem-file: convert OnOffAuto rom property " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 24/74] sev: convert OnOffAuto legacy-vm-type " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 25/74] whpx: convert OnOffAuto hyperv " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 26/74] whpx: convert OnOffAuto arch properties " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 27/74] accel/kvm: convert OnOffSplit property " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 28/74] whpx: " Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 29/74] ppc/spapr-caps: convert to QAPI-aware property registration Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 30/74] system/memory: fix "priority" property typename Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 31/74] backends/hostmem: fix property typenames Marc-André Lureau
2026-08-18 11:10 ` [PATCH v3 32/74] backends/hostmem-file: fix "align" property typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 33/74] accel/tcg: fix "tb-size" " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 34/74] block/throttle-groups: fix throttle properties typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 35/74] event-loop-base: fix property typenames Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 36/74] iothread: fix poll properties typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 37/74] util/thread-context: fix property typenames Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 38/74] target/i386: fix CPUID version properties typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 39/74] ppc/pnv: fix phb-id and chip-id " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 40/74] backends/hostmem-memfd: fix "hugetlbsize" property typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 41/74] hw/acpi: fix "node" properties typename Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 42/74] net/colo-compare: fix compare_timeout setter visitor type Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 43/74] net/colo-compare: fix max_queue_size " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 44/74] hw/misc/xlnx-versal-trng: add missing getter for fips-fault-events Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 45/74] qom: convert scalar properties to QAPI-aware registration Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 46/74] i386/cpu: convert strList property " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 47/74] accel/hvf: convert OnOffSplit " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 48/74] i386/x86: convert SgxEPCList " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 49/74] virtio-balloon: convert guest-stats property to QAPI type Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 50/74] qom: replace object_property_add_tm with StructTm " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 51/74] hw/nvdimm: convert UUID property to QAPI-aware registration Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 52/74] hw/s390-virtio-ccw: convert loadparm " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 53/74] hw/ppc/spapr_drc: convert fdt " Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 54/74] spdm-socket: convert SpdmTransportType to QAPI enum Marc-André Lureau
2026-08-18 11:11 ` [PATCH v3 55/74] hw/gpio/pca955x: use QAPI enums for led and pin properties Marc-André Lureau
2026-08-18 12:36 ` [PATCH v3 56/74] include: add QEMU_REPEAT helper macro Marc-André Lureau
2026-08-18 12:36 ` [PATCH v3 57/74] hw/gpio/pca955x: convert pin/led property to QAPI-aware enum Marc-André Lureau
2026-08-18 12:36 ` [PATCH v3 58/74] hw/pci: change the busnr type to uint8 Marc-André Lureau
2026-08-18 12:36 ` [PATCH v3 59/74] qdev: add qapi_type field to PropertyInfo with fallback registration Marc-André Lureau
2026-08-18 12:36 ` [PATCH v3 60/74] qdev: convert core PropertyInfo definitions to use qapi_type Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 61/74] qdev: adjust PciDevfn declared type Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 62/74] qdev: convert system PropertyInfo definitions to use qapi_type Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 63/74] hw: convert device-local " Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 64/74] target/riscv: fix incorrect QAPI types and u8 casting Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 65/74] target/riscv: convert PropertyInfo definitions to use qapi_type Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 66/74] qdev: " Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 67/74] qdev: introduce typed array PropertyInfos Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 68/74] qdev: simplify DEFINE_PROP_ARRAY and remove generic array PropertyInfo Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 69/74] qdev: remove deprecated PropertyInfo.type and .enum_table fields Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 70/74] memory: use object_property_add_link for container property Marc-André Lureau
2026-08-20 18:17   ` Peter Xu
2026-08-18 13:29 ` [PATCH v3 71/74] hw/i386: convert PCSouthBridgeOption to QAPI enum Marc-André Lureau
2026-08-18 13:29 ` [PATCH v3 72/74] qom: use QAPITypeInfo in object_property_get_enum Marc-André Lureau
2026-08-18 13:29 ` Marc-André Lureau [this message]
2026-08-18 13:29 ` [PATCH v3 74/74] tests/qmp-cmd-test: assert qapi-type resolves in query-qmp-schema Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260818-qom-qapi-v3-73-24b8bbbe3d86@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@mailo.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.