Hash :
63f98ee8
Author :
Date :
2025-06-25T14:27:37
tests: Skip functions taking va_lists in testapi.c See !325.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
#!/usr/bin/env python3
#
# generate a test program for the API
#
import xml.etree.ElementTree as etree
import os
import re
import sys
import xmlmod
# Globals
dtors = {
'htmlDoc *': 'xmlFreeDoc',
'htmlParserCtxt *': 'htmlFreeParserCtxt',
'xmlAutomata *': 'xmlFreeAutomata',
'xmlBuffer *': 'xmlBufferFree',
'xmlCatalog *': 'xmlFreeCatalog',
'xmlChar *': 'xmlFree',
'xmlDOMWrapCtxt *': 'xmlDOMWrapFreeCtxt',
'xmlDict *': 'xmlDictFree',
'xmlDoc *': 'xmlFreeDoc',
'xmlDtd *': 'xmlFreeDtd',
'xmlEntitiesTable *': 'xmlFreeEntitiesTable',
'xmlElementContent *': 'xmlFreeElementContent',
'xmlEnumeration *': 'xmlFreeEnumeration',
'xmlList *': 'xmlListDelete',
'xmlModule *': 'xmlModuleFree',
'xmlMutex *': 'xmlFreeMutex',
'xmlNode *': 'xmlFreeNode',
'xmlNodeSet *': 'xmlXPathFreeNodeSet',
'xmlNs *': 'xmlFreeNs',
'xmlOutputBuffer *': 'xmlOutputBufferClose',
'xmlParserCtxt *': 'xmlFreeParserCtxt',
'xmlParserInputBuffer *': 'xmlFreeParserInputBuffer',
'xmlParserInput *': 'xmlFreeInputStream',
'xmlRMutex *': 'xmlFreeRMutex',
'xmlRelaxNGValidCtxt *': 'xmlRelaxNGFreeValidCtxt',
'xmlSaveCtxt *': 'xmlSaveClose',
'xmlSchemaFacet *': 'xmlSchemaFreeFacet',
'xmlSchemaVal *': 'xmlSchemaFreeValue',
'xmlSchemaValidCtxt *': 'xmlSchemaFreeValidCtxt',
'xmlTextWriter *': 'xmlFreeTextWriter',
'xmlURI *': 'xmlFreeURI',
'xmlValidCtxt *': 'xmlFreeValidCtxt',
'xmlXPathContext *': 'xmlXPathFreeContext',
'xmlXPathParserContext *': 'xmlXPathFreeParserContext',
'xmlXPathObject *': 'xmlXPathFreeObject',
}
blockList = {
# init/cleanup
'xmlCleanupParser': True,
'xmlInitParser': True,
# arg must be non-NULL
'xmlMemStrdupLoc': True,
'xmlMemoryStrdup': True,
# Returns void pointer which must be freed
'xmlMallocAtomicLoc': True,
'xmlMallocLoc': True,
'xmlMemMalloc': True,
'xmlMemRealloc': True,
'xmlReallocLoc': True,
# Would reset the error handler
'xmlSetStructuredErrorFunc': True,
# Prints errors
'xmlCatalogGetPublic': True,
'xmlCatalogGetSystem': True,
'xmlDebugDumpDTD': True,
'xmlDebugDumpDocument': True,
'xmlDebugDumpNode': True,
'xmlDebugDumpString': True,
'xmlParserError': True,
'xmlParserWarning': True,
'xmlParserValidityError': True,
'xmlParserValidityWarning': True,
# Internal parser unctions, ctxt must be non-NULL
'xmlParseAttribute': True,
'xmlParseAttributeListDecl': True,
'xmlParseAttributeType': True,
'xmlParseCDSect': True,
'xmlParseCharData': True,
'xmlParseCharRef': True,
'xmlParseComment': True,
'xmlParseDefaultDecl': True,
'xmlParseDocTypeDecl': True,
'xmlParseEndTag': True,
'xmlParseElement': True,
'xmlParseElementChildrenContentDecl': True,
'xmlParseElementContentDecl': True,
'xmlParseElementDecl': True,
'xmlParseElementMixedContentDecl': True,
'xmlParseEncName': True,
'xmlParseEncodingDecl': True,
'xmlParseEntityDecl': True,
'xmlParseEntityValue': True,
'xmlParseEnumeratedType': True,
'xmlParseEnumerationType': True,
'xmlParseExternalID': True,
'xmlParseExternalSubset': True,
'xmlParseMarkupDecl': True,
'xmlParseMisc': True,
'xmlParseName': True,
'xmlParseNmtoken': True,
'xmlParseNotationDecl': True,
'xmlParseNotationType': True,
'xmlParsePEReference': True,
'xmlParsePI': True,
'xmlParsePITarget': True,
'xmlParsePubidLiteral': True,
'xmlParseReference': True,
'xmlParseSDDecl': True,
'xmlParseStartTag': True,
'xmlParseSystemLiteral': True,
'xmlParseTextDecl': True,
'xmlParseVersionInfo': True,
'xmlParseVersionNum': True,
'xmlParseXMLDecl': True,
'xmlParserHandlePEReference': True,
'xmlSkipBlankChars': True,
# reads from stdin
'htmlReadFd': True,
'xmlReadFd': True,
'xmlReaderForFd': True,
}
# Parse document
if len(sys.argv) > 1:
buildDir = sys.argv[1]
else:
buildDir = '.'
xmlDocDir = buildDir + '/doc/xml'
filenames = {}
functions = {}
for file in os.listdir(xmlDocDir):
if not file.endswith('_8h.xml'):
continue
doc = etree.parse(xmlDocDir + '/' + file)
compound = doc.find('compounddef')
module = compound.find('compoundname').text
if not module.endswith('.h'):
continue
module = module[:-2]
for section in compound.findall('sectiondef'):
if section.get('kind') != 'func':
continue
for func in section.findall('memberdef'):
name = func.find('name').text
if name in blockList:
continue
module1, module2 = xmlmod.findModules(module, name)
cargs = []
skip = False
for arg in func.findall('param'):
atype = etree.tostring(arg.find('type'),
method='text', encoding='unicode').rstrip()
if atype == 'void':
continue
if atype == 'va_list':
skip = True
break
if re.search(r'(Ptr|\*)$', atype):
cargs.append('NULL')
else:
cargs.append('0')
if skip:
continue
mfunc = functions.get(module1)
if mfunc is None:
mfunc = {}
functions[module1] = mfunc
mmfunc = mfunc.get(module2)
if mmfunc is None:
mmfunc = {}
mfunc[module2] = mmfunc
code = f'{name}({', '.join(cargs)})'
rtype = etree.tostring(func.find('type'),
method='text', encoding='unicode').rstrip()
dtor = dtors.get(rtype)
if dtor is not None:
code = f'{dtor}({code})'
elif rtype == 'xmlHashTable *':
code = f'xmlHashFree({code}, NULL)'
mmfunc[name] = f' {code};\n'
# Write output
test = open('testapi.c', 'w')
test.write("""/*
* testapi.c: libxml2 API tester program.
*
* Automatically generated by gentest.py
*
* See Copyright for the status of this software.
*/
/* Disable deprecation warnings */
#define XML_DEPRECATED
#include "libxml.h"
#include <libxml/HTMLparser.h>
#include <libxml/HTMLtree.h>
#include <libxml/c14n.h>
#include <libxml/catalog.h>
#include <libxml/debugXML.h>
#include <libxml/parserInternals.h>
#include <libxml/pattern.h>
#include <libxml/relaxng.h>
#include <libxml/schematron.h>
#include <libxml/uri.h>
#include <libxml/xinclude.h>
#include <libxml/xlink.h>
#include <libxml/xmlmodule.h>
#include <libxml/xmlreader.h>
#include <libxml/xmlsave.h>
#include <libxml/xmlschemas.h>
#include <libxml/xmlschemastypes.h>
#include <libxml/xmlwriter.h>
#include <libxml/xpathInternals.h>
#include <libxml/xpointer.h>
static void
ignoreError(void *userData ATTRIBUTE_UNUSED,
const xmlError *error ATTRIBUTE_UNUSED) {
}
int
main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
xmlInitParser();
xmlSetStructuredErrorFunc(NULL, ignoreError);
""")
for module1 in sorted(functions.keys()):
mfunc = functions[module1]
if module1 != '':
test.write(f'#ifdef LIBXML_{module1}_ENABLED\n')
for module2 in sorted(mfunc.keys()):
mmfunc = mfunc[module2]
if module2 != '':
test.write(f'#ifdef LIBXML_{module2}_ENABLED\n')
for name in sorted(mmfunc.keys()):
test.write(mmfunc[name])
if module2 != '':
test.write(f'#endif /* LIBXML_{module2}_ENABLED */\n')
if module1 != '':
test.write(f'#endif /* LIBXML_{module1}_ENABLED */\n')
test.write('\n')
test.write(""" xmlCleanupParser();
return 0;
}
""")