summaryrefslogtreecommitdiff
path: root/gi/pygi-marshal-from-py.c
diff options
context:
space:
mode:
Diffstat (limited to 'gi/pygi-marshal-from-py.c')
-rw-r--r--gi/pygi-marshal-from-py.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 4ddfbb4..9f7d874 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -32,7 +32,7 @@
#include "pygi-marshal-cleanup.h"
#include "pygi-marshal-from-py.h"
-gboolean
+static gboolean
gi_argument_from_py_ssize_t (GIArgument *arg_out,
Py_ssize_t size_in,
GITypeTag type_tag)
@@ -134,7 +134,7 @@ gi_argument_from_py_ssize_t (GIArgument *arg_out,
return FALSE;
}
-gboolean
+static gboolean
gi_argument_from_c_long (GIArgument *arg_out,
long c_long_in,
GITypeTag type_tag)
@@ -235,7 +235,11 @@ _pygi_marshal_from_py_void (PyGIInvokeState *state,
{
g_warn_if_fail (arg_cache->transfer == GI_TRANSFER_NOTHING);
- arg->v_pointer = py_arg;
+ if (PYGLIB_CPointer_Check(py_arg)) {
+ arg->v_pointer = PYGLIB_CPointer_GetPointer (py_arg, NULL);
+ } else {
+ arg->v_pointer = py_arg;
+ }
return TRUE;
}
@@ -659,6 +663,23 @@ _pygi_marshal_from_py_uint64 (PyGIInvokeState *state,
return TRUE;
}
+static gboolean
+check_valid_double (double x, double min, double max)
+{
+ char buf[100];
+
+ if ((x < min || x > max) && x != INFINITY && x != -INFINITY && x != NAN) {
+ if (PyErr_Occurred())
+ PyErr_Clear ();
+
+ /* we need this as PyErr_Format() does not support float types */
+ snprintf (buf, sizeof (buf), "%g not in range %g to %g", x, min, max);
+ PyErr_SetString (PyExc_ValueError, buf);
+ return FALSE;
+ }
+ return TRUE;
+}
+
gboolean
_pygi_marshal_from_py_float (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
@@ -682,16 +703,8 @@ _pygi_marshal_from_py_float (PyGIInvokeState *state,
double_ = PyFloat_AsDouble (py_float);
Py_DECREF (py_float);
- if (PyErr_Occurred ()) {
- PyErr_Clear ();
- PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXFLOAT, G_MAXFLOAT);
- return FALSE;
- }
-
- if (double_ < -G_MAXFLOAT || double_ > G_MAXFLOAT) {
- PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXFLOAT, G_MAXFLOAT);
+ if (PyErr_Occurred () || !check_valid_double (double_, -G_MAXFLOAT, G_MAXFLOAT))
return FALSE;
- }
arg->v_float = double_;
@@ -721,16 +734,8 @@ _pygi_marshal_from_py_double (PyGIInvokeState *state,
double_ = PyFloat_AsDouble (py_float);
Py_DECREF (py_float);
- if (PyErr_Occurred ()) {
- PyErr_Clear ();
- PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXDOUBLE, G_MAXDOUBLE);
+ if (PyErr_Occurred () || !check_valid_double (double_, -G_MAXDOUBLE, G_MAXDOUBLE))
return FALSE;
- }
-
- if (double_ < -G_MAXDOUBLE || double_ > G_MAXDOUBLE) {
- PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXDOUBLE, G_MAXDOUBLE);
- return FALSE;
- }
arg->v_double = double_;