Skip to contentSkip to conversation

qom: Rename object_new_with_props to object_new_child

RFC PATCH In review Thomas Huth 3 participants 6 messages Aug 17, 2018 Crypto API

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 qom: Rename object_new_with_props to object_new_child

While adding the object_initialize_child() function, Paolo suggested to rename the similar object_new_with_props() function accordingly:

http://marc.info/[email protected]

This way it is more obvious that this function creates a new object as a child of another object.

---
 hw/misc/auxbus.c                 |  4 +--
 include/crypto/tlscredsanon.h    |  4 +--
 include/crypto/tlscredspsk.h     |  4 +--
 include/crypto/tlscredsx509.h    |  4 +--
 include/qom/object.h             | 44 +++++++++++++--------------
 iothread.c                       |  6 ++--
 qom/object.c                     | 22 +++++++-------
 tests/check-qom-proplist.c       | 66 +++++++++++++++++++---------------------
 tests/test-crypto-block.c        |  2 +-
 tests/test-crypto-secret.c       | 44 +++++++++++++--------------
 tests/test-crypto-tlscredsx509.c |  2 +-
 tests/test-crypto-tlssession.c   |  4 +--
 tests/test-io-channel-tls.c      |  2 +-
 ui/vnc.c                         | 28 ++++++++---------
 14 files changed, 116 insertions(+), 120 deletions(-)
hw/misc/auxbus.c +2 -2
index 0e56d9a..c3729e5 100644
@@ -67,8 +67,8 @@ AUXBus *aux_init_bus(DeviceState *parent, const char *name)
     Object *auxtoi2c;
 
     bus = AUX_BUS(qbus_create(TYPE_AUX_BUS, parent, name));
-    auxtoi2c = object_new_with_props(TYPE_AUXTOI2C, OBJECT(bus), "i2c",
-                                     &error_abort, NULL);
+    auxtoi2c = object_new_child(TYPE_AUXTOI2C, OBJECT(bus), "i2c",
+                                &error_abort, NULL);
     qdev_set_parent_bus(DEVICE(auxtoi2c), BUS(bus));
 
     bus->bridge = AUXTOI2C(auxtoi2c);
include/crypto/tlscredsanon.h +2 -2
index 4d6b7e4..7cfa03f 100644
@@ -41,14 +41,14 @@ typedef struct QCryptoTLSCredsAnonClass QCryptoTLSCredsAnonClass;
  * due to lacking MITM attack protection amongst other problems.
  *
  * This is a user creatable object, which can be instantiated
- * via object_new_propv():
+ * via object_new_child():
  *
  * <example>
  *   <title>Creating anonymous TLS credential objects in code</title>
  *   <programlisting>
  *   Object *obj;
  *   Error *err = NULL;
- *   obj = object_new_propv(TYPE_QCRYPTO_TLS_CREDS_ANON,
+ *   obj = object_new_child(TYPE_QCRYPTO_TLS_CREDS_ANON,
  *                          "tlscreds0",
  *                          &err,
  *                          "endpoint", "server",
include/crypto/tlscredspsk.h +2 -2
index 306d36c..781ac56 100644
@@ -39,14 +39,14 @@ typedef struct QCryptoTLSCredsPSKClass QCryptoTLSCredsPSKClass;
  * of the Pre-Shared Key credential used to perform a TLS handshake.
  *
  * This is a user creatable object, which can be instantiated
- * via object_new_propv():
+ * via object_new_child():
  *
  * <example>
  *   <title>Creating TLS-PSK credential objects in code</title>
  *   <programlisting>
  *   Object *obj;
  *   Error *err = NULL;
- *   obj = object_new_propv(TYPE_QCRYPTO_TLS_CREDS_PSK,
+ *   obj = object_new_child(TYPE_QCRYPTO_TLS_CREDS_PSK,
  *                          "tlscreds0",
  *                          &err,
  *                          "dir", "/path/to/dir",
include/crypto/tlscredsx509.h +2 -2
index 66ad6a7..d0ef017 100644
@@ -45,14 +45,14 @@ typedef struct QCryptoTLSCredsX509Class QCryptoTLSCredsX509Class;
  * of x509 credentials used to perform a TLS handshake.
  *
  * This is a user creatable object, which can be instantiated
- * via object_new_propv():
+ * via object_new_child():
  *
  * <example>
  *   <title>Creating x509 TLS credential objects in code</title>
  *   <programlisting>
  *   Object *obj;
  *   Error *err = NULL;
- *   obj = object_new_propv(TYPE_QCRYPTO_TLS_CREDS_X509,
+ *   obj = object_new_child(TYPE_QCRYPTO_TLS_CREDS_X509,
  *                          "tlscreds0",
  *                          &err,
  *                          "endpoint", "server",
include/qom/object.h +22 -22

71 lines not on this page · raw message

iothread.c +3 -3
index aff1281..02dfeaa 100644
@@ -363,9 +363,9 @@ IOThread *iothread_create(const char *id, Error **errp)
 {
     Object *obj;
 
-    obj = object_new_with_props(TYPE_IOTHREAD,
-                                object_get_internal_root(),
-                                id, errp, NULL);
+    obj = object_new_child(TYPE_IOTHREAD,
+                           object_get_internal_root(),
+                           id, errp, NULL);
 
     return IOTHREAD(obj);
 }
qom/object.c +11 -11
index 75d1d48..aa3074a 100644
@@ -557,28 +557,28 @@ Object *object_new(const char *typename)
 }
 
 
-Object *object_new_with_props(const char *typename,
-                              Object *parent,
-                              const char *id,
-                              Error **errp,
-                              ...)
+Object *object_new_child(const char *typename,
+                         Object *parent,
+                         const char *id,
+                         Error **errp,
+                         ...)
 {
     va_list vargs;
     Object *obj;
 
     va_start(vargs, errp);
-    obj = object_new_with_propv(typename, parent, id, errp, vargs);
+    obj = object_new_childv(typename, parent, id, errp, vargs);
     va_end(vargs);
 
     return obj;
 }
 
 
-Object *object_new_with_propv(const char *typename,
-                              Object *parent,
-                              const char *id,
-                              Error **errp,
-                              va_list vargs)
+Object *object_new_childv(const char *typename,
+                          Object *parent,
+                          const char *id,
+                          Error **errp,
+                          va_list vargs)
 {
     Object *obj;
     ObjectClass *klass;
tests/check-qom-proplist.c +31 -35

102 lines not on this page · raw message

tests/test-crypto-block.c +1 -1
index fd29a04..6e14c47 100644
@@ -239,7 +239,7 @@ static ssize_t test_block_write_func(QCryptoBlock *block,
 
 static Object *test_block_secret(void)
 {
-    return object_new_with_props(
+    return object_new_child(
         TYPE_QCRYPTO_SECRET,
         object_get_objects_root(),
         "sec0",
tests/test-crypto-secret.c +22 -22

176 lines not on this page · raw message

tests/test-crypto-tlscredsx509.c +1 -1
index 30f9ac4..19d8aa0 100644
@@ -42,7 +42,7 @@ static QCryptoTLSCreds *test_tls_creds_create(QCryptoTLSCredsEndpoint endpoint,
                                               Error **errp)
 {
     Object *parent = object_get_objects_root();
-    Object *creds = object_new_with_props(
+    Object *creds = object_new_child(
         TYPE_QCRYPTO_TLS_CREDS_X509,
         parent,
         "testtlscreds",
tests/test-crypto-tlssession.c +2 -2
index 6fa9950..6e4c268 100644
@@ -55,7 +55,7 @@ static QCryptoTLSCreds *test_tls_creds_psk_create(
     const char *dir)
 {
     Object *parent = object_get_objects_root();
-    Object *creds = object_new_with_props(
+    Object *creds = object_new_child(
         TYPE_QCRYPTO_TLS_CREDS_PSK,
         parent,
         (endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ?
@@ -187,7 +187,7 @@ static QCryptoTLSCreds *test_tls_creds_x509_create(
     const char *certdir)
 {
     Object *parent = object_get_objects_root();
-    Object *creds = object_new_with_props(
+    Object *creds = object_new_child(
         TYPE_QCRYPTO_TLS_CREDS_X509,
         parent,
         (endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ?
tests/test-io-channel-tls.c +1 -1
index 4900c6d..2118b61 100644
@@ -68,7 +68,7 @@ static QCryptoTLSCreds *test_tls_creds_create(QCryptoTLSCredsEndpoint endpoint,
                                               const char *certdir)
 {
     Object *parent = object_get_objects_root();
-    Object *creds = object_new_with_props(
+    Object *creds = object_new_child(
         TYPE_QCRYPTO_TLS_CREDS_X509,
         parent,
         (endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ?
ui/vnc.c +14 -14
index 3596932..4e1cefa 100644
@@ -3536,21 +3536,21 @@ vnc_display_create_creds(bool x509,
     Error *err = NULL;
 
     if (x509) {
-        creds = object_new_with_props(TYPE_QCRYPTO_TLS_CREDS_X509,
-                                      parent,
-                                      credsid,
-                                      &err,
-                                      "endpoint", "server",
-                                      "dir", dir,
-                                      "verify-peer", x509verify ? "yes" : "no",
-                                      NULL);
+        creds = object_new_child(TYPE_QCRYPTO_TLS_CREDS_X509,
+                                 parent,
+                                 credsid,
+                                 &err,
+                                 "endpoint", "server",
+                                 "dir", dir,
+                                 "verify-peer", x509verify ? "yes" : "no",
+                                  NULL);
     } else {
-        creds = object_new_with_props(TYPE_QCRYPTO_TLS_CREDS_ANON,
-                                      parent,
-                                      credsid,
-                                      &err,
-                                      "endpoint", "server",
-                                      NULL);
+        creds = object_new_child(TYPE_QCRYPTO_TLS_CREDS_ANON,
+                                 parent,
+                                 credsid,
+                                 &err,
+                                 "endpoint", "server",
+                                 NULL);
     }
 
     g_free(credsid);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 7 lines · Thomas Huth

While adding the object_initialize_child() function, Paolo suggested to rename the similar object_new_with_props() function accordingly:

http://marc.info/[email protected]

This way it is more obvious that this function creates a new object as a child of another object.

I'd expect 'object_new_with_child' to be the same as 'object_new', but with only 'parent' & 'id' args added, which isn't the case here.

If we want the full & consistent design then we should have

object_new(typename)
object_new_with_child(typename, parent, id) object_new_props(typename, ...) object_new_propv(typename, va_arg props) object_new_with_child_props(typename, parent, id, ...) object_new_with_child_propv(typename, parent, id, va_arg props)

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 :|
#4 lore raw
In reply to Daniel P. Berrangé
Quoted 23 lines · Daniel P. Berrangé
Quoted 22 lines · Thomas Huth
Quoted 20 lines · Daniel P. Berrangé
Quoted 7 lines · Thomas Huth

While adding the object_initialize_child() function, Paolo suggested to rename the similar object_new_with_props() function accordingly:

http://marc.info/[email protected]

This way it is more obvious that this function creates a new object as a child of another object.

I'd expect 'object_new_with_child' to be the same as 'object_new', but with only 'parent' & 'id' args added, which isn't the case here.

If we want the full & consistent design then we should have

object_new(typename)
object_new_with_child(typename, parent, id) object_new_props(typename, ...) object_new_propv(typename, va_arg props) object_new_with_child_props(typename, parent, id, ...) object_new_with_child_propv(typename, parent, id, va_arg props)

Quoted 6 lines
Quoted 4 lines

"new_with_child" sounds wrong, too, since the parent is not created here, but the child. Anyway, I guess the naming of these functions is too much subject to bikeshedding, so never mind, let's keep it as it currently is.

True, 'new_with_parent' is a better choice in retrospect :-)

Or indeed 'object_new_child' and 'object_new_child_prop{s,v}' approx as you had suggested

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 :|
#3 lore raw
In reply to Thomas Huth
Quoted 22 lines · Thomas Huth
Quoted 12 lines · Daniel P. Berrangé
Quoted 7 lines · Thomas Huth

While adding the object_initialize_child() function, Paolo suggested to rename the similar object_new_with_props() function accordingly:

http://marc.info/[email protected]

This way it is more obvious that this function creates a new object as a child of another object.

I'd expect 'object_new_with_child' to be the same as 'object_new', but with only 'parent' & 'id' args added, which isn't the case here.

Quoted 8 lines

If we want the full & consistent design then we should have

object_new(typename)
object_new_with_child(typename, parent, id) object_new_props(typename, ...) object_new_propv(typename, va_arg props) object_new_with_child_props(typename, parent, id, ...) object_new_with_child_propv(typename, parent, id, va_arg props)

Quoted 4 lines

"new_with_child" sounds wrong, too, since the parent is not created here, but the child. Anyway, I guess the naming of these functions is too much subject to bikeshedding, so never mind, let's keep it as it currently is.

True, 'new_with_parent' is a better choice in retrospect :-)

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 :|
#2 lore raw
In reply to Daniel P. Berrangé
Quoted 12 lines · Daniel P. Berrangé
Quoted 7 lines · Thomas Huth

While adding the object_initialize_child() function, Paolo suggested to rename the similar object_new_with_props() function accordingly:

http://marc.info/[email protected]

This way it is more obvious that this function creates a new object as a child of another object.

I'd expect 'object_new_with_child' to be the same as 'object_new', but with only 'parent' & 'id' args added, which isn't the case here.

Quoted 8 lines

If we want the full & consistent design then we should have

object_new(typename)
object_new_with_child(typename, parent, id) object_new_props(typename, ...) object_new_propv(typename, va_arg props) object_new_with_child_props(typename, parent, id, ...) object_new_with_child_propv(typename, parent, id, va_arg props)

"new_with_child" sounds wrong, too, since the parent is not created here, but the child. Anyway, I guess the naming of these functions is too much subject to bikeshedding, so never mind, let's keep it as it currently is.

Thomas

#5 lore raw
In reply to Daniel P. Berrangé
Quoted 29 lines · Daniel P. Berrangé
Quoted 28 lines · Daniel P. Berrangé
Quoted 26 lines · Thomas Huth
Quoted 12 lines · Daniel P. Berrangé
Quoted 7 lines · Thomas Huth

While adding the object_initialize_child() function, Paolo suggested to rename the similar object_new_with_props() function accordingly:

http://marc.info/[email protected]

This way it is more obvious that this function creates a new object as a child of another object.

I'd expect 'object_new_with_child' to be the same as 'object_new', but with only 'parent' & 'id' args added, which isn't the case here.

Quoted 8 lines

If we want the full & consistent design then we should have

object_new(typename)
object_new_with_child(typename, parent, id) object_new_props(typename, ...) object_new_propv(typename, va_arg props) object_new_with_child_props(typename, parent, id, ...) object_new_with_child_propv(typename, parent, id, va_arg props)

"new_with_child" sounds wrong, too, since the parent is not created here, but the child. Anyway, I guess the naming of these functions is too much subject to bikeshedding, so never mind, let's keep it as it currently is.

Quoted 4 lines
Quoted 1 line

True, 'new_with_parent' is a better choice in retrospect :-)

Or indeed 'object_new_child' and 'object_new_child_prop{s,v}' approx as you had suggested

That would work for me too. Really anything works as long as the initialize and new names are consistent.

In practice object_new_child would be unused, hence the shortcut of adding the props argument directly to object_new_child{,v}.

Thanks,

Paolo