mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
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.
This commit is contained in:
parent
340d98f564
commit
eefac35594
2 changed files with 22 additions and 0 deletions
|
|
@ -164,6 +164,7 @@ class FunctionGenerator(BaseFunctionGenerator):
|
||||||
|
|
||||||
def functionbody(self):
|
def functionbody(self):
|
||||||
self.declarations()
|
self.declarations()
|
||||||
|
self.precheck()
|
||||||
self.getargs()
|
self.getargs()
|
||||||
self.callit()
|
self.callit()
|
||||||
self.checkit()
|
self.checkit()
|
||||||
|
|
@ -194,6 +195,9 @@ class FunctionGenerator(BaseFunctionGenerator):
|
||||||
continue
|
continue
|
||||||
if arg.mode in (InMode, InOutMode):
|
if arg.mode in (InMode, InOutMode):
|
||||||
arg.getargsCheck()
|
arg.getargsCheck()
|
||||||
|
|
||||||
|
def precheck(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def callit(self):
|
def callit(self):
|
||||||
args = ""
|
args = ""
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,14 @@ VarVarOutBuffer = VarVarHeapOutputBufferType('char', 'long', 'l') # (buf, len, &
|
||||||
includestuff = """
|
includestuff = """
|
||||||
#include "macglue.h"
|
#include "macglue.h"
|
||||||
#include "pymactoolbox.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
|
# Stuff added just before the module's init function
|
||||||
|
|
@ -145,6 +153,16 @@ class OSErrMixIn:
|
||||||
class OSErrFunctionGenerator(OSErrMixIn, FunctionGenerator): pass
|
class OSErrFunctionGenerator(OSErrMixIn, FunctionGenerator): pass
|
||||||
class OSErrMethodGenerator(OSErrMixIn, MethodGenerator): 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):
|
class MacModule(Module):
|
||||||
"Subclass which gets the exception initializer from macglue.c"
|
"Subclass which gets the exception initializer from macglue.c"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue