From a6ee6f1a87bf62da7d4ccc0ab3f32bb2640eebc6 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Tue, 20 Mar 2018 11:09:43 -0400 Subject: [PATCH] qobject: introduce qobject_get_try_str() A quick way to fetch string from qobject when it's a QString. Backports commit b26ae1cb8eb0756524e322169138830b9b542311 from qemu --- qemu/aarch64.h | 1 + qemu/aarch64eb.h | 1 + qemu/arm.h | 1 + qemu/armeb.h | 1 + qemu/header_gen.py | 1 + qemu/include/qapi/qmp/qstring.h | 1 + qemu/m68k.h | 1 + qemu/mips.h | 1 + qemu/mips64.h | 1 + qemu/mips64el.h | 1 + qemu/mipsel.h | 1 + qemu/powerpc.h | 1 + qemu/qobject/qstring.c | 11 +++++++++++ qemu/sparc.h | 1 + qemu/sparc64.h | 1 + qemu/x86_64.h | 1 + 16 files changed, 26 insertions(+) diff --git a/qemu/aarch64.h b/qemu/aarch64.h index 73cf65cb..3be2220a 100644 --- a/qemu/aarch64.h +++ b/qemu/aarch64.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_aarch64 #define qlit_equal_qobject qlit_equal_qobject_aarch64 #define qobject_from_qlit qobject_from_qlit_aarch64 +#define qobject_get_try_str qobject_get_try_str_aarch64 #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_aarch64 #define qobject_input_end_list qobject_input_end_list_aarch64 #define qobject_input_end_struct qobject_input_end_struct_aarch64 diff --git a/qemu/aarch64eb.h b/qemu/aarch64eb.h index 2b49dd0f..ddfc84a5 100644 --- a/qemu/aarch64eb.h +++ b/qemu/aarch64eb.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_aarch64eb #define qlit_equal_qobject qlit_equal_qobject_aarch64eb #define qobject_from_qlit qobject_from_qlit_aarch64eb +#define qobject_get_try_str qobject_get_try_str_aarch64eb #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_aarch64eb #define qobject_input_end_list qobject_input_end_list_aarch64eb #define qobject_input_end_struct qobject_input_end_struct_aarch64eb diff --git a/qemu/arm.h b/qemu/arm.h index 8a8a0be8..da113846 100644 --- a/qemu/arm.h +++ b/qemu/arm.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_arm #define qlit_equal_qobject qlit_equal_qobject_arm #define qobject_from_qlit qobject_from_qlit_arm +#define qobject_get_try_str qobject_get_try_str_arm #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_arm #define qobject_input_end_list qobject_input_end_list_arm #define qobject_input_end_struct qobject_input_end_struct_arm diff --git a/qemu/armeb.h b/qemu/armeb.h index 24d7b388..d44cf486 100644 --- a/qemu/armeb.h +++ b/qemu/armeb.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_armeb #define qlit_equal_qobject qlit_equal_qobject_armeb #define qobject_from_qlit qobject_from_qlit_armeb +#define qobject_get_try_str qobject_get_try_str_armeb #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_armeb #define qobject_input_end_list qobject_input_end_list_armeb #define qobject_input_end_struct qobject_input_end_struct_armeb diff --git a/qemu/header_gen.py b/qemu/header_gen.py index 4d16515a..e8b82956 100644 --- a/qemu/header_gen.py +++ b/qemu/header_gen.py @@ -2210,6 +2210,7 @@ symbols = ( 'qlist_type', 'qlit_equal_qobject', 'qobject_from_qlit', + 'qobject_get_try_str', 'qobject_input_end_implicit_struct', 'qobject_input_end_list', 'qobject_input_end_struct', diff --git a/qemu/include/qapi/qmp/qstring.h b/qemu/include/qapi/qmp/qstring.h index 497c896b..9e476617 100644 --- a/qemu/include/qapi/qmp/qstring.h +++ b/qemu/include/qapi/qmp/qstring.h @@ -29,6 +29,7 @@ QString *qstring_from_substr(const char *str, int start, int end); size_t qstring_get_length(const QString *qstring); const char *qstring_get_str(const QString *qstring); const char *qstring_get_try_str(const QString *qstring); +const char *qobject_get_try_str(const QObject *qstring); void qstring_append_int(QString *qstring, int64_t value); void qstring_append(QString *qstring, const char *str); void qstring_append_chr(QString *qstring, int c); diff --git a/qemu/m68k.h b/qemu/m68k.h index 28d33a02..926f1bb3 100644 --- a/qemu/m68k.h +++ b/qemu/m68k.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_m68k #define qlit_equal_qobject qlit_equal_qobject_m68k #define qobject_from_qlit qobject_from_qlit_m68k +#define qobject_get_try_str qobject_get_try_str_m68k #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_m68k #define qobject_input_end_list qobject_input_end_list_m68k #define qobject_input_end_struct qobject_input_end_struct_m68k diff --git a/qemu/mips.h b/qemu/mips.h index 33589bf9..f35826b9 100644 --- a/qemu/mips.h +++ b/qemu/mips.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_mips #define qlit_equal_qobject qlit_equal_qobject_mips #define qobject_from_qlit qobject_from_qlit_mips +#define qobject_get_try_str qobject_get_try_str_mips #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_mips #define qobject_input_end_list qobject_input_end_list_mips #define qobject_input_end_struct qobject_input_end_struct_mips diff --git a/qemu/mips64.h b/qemu/mips64.h index d58f61ac..e10cb052 100644 --- a/qemu/mips64.h +++ b/qemu/mips64.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_mips64 #define qlit_equal_qobject qlit_equal_qobject_mips64 #define qobject_from_qlit qobject_from_qlit_mips64 +#define qobject_get_try_str qobject_get_try_str_mips64 #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_mips64 #define qobject_input_end_list qobject_input_end_list_mips64 #define qobject_input_end_struct qobject_input_end_struct_mips64 diff --git a/qemu/mips64el.h b/qemu/mips64el.h index 3027c9b7..c3fd3f7a 100644 --- a/qemu/mips64el.h +++ b/qemu/mips64el.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_mips64el #define qlit_equal_qobject qlit_equal_qobject_mips64el #define qobject_from_qlit qobject_from_qlit_mips64el +#define qobject_get_try_str qobject_get_try_str_mips64el #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_mips64el #define qobject_input_end_list qobject_input_end_list_mips64el #define qobject_input_end_struct qobject_input_end_struct_mips64el diff --git a/qemu/mipsel.h b/qemu/mipsel.h index ea037e83..8e67aa8d 100644 --- a/qemu/mipsel.h +++ b/qemu/mipsel.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_mipsel #define qlit_equal_qobject qlit_equal_qobject_mipsel #define qobject_from_qlit qobject_from_qlit_mipsel +#define qobject_get_try_str qobject_get_try_str_mipsel #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_mipsel #define qobject_input_end_list qobject_input_end_list_mipsel #define qobject_input_end_struct qobject_input_end_struct_mipsel diff --git a/qemu/powerpc.h b/qemu/powerpc.h index 6796f44b..f527cdca 100644 --- a/qemu/powerpc.h +++ b/qemu/powerpc.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_powerpc #define qlit_equal_qobject qlit_equal_qobject_powerpc #define qobject_from_qlit qobject_from_qlit_powerpc +#define qobject_get_try_str qobject_get_try_str_powerpc #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_powerpc #define qobject_input_end_list qobject_input_end_list_powerpc #define qobject_input_end_struct qobject_input_end_struct_powerpc diff --git a/qemu/qobject/qstring.c b/qemu/qobject/qstring.c index ab5346a5..b4bee272 100644 --- a/qemu/qobject/qstring.c +++ b/qemu/qobject/qstring.c @@ -134,6 +134,17 @@ bool qstring_is_equal(const QObject *x, const QObject *y) qobject_to(QString, y)->string); } +/** + * qobject_get_try_str(): Return a pointer to the corresponding string + * + * NOTE: the string will only be returned if the object is valid, and + * its type is QString, otherwise NULL is returned. + */ +const char *qobject_get_try_str(const QObject *qstring) +{ + return qstring_get_try_str(qobject_to(QString, qstring)); +} + /** * qstring_destroy_obj(): Free all memory allocated by a QString * object diff --git a/qemu/sparc.h b/qemu/sparc.h index 493694cd..7f3d0ca4 100644 --- a/qemu/sparc.h +++ b/qemu/sparc.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_sparc #define qlit_equal_qobject qlit_equal_qobject_sparc #define qobject_from_qlit qobject_from_qlit_sparc +#define qobject_get_try_str qobject_get_try_str_sparc #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_sparc #define qobject_input_end_list qobject_input_end_list_sparc #define qobject_input_end_struct qobject_input_end_struct_sparc diff --git a/qemu/sparc64.h b/qemu/sparc64.h index 90eb9082..8667a157 100644 --- a/qemu/sparc64.h +++ b/qemu/sparc64.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_sparc64 #define qlit_equal_qobject qlit_equal_qobject_sparc64 #define qobject_from_qlit qobject_from_qlit_sparc64 +#define qobject_get_try_str qobject_get_try_str_sparc64 #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_sparc64 #define qobject_input_end_list qobject_input_end_list_sparc64 #define qobject_input_end_struct qobject_input_end_struct_sparc64 diff --git a/qemu/x86_64.h b/qemu/x86_64.h index e44305fe..8802fe8b 100644 --- a/qemu/x86_64.h +++ b/qemu/x86_64.h @@ -2204,6 +2204,7 @@ #define qlist_type qlist_type_x86_64 #define qlit_equal_qobject qlit_equal_qobject_x86_64 #define qobject_from_qlit qobject_from_qlit_x86_64 +#define qobject_get_try_str qobject_get_try_str_x86_64 #define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_x86_64 #define qobject_input_end_list qobject_input_end_list_x86_64 #define qobject_input_end_struct qobject_input_end_struct_x86_64