[Python-checkins] CVS: python/dist/src/Tools/bgen/bgen macsupport.py,1.22,1.23
Jack Jansen
jackjansen@users.sourceforge.net
2001年7月01日 15:09:31 -0700
Update of /cvsroot/python/python/dist/src/Tools/bgen/bgen
In directory usw-pr-cvs1:/tmp/cvs-serv16429/Python/Tools/bgen/bgen
Modified Files:
macsupport.py
Log Message:
Added WeakLink...Generator classes (should have done that ages ago). These check the c-function pointer for being NULL before calling it and raise UnimplementedError if it is.
This allows system libs to be weak-linked, thereby allowing us to generate functions that are only available on some OS versions without getting a NULL dereference if the function isn't available.
Index: macsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/bgen/bgen/macsupport.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** macsupport.py 2001年06月27日 21:58:40 1.22
--- macsupport.py 2001年07月01日 22:09:29 1.23
***************
*** 119,122 ****
--- 119,130 ----
#include "macglue.h"
#include "pymactoolbox.h"
+
+ /* Macro to test whether a weak-loaded CFM function exists */
+ #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\\
+ PyErr_SetString(PyExc_NotImplementedError, \\
+ "Not available in this shared library/OS version"); \\
+ return NULL; \\
+ }} while(0)
+
"""
***************
*** 146,149 ****
--- 154,167 ----
class OSErrMethodGenerator(OSErrMixIn, MethodGenerator): pass
+ class WeakLinkMixIn:
+ "Mix-in to test the function actually exists (!= NULL) before calling"
+
+ def precheck(self):
+ Output('PyMac_PRECHECK(%s);', self.name)
+
+ class WeakLinkFunctionGenerator(WeakLinkMixIn, FunctionGenerator): pass
+ class WeakLinkMethodGenerator(WeakLinkMixIn, MethodGenerator): pass
+ class OSErrWeakLinkFunctionGenerator(OSErrMixIn, WeakLinkMixIn, FunctionGenerator): pass
+ class OSErrWeakLinkMethodGenerator(OSErrMixIn, WeakLinkMixIn, MethodGenerator): pass
class MacModule(Module):