Use builtin SWIG conversions for glib types

Where possible in the Python SWIG code use the builtin SWIG conversion
code over custom code. This ensures appropriate overflow/type checking.
With this I have enabled GncNumeric from longs and tested for correct
overflow handling.

Note: This could be extended to GUILE but I am not familiar enought to
safely enable this.
This commit is contained in:
Guy Taylor
2017-06-03 17:51:54 +01:00
committed by John Ralls
parent c9c5876431
commit 744cdac5a4
6 changed files with 122 additions and 36 deletions

View File

@@ -169,38 +169,16 @@ typedef char gchar;
#elif defined(SWIGPYTHON) /* Typemaps for Python */
%import "glib.h"
%include <stdint.i>
%typemap(in) gint8, gint16, gint32, gint64, gshort, glong {
$1 = ($1_type)PyInt_AsLong($input);
}
%typemap(out) gint8, gint16, gint32, gint64, gshort, glong {
$result = PyInt_FromLong($1);
}
%typemap(in) guint8, guint16, guint32, guint64, gushort, gulong {
$1 = ($1_type)PyLong_AsUnsignedLong($input);
}
%typemap(out) guint8, guint16, guint32, guint64, gushort, gulong {
$result = PyLong_FromUnsignedLong($1);
}
%typemap(in) gdouble {
$1 = ($1_type)PyFloat_AsDouble($input);
}
%typemap(out) gdouble {
$result = PyFloat_FromDouble($1);
}
%typemap(in) gchar * {
$1 = ($1_ltype)PyString_AsString($input);
}
%typemap(out) gchar * {
$result = PyString_FromString($1);
}
%apply int { gint };
%apply unsigned int { guint };
%apply long { glong };
%apply int64_t { gint64 };
%apply unsigned long { gulong };
%apply uint64_t { guint64 };
%apply double { gdouble };
%apply char* { gchar* };
%typemap(in) gboolean {
if ($input == Py_True)