Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1 | From 2c20198b1ddb1bfb47269b8caf929ffb83748f78 Mon Sep 17 00:00:00 2001 |
| 2 | From: Nick Wellnhofer <wellnhofer@aevum.de> |
| 3 | Date: Thu, 21 Apr 2022 00:45:58 +0200 |
| 4 | Subject: [PATCH] Port gentest.py to Python 3 |
| 5 | |
| 6 | Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/libxml2/-/commit/343fc1421cdae097fa6c4cffeb1a065a40be6bbb] |
| 7 | |
| 8 | * fixes: |
| 9 | |
| 10 | make[1]: 'testReader' is up to date. |
| 11 | File "../libxml2-2.9.10/gentest.py", line 11 |
| 12 | print "libxml2 python bindings not available, skipping testapi.c generation" |
| 13 | ^ |
| 14 | SyntaxError: Missing parentheses in call to 'print'. Did you mean print("libxml2 python bindings not available, skipping testapi.c generation")? |
| 15 | make[1]: [Makefile:2078: testapi.c] Error 1 (ignored) |
| 16 | |
| 17 | ... |
| 18 | |
| 19 | make[1]: 'testReader' is up to date. |
| 20 | File "../libxml2-2.9.10/gentest.py", line 271 |
| 21 | return 1 |
| 22 | ^ |
| 23 | TabError: inconsistent use of tabs and spaces in indentation |
| 24 | make[1]: [Makefile:2078: testapi.c] Error 1 (ignored) |
| 25 | |
| 26 | ... |
| 27 | |
| 28 | aarch64-oe-linux-gcc: error: testapi.c: No such file or directory |
| 29 | aarch64-oe-linux-gcc: fatal error: no input files |
| 30 | compilation terminated. |
| 31 | make[1]: *** [Makefile:1275: testapi.o] Error 1 |
| 32 | |
| 33 | But there is still a bit mystery why it worked before, because check-am |
| 34 | calls gentest.py with $(PYTHON), so it ignores the shebang in the script |
| 35 | and libxml2 is using python3native (through python3targetconfig.bbclass) |
| 36 | so something like: |
| 37 | |
| 38 | libxml2/2.9.10-r0/recipe-sysroot-native/usr/bin/python3-native/python3 gentest.py |
| 39 | |
| 40 | But that still fails (now without SyntaxError) with: |
| 41 | libxml2 python bindings not available, skipping testapi.c generation |
| 42 | |
| 43 | because we don't have dependency on libxml2-native (to provide libxml2 |
| 44 | python bindings form python3native) and exported PYTHON_SITE_PACKAGES |
| 45 | might be useless (e.g. /usr/lib/python3.8/site-packages on Ubuntu-22.10 |
| 46 | which uses python 3.10 and there is no site-packages with libxml2) |
| 47 | |
| 48 | Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> |
| 49 | |
| 50 | --- |
| 51 | gentest.py | 421 ++++++++++++++++++++++++++--------------------------- |
| 52 | 1 file changed, 209 insertions(+), 212 deletions(-) |
| 53 | |
| 54 | diff --git a/gentest.py b/gentest.py |
| 55 | index b6cd866..af15a4f 100755 |
| 56 | --- a/gentest.py |
| 57 | +++ b/gentest.py |
| 58 | @@ -8,7 +8,7 @@ import string |
| 59 | try: |
| 60 | import libxml2 |
| 61 | except: |
| 62 | - print "libxml2 python bindings not available, skipping testapi.c generation" |
| 63 | + print("libxml2 python bindings not available, skipping testapi.c generation") |
| 64 | sys.exit(0) |
| 65 | |
| 66 | if len(sys.argv) > 1: |
| 67 | @@ -227,7 +227,7 @@ extra_post_call = { |
| 68 | if (old != NULL) { |
| 69 | xmlUnlinkNode(old); |
| 70 | xmlFreeNode(old) ; old = NULL ; } |
| 71 | - ret_val = NULL;""", |
| 72 | +\t ret_val = NULL;""", |
| 73 | "xmlTextMerge": |
| 74 | """if ((first != NULL) && (first->type != XML_TEXT_NODE)) { |
| 75 | xmlUnlinkNode(second); |
| 76 | @@ -236,7 +236,7 @@ extra_post_call = { |
| 77 | """if ((ret_val != NULL) && (ret_val != ncname) && |
| 78 | (ret_val != prefix) && (ret_val != memory)) |
| 79 | xmlFree(ret_val); |
| 80 | - ret_val = NULL;""", |
| 81 | +\t ret_val = NULL;""", |
| 82 | "xmlNewDocElementContent": |
| 83 | """xmlFreeDocElementContent(doc, ret_val); ret_val = NULL;""", |
| 84 | "xmlDictReference": "xmlDictFree(dict);", |
| 85 | @@ -268,29 +268,29 @@ modules = [] |
| 86 | def is_skipped_module(name): |
| 87 | for mod in skipped_modules: |
| 88 | if mod == name: |
| 89 | - return 1 |
| 90 | + return 1 |
| 91 | return 0 |
| 92 | |
| 93 | def is_skipped_function(name): |
| 94 | for fun in skipped_functions: |
| 95 | if fun == name: |
| 96 | - return 1 |
| 97 | + return 1 |
| 98 | # Do not test destructors |
| 99 | - if string.find(name, 'Free') != -1: |
| 100 | + if name.find('Free') != -1: |
| 101 | return 1 |
| 102 | return 0 |
| 103 | |
| 104 | def is_skipped_memcheck(name): |
| 105 | for fun in skipped_memcheck: |
| 106 | if fun == name: |
| 107 | - return 1 |
| 108 | + return 1 |
| 109 | return 0 |
| 110 | |
| 111 | missing_types = {} |
| 112 | def add_missing_type(name, func): |
| 113 | try: |
| 114 | list = missing_types[name] |
| 115 | - list.append(func) |
| 116 | + list.append(func) |
| 117 | except: |
| 118 | missing_types[name] = [func] |
| 119 | |
| 120 | @@ -310,7 +310,7 @@ def add_missing_functions(name, module): |
| 121 | missing_functions_nr = missing_functions_nr + 1 |
| 122 | try: |
| 123 | list = missing_functions[module] |
| 124 | - list.append(name) |
| 125 | + list.append(name) |
| 126 | except: |
| 127 | missing_functions[module] = [name] |
| 128 | |
| 129 | @@ -319,45 +319,45 @@ def add_missing_functions(name, module): |
| 130 | # |
| 131 | |
| 132 | def type_convert(str, name, info, module, function, pos): |
| 133 | -# res = string.replace(str, " ", " ") |
| 134 | -# res = string.replace(str, " ", " ") |
| 135 | -# res = string.replace(str, " ", " ") |
| 136 | - res = string.replace(str, " *", "_ptr") |
| 137 | -# res = string.replace(str, "*", "_ptr") |
| 138 | - res = string.replace(res, " ", "_") |
| 139 | +# res = str.replace(" ", " ") |
| 140 | +# res = str.replace(" ", " ") |
| 141 | +# res = str.replace(" ", " ") |
| 142 | + res = str.replace(" *", "_ptr") |
| 143 | +# res = str.replace("*", "_ptr") |
| 144 | + res = res.replace(" ", "_") |
| 145 | if res == 'const_char_ptr': |
| 146 | - if string.find(name, "file") != -1 or \ |
| 147 | - string.find(name, "uri") != -1 or \ |
| 148 | - string.find(name, "URI") != -1 or \ |
| 149 | - string.find(info, "filename") != -1 or \ |
| 150 | - string.find(info, "URI") != -1 or \ |
| 151 | - string.find(info, "URL") != -1: |
| 152 | - if string.find(function, "Save") != -1 or \ |
| 153 | - string.find(function, "Create") != -1 or \ |
| 154 | - string.find(function, "Write") != -1 or \ |
| 155 | - string.find(function, "Fetch") != -1: |
| 156 | - return('fileoutput') |
| 157 | - return('filepath') |
| 158 | + if name.find("file") != -1 or \ |
| 159 | + name.find("uri") != -1 or \ |
| 160 | + name.find("URI") != -1 or \ |
| 161 | + info.find("filename") != -1 or \ |
| 162 | + info.find("URI") != -1 or \ |
| 163 | + info.find("URL") != -1: |
| 164 | + if function.find("Save") != -1 or \ |
| 165 | + function.find("Create") != -1 or \ |
| 166 | + function.find("Write") != -1 or \ |
| 167 | + function.find("Fetch") != -1: |
| 168 | + return('fileoutput') |
| 169 | + return('filepath') |
| 170 | if res == 'void_ptr': |
| 171 | if module == 'nanoftp' and name == 'ctx': |
| 172 | - return('xmlNanoFTPCtxtPtr') |
| 173 | + return('xmlNanoFTPCtxtPtr') |
| 174 | if function == 'xmlNanoFTPNewCtxt' or \ |
| 175 | - function == 'xmlNanoFTPConnectTo' or \ |
| 176 | - function == 'xmlNanoFTPOpen': |
| 177 | - return('xmlNanoFTPCtxtPtr') |
| 178 | + function == 'xmlNanoFTPConnectTo' or \ |
| 179 | + function == 'xmlNanoFTPOpen': |
| 180 | + return('xmlNanoFTPCtxtPtr') |
| 181 | if module == 'nanohttp' and name == 'ctx': |
| 182 | - return('xmlNanoHTTPCtxtPtr') |
| 183 | - if function == 'xmlNanoHTTPMethod' or \ |
| 184 | - function == 'xmlNanoHTTPMethodRedir' or \ |
| 185 | - function == 'xmlNanoHTTPOpen' or \ |
| 186 | - function == 'xmlNanoHTTPOpenRedir': |
| 187 | - return('xmlNanoHTTPCtxtPtr'); |
| 188 | + return('xmlNanoHTTPCtxtPtr') |
| 189 | + if function == 'xmlNanoHTTPMethod' or \ |
| 190 | + function == 'xmlNanoHTTPMethodRedir' or \ |
| 191 | + function == 'xmlNanoHTTPOpen' or \ |
| 192 | + function == 'xmlNanoHTTPOpenRedir': |
| 193 | + return('xmlNanoHTTPCtxtPtr'); |
| 194 | if function == 'xmlIOHTTPOpen': |
| 195 | - return('xmlNanoHTTPCtxtPtr') |
| 196 | - if string.find(name, "data") != -1: |
| 197 | - return('userdata') |
| 198 | - if string.find(name, "user") != -1: |
| 199 | - return('userdata') |
| 200 | + return('xmlNanoHTTPCtxtPtr') |
| 201 | + if name.find("data") != -1: |
| 202 | + return('userdata') |
| 203 | + if name.find("user") != -1: |
| 204 | + return('userdata') |
| 205 | if res == 'xmlDoc_ptr': |
| 206 | res = 'xmlDocPtr' |
| 207 | if res == 'xmlNode_ptr': |
| 208 | @@ -366,18 +366,18 @@ def type_convert(str, name, info, module, function, pos): |
| 209 | res = 'xmlDictPtr' |
| 210 | if res == 'xmlNodePtr' and pos != 0: |
| 211 | if (function == 'xmlAddChild' and pos == 2) or \ |
| 212 | - (function == 'xmlAddChildList' and pos == 2) or \ |
| 213 | + (function == 'xmlAddChildList' and pos == 2) or \ |
| 214 | (function == 'xmlAddNextSibling' and pos == 2) or \ |
| 215 | (function == 'xmlAddSibling' and pos == 2) or \ |
| 216 | (function == 'xmlDocSetRootElement' and pos == 2) or \ |
| 217 | (function == 'xmlReplaceNode' and pos == 2) or \ |
| 218 | (function == 'xmlTextMerge') or \ |
| 219 | - (function == 'xmlAddPrevSibling' and pos == 2): |
| 220 | - return('xmlNodePtr_in'); |
| 221 | + (function == 'xmlAddPrevSibling' and pos == 2): |
| 222 | + return('xmlNodePtr_in'); |
| 223 | if res == 'const xmlBufferPtr': |
| 224 | res = 'xmlBufferPtr' |
| 225 | if res == 'xmlChar_ptr' and name == 'name' and \ |
| 226 | - string.find(function, "EatName") != -1: |
| 227 | + function.find("EatName") != -1: |
| 228 | return('eaten_name') |
| 229 | if res == 'void_ptr*': |
| 230 | res = 'void_ptr_ptr' |
| 231 | @@ -393,7 +393,7 @@ def type_convert(str, name, info, module, function, pos): |
| 232 | res = 'debug_FILE_ptr'; |
| 233 | if res == 'int' and name == 'options': |
| 234 | if module == 'parser' or module == 'xmlreader': |
| 235 | - res = 'parseroptions' |
| 236 | + res = 'parseroptions' |
| 237 | |
| 238 | return res |
| 239 | |
| 240 | @@ -402,28 +402,28 @@ known_param_types = [] |
| 241 | def is_known_param_type(name): |
| 242 | for type in known_param_types: |
| 243 | if type == name: |
| 244 | - return 1 |
| 245 | + return 1 |
| 246 | return name[-3:] == 'Ptr' or name[-4:] == '_ptr' |
| 247 | |
| 248 | def generate_param_type(name, rtype): |
| 249 | global test |
| 250 | for type in known_param_types: |
| 251 | if type == name: |
| 252 | - return |
| 253 | + return |
| 254 | for type in generated_param_types: |
| 255 | if type == name: |
| 256 | - return |
| 257 | + return |
| 258 | |
| 259 | if name[-3:] == 'Ptr' or name[-4:] == '_ptr': |
| 260 | if rtype[0:6] == 'const ': |
| 261 | - crtype = rtype[6:] |
| 262 | - else: |
| 263 | - crtype = rtype |
| 264 | + crtype = rtype[6:] |
| 265 | + else: |
| 266 | + crtype = rtype |
| 267 | |
| 268 | define = 0 |
| 269 | - if modules_defines.has_key(module): |
| 270 | - test.write("#ifdef %s\n" % (modules_defines[module])) |
| 271 | - define = 1 |
| 272 | + if module in modules_defines: |
| 273 | + test.write("#ifdef %s\n" % (modules_defines[module])) |
| 274 | + define = 1 |
| 275 | test.write(""" |
| 276 | #define gen_nb_%s 1 |
| 277 | static %s gen_%s(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
| 278 | @@ -433,7 +433,7 @@ static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTR |
| 279 | } |
| 280 | """ % (name, crtype, name, name, rtype)) |
| 281 | if define == 1: |
| 282 | - test.write("#endif\n\n") |
| 283 | + test.write("#endif\n\n") |
| 284 | add_generated_param_type(name) |
| 285 | |
| 286 | # |
| 287 | @@ -445,7 +445,7 @@ known_return_types = [] |
| 288 | def is_known_return_type(name): |
| 289 | for type in known_return_types: |
| 290 | if type == name: |
| 291 | - return 1 |
| 292 | + return 1 |
| 293 | return 0 |
| 294 | |
| 295 | # |
| 296 | @@ -471,7 +471,7 @@ def compare_and_save(): |
| 297 | try: |
| 298 | os.system("rm testapi.c; mv testapi.c.new testapi.c") |
| 299 | except: |
| 300 | - os.system("mv testapi.c.new testapi.c") |
| 301 | + os.system("mv testapi.c.new testapi.c") |
| 302 | print("Updated testapi.c") |
| 303 | else: |
| 304 | print("Generated testapi.c is identical") |
| 305 | @@ -481,17 +481,17 @@ while line != "": |
| 306 | if line == "/* CUT HERE: everything below that line is generated */\n": |
| 307 | break; |
| 308 | if line[0:15] == "#define gen_nb_": |
| 309 | - type = string.split(line[15:])[0] |
| 310 | - known_param_types.append(type) |
| 311 | + type = line[15:].split()[0] |
| 312 | + known_param_types.append(type) |
| 313 | if line[0:19] == "static void desret_": |
| 314 | - type = string.split(line[19:], '(')[0] |
| 315 | - known_return_types.append(type) |
| 316 | + type = line[19:].split('(')[0] |
| 317 | + known_return_types.append(type) |
| 318 | test.write(line) |
| 319 | line = input.readline() |
| 320 | input.close() |
| 321 | |
| 322 | if line == "": |
| 323 | - print "Could not find the CUT marker in testapi.c skipping generation" |
| 324 | + print("Could not find the CUT marker in testapi.c skipping generation") |
| 325 | test.close() |
| 326 | sys.exit(0) |
| 327 | |
| 328 | @@ -505,7 +505,7 @@ test.write("/* CUT HERE: everything below that line is generated */\n") |
| 329 | # |
| 330 | doc = libxml2.readFile(srcPref + 'doc/libxml2-api.xml', None, 0) |
| 331 | if doc == None: |
| 332 | - print "Failed to load doc/libxml2-api.xml" |
| 333 | + print("Failed to load doc/libxml2-api.xml") |
| 334 | sys.exit(1) |
| 335 | ctxt = doc.xpathNewContext() |
| 336 | |
| 337 | @@ -519,9 +519,9 @@ for arg in args: |
| 338 | mod = arg.xpathEval('string(../@file)') |
| 339 | func = arg.xpathEval('string(../@name)') |
| 340 | if (mod not in skipped_modules) and (func not in skipped_functions): |
| 341 | - type = arg.xpathEval('string(@type)') |
| 342 | - if not argtypes.has_key(type): |
| 343 | - argtypes[type] = func |
| 344 | + type = arg.xpathEval('string(@type)') |
| 345 | + if type not in argtypes: |
| 346 | + argtypes[type] = func |
| 347 | |
| 348 | # similarly for return types |
| 349 | rettypes = {} |
| 350 | @@ -531,8 +531,8 @@ for ret in rets: |
| 351 | func = ret.xpathEval('string(../@name)') |
| 352 | if (mod not in skipped_modules) and (func not in skipped_functions): |
| 353 | type = ret.xpathEval('string(@type)') |
| 354 | - if not rettypes.has_key(type): |
| 355 | - rettypes[type] = func |
| 356 | + if type not in rettypes: |
| 357 | + rettypes[type] = func |
| 358 | |
| 359 | # |
| 360 | # Generate constructors and return type handling for all enums |
| 361 | @@ -549,49 +549,49 @@ for enum in enums: |
| 362 | continue; |
| 363 | define = 0 |
| 364 | |
| 365 | - if argtypes.has_key(name) and is_known_param_type(name) == 0: |
| 366 | - values = ctxt.xpathEval("/api/symbols/enum[@type='%s']" % name) |
| 367 | - i = 0 |
| 368 | - vals = [] |
| 369 | - for value in values: |
| 370 | - vname = value.xpathEval('string(@name)') |
| 371 | - if vname == None: |
| 372 | - continue; |
| 373 | - i = i + 1 |
| 374 | - if i >= 5: |
| 375 | - break; |
| 376 | - vals.append(vname) |
| 377 | - if vals == []: |
| 378 | - print "Didn't find any value for enum %s" % (name) |
| 379 | - continue |
| 380 | - if modules_defines.has_key(module): |
| 381 | - test.write("#ifdef %s\n" % (modules_defines[module])) |
| 382 | - define = 1 |
| 383 | - test.write("#define gen_nb_%s %d\n" % (name, len(vals))) |
| 384 | - test.write("""static %s gen_%s(int no, int nr ATTRIBUTE_UNUSED) {\n""" % |
| 385 | - (name, name)) |
| 386 | - i = 1 |
| 387 | - for value in vals: |
| 388 | - test.write(" if (no == %d) return(%s);\n" % (i, value)) |
| 389 | - i = i + 1 |
| 390 | - test.write(""" return(0); |
| 391 | + if (name in argtypes) and is_known_param_type(name) == 0: |
| 392 | + values = ctxt.xpathEval("/api/symbols/enum[@type='%s']" % name) |
| 393 | + i = 0 |
| 394 | + vals = [] |
| 395 | + for value in values: |
| 396 | + vname = value.xpathEval('string(@name)') |
| 397 | + if vname == None: |
| 398 | + continue; |
| 399 | + i = i + 1 |
| 400 | + if i >= 5: |
| 401 | + break; |
| 402 | + vals.append(vname) |
| 403 | + if vals == []: |
| 404 | + print("Didn't find any value for enum %s" % (name)) |
| 405 | + continue |
| 406 | + if module in modules_defines: |
| 407 | + test.write("#ifdef %s\n" % (modules_defines[module])) |
| 408 | + define = 1 |
| 409 | + test.write("#define gen_nb_%s %d\n" % (name, len(vals))) |
| 410 | + test.write("""static %s gen_%s(int no, int nr ATTRIBUTE_UNUSED) {\n""" % |
| 411 | + (name, name)) |
| 412 | + i = 1 |
| 413 | + for value in vals: |
| 414 | + test.write(" if (no == %d) return(%s);\n" % (i, value)) |
| 415 | + i = i + 1 |
| 416 | + test.write(""" return(0); |
| 417 | } |
| 418 | |
| 419 | static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
| 420 | } |
| 421 | |
| 422 | """ % (name, name)); |
| 423 | - known_param_types.append(name) |
| 424 | + known_param_types.append(name) |
| 425 | |
| 426 | if (is_known_return_type(name) == 0) and (name in rettypes): |
| 427 | - if define == 0 and modules_defines.has_key(module): |
| 428 | - test.write("#ifdef %s\n" % (modules_defines[module])) |
| 429 | - define = 1 |
| 430 | + if define == 0 and (module in modules_defines): |
| 431 | + test.write("#ifdef %s\n" % (modules_defines[module])) |
| 432 | + define = 1 |
| 433 | test.write("""static void desret_%s(%s val ATTRIBUTE_UNUSED) { |
| 434 | } |
| 435 | |
| 436 | """ % (name, name)) |
| 437 | - known_return_types.append(name) |
| 438 | + known_return_types.append(name) |
| 439 | if define == 1: |
| 440 | test.write("#endif\n\n") |
| 441 | |
| 442 | @@ -615,9 +615,9 @@ for file in headers: |
| 443 | # do not test deprecated APIs |
| 444 | # |
| 445 | desc = file.xpathEval('string(description)') |
| 446 | - if string.find(desc, 'DEPRECATED') != -1: |
| 447 | - print "Skipping deprecated interface %s" % name |
| 448 | - continue; |
| 449 | + if desc.find('DEPRECATED') != -1: |
| 450 | + print("Skipping deprecated interface %s" % name) |
| 451 | + continue; |
| 452 | |
| 453 | test.write("#include <libxml/%s.h>\n" % name) |
| 454 | modules.append(name) |
| 455 | @@ -679,7 +679,7 @@ def generate_test(module, node): |
| 456 | # and store the information for the generation |
| 457 | # |
| 458 | try: |
| 459 | - args = node.xpathEval("arg") |
| 460 | + args = node.xpathEval("arg") |
| 461 | except: |
| 462 | args = [] |
| 463 | t_args = [] |
| 464 | @@ -687,37 +687,37 @@ def generate_test(module, node): |
| 465 | for arg in args: |
| 466 | n = n + 1 |
| 467 | rtype = arg.xpathEval("string(@type)") |
| 468 | - if rtype == 'void': |
| 469 | - break; |
| 470 | - info = arg.xpathEval("string(@info)") |
| 471 | - nam = arg.xpathEval("string(@name)") |
| 472 | + if rtype == 'void': |
| 473 | + break; |
| 474 | + info = arg.xpathEval("string(@info)") |
| 475 | + nam = arg.xpathEval("string(@name)") |
| 476 | type = type_convert(rtype, nam, info, module, name, n) |
| 477 | - if is_known_param_type(type) == 0: |
| 478 | - add_missing_type(type, name); |
| 479 | - no_gen = 1 |
| 480 | + if is_known_param_type(type) == 0: |
| 481 | + add_missing_type(type, name); |
| 482 | + no_gen = 1 |
| 483 | if (type[-3:] == 'Ptr' or type[-4:] == '_ptr') and \ |
| 484 | - rtype[0:6] == 'const ': |
| 485 | - crtype = rtype[6:] |
| 486 | - else: |
| 487 | - crtype = rtype |
| 488 | - t_args.append((nam, type, rtype, crtype, info)) |
| 489 | + rtype[0:6] == 'const ': |
| 490 | + crtype = rtype[6:] |
| 491 | + else: |
| 492 | + crtype = rtype |
| 493 | + t_args.append((nam, type, rtype, crtype, info)) |
| 494 | |
| 495 | try: |
| 496 | - rets = node.xpathEval("return") |
| 497 | + rets = node.xpathEval("return") |
| 498 | except: |
| 499 | rets = [] |
| 500 | t_ret = None |
| 501 | for ret in rets: |
| 502 | rtype = ret.xpathEval("string(@type)") |
| 503 | - info = ret.xpathEval("string(@info)") |
| 504 | + info = ret.xpathEval("string(@info)") |
| 505 | type = type_convert(rtype, 'return', info, module, name, 0) |
| 506 | - if rtype == 'void': |
| 507 | - break |
| 508 | - if is_known_return_type(type) == 0: |
| 509 | - add_missing_type(type, name); |
| 510 | - no_gen = 1 |
| 511 | - t_ret = (type, rtype, info) |
| 512 | - break |
| 513 | + if rtype == 'void': |
| 514 | + break |
| 515 | + if is_known_return_type(type) == 0: |
| 516 | + add_missing_type(type, name); |
| 517 | + no_gen = 1 |
| 518 | + t_ret = (type, rtype, info) |
| 519 | + break |
| 520 | |
| 521 | if no_gen == 0: |
| 522 | for t_arg in t_args: |
| 523 | @@ -733,7 +733,7 @@ test_%s(void) { |
| 524 | |
| 525 | if no_gen == 1: |
| 526 | add_missing_functions(name, module) |
| 527 | - test.write(""" |
| 528 | + test.write(""" |
| 529 | /* missing type support */ |
| 530 | return(test_ret); |
| 531 | } |
| 532 | @@ -742,22 +742,22 @@ test_%s(void) { |
| 533 | return |
| 534 | |
| 535 | try: |
| 536 | - conds = node.xpathEval("cond") |
| 537 | - for cond in conds: |
| 538 | - test.write("#if %s\n" % (cond.get_content())) |
| 539 | - nb_cond = nb_cond + 1 |
| 540 | + conds = node.xpathEval("cond") |
| 541 | + for cond in conds: |
| 542 | + test.write("#if %s\n" % (cond.get_content())) |
| 543 | + nb_cond = nb_cond + 1 |
| 544 | except: |
| 545 | pass |
| 546 | |
| 547 | define = 0 |
| 548 | - if function_defines.has_key(name): |
| 549 | + if name in function_defines: |
| 550 | test.write("#ifdef %s\n" % (function_defines[name])) |
| 551 | - define = 1 |
| 552 | + define = 1 |
| 553 | |
| 554 | # Declare the memory usage counter |
| 555 | no_mem = is_skipped_memcheck(name) |
| 556 | if no_mem == 0: |
| 557 | - test.write(" int mem_base;\n"); |
| 558 | + test.write(" int mem_base;\n"); |
| 559 | |
| 560 | # Declare the return value |
| 561 | if t_ret != None: |
| 562 | @@ -766,29 +766,29 @@ test_%s(void) { |
| 563 | # Declare the arguments |
| 564 | for arg in t_args: |
| 565 | (nam, type, rtype, crtype, info) = arg; |
| 566 | - # add declaration |
| 567 | - test.write(" %s %s; /* %s */\n" % (crtype, nam, info)) |
| 568 | - test.write(" int n_%s;\n" % (nam)) |
| 569 | + # add declaration |
| 570 | + test.write(" %s %s; /* %s */\n" % (crtype, nam, info)) |
| 571 | + test.write(" int n_%s;\n" % (nam)) |
| 572 | test.write("\n") |
| 573 | |
| 574 | # Cascade loop on of each argument list of values |
| 575 | for arg in t_args: |
| 576 | (nam, type, rtype, crtype, info) = arg; |
| 577 | - # |
| 578 | - test.write(" for (n_%s = 0;n_%s < gen_nb_%s;n_%s++) {\n" % ( |
| 579 | - nam, nam, type, nam)) |
| 580 | + # |
| 581 | + test.write(" for (n_%s = 0;n_%s < gen_nb_%s;n_%s++) {\n" % ( |
| 582 | + nam, nam, type, nam)) |
| 583 | |
| 584 | # log the memory usage |
| 585 | if no_mem == 0: |
| 586 | - test.write(" mem_base = xmlMemBlocks();\n"); |
| 587 | + test.write(" mem_base = xmlMemBlocks();\n"); |
| 588 | |
| 589 | # prepare the call |
| 590 | i = 0; |
| 591 | for arg in t_args: |
| 592 | (nam, type, rtype, crtype, info) = arg; |
| 593 | - # |
| 594 | - test.write(" %s = gen_%s(n_%s, %d);\n" % (nam, type, nam, i)) |
| 595 | - i = i + 1; |
| 596 | + # |
| 597 | + test.write(" %s = gen_%s(n_%s, %d);\n" % (nam, type, nam, i)) |
| 598 | + i = i + 1; |
| 599 | |
| 600 | # add checks to avoid out-of-bounds array access |
| 601 | i = 0; |
| 602 | @@ -797,7 +797,7 @@ test_%s(void) { |
| 603 | # assume that "size", "len", and "start" parameters apply to either |
| 604 | # the nearest preceding or following char pointer |
| 605 | if type == "int" and (nam == "size" or nam == "len" or nam == "start"): |
| 606 | - for j in range(i - 1, -1, -1) + range(i + 1, len(t_args)): |
| 607 | + for j in (*range(i - 1, -1, -1), *range(i + 1, len(t_args))): |
| 608 | (bnam, btype) = t_args[j][:2] |
| 609 | if btype == "const_char_ptr" or btype == "const_xmlChar_ptr": |
| 610 | test.write( |
| 611 | @@ -806,42 +806,42 @@ test_%s(void) { |
| 612 | " continue;\n" |
| 613 | % (bnam, nam, bnam)) |
| 614 | break |
| 615 | - i = i + 1; |
| 616 | + i = i + 1; |
| 617 | |
| 618 | # do the call, and clanup the result |
| 619 | - if extra_pre_call.has_key(name): |
| 620 | - test.write(" %s\n"% (extra_pre_call[name])) |
| 621 | + if name in extra_pre_call: |
| 622 | + test.write(" %s\n"% (extra_pre_call[name])) |
| 623 | if t_ret != None: |
| 624 | - test.write("\n ret_val = %s(" % (name)) |
| 625 | - need = 0 |
| 626 | - for arg in t_args: |
| 627 | - (nam, type, rtype, crtype, info) = arg |
| 628 | - if need: |
| 629 | - test.write(", ") |
| 630 | - else: |
| 631 | - need = 1 |
| 632 | - if rtype != crtype: |
| 633 | - test.write("(%s)" % rtype) |
| 634 | - test.write("%s" % nam); |
| 635 | - test.write(");\n") |
| 636 | - if extra_post_call.has_key(name): |
| 637 | - test.write(" %s\n"% (extra_post_call[name])) |
| 638 | - test.write(" desret_%s(ret_val);\n" % t_ret[0]) |
| 639 | + test.write("\n ret_val = %s(" % (name)) |
| 640 | + need = 0 |
| 641 | + for arg in t_args: |
| 642 | + (nam, type, rtype, crtype, info) = arg |
| 643 | + if need: |
| 644 | + test.write(", ") |
| 645 | + else: |
| 646 | + need = 1 |
| 647 | + if rtype != crtype: |
| 648 | + test.write("(%s)" % rtype) |
| 649 | + test.write("%s" % nam); |
| 650 | + test.write(");\n") |
| 651 | + if name in extra_post_call: |
| 652 | + test.write(" %s\n"% (extra_post_call[name])) |
| 653 | + test.write(" desret_%s(ret_val);\n" % t_ret[0]) |
| 654 | else: |
| 655 | - test.write("\n %s(" % (name)); |
| 656 | - need = 0; |
| 657 | - for arg in t_args: |
| 658 | - (nam, type, rtype, crtype, info) = arg; |
| 659 | - if need: |
| 660 | - test.write(", ") |
| 661 | - else: |
| 662 | - need = 1 |
| 663 | - if rtype != crtype: |
| 664 | - test.write("(%s)" % rtype) |
| 665 | - test.write("%s" % nam) |
| 666 | - test.write(");\n") |
| 667 | - if extra_post_call.has_key(name): |
| 668 | - test.write(" %s\n"% (extra_post_call[name])) |
| 669 | + test.write("\n %s(" % (name)); |
| 670 | + need = 0; |
| 671 | + for arg in t_args: |
| 672 | + (nam, type, rtype, crtype, info) = arg; |
| 673 | + if need: |
| 674 | + test.write(", ") |
| 675 | + else: |
| 676 | + need = 1 |
| 677 | + if rtype != crtype: |
| 678 | + test.write("(%s)" % rtype) |
| 679 | + test.write("%s" % nam) |
| 680 | + test.write(");\n") |
| 681 | + if name in extra_post_call: |
| 682 | + test.write(" %s\n"% (extra_post_call[name])) |
| 683 | |
| 684 | test.write(" call_tests++;\n"); |
| 685 | |
| 686 | @@ -849,32 +849,32 @@ test_%s(void) { |
| 687 | i = 0; |
| 688 | for arg in t_args: |
| 689 | (nam, type, rtype, crtype, info) = arg; |
| 690 | - # This is a hack to prevent generating a destructor for the |
| 691 | - # 'input' argument in xmlTextReaderSetup. There should be |
| 692 | - # a better, more generic way to do this! |
| 693 | - if string.find(info, 'destroy') == -1: |
| 694 | - test.write(" des_%s(n_%s, " % (type, nam)) |
| 695 | - if rtype != crtype: |
| 696 | - test.write("(%s)" % rtype) |
| 697 | - test.write("%s, %d);\n" % (nam, i)) |
| 698 | - i = i + 1; |
| 699 | + # This is a hack to prevent generating a destructor for the |
| 700 | + # 'input' argument in xmlTextReaderSetup. There should be |
| 701 | + # a better, more generic way to do this! |
| 702 | + if info.find('destroy') == -1: |
| 703 | + test.write(" des_%s(n_%s, " % (type, nam)) |
| 704 | + if rtype != crtype: |
| 705 | + test.write("(%s)" % rtype) |
| 706 | + test.write("%s, %d);\n" % (nam, i)) |
| 707 | + i = i + 1; |
| 708 | |
| 709 | test.write(" xmlResetLastError();\n"); |
| 710 | # Check the memory usage |
| 711 | if no_mem == 0: |
| 712 | - test.write(""" if (mem_base != xmlMemBlocks()) { |
| 713 | + test.write(""" if (mem_base != xmlMemBlocks()) { |
| 714 | printf("Leak of %%d blocks found in %s", |
| 715 | - xmlMemBlocks() - mem_base); |
| 716 | - test_ret++; |
| 717 | +\t xmlMemBlocks() - mem_base); |
| 718 | +\t test_ret++; |
| 719 | """ % (name)); |
| 720 | - for arg in t_args: |
| 721 | - (nam, type, rtype, crtype, info) = arg; |
| 722 | - test.write(""" printf(" %%d", n_%s);\n""" % (nam)) |
| 723 | - test.write(""" printf("\\n");\n""") |
| 724 | - test.write(" }\n") |
| 725 | + for arg in t_args: |
| 726 | + (nam, type, rtype, crtype, info) = arg; |
| 727 | + test.write(""" printf(" %%d", n_%s);\n""" % (nam)) |
| 728 | + test.write(""" printf("\\n");\n""") |
| 729 | + test.write(" }\n") |
| 730 | |
| 731 | for arg in t_args: |
| 732 | - test.write(" }\n") |
| 733 | + test.write(" }\n") |
| 734 | |
| 735 | test.write(" function_tests++;\n") |
| 736 | # |
| 737 | @@ -882,7 +882,7 @@ test_%s(void) { |
| 738 | # |
| 739 | while nb_cond > 0: |
| 740 | test.write("#endif\n") |
| 741 | - nb_cond = nb_cond -1 |
| 742 | + nb_cond = nb_cond -1 |
| 743 | if define == 1: |
| 744 | test.write("#endif\n") |
| 745 | |
| 746 | @@ -900,10 +900,10 @@ test_%s(void) { |
| 747 | for module in modules: |
| 748 | # gather all the functions exported by that module |
| 749 | try: |
| 750 | - functions = ctxt.xpathEval("/api/symbols/function[@file='%s']" % (module)) |
| 751 | + functions = ctxt.xpathEval("/api/symbols/function[@file='%s']" % (module)) |
| 752 | except: |
| 753 | - print "Failed to gather functions from module %s" % (module) |
| 754 | - continue; |
| 755 | + print("Failed to gather functions from module %s" % (module)) |
| 756 | + continue; |
| 757 | |
| 758 | # iterate over all functions in the module generating the test |
| 759 | i = 0 |
| 760 | @@ -923,14 +923,14 @@ test_%s(void) { |
| 761 | # iterate over all functions in the module generating the call |
| 762 | for function in functions: |
| 763 | name = function.xpathEval('string(@name)') |
| 764 | - if is_skipped_function(name): |
| 765 | - continue |
| 766 | - test.write(" test_ret += test_%s();\n" % (name)) |
| 767 | + if is_skipped_function(name): |
| 768 | + continue |
| 769 | + test.write(" test_ret += test_%s();\n" % (name)) |
| 770 | |
| 771 | # footer |
| 772 | test.write(""" |
| 773 | if (test_ret != 0) |
| 774 | - printf("Module %s: %%d errors\\n", test_ret); |
| 775 | +\tprintf("Module %s: %%d errors\\n", test_ret); |
| 776 | return(test_ret); |
| 777 | } |
| 778 | """ % (module)) |
| 779 | @@ -948,7 +948,7 @@ test.write(""" return(0); |
| 780 | } |
| 781 | """); |
| 782 | |
| 783 | -print "Generated test for %d modules and %d functions" %(len(modules), nb_tests) |
| 784 | +print("Generated test for %d modules and %d functions" %(len(modules), nb_tests)) |
| 785 | |
| 786 | compare_and_save() |
| 787 | |
| 788 | @@ -960,11 +960,8 @@ for missing in missing_types.keys(): |
| 789 | n = len(missing_types[missing]) |
| 790 | missing_list.append((n, missing)) |
| 791 | |
| 792 | -def compare_missing(a, b): |
| 793 | - return b[0] - a[0] |
| 794 | - |
| 795 | -missing_list.sort(compare_missing) |
| 796 | -print "Missing support for %d functions and %d types see missing.lst" % (missing_functions_nr, len(missing_list)) |
| 797 | +missing_list.sort(key=lambda a: a[0]) |
| 798 | +print("Missing support for %d functions and %d types see missing.lst" % (missing_functions_nr, len(missing_list))) |
| 799 | lst = open("missing.lst", "w") |
| 800 | lst.write("Missing support for %d types" % (len(missing_list))) |
| 801 | lst.write("\n") |
| 802 | @@ -974,9 +971,9 @@ for miss in missing_list: |
| 803 | for n in missing_types[miss[1]]: |
| 804 | i = i + 1 |
| 805 | if i > 5: |
| 806 | - lst.write(" ...") |
| 807 | - break |
| 808 | - lst.write(" %s" % (n)) |
| 809 | + lst.write(" ...") |
| 810 | + break |
| 811 | + lst.write(" %s" % (n)) |
| 812 | lst.write("\n") |
| 813 | lst.write("\n") |
| 814 | lst.write("\n") |