1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

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.
This commit is contained in:
Nick Wellnhofer
2019-01-01 19:20:22 +01:00
parent 731b506409
commit e8fdf5df6e
3 changed files with 93 additions and 122 deletions

View File

@@ -10,13 +10,13 @@ matrix:
# Try to emulate a C89 compiler on a POSIX system by disabling as many # Try to emulate a C89 compiler on a POSIX system by disabling as many
# GNU extensions as possible. # GNU extensions as possible.
- compiler: gcc - 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. # clang with AddressSanitizer and UndefinedBehaviorSanitizer.
- compiler: clang - compiler: clang
sudo: required sudo: required
dist: trusty dist: trusty
env: CONFIG="--without-python" 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 UBSAN_OPTIONS=print_stacktrace=1
script: sh autogen.sh $CONFIG && make -j2 V=1 && make check script: sh autogen.sh $CONFIG && make -j2 V=1 && make check
git: git:

View File

@@ -399,14 +399,20 @@ def type_convert(str, name, info, module, function, pos):
known_param_types = [] known_param_types = []
def is_known_param_type(name, rtype): def is_known_param_type(name):
global test
for type in known_param_types: for type in known_param_types:
if type == name: if type == name:
return 1 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: for type in generated_param_types:
if type == name: if type == name:
return 1 return
if name[-3:] == 'Ptr' or name[-4:] == '_ptr': if name[-3:] == 'Ptr' or name[-4:] == '_ptr':
if rtype[0:6] == 'const ': 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: if define == 1:
test.write("#endif\n\n") test.write("#endif\n\n")
add_generated_param_type(name) add_generated_param_type(name)
return 1
return 0
# #
# Provide the type destructors for the return values # Provide the type destructors for the return values
@@ -546,7 +549,7 @@ for enum in enums:
continue; continue;
define = 0 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) values = ctxt.xpathEval("/api/symbols/enum[@type='%s']" % name)
i = 0 i = 0
vals = [] vals = []
@@ -689,7 +692,7 @@ def generate_test(module, node):
info = arg.xpathEval("string(@info)") info = arg.xpathEval("string(@info)")
nam = arg.xpathEval("string(@name)") nam = arg.xpathEval("string(@name)")
type = type_convert(rtype, nam, info, module, name, n) 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); add_missing_type(type, name);
no_gen = 1 no_gen = 1
if (type[-3:] == 'Ptr' or type[-4:] == '_ptr') and \ if (type[-3:] == 'Ptr' or type[-4:] == '_ptr') and \
@@ -716,6 +719,11 @@ def generate_test(module, node):
t_ret = (type, rtype, info) t_ret = (type, rtype, info)
break 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(""" test.write("""
static int static int
test_%s(void) { test_%s(void) {

187
testapi.c
View File

@@ -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 static int
test_xmlShell(void) { test_xmlShell(void) {
int test_ret = 0; 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 static int
test_xmlShellBase(void) { test_xmlShellBase(void) {
int test_ret = 0; 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 static int
test_xmlCopyEntitiesTable(void) { test_xmlCopyEntitiesTable(void) {
int test_ret = 0; 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 static int
test_xmlDumpEntitiesTable(void) { test_xmlDumpEntitiesTable(void) {
int test_ret = 0; int test_ret = 0;
@@ -18145,16 +18145,6 @@ test_xmlSchematronNewParserCtxt(void) {
return(test_ret); 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 static int
test_xmlSchematronNewValidCtxt(void) { test_xmlSchematronNewValidCtxt(void) {
@@ -18165,16 +18155,6 @@ test_xmlSchematronNewValidCtxt(void) {
return(test_ret); 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) {
}
#endif
static int static int
test_xmlSchematronParse(void) { test_xmlSchematronParse(void) {
@@ -18185,6 +18165,16 @@ test_xmlSchematronParse(void) {
return(test_ret); return(test_ret);
} }
static int
test_xmlSchematronSetValidStructuredErrors(void) {
int test_ret = 0;
/* missing type support */
return(test_ret);
}
#ifdef LIBXML_SCHEMATRON_ENABLED #ifdef LIBXML_SCHEMATRON_ENABLED
#define gen_nb_xmlSchematronValidCtxtPtr 1 #define gen_nb_xmlSchematronValidCtxtPtr 1
@@ -18196,16 +18186,6 @@ static void des_xmlSchematronValidCtxtPtr(int no ATTRIBUTE_UNUSED, xmlSchematron
#endif #endif
static int
test_xmlSchematronSetValidStructuredErrors(void) {
int test_ret = 0;
/* missing type support */
return(test_ret);
}
static int static int
test_xmlSchematronValidateDoc(void) { test_xmlSchematronValidateDoc(void) {
int test_ret = 0; 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 static int
test_xmlBufUse(void) { test_xmlBufUse(void) {
int test_ret = 0; 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 static int
test_xmlCopyAttributeTable(void) { test_xmlCopyAttributeTable(void) {
int test_ret = 0; 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 static int
test_xmlCopyElementTable(void) { test_xmlCopyElementTable(void) {
int test_ret = 0; 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 static int
test_xmlCopyNotationTable(void) { test_xmlCopyNotationTable(void) {
int test_ret = 0; 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 static int
test_xmlDumpAttributeTable(void) { test_xmlDumpAttributeTable(void) {
int test_ret = 0; 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 static int
test_xmlDumpElementTable(void) { test_xmlDumpElementTable(void) {
int test_ret = 0; 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 static int
test_xmlDumpNotationTable(void) { test_xmlDumpNotationTable(void) {
int test_ret = 0; int test_ret = 0;
@@ -29389,16 +29362,6 @@ test_xmlIO(void) {
printf("Module xmlIO: %d errors\n", test_ret); printf("Module xmlIO: %d errors\n", test_ret);
return(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 static int
test_xmlAutomataCompile(void) { test_xmlAutomataCompile(void) {
@@ -29419,6 +29382,16 @@ test_xmlAutomataGetInitState(void) {
return(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 static int
test_xmlAutomataIsDeterminist(void) { test_xmlAutomataIsDeterminist(void) {
@@ -29453,16 +29426,6 @@ test_xmlAutomataIsDeterminist(void) {
return(test_ret); 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 static int
test_xmlAutomataNewAllTrans(void) { test_xmlAutomataNewAllTrans(void) {
@@ -29631,6 +29594,16 @@ test_xmlAutomataNewTransition2(void) {
return(test_ret); 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 static int
test_xmlAutomataSetFinalState(void) { test_xmlAutomataSetFinalState(void) {
@@ -33908,16 +33881,6 @@ test_xmlRegExecPushString2(void) {
return(test_ret); 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 static int
test_xmlRegNewExecCtxt(void) { test_xmlRegNewExecCtxt(void) {
@@ -33938,6 +33901,16 @@ test_xmlRegexpCompile(void) {
return(test_ret); 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 static int
test_xmlRegexpExec(void) { test_xmlRegexpExec(void) {
@@ -34662,16 +34635,6 @@ test_xmlSchemaParse(void) {
return(test_ret); 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 static int
test_xmlSchemaSAXPlug(void) { test_xmlSchemaSAXPlug(void) {