From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, aliguori@us.ibm.com, armbru@redhat.com,
afaerber@suse.de, peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH 12/14] error: turn QERR_ macros into an enumeration
Date: Wed, 25 Jul 2012 17:50:29 -0300 [thread overview]
Message-ID: <1343249431-9245-13-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1343249431-9245-1-git-send-email-lcapitulino@redhat.com>
The enum is called ErrClass, and is autogenerated.
FIXME: also converts error_is_type() and probably breaks other error
functions used to query the error object.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
error.c | 24 ++----------------------
error.h | 3 ++-
scripts/qapi-errors.py | 47 ++++++++++++++++++-----------------------------
3 files changed, 22 insertions(+), 52 deletions(-)
diff --git a/error.c b/error.c
index a410cc2..529e75f 100644
--- a/error.c
+++ b/error.c
@@ -102,29 +102,9 @@ void error_free(Error *err)
}
}
-bool error_is_type(Error *err, const char *fmt)
+bool error_is_type(Error *err, ErrClass err_class)
{
- const char *error_class;
- char *ptr;
- char *end;
-
- if (!err) {
- return false;
- }
-
- ptr = strstr(fmt, "'class': '");
- assert(ptr != NULL);
- ptr += strlen("'class': '");
-
- end = strchr(ptr, '\'');
- assert(end != NULL);
-
- error_class = error_get_field(err, "class");
- if (strlen(error_class) != end - ptr) {
- return false;
- }
-
- return strncmp(ptr, error_class, end - ptr) == 0;
+ return (err && (err->err_class == err_class));
}
void error_propagate(Error **dst_err, Error *local_err)
diff --git a/error.h b/error.h
index de98e48..19116ef 100644
--- a/error.h
+++ b/error.h
@@ -13,6 +13,7 @@
#define ERROR_H
#include "compiler.h"
+#include "qapi-errors.h"
#include <stdbool.h>
/**
@@ -70,6 +71,6 @@ void error_free(Error *err);
* Determine if an error is of a speific type (based on the qerror format).
* Non-QEMU users should get the `class' field to identify the error type.
*/
-bool error_is_type(Error *err, const char *fmt);
+bool error_is_type(Error *err, ErrClass err_class);
#endif
diff --git a/scripts/qapi-errors.py b/scripts/qapi-errors.py
index dc656f2..0f52f43 100644
--- a/scripts/qapi-errors.py
+++ b/scripts/qapi-errors.py
@@ -51,7 +51,7 @@ def gen_error_def_prologue(error_header, prefix=""):
prefix=prefix, error_header=error_header)
return ret
-def gen_error_macro(err_domain):
+def gen_error_enum_name(err_domain):
string = ''
cur = err_domain[0]
for nxt in err_domain[1:]:
@@ -82,13 +82,15 @@ static const char *error_object_table[] = {
''')
for err in exprs:
+ enum = gen_error_enum_name(err['error'])
data = gen_error_data_obj({})
if err.has_key('data'):
data = gen_error_data_obj(err['data'])
ret += mcgen('''
- "{ 'class': '%(error_class)s', 'data': { %(error_data)s } }",
+ [%(error_enum)s] =
+ "{ 'class': '%(error_class)s', 'data': { %(error_data)s } }",
''',
- error_class=err['error'], error_data=data)
+ error_enum=enum, error_class=err['error'], error_data=data)
ret += mcgen('''
NULL,
@@ -98,35 +100,22 @@ static const char *error_object_table[] = {
return ret;
-def gen_error_macro_data_str(data):
- colon = ''
- data_str = ''
- for k, v in data.items():
- data_str += colon + "'%s': " % k
- if v == 'str':
- data_str += "%s"
- elif v == 'int':
- data_str += '%"PRId64"'
- else:
- sys.exit("unknown data type '%s' for error '%s'" % (v, name))
- colon = ', '
- return data_str
+def gen_error_enum(exprs):
+ ret = mcgen('''
+typedef enum ErrClass {
+''')
-def gen_error_decl_macros(exprs):
- ret = ''
for err in exprs:
- data = gen_error_macro_data_str({})
- if err.has_key('data'):
- data = gen_error_macro_data_str(err['data'])
- macro = gen_error_macro(err['error'])
- name = err['error']
-
ret += mcgen('''
-#define %(error_macro)s \\
- "{ 'class': '%(error_class)s', 'data': { %(error_data)s } }"
-
+ %(enum)s,
''',
- error_macro=macro, error_class=name, error_data=data)
+ enum=gen_error_enum_name(err['error']))
+
+ ret += mcgen('''
+} ErrClass;
+
+''')
+
return ret
def maybe_open(really, name, opt):
@@ -172,7 +161,7 @@ if __name__ == '__main__':
ret = gen_error_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix)
fdecl.write(ret)
- ret = gen_error_decl_macros(exprs)
+ ret = gen_error_enum(exprs)
fdecl.write(ret)
fdecl.write("#endif\n")
--
1.7.11.2.249.g31c7954.dirty
next prev parent reply other threads:[~2012-07-25 20:50 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 01/14] monitor: drop unused monitor debug code Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 02/14] qerror: reduce public exposure Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort() Luiz Capitulino
2012-07-26 12:33 ` Markus Armbruster
2012-07-26 15:02 ` Luiz Capitulino
2012-07-26 12:59 ` Eric Blake
2012-07-25 20:50 ` [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal() Luiz Capitulino
2012-07-26 12:35 ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 05/14] qerror: qerror_format(): return an allocated string Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 06/14] qerror: don't delay error message construction Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 07/14] error: " Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[] Luiz Capitulino
2012-07-26 12:52 ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 09/14] qerror: qerror_report(): take an index and a human error message Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 10/14] error: error_set(): " Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good Luiz Capitulino
2012-07-26 12:54 ` Markus Armbruster
2012-07-25 20:50 ` Luiz Capitulino [this message]
2012-07-25 20:50 ` [Qemu-devel] [PATCH 13/14] qerror: change all qerror_report() calls to use the ErrClass enum Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 14/14] error: change all error_set() " Luiz Capitulino
2012-07-26 2:43 ` [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Anthony Liguori
2012-07-26 9:45 ` Kevin Wolf
2012-07-26 12:41 ` Anthony Liguori
2012-07-26 14:12 ` Luiz Capitulino
2012-07-26 15:05 ` Anthony Liguori
2012-07-26 15:52 ` Markus Armbruster
2012-07-26 14:40 ` Kevin Wolf
2012-07-26 15:20 ` Anthony Liguori
2012-07-26 16:12 ` Daniel P. Berrange
2012-07-26 16:38 ` Markus Armbruster
2012-07-26 15:54 ` Markus Armbruster
2012-07-26 16:03 ` Paolo Bonzini
2012-07-26 16:37 ` Luiz Capitulino
2012-07-27 13:17 ` Andreas Färber
2012-07-27 13:45 ` Anthony Liguori
2012-07-27 14:27 ` Luiz Capitulino
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=1343249431-9245-13-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).