1111import json
1212import yaml
1313import copy
14- from templates .helper import param_traits , type_traits , value_traits , get_tag
14+ from templates .helper import param_traits , type_traits , value_traits , get_tag , version_key
1515
1616default_version = "1.0"
1717all_versions = ["1.0" , "1.1" , "1.2" , "1.3" , "1.4" , "1.5" , "1.6" , "1.7" , "1.8" , "1.9" , "1.10" , "2.0" ]
@@ -526,120 +526,22 @@ def _validate_struct_enum_mapping(specs, tags):
526526"""
527527 filters object by version
528528"""
529+ # Version comparisons route through helper.version_key (single source of truth
530+ # for major/minor decomposition). Do NOT reintroduce float(version) here.
529531def _version_compare_greater (a , b ):
530- a_major = int (a .split ('.' )[0 ])
531- a_minor = int (a .split ('.' )[1 ])
532-
533- b_major = int (b .split ('.' )[0 ])
534- b_minor = int (b .split ('.' )[1 ])
535-
536- if (a_major > b_major ):
537- # print("DEBUG: greater(%d.%d, %d.%d) -> True (major)" % (a_major, a_minor, b_major, b_minor))
538- return True
539-
540- if (a_major < b_major ):
541- # print("DEBUG: greater(%d.%d, %d.%d) -> False (major)" % (a_major, a_minor, b_major, b_minor))
542- return False
543-
544- # a_major == b_major
545-
546- if (a_minor > b_minor ):
547- # print("DEBUG: greater(%d.%d, %d.%d) -> True (minor)" % (a_major, a_minor, b_major, b_minor))
548- return True
549-
550- # a_minor <= b_minor
551-
552- # print("DEBUG: greater(%d.%d, %d.%d) -> False (minor)" % (a_major, a_minor, b_major, b_minor))
553- return False
532+ return version_key (a ) > version_key (b )
554533
555534def _version_compare_equal (a , b ):
556- a_major = int (a .split ('.' )[0 ])
557- a_minor = int (a .split ('.' )[1 ])
558-
559- b_major = int (b .split ('.' )[0 ])
560- b_minor = int (b .split ('.' )[1 ])
561-
562- ret_val = ((a_major == b_major ) and (a_minor == b_minor ))
563- # print("DEBUG: equal(%d.%d, %d.%d) -> %s" % (a_major, a_minor, b_major, b_minor, ret_val))
564- return ret_val
535+ return version_key (a ) == version_key (b )
565536
566537def _version_compare_less (a , b ):
567- a_major = int (a .split ('.' )[0 ])
568- a_minor = int (a .split ('.' )[1 ])
569-
570- b_major = int (b .split ('.' )[0 ])
571- b_minor = int (b .split ('.' )[1 ])
572-
573- if a_major > b_major :
574- # print("DEBUG: less(%d.%d, %d.%d) -> False (major)" % (a_major, a_minor, b_major, b_minor))
575- return False
576-
577- if a_major < b_major :
578- # print("DEBUG: less(%d.%d, %d.%d) -> True (major)" % (a_major, a_minor, b_major, b_minor))
579- return True
580-
581- # a_major == b_major
582-
583- if a_minor < b_minor :
584- # print("DEBUG: less(%d.%d, %d.%d) -> True (minor)" % (a_major, a_minor, b_major, b_minor))
585- return True
586-
587- # a_minor >= b_minor
588-
589- # print("DEBUG: less(%d.%d, %d.%d) -> False (minor)" % (a_major, a_minor, b_major, b_minor))
590- return False
538+ return version_key (a ) < version_key (b )
591539
592540def _version_compare_lequal (a , b ):
593- a_major = int (a .split ('.' )[0 ])
594- a_minor = int (a .split ('.' )[1 ])
595-
596- b_major = int (b .split ('.' )[0 ])
597- b_minor = int (b .split ('.' )[1 ])
598-
599- if a_major > b_major :
600- # print("DEBUG: lequal(%d.%d, %d.%d) -> False (major)" % (a_major, a_minor, b_major, b_minor))
601- return False
602-
603- if a_major < b_major :
604- # print("DEBUG: lequal(%d.%d, %d.%d) -> True (major)" % (a_major, a_minor, b_major, b_minor))
605- return True
606-
607- # a_major == b_major
608-
609- if a_minor <= b_minor :
610- # print("DEBUG: lequal(%d.%d, %d.%d) -> True (minor)" % (a_major, a_minor, b_major, b_minor))
611- return True
612-
613- # a_minor > b_minor
614-
615- # print("DEBUG: lequal(%d.%d, %d.%d) -> False (minor)" % (a_major, a_minor, b_major, b_minor))
616- return False
541+ return version_key (a ) <= version_key (b )
617542
618543def _version_compare_gequal (a , b ):
619- a_major = int (a .split ('.' )[0 ])
620- a_minor = int (a .split ('.' )[1 ])
621-
622- b_major = int (b .split ('.' )[0 ])
623- b_minor = int (b .split ('.' )[1 ])
624-
625- if a_major > b_major :
626- # print("DEBUG: gequal(%d.%d, %d.%d) -> True (major)" % (a_major, a_minor, b_major, b_minor))
627- return True
628-
629- if a_major < b_major :
630- # print("DEBUG: gequal(%d.%d, %d.%d) -> False (major)" % (a_major, a_minor, b_major, b_minor))
631- return False
632-
633- # a_major == b_major
634-
635- if a_minor >= b_minor :
636- # print("DEBUG: gequal(%d.%d, %d.%d) -> True (minor)" % (a_major, a_minor, b_major, b_minor))
637- return True
638-
639- # a_minor < b_minor
640-
641- # print("DEBUG: gequal(%d.%d, %d.%d) -> False (minor)" % (a_major, a_minor, b_major, b_minor))
642- return False
544+ return version_key (a ) >= version_key (b )
643545
644546def _filter_version (d , max_ver ):
645547 ver = d .get ('version' , default_version )
@@ -662,7 +564,7 @@ def __filter_detail(det):
662564 detail = None
663565 for k , v in det .items ():
664566 try :
665- version = float (k )
567+ version_key (k )
666568 except :
667569 return det
668570 if _version_compare_lequal (k , max_ver ):
@@ -1122,7 +1024,12 @@ def parse(section, version, tags, meta, ref):
11221024 # extract header from objects
11231025 if re .match (r"header" , d ['type' ]):
11241026 header = d
1125- header ['ordinal' ] = int (int (header .get ('ordinal' ,"1000" )) * float (header .get ('version' ,"1.0" )))
1027+ # Header ordinal drives DDI table/class order (and the global
1028+ # spec emission sort below). version_key() decomposes major/minor
1029+ # so e.g. "1.17" sorts after "1.4"; a naive float(version) would
1030+ # treat "1.17" as 1.17 < "1.4"==1.4 and misplace sub-tables,
1031+ # breaking N-1 ABI. See helper.version_key.
1032+ header ['ordinal' ] = int (int (header .get ('ordinal' ,"1000" )) * version_key (header .get ('version' ,"1.0" )))
11261033 header ['ordinal' ] *= 1000 if re .match (r"extension" , header .get ('desc' ,"" ).lower ()) else 1
11271034 header ['ordinal' ] *= 1000 if re .match (r"experimental" , header .get ('desc' ,"" ).lower ()) else 1
11281035
0 commit comments