Skip to content

Commit

Permalink
SWIG: use argument_fail for consistent type error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Feb 10, 2024
1 parent 564df00 commit 4e87c30
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions Components/Overlay/include/ImGui.i
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
if(SWIG_IsOK(res))
$1 = ($ltype)(argp);
else
SWIG_exception_fail(SWIG_TypeError, "Expected size_t");
%argument_fail(SWIG_TypeError, "size_t", $symname, $argnum);
}
%typecheck(SWIG_TYPECHECK_POINTER) ImTextureID {
$1 = true; // actual check in the typemap
Expand All @@ -40,7 +40,7 @@
if (SWIG_IsOK(res)) {
$1 = ($ltype)argp;
} else {
SWIG_exception_fail(SWIG_TypeError, "Expected ImVec4");
%argument_fail(SWIG_TypeError, "ImVec4", $symname, $argnum);
}
}

Expand All @@ -61,8 +61,7 @@
PyBuffer_Release(&view);

if(view.ndim != 1 || strcmp(view.format, "f") != 0) {
PyErr_SetString(PyExc_TypeError, "Expected a 1D array of floats");
SWIG_fail;
%argument_fail(SWIG_TypeError, "array(f)", $symname, $argnum);
}

$1 = ($ltype)view.buf;
Expand Down
4 changes: 2 additions & 2 deletions OgreMain/include/Ogre.i
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ CS_VECTOR_OPS(4);
$1 = &tmp;

if (!SWIG_IsOK(res))
SWIG_exception_fail(SWIG_TypeError, "Expected float (Ogre::Radian) or Ogre::Degree");
%argument_fail(SWIG_TypeError, "float (Ogre::Radian) or Ogre::Degree", $symname, $argnum);
}
}
// punch through overload resolution
Expand Down Expand Up @@ -396,7 +396,7 @@ CS_VECTOR_OPS(4);
PyObject *o = PySequence_GetItem($input, i);
if (!PyNumber_Check(o)) {
Py_XDECREF(o);
SWIG_exception_fail(SWIG_TypeError, "Sequence elements must be numbers");
%argument_fail(SWIG_TypeError, "Sequence[float]", $symname, $argnum);
}
temp.ptr()[i] = (float)PyFloat_AsDouble(o);
Py_DECREF(o);
Expand Down

0 comments on commit 4e87c30

Please sign in to comment.