simplify generated code and more consistent names/sections

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8781 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2006-02-11 01:57:32 +00:00
commit a3555839e4
4 changed files with 126 additions and 108 deletions

View file

@ -42,6 +42,127 @@
#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer)
#define SWIG_NewClientData(obj) PySwigClientData_New(obj)
#define SWIG_SetErrorObj SWIG_Python_SetErrorObj
#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg
#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code)
#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg)
#define SWIG_fail goto fail
/* Runtime API implementation */
/* Error manipulation */
SWIGINTERN void
SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetObject(errtype, obj);
Py_DECREF(obj);
SWIG_PYTHON_THREAD_END_BLOCK;
}
SWIGINTERN void
SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetString(errtype, (char *) msg);
SWIG_PYTHON_THREAD_END_BLOCK;
}
#define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj)
/* Set a constant value */
SWIGINTERN void
SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) {
PyDict_SetItemString(d, (char*) name, obj);
Py_DECREF(obj);
}
/* Append a value to the result obj */
SWIGINTERN PyObject*
SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) {
#if !defined(SWIG_PYTHON_OUTPUT_TUPLE)
if (!result) {
result = obj;
} else if (result == Py_None) {
Py_DECREF(result);
result = obj;
} else {
if (!PyList_Check(result)) {
PyObject *o2 = result;
result = PyList_New(1);
PyList_SetItem(result, 0, o2);
}
PyList_Append(result,obj);
Py_DECREF(obj);
}
return result;
#else
PyObject* o2;
PyObject* o3;
if (!result) {
result = obj;
} else if (result == Py_None) {
Py_DECREF(result);
result = obj;
} else {
if (!PyTuple_Check(result)) {
o2 = result;
result = PyTuple_New(1);
PyTuple_SET_ITEM(result, 0, o2);
}
o3 = PyTuple_New(1);
PyTuple_SET_ITEM(o3, 0, obj);
o2 = result;
result = PySequence_Concat(o2, o3);
Py_DECREF(o2);
Py_DECREF(o3);
}
return result;
#endif
}
/* Unpack the argument tuple */
SWIGINTERN int
SWIG_Python_UnpackTuple(PyObject *args, const char *name, int min, int max, PyObject **objs)
{
if (!args) {
if (!min && !max) {
return 1;
} else {
PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none",
name, (min == max ? "" : "at least "), min);
return 0;
}
}
if (!PyTuple_Check(args)) {
PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple");
return 0;
} else {
register int l = PyTuple_GET_SIZE(args);
if (l < min) {
PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d",
name, (min == max ? "" : "at least "), min, l);
return 0;
} else if (l > max) {
PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d",
name, (min == max ? "" : "at most "), max, l);
return 0;
} else {
register int i;
for (i = 0; i < l; ++i) {
objs[i] = PyTuple_GET_ITEM(args, i);
}
for (; l < max; ++l) {
objs[l] = 0;
}
return i + 1;
}
}
}
/* A functor is a function object with one single object argument */
#if PY_VERSION_HEX >= 0x02020000
#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL);
@ -49,14 +170,6 @@
#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj);
#endif
/* Error manipulation */
#define SWIG_SetErrorObj(type, obj) {SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_SetObject(type, obj); SWIG_PYTHON_THREAD_END_BLOCK; }
#define SWIG_SetErrorMsg(type, msg) {SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_SetString(type, msg); SWIG_PYTHON_THREAD_END_BLOCK; }
#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code)
#define SWIG_Error(code, msg) SWIG_SetErrorMsg(SWIG_Python_ErrorType(code), msg)
#define SWIG_fail goto fail
/*
Helper for static pointer initialization for both C and C++ code, for example
static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...);
@ -123,88 +236,6 @@ SWIG_Py_Void(void)
return none;
}
/* Append a value to the result obj */
SWIGINTERN PyObject*
SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) {
#if !defined(SWIG_PYTHON_OUTPUT_TUPLE)
if (!result) {
result = obj;
} else if (result == Py_None) {
Py_DECREF(result);
result = obj;
} else {
if (!PyList_Check(result)) {
PyObject *o2 = result;
result = PyList_New(1);
PyList_SetItem(result, 0, o2);
}
PyList_Append(result,obj);
Py_DECREF(obj);
}
return result;
#else
PyObject* o2;
PyObject* o3;
if (!result) {
result = obj;
} else if (result == Py_None) {
Py_DECREF(result);
result = obj;
} else {
if (!PyTuple_Check(result)) {
o2 = result;
result = PyTuple_New(1);
PyTuple_SET_ITEM(result, 0, o2);
}
o3 = PyTuple_New(1);
PyTuple_SET_ITEM(o3, 0, obj);
o2 = result;
result = PySequence_Concat(o2, o3);
Py_DECREF(o2);
Py_DECREF(o3);
}
return result;
#endif
}
SWIGINTERN int
SWIG_Python_UnpackTuple(PyObject *args, const char *name, int min, int max, PyObject **objs)
{
if (!args) {
if (!min && !max) {
return 1;
} else {
PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none",
name, (min == max ? "" : "at least "), min);
return 0;
}
}
if (!PyTuple_Check(args)) {
PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple");
return 0;
} else {
register int l = PyTuple_GET_SIZE(args);
if (l < min) {
PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d",
name, (min == max ? "" : "at least "), min, l);
return 0;
} else if (l > max) {
PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d",
name, (min == max ? "" : "at most "), max, l);
return 0;
} else {
register int i;
for (i = 0; i < l; ++i) {
objs[i] = PyTuple_GET_ITEM(args, i);
}
for (; l < max; ++l) {
objs[l] = 0;
}
return i + 1;
}
}
}
/* PySwigClientData */

View file

@ -48,25 +48,13 @@
/* Overload of the output/constant/exception/dirout handling */
/* append output */
#define SWIG_AppendOutput(result,obj) SWIG_Python_AppendOutput(result, obj)
#define SWIG_AppendOutput(result, obj) SWIG_Python_AppendOutput(result, obj)
/* set constant */
%define %set_constant(name, obj) %begin_block
PyObject *_obj = obj;
PyDict_SetItemString(d, (char*) name, _obj);
Py_DECREF(_obj);
%end_block %enddef
#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, name,obj)
/* raise */
%define %raise(obj, type, desc)
PyObject *_obj = obj;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetObject(SWIG_Python_ExceptionType(desc), _obj);
SWIG_PYTHON_THREAD_END_BLOCK;
Py_DECREF(_obj);
SWIG_fail %enddef
#define SWIG_Raise(obj, type, desc) SWIG_Python_Raise(obj, type, desc)
/* Include the unified typemap library */
%include <typemaps/swigtypemaps.swg>

View file

@ -21,8 +21,7 @@
%define_as(SWIG_exception_fail(code, msg), %block(%error(code, msg); SWIG_fail))
%define_as(SWIG_contract_assert(expr, msg),
if (!(expr)) { %error(SWIG_RuntimeError, msg); SWIG_fail; } else)
%define_as(SWIG_contract_assert(expr, msg), if (!(expr)) { %error(SWIG_RuntimeError, msg); SWIG_fail; } else)
}

View file

@ -113,7 +113,7 @@
#ifndef %raise
#if defined(SWIG_Raise)
/* simple raise operation */
#define %raise(obj, type, desc) %error_block(SWIG_Raise(obj, type, desc); SWIG_fail)
#define %raise(obj, type, desc) SWIG_Raise(obj, type, desc); SWIG_fail
#else
#error "Language must define SWIG_Raise or %raise"
#endif