qemu/docs/devel
Daniel P. Berrangé 221db5daf6 qapi: enable use of g_autoptr with QAPI types
Currently QAPI generates a type and function for free'ing it:

  typedef struct QCryptoBlockCreateOptions QCryptoBlockCreateOptions;
  void qapi_free_QCryptoBlockCreateOptions(QCryptoBlockCreateOptions *obj);

This is used in the traditional manner:

  QCryptoBlockCreateOptions *opts = NULL;

  opts = g_new0(QCryptoBlockCreateOptions, 1);

  ....do stuff with opts...

  qapi_free_QCryptoBlockCreateOptions(opts);

Since bumping the min glib to 2.48, QEMU has incrementally adopted the
use of g_auto/g_autoptr. This allows the compiler to run a function to
free a variable when it goes out of scope, the benefit being the
compiler can guarantee it is freed in all possible code ptahs.

This benefit is applicable to QAPI types too, and given the seriously
long method names for some qapi_free_XXXX() functions, is much less
typing. This change thus makes the code generator emit:

 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlockCreateOptions,
                              qapi_free_QCryptoBlockCreateOptions)

The above code example now becomes

  g_autoptr(QCryptoBlockCreateOptions) opts = NULL;

  opts = g_new0(QCryptoBlockCreateOptions, 1);

  ....do stuff with opts...

Note, if the local pointer needs to live beyond the scope holding the
variable, then g_steal_pointer can be used. This is useful to return the
pointer to the caller in the success codepath, while letting it be freed
in all error codepaths.

  return g_steal_pointer(&opts);

The crypto/block.h header needs updating to avoid symbol clash now that
the g_autoptr support is a standard QAPI feature.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200723153845.2934357-1-berrange@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2020-09-03 09:38:36 +02:00
..
atomics.rst atomics: update documentation 2020-04-13 02:56:03 -04:00
bitops.rst docs: Create bitops.rst as example of kernel-docs 2019-12-17 19:36:57 +01:00
blkdebug.txt
blkverify.txt meson: link emulators without Makefile.target 2020-08-21 06:30:40 -04:00
build-system.rst meson: use pkg-config method to find dependencies 2020-09-01 08:51:35 -04:00
clocks.rst docs/clocks: add device's clock documentation 2020-04-30 15:35:40 +01:00
conf.py docs: Provide separate conf.py for each manual we want 2019-03-07 14:26:46 +00:00
decodetree.rst docs/devel: Document decodetree no-overlap groups 2020-08-04 16:33:47 +01:00
fuzzing.txt docs/fuzz: add instructions for generating a coverage report 2020-07-21 07:29:18 +02:00
index.rst docs: convert build system documentation to rST 2020-08-21 06:30:45 -04:00
kconfig.rst docs: Be consistent about capitalization of 'Arm' 2020-03-12 11:20:20 +00:00
loads-stores.rst accel/tcg: Add endian-specific cpu_{ld, st}* operations 2020-05-11 11:22:06 +01:00
lockcnt.txt docs: fix broken paths to docs/devel/atomics.txt 2017-07-31 13:12:47 +03:00
memory.rst docs: add memory API reference 2019-12-17 19:36:58 +01:00
migration.rst docs/devel/migration: start a debugging section 2020-05-07 17:40:24 +01:00
multi-thread-tcg.rst docs/devel: fix grammar in multi-thread-tcg 2020-07-15 11:52:39 +01:00
multiple-iothreads.txt block: Remove bdrv_set_aio_context() 2019-06-04 16:55:58 +02:00
qapi-code-gen.txt qapi: enable use of g_autoptr with QAPI types 2020-09-03 09:38:36 +02:00
rcu.txt rcu: do not mention atomic_mb_read/set in documentation 2020-04-13 02:56:18 -04:00
replay.txt replay: document development rules 2019-08-20 17:26:21 +02:00
reset.rst docs/devel/reset.rst: add doc about Resettable interface 2020-01-30 16:02:05 +00:00
s390-dasd-ipl.rst docs: rstfy s390 dasd ipl documentation 2020-02-26 18:57:07 +01:00
secure-coding-practices.rst docs: add Secure Coding Practices to developer docs 2019-05-10 10:53:52 +01:00
stable-process.rst docs/devel: fix stable process doc formatting 2020-01-27 12:13:09 +01:00
tcg-icount.rst docs/devel: add some notes on tcg-icount for developers 2020-07-11 15:53:00 +01:00
tcg-plugins.rst docs/devel: document query handle lifetimes 2020-02-25 20:20:23 +00:00
tcg.rst docs: Be consistent about capitalization of 'Arm' 2020-03-12 11:20:20 +00:00
testing.rst meson: link emulators without Makefile.target 2020-08-21 06:30:40 -04:00
tracing.txt libqemuutil, qapi, trace: convert to meson 2020-08-21 06:30:08 -04:00
virtio-migration.txt
writing-qmp-commands.txt monitor: Move {hmp, qmp}.c to monitor/{hmp, qmp}-cmds.c 2019-06-17 20:36:56 +02:00