summaryrefslogtreecommitdiff
path: root/gi
diff options
context:
space:
mode:
authorThibault Saunier <tsaunier@igalia.com>2019-12-10 11:58:01 -0300
committerThibault Saunier <tsaunier@igalia.com>2019-12-10 12:05:19 -0300
commitd365954fc0793d3d6edc12a1532682e676a753d0 (patch)
tree493337a7197a44b5df0931098b3bebf28caf75f0 /gi
parent6d53d0ae0e99fe47e04a7fd6962093934cbbb6b8 (diff)
Subclass Exception for mapping and unmapping errors
And minor cleanup in the way errors are handled
Diffstat (limited to 'gi')
-rw-r--r--gi/overrides/Gst.py25
-rw-r--r--gi/overrides/gstmodule.c31
2 files changed, 36 insertions, 20 deletions
diff --git a/gi/overrides/Gst.py b/gi/overrides/Gst.py
index 54bdd5d..c62d9e1 100644
--- a/gi/overrides/Gst.py
+++ b/gi/overrides/Gst.py
@@ -225,6 +225,11 @@ class LinkError(Exception):
pass
__all__.append('LinkError')
+class MapError(Exception):
+ pass
+__all__.append('MapError')
+
+
class Iterator(Gst.Iterator):
def __iter__(self):
while True:
@@ -612,23 +617,22 @@ __all__.append("MapInfo")
class Buffer(Gst.Buffer):
def map_range(self, idx, length, flags):
- mapinfo = MapInfo()
+ mapinfo = MapInfo()
if (_gi_gst.buffer_override_map_range(self, mapinfo, idx, length, int(flags))):
mapinfo.__parent__ = self
return (mapinfo)
- raise Exception('MappingError','Buffer mapping was not successfull')
- return None
+ raise MapError('MappingError','Buffer mapping was not successfull')
def map(self, flags):
mapinfo = MapInfo()
- if (_gi_gst.buffer_override_map(self, mapinfo, int(flags))):
+ if _gi_gst.buffer_override_map(self, mapinfo, int(flags)):
mapinfo.__parent__ = self
- return (mapinfo)
- raise Exception('MappingError','Buffer mapping was not successfull')
- return None
+ return mapinfo
+ raise MapError('MappingError','Buffer mapping was not successfull')
def unmap(self, mapinfo):
- _gi_gst.buffer_override_unmap(self, mapinfo)
+ if _gi_gst.buffer_override_unmap(self, mapinfo) is not True:
+ raise MapError('UnmappingError','Buffer unmapping was not successfull')
Buffer = override(Buffer)
__all__.append('Buffer')
@@ -640,11 +644,10 @@ class Memory(Gst.Memory):
if (_gi_gst.memory_override_map(self, mapinfo, int(flags))):
mapinfo.__parent__ = self
return (mapinfo)
- raise Exception('MappingError','Memory mapping was not successfull')
- return None
+ raise MapError('MappingError','Memory mapping was not successfull')
def unmap(self, mapinfo):
- _gi_gst.memory_override_unmap(self, mapinfo)
+ return _gi_gst.memory_override_unmap(self, mapinfo)
Memory = override(Memory)
__all__.append('Memory')
diff --git a/gi/overrides/gstmodule.c b/gi/overrides/gstmodule.c
index 6e65753..b0986b2 100644
--- a/gi/overrides/gstmodule.c
+++ b/gi/overrides/gstmodule.c
@@ -805,14 +805,18 @@ _gst_memory_override_unmap (PyObject * self, PyObject * args)
/* Look up Gst.Buffer and Gst.Mapinfo parameters */
gst_memory_type = pygobject_lookup_class (_gst_memory_type);
- if (!PyArg_ParseTuple (args, "O!O", gst_memory_type, &py_memory, &py_mapinfo))
+ if (!PyArg_ParseTuple (args, "O!O", gst_memory_type, &py_memory, &py_mapinfo)) {
+ PyErr_BadArgument ();
return NULL;
+ }
/* Extract attributes from Gst.MapInfo */
if (!(mview = PyObject_GetAttrString (py_mapinfo, "data")))
goto err;
+
if (!PyObject_HasAttrString (py_mapinfo, "__cmapinfo"))
goto end;
+
if (!(py_cmapinfo = PyObject_GetAttrString (py_mapinfo, "__cmapinfo")))
goto err;
@@ -835,10 +839,10 @@ _gst_memory_override_unmap (PyObject * self, PyObject * args)
g_free (mapinfo);
end:
Py_DECREF (mview);
- Py_RETURN_NONE;
+ return Py_True;
err:
- return NULL;
+ return Py_False;
}
static PyObject *
@@ -856,7 +860,7 @@ _gst_buffer_override_map_range (PyObject * self, PyObject * args)
gst_buffer_type = pygobject_lookup_class (_gst_buffer_type);
if (!PyArg_ParseTuple (args, "O!OIii", gst_buffer_type, &py_buffer,
&py_mapinfo, &idx, &range, &flags))
- return NULL;
+ return Py_False;
/* Since Python does only support r/o or r/w it has to be changed to either */
flags = (flags & GST_MAP_WRITE) ? GST_MAP_READWRITE : GST_MAP_READ;
@@ -893,8 +897,10 @@ _gst_buffer_override_map (PyObject * self, PyObject * args)
/* Look up Gst.Buffer, Gst.MapInfo, and Gst.MapFlags parameters */
gst_buffer_type = pygobject_lookup_class (_gst_buffer_type);
if (!PyArg_ParseTuple (args, "O!Oi", gst_buffer_type, &py_buffer, &py_mapinfo,
- &flags))
+ &flags)) {
+ PyErr_BadArgument ();
return NULL;
+ }
/* Since Python does only support r/o or r/w it has to be changed to either */
flags = (flags & GST_MAP_WRITE) ? GST_MAP_READWRITE : GST_MAP_READ;
@@ -928,14 +934,18 @@ _gst_buffer_override_unmap (PyObject * self, PyObject * args)
/* Look up Gst.Buffer and Gst.Mapinfo parameters */
gst_buf_type = pygobject_lookup_class (_gst_buffer_type);
- if (!PyArg_ParseTuple (args, "O!O", gst_buf_type, &py_buffer, &py_mapinfo))
+ if (!PyArg_ParseTuple (args, "O!O", gst_buf_type, &py_buffer, &py_mapinfo)) {
+ PyErr_BadArgument ();
return NULL;
+ }
/* Extract attributes from Gst.MapInfo */
if (!(mview = PyObject_GetAttrString (py_mapinfo, "data")))
goto err;
+
if (!PyObject_HasAttrString (py_mapinfo, "__cmapinfo"))
goto end;
+
if (!(py_cmapinfo = PyObject_GetAttrString (py_mapinfo, "__cmapinfo")))
goto err;
@@ -946,8 +956,11 @@ _gst_buffer_override_unmap (PyObject * self, PyObject * args)
/* Call the memoryview.release() Python method, there is no C API */
PyObject *ret = PyObject_CallMethod (mview, "release", NULL);
- if (!ret)
+ if (!ret) {
+ GST_ERROR ("Could not call `.release()` on the memoryview.");
+
goto err;
+ }
Py_DECREF (ret);
Py_DECREF (py_cmapinfo);
PyObject_SetAttrString (py_mapinfo, "__cmapinfo", NULL);
@@ -957,10 +970,10 @@ _gst_buffer_override_unmap (PyObject * self, PyObject * args)
g_free (mapinfo);
end:
Py_DECREF (mview);
- Py_RETURN_NONE;
+ return Py_True;
err:
- return NULL;
+ return Py_False;
}
static PyMethodDef _gi_gst_functions[] = {