PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/python/defarg.swg

#
Unknown | 37 lines | 28 code | 9 blank | 0 comment | 0 complexity | 779551a0b0407862c6de3e5fb8651fb8 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* This file defines an internal function for processing default arguments
  2. with proxy classes.
  3. There seems to be no straightforward way to write proxy functions
  4. involving default arguments. For example :
  5. def foo(arg1,arg2,*args):
  6. proxyc.foo(arg1,arg2,args)
  7. This fails because args is now a tuple and SWIG doesn't know what to
  8. do with it.
  9. This file allows a different approach :
  10. def foo(arg1,arg2,*args):
  11. proxyc.__call_defarg(proxyc.foo,(arg1,arg2,)+args)
  12. Basically, we form a new tuple from the object, call this special
  13. __call_defarg method and it passes control to the real wrapper function.
  14. An ugly hack, but it works.
  15. */
  16. SWIGINTERN PyObject *swig_call_defargs(PyObject *self, PyObject *args) {
  17. PyObject *func;
  18. PyObject *parms;
  19. if (!PyArg_ParseTuple(args,"OO",&func,&parms))
  20. return NULL;
  21. if (!PyCallable_Check(func)) {
  22. SWIG_PYTHON_THREAD_BEGIN_BLOCK;
  23. PyErr_SetString(PyExc_TypeError, "__call_defarg : Need a callable object!");
  24. SWIG_PYTHON_THREAD_END_BLOCK;
  25. return NULL;
  26. }
  27. return PyEval_CallObject(func,parms);
  28. }