[libxml2] Fix unused function warning in testapi.c



commit e8fdf5df6e547b44092a549c01bb127aa75c01c7
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Tue Jan 1 19:20:22 2019 +0100

    Fix unused function warning in testapi.c
    
    Check whether all param and return types are known before generating
    functions for param types. Otherwise, unused functions end up in
    testapi.c.

 .travis.yml |   4 +-
 gentest.py  |  24 +++++---
 testapi.c   | 183 ++++++++++++++++++++++++------------------------------------
 3 files changed, 91 insertions(+), 120 deletions(-)
---
diff --git a/.travis.yml b/.travis.yml
index 469f9c50..5275c4f3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,13 +10,13 @@ matrix:
     # Try to emulate a C89 compiler on a POSIX system by disabling as many
     # GNU extensions as possible.
     - compiler: gcc
-      env: CFLAGS="-O2 -std=c89 -D_XOPEN_SOURCE=700 -Werror -Wno-error=unused-function"
+      env: CFLAGS="-O2 -std=c89 -D_XOPEN_SOURCE=700 -Werror"
     # clang with AddressSanitizer and UndefinedBehaviorSanitizer.
     - compiler: clang
       sudo: required
       dist: trusty
       env: CONFIG="--without-python"
-           CFLAGS="-O2 -g -fno-omit-frame-pointer -fsanitize=address,undefined 
-fno-sanitize=float-divide-by-zero,pointer-overflow -fno-sanitize-recover=all -Werror 
-Wno-error=unused-function -Wno-error=cast-align"
+           CFLAGS="-O2 -g -fno-omit-frame-pointer -fsanitize=address,undefined 
-fno-sanitize=float-divide-by-zero,pointer-overflow -fno-sanitize-recover=all -Werror -Wno-error=cast-align"
            UBSAN_OPTIONS=print_stacktrace=1
 script: sh autogen.sh $CONFIG && make -j2 V=1 && make check
 git:
diff --git a/gentest.py b/gentest.py
index e4a89325..b7633004 100755
--- a/gentest.py
+++ b/gentest.py
@@ -399,14 +399,20 @@ def type_convert(str, name, info, module, function, pos):
 
 known_param_types = []
 
-def is_known_param_type(name, rtype):
-    global test
+def is_known_param_type(name):
     for type in known_param_types:
         if type == name:
            return 1
+    return name[-3:] == 'Ptr' or name[-4:] == '_ptr'
+
+def generate_param_type(name, rtype):
+    global test
+    for type in known_param_types:
+        if type == name:
+           return
     for type in generated_param_types:
         if type == name:
-           return 1
+           return
 
     if name[-3:] == 'Ptr' or name[-4:] == '_ptr':
         if rtype[0:6] == 'const ':
@@ -429,9 +435,6 @@ static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTR
         if define == 1:
            test.write("#endif\n\n")
         add_generated_param_type(name)
-        return 1
-
-    return 0
 
 #
 # Provide the type destructors for the return values
@@ -546,7 +549,7 @@ for enum in enums:
         continue;
     define = 0
 
-    if argtypes.has_key(name) and is_known_param_type(name, name) == 0:
+    if argtypes.has_key(name) and is_known_param_type(name) == 0:
        values = ctxt.xpathEval("/api/symbols/enum[@type='%s']" % name)
        i = 0
        vals = []
@@ -689,7 +692,7 @@ def generate_test(module, node):
        info = arg.xpathEval("string(@info)")
        nam = arg.xpathEval("string(@name)")
         type = type_convert(rtype, nam, info, module, name, n)
-       if is_known_param_type(type, rtype) == 0:
+       if is_known_param_type(type) == 0:
            add_missing_type(type, name);
            no_gen = 1
         if (type[-3:] == 'Ptr' or type[-4:] == '_ptr') and \
@@ -716,6 +719,11 @@ def generate_test(module, node):
        t_ret = (type, rtype, info)
        break
 
+    if no_gen == 0:
+        for t_arg in t_args:
+            (nam, type, rtype, crtype, info) = t_arg
+            generate_param_type(type, rtype)
+
     test.write("""
 static int
 test_%s(void) {
diff --git a/testapi.c b/testapi.c
index 4a751e20..980d7fb5 100644
--- a/testapi.c
+++ b/testapi.c
@@ -7511,13 +7511,6 @@ test_xmlLsOneNode(void) {
 }
 
 
-#define gen_nb_char_ptr 1
-static char * gen_char_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_char_ptr(int no ATTRIBUTE_UNUSED, char * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_xmlShell(void) {
     int test_ret = 0;
@@ -7528,6 +7521,13 @@ test_xmlShell(void) {
 }
 
 
+#define gen_nb_char_ptr 1
+static char * gen_char_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_char_ptr(int no ATTRIBUTE_UNUSED, char * val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+
 static int
 test_xmlShellBase(void) {
     int test_ret = 0;
@@ -9334,13 +9334,6 @@ test_xmlCleanupPredefinedEntities(void) {
 }
 
 
-#define gen_nb_xmlEntitiesTablePtr 1
-static xmlEntitiesTablePtr gen_xmlEntitiesTablePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlEntitiesTablePtr(int no ATTRIBUTE_UNUSED, xmlEntitiesTablePtr val ATTRIBUTE_UNUSED, int 
nr ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_xmlCopyEntitiesTable(void) {
     int test_ret = 0;
@@ -9361,6 +9354,13 @@ test_xmlCreateEntitiesTable(void) {
 }
 
 
+#define gen_nb_xmlEntitiesTablePtr 1
+static xmlEntitiesTablePtr gen_xmlEntitiesTablePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_xmlEntitiesTablePtr(int no ATTRIBUTE_UNUSED, xmlEntitiesTablePtr val ATTRIBUTE_UNUSED, int 
nr ATTRIBUTE_UNUSED) {
+}
+
 static int
 test_xmlDumpEntitiesTable(void) {
     int test_ret = 0;
@@ -18145,16 +18145,6 @@ test_xmlSchematronNewParserCtxt(void) {
     return(test_ret);
 }
 
-#ifdef LIBXML_SCHEMATRON_ENABLED
-
-#define gen_nb_xmlSchematronPtr 1
-static xmlSchematronPtr gen_xmlSchematronPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlSchematronPtr(int no ATTRIBUTE_UNUSED, xmlSchematronPtr val ATTRIBUTE_UNUSED, int nr 
ATTRIBUTE_UNUSED) {
-}
-#endif
-
 
 static int
 test_xmlSchematronNewValidCtxt(void) {
@@ -18165,19 +18155,19 @@ test_xmlSchematronNewValidCtxt(void) {
     return(test_ret);
 }
 
-#ifdef LIBXML_SCHEMATRON_ENABLED
 
-#define gen_nb_xmlSchematronParserCtxtPtr 1
-static xmlSchematronParserCtxtPtr gen_xmlSchematronParserCtxtPtr(int no ATTRIBUTE_UNUSED, int nr 
ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlSchematronParserCtxtPtr(int no ATTRIBUTE_UNUSED, xmlSchematronParserCtxtPtr val 
ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+static int
+test_xmlSchematronParse(void) {
+    int test_ret = 0;
+
+
+    /* missing type support */
+    return(test_ret);
 }
-#endif
 
 
 static int
-test_xmlSchematronParse(void) {
+test_xmlSchematronSetValidStructuredErrors(void) {
     int test_ret = 0;
 
 
@@ -18196,16 +18186,6 @@ static void des_xmlSchematronValidCtxtPtr(int no ATTRIBUTE_UNUSED, xmlSchematron
 #endif
 
 
-static int
-test_xmlSchematronSetValidStructuredErrors(void) {
-    int test_ret = 0;
-
-
-    /* missing type support */
-    return(test_ret);
-}
-
-
 static int
 test_xmlSchematronValidateDoc(void) {
     int test_ret = 0;
@@ -18665,13 +18645,6 @@ test_xmlBufShrink(void) {
 }
 
 
-#define gen_nb_const_xmlBufPtr 1
-static xmlBufPtr gen_const_xmlBufPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_const_xmlBufPtr(int no ATTRIBUTE_UNUSED, const xmlBufPtr val ATTRIBUTE_UNUSED, int nr 
ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_xmlBufUse(void) {
     int test_ret = 0;
@@ -25100,13 +25073,6 @@ test_xmlAddRef(void) {
 }
 
 
-#define gen_nb_xmlAttributeTablePtr 1
-static xmlAttributeTablePtr gen_xmlAttributeTablePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlAttributeTablePtr(int no ATTRIBUTE_UNUSED, xmlAttributeTablePtr val ATTRIBUTE_UNUSED, int 
nr ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_xmlCopyAttributeTable(void) {
     int test_ret = 0;
@@ -25188,13 +25154,6 @@ test_xmlCopyElementContent(void) {
 }
 
 
-#define gen_nb_xmlElementTablePtr 1
-static xmlElementTablePtr gen_xmlElementTablePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlElementTablePtr(int no ATTRIBUTE_UNUSED, xmlElementTablePtr val ATTRIBUTE_UNUSED, int nr 
ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_xmlCopyElementTable(void) {
     int test_ret = 0;
@@ -25215,13 +25174,6 @@ test_xmlCopyEnumeration(void) {
 }
 
 
-#define gen_nb_xmlNotationTablePtr 1
-static xmlNotationTablePtr gen_xmlNotationTablePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlNotationTablePtr(int no ATTRIBUTE_UNUSED, xmlNotationTablePtr val ATTRIBUTE_UNUSED, int 
nr ATTRIBUTE_UNUSED) {
-}
-
 static int
 test_xmlCopyNotationTable(void) {
     int test_ret = 0;
@@ -25288,6 +25240,13 @@ test_xmlDumpAttributeDecl(void) {
 }
 
 
+#define gen_nb_xmlAttributeTablePtr 1
+static xmlAttributeTablePtr gen_xmlAttributeTablePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_xmlAttributeTablePtr(int no ATTRIBUTE_UNUSED, xmlAttributeTablePtr val ATTRIBUTE_UNUSED, int 
nr ATTRIBUTE_UNUSED) {
+}
+
 static int
 test_xmlDumpAttributeTable(void) {
     int test_ret = 0;
@@ -25373,6 +25332,13 @@ test_xmlDumpElementDecl(void) {
 }
 
 
+#define gen_nb_xmlElementTablePtr 1
+static xmlElementTablePtr gen_xmlElementTablePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_xmlElementTablePtr(int no ATTRIBUTE_UNUSED, xmlElementTablePtr val ATTRIBUTE_UNUSED, int nr 
ATTRIBUTE_UNUSED) {
+}
+
 static int
 test_xmlDumpElementTable(void) {
     int test_ret = 0;
@@ -25458,6 +25424,13 @@ test_xmlDumpNotationDecl(void) {
 }
 
 
+#define gen_nb_xmlNotationTablePtr 1
+static xmlNotationTablePtr gen_xmlNotationTablePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_xmlNotationTablePtr(int no ATTRIBUTE_UNUSED, xmlNotationTablePtr val ATTRIBUTE_UNUSED, int 
nr ATTRIBUTE_UNUSED) {
+}
+
 static int
 test_xmlDumpNotationTable(void) {
     int test_ret = 0;
@@ -29389,16 +29362,6 @@ test_xmlIO(void) {
        printf("Module xmlIO: %d errors\n", test_ret);
     return(test_ret);
 }
-#ifdef LIBXML_AUTOMATA_ENABLED
-
-#define gen_nb_xmlAutomataPtr 1
-static xmlAutomataPtr gen_xmlAutomataPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlAutomataPtr(int no ATTRIBUTE_UNUSED, xmlAutomataPtr val ATTRIBUTE_UNUSED, int nr 
ATTRIBUTE_UNUSED) {
-}
-#endif
-
 
 static int
 test_xmlAutomataCompile(void) {
@@ -29419,6 +29382,16 @@ test_xmlAutomataGetInitState(void) {
     return(test_ret);
 }
 
+#ifdef LIBXML_AUTOMATA_ENABLED
+
+#define gen_nb_xmlAutomataPtr 1
+static xmlAutomataPtr gen_xmlAutomataPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_xmlAutomataPtr(int no ATTRIBUTE_UNUSED, xmlAutomataPtr val ATTRIBUTE_UNUSED, int nr 
ATTRIBUTE_UNUSED) {
+}
+#endif
+
 
 static int
 test_xmlAutomataIsDeterminist(void) {
@@ -29453,16 +29426,6 @@ test_xmlAutomataIsDeterminist(void) {
     return(test_ret);
 }
 
-#ifdef LIBXML_AUTOMATA_ENABLED
-
-#define gen_nb_xmlAutomataStatePtr 1
-static xmlAutomataStatePtr gen_xmlAutomataStatePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlAutomataStatePtr(int no ATTRIBUTE_UNUSED, xmlAutomataStatePtr val ATTRIBUTE_UNUSED, int 
nr ATTRIBUTE_UNUSED) {
-}
-#endif
-
 
 static int
 test_xmlAutomataNewAllTrans(void) {
@@ -29631,6 +29594,16 @@ test_xmlAutomataNewTransition2(void) {
     return(test_ret);
 }
 
+#ifdef LIBXML_AUTOMATA_ENABLED
+
+#define gen_nb_xmlAutomataStatePtr 1
+static xmlAutomataStatePtr gen_xmlAutomataStatePtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_xmlAutomataStatePtr(int no ATTRIBUTE_UNUSED, xmlAutomataStatePtr val ATTRIBUTE_UNUSED, int 
nr ATTRIBUTE_UNUSED) {
+}
+#endif
+
 
 static int
 test_xmlAutomataSetFinalState(void) {
@@ -33908,16 +33881,6 @@ test_xmlRegExecPushString2(void) {
     return(test_ret);
 }
 
-#ifdef LIBXML_REGEXP_ENABLED
-
-#define gen_nb_xmlRegexpPtr 1
-static xmlRegexpPtr gen_xmlRegexpPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlRegexpPtr(int no ATTRIBUTE_UNUSED, xmlRegexpPtr val ATTRIBUTE_UNUSED, int nr 
ATTRIBUTE_UNUSED) {
-}
-#endif
-
 
 static int
 test_xmlRegNewExecCtxt(void) {
@@ -33938,6 +33901,16 @@ test_xmlRegexpCompile(void) {
     return(test_ret);
 }
 
+#ifdef LIBXML_REGEXP_ENABLED
+
+#define gen_nb_xmlRegexpPtr 1
+static xmlRegexpPtr gen_xmlRegexpPtr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+    return(NULL);
+}
+static void des_xmlRegexpPtr(int no ATTRIBUTE_UNUSED, xmlRegexpPtr val ATTRIBUTE_UNUSED, int nr 
ATTRIBUTE_UNUSED) {
+}
+#endif
+
 
 static int
 test_xmlRegexpExec(void) {
@@ -34662,16 +34635,6 @@ test_xmlSchemaParse(void) {
     return(test_ret);
 }
 
-#ifdef LIBXML_SCHEMAS_ENABLED
-
-#define gen_nb_xmlSAXHandlerPtr_ptr 1
-static xmlSAXHandlerPtr * gen_xmlSAXHandlerPtr_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-    return(NULL);
-}
-static void des_xmlSAXHandlerPtr_ptr(int no ATTRIBUTE_UNUSED, xmlSAXHandlerPtr * val ATTRIBUTE_UNUSED, int 
nr ATTRIBUTE_UNUSED) {
-}
-#endif
-
 
 static int
 test_xmlSchemaSAXPlug(void) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]