diff mbox

[11/14] qerror: drop qerror_table[] for good

Message ID 1343249431-9245-12-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino July 25, 2012, 8:50 p.m. UTC
Last commit deprecated it. Also drops the code that used it to generate
error objects.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qerror.c               | 95 --------------------------------------------------
 qerror.h               |  6 ----
 scripts/qapi-errors.py | 26 --------------
 3 files changed, 127 deletions(-)

Comments

Markus Armbruster July 26, 2012, 12:54 p.m. UTC | #1
Luiz Capitulino <lcapitulino@redhat.com> writes:

> Last commit deprecated it.

Do you mean "Unused since last commit"?

>                            Also drops the code that used it to generate
> error objects.
diff mbox

Patch

diff --git a/qerror.c b/qerror.c
index 6d61426..1118e2b 100644
--- a/qerror.c
+++ b/qerror.c
@@ -144,101 +144,6 @@  static QError *qerror_from_info(int err_class, const char *fmt, va_list *va)
     return qerr;
 }
 
-static void parse_error(const QErrorStringTable *entry, int c)
-{
-    fprintf(stderr, "expected '%c' in '%s'", c, entry->desc);
-    abort();
-}
-
-static const char *append_field(QDict *error, QString *outstr,
-                                const QErrorStringTable *entry,
-                                const char *start)
-{
-    QObject *obj;
-    QDict *qdict;
-    QString *key_qs;
-    const char *end, *key;
-
-    if (*start != '%')
-        parse_error(entry, '%');
-    start++;
-    if (*start != '(')
-        parse_error(entry, '(');
-    start++;
-
-    end = strchr(start, ')');
-    if (!end)
-        parse_error(entry, ')');
-
-    key_qs = qstring_from_substr(start, 0, end - start - 1);
-    key = qstring_get_str(key_qs);
-
-    qdict = qobject_to_qdict(qdict_get(error, "data"));
-    obj = qdict_get(qdict, key);
-    if (!obj) {
-        abort();
-    }
-
-    switch (qobject_type(obj)) {
-        case QTYPE_QSTRING:
-            qstring_append(outstr, qdict_get_str(qdict, key));
-            break;
-        case QTYPE_QINT:
-            qstring_append_int(outstr, qdict_get_int(qdict, key));
-            break;
-        default:
-            abort();
-    }
-
-    QDECREF(key_qs);
-    return ++end;
-}
-
-static QString *qerror_format_desc(QDict *error,
-                                   const QErrorStringTable *entry)
-{
-    QString *qstring;
-    const char *p;
-
-    assert(entry != NULL);
-
-    qstring = qstring_new();
-
-    for (p = entry->desc; *p != '\0';) {
-        if (*p != '%') {
-            qstring_append_chr(qstring, *p++);
-        } else if (*(p + 1) == '%') {
-            qstring_append_chr(qstring, '%');
-            p += 2;
-        } else {
-            p = append_field(error, qstring, entry, p);
-        }
-    }
-
-    return qstring;
-}
-
-char *qerror_format(const char *fmt, QDict *error)
-{
-    const QErrorStringTable *entry = NULL;
-    QString *qstr;
-    char *ret;
-    int i;
-
-    for (i = 0; qerror_table[i].error_fmt; i++) {
-        if (strcmp(qerror_table[i].error_fmt, fmt) == 0) {
-            entry = &qerror_table[i];
-            break;
-        }
-    }
-
-    qstr = qerror_format_desc(error, entry);
-    ret = g_strdup(qstring_get_str(qstr));
-    QDECREF(qstr);
-
-    return ret;
-}
-
 /**
  * qerror_human(): Format QError data into human-readable string.
  */
diff --git a/qerror.h b/qerror.h
index 32e9a22..10d83d8 100644
--- a/qerror.h
+++ b/qerror.h
@@ -19,11 +19,6 @@ 
 #include "error.h"
 #include <stdarg.h>
 
-typedef struct QErrorStringTable {
-    const char *desc;
-    const char *error_fmt;
-} QErrorStringTable;
-
 typedef struct QError {
     QObject_HEAD;
     QDict *error;
@@ -35,7 +30,6 @@  QString *qerror_human(const QError *qerror);
 void qerror_report(int err_class, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 void qerror_report_err(Error *err);
 void assert_no_error(Error *err);
-char *qerror_format(const char *fmt, QDict *error);
 QDict *build_error_dict(int err_class, const char *msg);
 
 #endif /* QERROR_H */
diff --git a/scripts/qapi-errors.py b/scripts/qapi-errors.py
index 5f8723e..dc656f2 100644
--- a/scripts/qapi-errors.py
+++ b/scripts/qapi-errors.py
@@ -62,29 +62,6 @@  def gen_error_macro(err_domain):
     string += cur
     return 'QERR_' + string.upper()
 
-def gen_error_def_table(exprs):
-    ret = mcgen('''
-static const QErrorStringTable qerror_table[] = {
-''')
-
-    for err in exprs:
-        macro = gen_error_macro(err['error'])
-        desc = err['description']
-        ret += mcgen('''
-        {
-            .error_fmt = %(error_macro)s,
-            .desc      = "%(error_desc)s",
-        },
-''',    
-                    error_macro=macro, error_desc=desc)
-
-    ret += mcgen('''
-    {}
-};
-''')
-
-    return ret
-
 def gen_error_data_obj(data):
     colon = ''
     data_str = ''
@@ -206,9 +183,6 @@  if __name__ == '__main__':
     ret = gen_error_def_prologue(error_header=h_file, prefix=prefix)
     fdef.write(ret)
 
-    ret = gen_error_def_table(exprs)
-    fdef.write(ret)
-
     ret = gen_error_obj_table(exprs)
     fdef.write(ret)