From 384370972713d60f772c56a34affe6100c31900a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 25 Apr 2005 02:36:27 +0000 Subject: [PATCH] gst/gstbuffer.override: handle the data correctly Original commit message from CVS: * gst/gstbuffer.override: handle the data correctly --- ChangeLog | 5 +++++ gst/gstbuffer.override | 16 ++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4157820ccb..907048b626 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-04-25 Benjamin Otte + + * gst/gstbuffer.override: + handle the data correctly + 2005-04-12 Thomas Vander Stichele * gst/gst.defs: diff --git a/gst/gstbuffer.override b/gst/gstbuffer.override index 129c137e62..32c6111273 100644 --- a/gst/gstbuffer.override +++ b/gst/gstbuffer.override @@ -49,13 +49,14 @@ _wrap_gst_buffer_new(PyGBoxed *self, PyObject *args, PyObject *kwargs) &data, &size, &buf_size)) return -1; + if (size < 0) { + PyErr_SetString(PyExc_TypeError, "buffer size must be >= 0"); + return -1; + } self->gtype = GST_TYPE_BUFFER; self->free_on_dealloc = FALSE; - if (buf_size != -1) - self->boxed = gst_buffer_new_and_alloc(buf_size); - else - self->boxed = gst_buffer_new(); + self->boxed = gst_buffer_new_and_alloc(buf_size > size ? buf_size : size); if (!self->boxed) { PyErr_SetString(PyExc_RuntimeError, "could not create GstBuffer object"); @@ -65,12 +66,7 @@ _wrap_gst_buffer_new(PyGBoxed *self, PyObject *args, PyObject *kwargs) if (data == NULL) return 0; - if (buf_size != -1 && buf_size != size) { - PyErr_Format(PyExc_TypeError, "data must be of length %d, not %d", size, buf_size); - return -1; - } - - GST_BUFFER_DATA (self->boxed) = data; + memcpy (GST_BUFFER_DATA (self->boxed), data, size); GST_BUFFER_SIZE (self->boxed) = size; return 0;