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/SWIG@5706 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-02-10 09:50:24 +00:00
commit 68024b15ce
17 changed files with 1465 additions and 1250 deletions

View file

@ -16,46 +16,56 @@
#include <string>
%}
/* defining the std::string as/from converters */
/* defining the std::string as/from/check methods */
%fragment("SWIG_PyObj_AsStdString","header") %{
static inline std::string
SWIG_PyObj_AsStdString(PyObject* obj) {
static swig_type_info* pchar_info = SWIG_TypeQuery("char *");
%fragment("SWIG_TryStdString","header",
fragment="SWIG_AsCharPtrAndSize") %{
SWIGSTATICINLINE(int)
SWIG_TryStdString(PyObject* obj, char*& buf, size_t& size) {
SWIG_AsCharPtrAndSize(obj, &buf, &size);
if (PyErr_Occurred() || !buf) {
if (PyErr_Occurred()) PyErr_Clear();
return 0;
}
return 1;
}
%}
%fragment("SWIG_CheckStdString","header",
fragment="SWIG_TryStdString") %{
SWIGSTATICINLINE(int)
SWIG_CheckStdString(PyObject* obj) {
char* buf = 0 ; size_t size = 0;
SWIG_PyObj_AsCharPtrAndSize(obj, pchar_info, &buf, &size);
if (PyErr_Occurred() || !buf) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,"a string is expected");
return std::string();
}
return std::string(buf, size);
return SWIG_TryStdString(obj, buf, size);
}
%}
%fragment("SWIG_PyObj_CheckStdString","header") %{
static inline void
SWIG_PyObj_CheckStdString(PyObject* obj) {
static swig_type_info* pchar_info = SWIG_TypeQuery("char *");
char* buf = 0; size_t size = 0;
SWIG_PyObj_AsCharPtrAndSize(obj, pchar_info, &buf, &size);
if (PyErr_Occurred() || !buf) {
PyErr_Clear();
%fragment("SWIG_AsStdString","header",
fragment="SWIG_TryStdString") %{
SWIGSTATICINLINE(std::string)
SWIG_AsStdString(PyObject* obj) {
char* buf = 0 ; size_t size = 0;
if (SWIG_TryStdString(obj, buf, size)) {
return std::string(buf, size);
} else {
PyErr_SetString(PyExc_TypeError,"a string is expected");
return std::string();
}
}
%}
%fragment("SWIG_PyObj_FromStdString","header") %{
static inline PyObject*
SWIG_PyObj_FromStdString(const std::string& s) {
return SWIG_PyObj_FromCharArray(s.data(), s.size());
%fragment("SWIG_FromStdString","header",
fragment="SWIG_FromCharArray") %{
SWIGSTATICINLINE(PyObject*)
SWIG_FromStdString(const std::string& s) {
return SWIG_FromCharArray(s.data(), s.size());
}
%}
/* declaring the typemaps */
%typemap_asfromcheck(std::string, STRING,
SWIG_PyObj_AsStdString, SWIG_PyObj_FromStdString,
SWIG_PyObj_CheckStdString);
%typemap_asfromcheck(std::string, STRING,
SWIG_AsStdString,
SWIG_FromStdString,
SWIG_CheckStdString);