Home
last modified time | relevance | path

Searched hist:"221 db5daf6b3666f1c8e4ca06ae45892e99a112f" (Results 1 – 4 of 4) sorted by relevance

/qemu/include/crypto/
H A Dblock.h221db5daf6b3666f1c8e4ca06ae45892e99a112f Thu Jul 23 15:38:45 UTC 2020 Daniel P. Berrangé <berrange@redhat.com> 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>
/qemu/tests/unit/
H A Dtest-qobject-input-visitor.c221db5daf6b3666f1c8e4ca06ae45892e99a112f Thu Jul 23 15:38:45 UTC 2020 Daniel P. Berrangé <berrange@redhat.com> 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>
/qemu/scripts/qapi/
H A Dtypes.py221db5daf6b3666f1c8e4ca06ae45892e99a112f Thu Jul 23 15:38:45 UTC 2020 Daniel P. Berrangé <berrange@redhat.com> 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>
/qemu/docs/devel/
H A Dqapi-code-gen.rst221db5daf6b3666f1c8e4ca06ae45892e99a112f Thu Jul 23 15:38:45 UTC 2020 Daniel P. Berrangé <berrange@redhat.com> 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>