Reducing pyrun.swg and splitting python.swg into different files
for clarity and for easier maintainance. pyrun.swg almost the same than 1.3.20, therefore there will be compatible again. code generated is reduced by the use and reuse of %fragments. as usual, all the test-suite is compiling and a much bigger "test project" too. with the new typemaps definition should be much eaiser and uniform add stl/std and user types. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5706 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
15923cd8b8
commit
c9d6e27b5c
17 changed files with 1465 additions and 1250 deletions
68
SWIG/Lib/python/argcargv.i
Normal file
68
SWIG/Lib/python/argcargv.i
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* ------------------------------------------------------------
|
||||
* --- Argc & Argv ---
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%fragment("SWIG_AsArgcArgv","header") %{
|
||||
SWIGSTATIC(char**)
|
||||
SWIG_AsArgcArgv(PyObject* input,
|
||||
swig_type_info* ppchar_info,
|
||||
swig_type_info* pchar_info,
|
||||
size_t* argc, int* owner)
|
||||
{
|
||||
char **argv = 0;
|
||||
size_t i = 0;
|
||||
if (SWIG_ConvertPtr(input, (void **)&argv, ppchar_info, 0) == -1) {
|
||||
PyErr_Clear();
|
||||
int list = PyList_Check(input);
|
||||
if (list || PyTuple_Check(input)) {
|
||||
*argc = list ? PyList_Size(input) : PyTuple_Size(input);
|
||||
argv = swig_new_array(char*, *argc + 1);
|
||||
*owner = 1;
|
||||
for (; i < *argc; ++i) {
|
||||
PyObject *obj = list ? PyList_GetItem(input,i) : PyTuple_GetItem(input,i);
|
||||
argv[i] = SWIG_AsCharPtr(obj, pchar_info);
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Clear();
|
||||
PyErr_SetString(PyExc_TypeError,"list or tuple must contain strings only");
|
||||
}
|
||||
}
|
||||
argv[i] = 0;
|
||||
return argv;
|
||||
} else {
|
||||
*argc = 0;
|
||||
PyErr_SetString(PyExc_TypeError,"a list or tuple is expected");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/* seems dangerous, but the user asked for it... */
|
||||
while (argv[i] != 0) ++i;
|
||||
*argc = i;
|
||||
owner = 0;
|
||||
return argv;
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
/*
|
||||
This typemap works with either a char**, a python list or a python
|
||||
tuple
|
||||
*/
|
||||
|
||||
%typemap(in,fragment="SWIG_AsArgcArgv") (int ARGC, char **ARGV)
|
||||
(int owner) {
|
||||
size_t argc = 0;
|
||||
char **argv = SWIG_AsArgcArgv($input, $descriptor(char**),
|
||||
$descriptor(char*), &argc, &owner);
|
||||
if (PyErr_Occurred()) {
|
||||
$1 = 0; $2 = 0;
|
||||
SWIG_fail;
|
||||
} else {
|
||||
$1 = ($1_ltype) argc;
|
||||
$2 = ($2_ltype) argv;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(freearg) (int ARGC, char **ARGV) (owner) {
|
||||
if (owner) swig_delete_array($2);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue