Commit a6af76cb authored by Jack Jansen's avatar Jack Jansen

Factored out the code that creates argument lists and formats for PyArg_Parse

and Py_BuildValue.
parent 7b8f0a18
...@@ -187,9 +187,21 @@ class FunctionGenerator(BaseFunctionGenerator): ...@@ -187,9 +187,21 @@ class FunctionGenerator(BaseFunctionGenerator):
arg.declare() arg.declare()
def getargs(self): 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 = "" fmt = ""
lst = "" lst = ""
sep = ",\n" + ' '*len("if (!PyArg_ParseTuple(")
for arg in self.argumentList: for arg in self.argumentList:
if arg.flags == SelfMode: if arg.flags == SelfMode:
continue continue
...@@ -199,15 +211,7 @@ class FunctionGenerator(BaseFunctionGenerator): ...@@ -199,15 +211,7 @@ class FunctionGenerator(BaseFunctionGenerator):
args = arg.getargsArgs() args = arg.getargsArgs()
if args: if args:
lst = lst + sep + args lst = lst + sep + args
Output("if (!PyArg_ParseTuple(_args, \"%s\"%s))", fmt, lst) return 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 precheck(self): def precheck(self):
pass pass
...@@ -236,16 +240,8 @@ class FunctionGenerator(BaseFunctionGenerator): ...@@ -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): ...@@ -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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment