diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2005-07-03 20:58:08 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2005-07-03 20:58:08 (GMT) |
commit | a6af76cbe4e5b188ccdba0b628f9d75771c623c1 (patch) | |
tree | 5bc7370882331b43c80675c68dafc3a307339066 /Tools/bgen | |
parent | 7b8f0a1843568f0b91c8c8c3f643210b1692dee3 (diff) | |
download | cpython-a6af76cbe4e5b188ccdba0b628f9d75771c623c1.zip cpython-a6af76cbe4e5b188ccdba0b628f9d75771c623c1.tar.gz cpython-a6af76cbe4e5b188ccdba0b628f9d75771c623c1.tar.bz2 |
Factored out the code that creates argument lists and formats for PyArg_Parse
and Py_BuildValue.
Diffstat (limited to 'Tools/bgen')
-rw-r--r-- | Tools/bgen/bgen/bgenGenerator.py | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/Tools/bgen/bgen/bgenGenerator.py b/Tools/bgen/bgen/bgenGenerator.py index d77da31..7311ddc 100644 --- a/Tools/bgen/bgen/bgenGenerator.py +++ b/Tools/bgen/bgen/bgenGenerator.py @@ -187,9 +187,21 @@ class FunctionGenerator(BaseFunctionGenerator): arg.declare() def getargs(self): + sep = ",\n" + ' '*len("if (!PyArg_ParseTuple(") + fmt, lst = self.getargsFormatArgs(sep) + Output("if (!PyArg_ParseTuple(_args, \"%s\"%s))", fmt, lst) + IndentLevel() + Output("return NULL;") + DedentLevel() + for arg in self.argumentList: + if arg.flags == SelfMode: + continue + if arg.mode in (InMode, InOutMode): + arg.getargsCheck() + + def getargsFormatArgs(self, sep): fmt = "" lst = "" - sep = ",\n" + ' '*len("if (!PyArg_ParseTuple(") for arg in self.argumentList: if arg.flags == SelfMode: continue @@ -199,15 +211,7 @@ class FunctionGenerator(BaseFunctionGenerator): args = arg.getargsArgs() if args: lst = lst + sep + args - Output("if (!PyArg_ParseTuple(_args, \"%s\"%s))", fmt, lst) - IndentLevel() - Output("return NULL;") - DedentLevel() - for arg in self.argumentList: - if arg.flags == SelfMode: - continue - if arg.mode in (InMode, InOutMode): - arg.getargsCheck() + return fmt, lst def precheck(self): pass @@ -236,16 +240,8 @@ class FunctionGenerator(BaseFunctionGenerator): arg.errorCheck() def returnvalue(self): - fmt = "" - lst = "" sep = ",\n" + ' '*len("return Py_BuildValue(") - for arg in self.argumentList: - if not arg: continue - if arg.flags == ErrorMode: continue - if arg.mode in (OutMode, InOutMode): - arg.mkvaluePreCheck() - fmt = fmt + arg.mkvalueFormat() - lst = lst + sep + arg.mkvalueArgs() + fmt, lst = self.mkvalueFormatArgs(sep) if fmt == "": Output("Py_INCREF(Py_None);") Output("_res = Py_None;"); @@ -258,6 +254,17 @@ class FunctionGenerator(BaseFunctionGenerator): arg.cleanup() Output("return _res;") + def mkvalueFormatArgs(self, sep): + fmt = "" + lst = "" + for arg in self.argumentList: + if not arg: continue + if arg.flags == ErrorMode: continue + if arg.mode in (OutMode, InOutMode): + arg.mkvaluePreCheck() + fmt = fmt + arg.mkvalueFormat() + lst = lst + sep + arg.mkvalueArgs() + return fmt, lst class MethodGenerator(FunctionGenerator): |