mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Factored out the code that creates argument lists and formats for PyArg_Parse
and Py_BuildValue.
This commit is contained in:
parent
7b8f0a1843
commit
a6af76cbe4
1 changed files with 27 additions and 20 deletions
|
@ -187,18 +187,8 @@ class FunctionGenerator(BaseFunctionGenerator):
|
||||||
arg.declare()
|
arg.declare()
|
||||||
|
|
||||||
def getargs(self):
|
def getargs(self):
|
||||||
fmt = ""
|
|
||||||
lst = ""
|
|
||||||
sep = ",\n" + ' '*len("if (!PyArg_ParseTuple(")
|
sep = ",\n" + ' '*len("if (!PyArg_ParseTuple(")
|
||||||
for arg in self.argumentList:
|
fmt, lst = self.getargsFormatArgs(sep)
|
||||||
if arg.flags == SelfMode:
|
|
||||||
continue
|
|
||||||
if arg.mode in (InMode, InOutMode):
|
|
||||||
arg.getargsPreCheck()
|
|
||||||
fmt = fmt + arg.getargsFormat()
|
|
||||||
args = arg.getargsArgs()
|
|
||||||
if args:
|
|
||||||
lst = lst + sep + args
|
|
||||||
Output("if (!PyArg_ParseTuple(_args, \"%s\"%s))", fmt, lst)
|
Output("if (!PyArg_ParseTuple(_args, \"%s\"%s))", fmt, lst)
|
||||||
IndentLevel()
|
IndentLevel()
|
||||||
Output("return NULL;")
|
Output("return NULL;")
|
||||||
|
@ -209,6 +199,20 @@ class FunctionGenerator(BaseFunctionGenerator):
|
||||||
if arg.mode in (InMode, InOutMode):
|
if arg.mode in (InMode, InOutMode):
|
||||||
arg.getargsCheck()
|
arg.getargsCheck()
|
||||||
|
|
||||||
|
def getargsFormatArgs(self, sep):
|
||||||
|
fmt = ""
|
||||||
|
lst = ""
|
||||||
|
for arg in self.argumentList:
|
||||||
|
if arg.flags == SelfMode:
|
||||||
|
continue
|
||||||
|
if arg.mode in (InMode, InOutMode):
|
||||||
|
arg.getargsPreCheck()
|
||||||
|
fmt = fmt + arg.getargsFormat()
|
||||||
|
args = arg.getargsArgs()
|
||||||
|
if args:
|
||||||
|
lst = lst + sep + args
|
||||||
|
return fmt, lst
|
||||||
|
|
||||||
def precheck(self):
|
def precheck(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -236,16 +240,8 @@ class FunctionGenerator(BaseFunctionGenerator):
|
||||||
arg.errorCheck()
|
arg.errorCheck()
|
||||||
|
|
||||||
def returnvalue(self):
|
def returnvalue(self):
|
||||||
fmt = ""
|
|
||||||
lst = ""
|
|
||||||
sep = ",\n" + ' '*len("return Py_BuildValue(")
|
sep = ",\n" + ' '*len("return Py_BuildValue(")
|
||||||
for arg in self.argumentList:
|
fmt, lst = self.mkvalueFormatArgs(sep)
|
||||||
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()
|
|
||||||
if fmt == "":
|
if fmt == "":
|
||||||
Output("Py_INCREF(Py_None);")
|
Output("Py_INCREF(Py_None);")
|
||||||
Output("_res = Py_None;");
|
Output("_res = Py_None;");
|
||||||
|
@ -258,6 +254,17 @@ class FunctionGenerator(BaseFunctionGenerator):
|
||||||
arg.cleanup()
|
arg.cleanup()
|
||||||
Output("return _res;")
|
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):
|
class MethodGenerator(FunctionGenerator):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue