@@ -60,15 +60,33 @@ def get_exported_symbols(library, dynamic=False):
6060 yield symbol
6161
6262
63- def check_library (library , abi_funcs , dynamic = False ):
63+ def check_library (stable_abi_file , library , abi_funcs , dynamic = False ):
6464 available_symbols = set (get_exported_symbols (library , dynamic ))
6565 missing_symbols = abi_funcs - available_symbols
6666 if missing_symbols :
67- print (
68- f"Some symbols from the stable ABI are missing: { ', ' .join (missing_symbols )} "
67+ raise Exception (
68+ f"""\
69+ Some symbols from the limited API are missing: { ', ' .join (missing_symbols )}
70+
71+ This error means that there are some missing symbols among the ones exported
72+ in the Python library ("libpythonx.x.a" or "libpythonx.x.so"). This normally
73+ means that some symbol, function implementation or a prototype, belonging to
74+ a symbol in the limited API has been deleted or is missing.
75+
76+ Check if this was a mistake and if not, update the file containing the limited
77+ API symbols. This file is located at:
78+
79+ { stable_abi_file }
80+
81+ You can read more about the limited API and its contracts at:
82+
83+ https://docs.python.org/3/c-api/stable.html
84+
85+ And in PEP 384:
86+
87+ https://www.python.org/dev/peps/pep-0384/
88+ """
6989 )
70- return 1
71- return 0
7290
7391
7492def generate_limited_api_symbols (args ):
@@ -107,7 +125,6 @@ def generate_limited_api_symbols(args):
107125 )
108126 for symbol in sorted (stable_symbols ):
109127 output_file .write (f"{ symbol } \n " )
110- sys .exit (0 )
111128
112129
113130def get_limited_api_macros (headers ):
@@ -187,21 +204,24 @@ def check_symbols(parser_args):
187204 if symbol and not symbol .startswith ("#" )
188205 }
189206
190- ret = 0
191- # static library
192- LIBRARY = sysconfig .get_config_var ("LIBRARY" )
193- if not LIBRARY :
194- raise Exception ("failed to get LIBRARY variable from sysconfig" )
195- ret = check_library (LIBRARY , abi_funcs )
196-
197- # dynamic library
198- LDLIBRARY = sysconfig .get_config_var ("LDLIBRARY" )
199- if not LDLIBRARY :
200- raise Exception ("failed to get LDLIBRARY variable from sysconfig" )
201- if LDLIBRARY != LIBRARY :
202- ret |= check_library (LDLIBRARY , abi_funcs , dynamic = True )
203-
204- sys .exit (ret )
207+ try :
208+ # static library
209+ LIBRARY = sysconfig .get_config_var ("LIBRARY" )
210+ if not LIBRARY :
211+ raise Exception ("failed to get LIBRARY variable from sysconfig" )
212+ check_library (parser_args .stable_abi_file , LIBRARY , abi_funcs )
213+
214+ # dynamic library
215+ LDLIBRARY = sysconfig .get_config_var ("LDLIBRARY" )
216+ if not LDLIBRARY :
217+ raise Exception ("failed to get LDLIBRARY variable from sysconfig" )
218+ if LDLIBRARY != LIBRARY :
219+ check_library (
220+ parser_args .stable_abi_file , LDLIBRARY , abi_funcs , dynamic = True
221+ )
222+ except Exception as e :
223+ print (e , file = sys .stderr )
224+ sys .exit (1 )
205225
206226
207227def main ():
0 commit comments