diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2001-07-01 22:09:29 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2001-07-01 22:09:29 (GMT) |
commit | eefac35594980b517f92261ac8baa26d8d320e96 (patch) | |
tree | 24dfcd3b04c602e08d3151aeab00d8cf199d57f8 | |
parent | 340d98f564ac3ce8ee46b1f2c4f382718c10effe (diff) | |
download | cpython-eefac35594980b517f92261ac8baa26d8d320e96.zip cpython-eefac35594980b517f92261ac8baa26d8d320e96.tar.gz cpython-eefac35594980b517f92261ac8baa26d8d320e96.tar.bz2 |
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.
-rw-r--r-- | Tools/bgen/bgen/bgenGenerator.py | 4 | ||||
-rw-r--r-- | Tools/bgen/bgen/macsupport.py | 18 |
2 files changed, 22 insertions, 0 deletions
diff --git a/Tools/bgen/bgen/bgenGenerator.py b/Tools/bgen/bgen/bgenGenerator.py index 94905be..47fed8e 100644 --- a/Tools/bgen/bgen/bgenGenerator.py +++ b/Tools/bgen/bgen/bgenGenerator.py @@ -164,6 +164,7 @@ class FunctionGenerator(BaseFunctionGenerator): def functionbody(self): self.declarations() + self.precheck() self.getargs() self.callit() self.checkit() @@ -194,6 +195,9 @@ class FunctionGenerator(BaseFunctionGenerator): continue if arg.mode in (InMode, InOutMode): arg.getargsCheck() + + def precheck(self): + pass def callit(self): args = "" diff --git a/Tools/bgen/bgen/macsupport.py b/Tools/bgen/bgen/macsupport.py index 50b2eaa..d8677b0 100644 --- a/Tools/bgen/bgen/macsupport.py +++ b/Tools/bgen/bgen/macsupport.py @@ -118,6 +118,14 @@ VarVarOutBuffer = VarVarHeapOutputBufferType('char', 'long', 'l') # (buf, len, & includestuff = """ #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) + """ # Stuff added just before the module's init function @@ -145,6 +153,16 @@ class OSErrMixIn: class OSErrFunctionGenerator(OSErrMixIn, FunctionGenerator): pass 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): "Subclass which gets the exception initializer from macglue.c" |