Removal of all glib < 2.8 cruft since GStreamer core now requires glib >= 2.8

Original commit message from CVS:
Removal of all glib < 2.8 cruft since GStreamer core now requires
glib >= 2.8
* codegen/argtypes.py:
remove gstobject cruft from ObjectArg
* configure.ac:
Require glib >= 2.8.0
* gst/Makefile.am:
* gst/pygstobject.c:
* gst/pygstobject.h:
Remove pygstobject.[ch]
* gst/common.h:
Don't include removed header file.
* gst/gst.override:
* gst/gstbin.override:
* gst/gstbus.override:
* gst/gstelement.override:
* gst/gstelementfactory.override:
* gst/gstmessage.override:
* gst/gstobject.override:
* gst/gstpad.override:
* gst/interfaces.override:
* gst/pygstiterator.c: (pygst_iterator_iter_next):
Switch from using pygstobject* functions to using pygobject* functions.
* gst/gstmodule.c: (sink_gstobject), (init_gst):
Move GstObject sink function here and use standard gobject refcounting.
This commit is contained in:
Edward Hervey 2006-07-02 15:25:04 +00:00
parent 33b77c7759
commit 1c5a18e82c
19 changed files with 70 additions and 321 deletions

View file

@ -1,3 +1,32 @@
2006-07-02 Edward Hervey <edward@fluendo.com>
Removal of all glib < 2.8 cruft since GStreamer core now requires
glib >= 2.8
* codegen/argtypes.py:
remove gstobject cruft from ObjectArg
* configure.ac:
Require glib >= 2.8.0
* gst/Makefile.am:
* gst/pygstobject.c:
* gst/pygstobject.h:
Remove pygstobject.[ch]
* gst/common.h:
Don't include removed header file.
* gst/gst.override:
* gst/gstbin.override:
* gst/gstbus.override:
* gst/gstelement.override:
* gst/gstelementfactory.override:
* gst/gstmessage.override:
* gst/gstobject.override:
* gst/gstpad.override:
* gst/interfaces.override:
* gst/pygstiterator.c: (pygst_iterator_iter_next):
Switch from using pygstobject* functions to using pygobject* functions.
* gst/gstmodule.c: (sink_gstobject), (init_gst):
Move GstObject sink function here and use standard gobject refcounting.
2006-06-22 Edward Hervey <edward@fluendo.com>
* configure.ac: (GST_LIBS):

View file

@ -514,13 +514,13 @@ class ObjectArg(ArgType):
info.varlist.add('PyObject', '*py_ret')
# < GLib 2.8: using our custom _new and _unref functions
# makes sure we update the proper GstObject refcount
info.codeafter.append(' py_ret = pygstobject_new((GObject *)ret);\n'
info.codeafter.append(' py_ret = pygobject_new((GObject *)ret);\n'
' if (ret != NULL)\n'
' pygst_object_unref((GObject *)ret);\n'
' g_object_unref((GObject *)ret);\n'
' return py_ret;')
else:
info.codeafter.append(' /* pygstobject_new handles NULL checking */\n' +
' return pygstobject_new((GObject *)ret);')
info.codeafter.append(' /* pygobject_new handles NULL checking */\n' +
' return pygobject_new((GObject *)ret);')
class MiniObjectArg(ArgType):
# should change these checks to more typesafe versions that check

2
common

@ -1 +1 @@
Subproject commit 123195d3bbcc0b6e1cf867d3a180685f8766a0be
Subproject commit 9eb7943282c38c815cfbac34cff4062a94e72e62

View file

@ -35,7 +35,7 @@ AC_SUBST(ACLOCAL_AMFLAGS, "-I common/m4")
dnl required versions of other packages
AC_SUBST(PYGTK_REQ, 2.6.3)
AC_SUBST(GLIB_REQ, 2.6.0)
AC_SUBST(GLIB_REQ, 2.8.0)
AC_SUBST(GTK_REQ, 2.6.0)
AC_SUBST(GST_REQ, 0.10.2)
AC_SUBST(GSTPB_REQ, 0.10.0.2)

View file

@ -20,7 +20,7 @@ defs_DATA = gst-types.defs \
base.defs
defsdir = $(pkgdatadir)/$(GST_MAJORMINOR)/defs
noinst_HEADERS = common.h pygstvalue.h pygstminiobject.h pygstobject.h pygstexception.h
noinst_HEADERS = common.h pygstvalue.h pygstminiobject.h pygstexception.h
versioned_overrides = \
gst-0.10.3.ignore \
@ -44,7 +44,6 @@ _gst_la_SOURCES = \
gstmodule.c \
pygstiterator.c \
pygstminiobject.c \
pygstobject.c \
pygstvalue.c \
pygstexception.c

View file

@ -29,7 +29,6 @@
#include <gst/gst.h>
#include "pygobject.h"
#include "pygstobject.h"
#include "pygstminiobject.h"
#if (defined HAVE_OLD_PYGTK && (PY_VERSION_HEX < 0x02030000))

View file

@ -475,7 +475,7 @@ _wrap_gst_registry_get_plugin_list (PyGObject *self)
list = PyList_New (g_list_length(plugins));
for (l = plugins, i = 0; l; l = l->next, ++i) {
GstPlugin *plugin = (GstPlugin *) l->data;
PyObject *object = pygstobject_new (G_OBJECT (plugin));
PyObject *object = pygobject_new (G_OBJECT (plugin));
gst_object_unref (plugin);
PyList_SetItem (list, i, object);
@ -608,7 +608,7 @@ _wrap_gst_xml_get_topelements(PyGObject *self)
py_list = PyList_New(g_list_length(xml_elements));
for (l = xml_elements, i = 0; l; l = l->next, ++i) {
GstElement *element = (GstElement*)l->data;
PyList_SetItem(py_list, i, pygstobject_new(G_OBJECT(element)));
PyList_SetItem(py_list, i, pygobject_new(G_OBJECT(element)));
gst_object_unref (element);
}
@ -872,7 +872,7 @@ _wrap_gst_type_find_factory_get_list (PyObject *self)
GstTypeFindFactory *fact = (GstTypeFindFactory*) l->data;
PyList_SetItem(py_list, i,
pygstobject_new (G_OBJECT (fact)));
pygobject_new (G_OBJECT (fact)));
}
g_list_free (list);

View file

@ -135,7 +135,7 @@ _wrap_gst_bin_get_by_name(PyGObject *self, PyObject *args, PyObject *kwargs)
el = gst_bin_get_by_name(GST_BIN(self->obj), name);
/* pygobject_new handles NULL checking */
ret = pygstobject_new((GObject *)el);
ret = pygobject_new((GObject *)el);
if (el)
gst_object_unref (el); /* from get_by_name */
return ret;

View file

@ -49,7 +49,7 @@ bus_sync_handler (GstBus *bus, GstMessage *message, gpointer user_data)
/* Using N we give away our references to the args tuple */
args = Py_BuildValue ("(NN)",
pygstobject_new (G_OBJECT (bus)),
pygobject_new (G_OBJECT (bus)),
py_msg);
/* add all *args to the args tuple object */
@ -108,7 +108,7 @@ bus_func (GstBus *bus, GstMessage *message, gpointer user_data)
/* Using N we give away our references to the args tuple */
args = Py_BuildValue ("(NN)",
pygstobject_new (G_OBJECT (bus)),
pygobject_new (G_OBJECT (bus)),
py_msg);
g_assert (args);

View file

@ -41,7 +41,7 @@ _wrap_gst_element_get_pad_template(PyGObject *self, PyObject *args)
(GST_ELEMENT_GET_CLASS (self->obj), name);
if (tmpl) {
ret = pygstobject_new (G_OBJECT (tmpl));
ret = pygobject_new (G_OBJECT (tmpl));
} else {
ret = Py_None;
Py_INCREF (ret);
@ -507,7 +507,7 @@ _wrap_gst_element_get_pad_template_list(PyGObject *self)
ret = PyList_New (i);
for (i = 0 ; res ; res = g_list_next (res), i++) {
GstPadTemplate * tmpl = (GstPadTemplate *) res->data;
PyList_SetItem (ret, i, pygstobject_new (G_OBJECT (tmpl)));
PyList_SetItem (ret, i, pygobject_new (G_OBJECT (tmpl)));
}
} else {
ret = Py_None;

View file

@ -38,8 +38,8 @@ _wrap_gst_element_factory_make(PyObject *self, PyObject *args, PyObject *kwargs)
PyErr_SetString(PyGstExc_PluginNotFoundError, factoryname);
return NULL;
}
py_ret = pygstobject_new((GObject *)ret);
pygst_object_unref((GObject *)ret);
py_ret = pygobject_new((GObject *)ret);
g_object_unref((GObject *)ret);
return py_ret;
}
%%

View file

@ -207,7 +207,7 @@ _wrap_gst_message_parse_clock_provide (PyGstMiniObject *self)
gst_message_parse_clock_provide (GST_MESSAGE(self->obj), &clock, &ready);
ret = PyList_New(2);
PyList_SET_ITEM(ret, 0, pygstobject_new(G_OBJECT (clock)));
PyList_SET_ITEM(ret, 0, pygobject_new(G_OBJECT (clock)));
PyList_SET_ITEM(ret, 1, PyBool_FromLong(ready));
return ret;
@ -226,7 +226,7 @@ _wrap_gst_message_parse_clock_lost (PyGstMiniObject *self)
gst_message_parse_clock_lost (GST_MESSAGE(self->obj), &clock);
return pygstobject_new(G_OBJECT(clock));
return pygobject_new(G_OBJECT(clock));
}
%%
override gst_message_parse_new_clock noargs
@ -242,7 +242,7 @@ _wrap_gst_message_parse_new_clock (PyGstMiniObject *self)
gst_message_parse_new_clock (GST_MESSAGE(self->obj), &clock);
return pygstobject_new(G_OBJECT(clock));
return pygobject_new(G_OBJECT(clock));
}
%%
override gst_message_parse_duration noargs

View file

@ -97,6 +97,15 @@ pygstminiobject_to_gvalue(GValue *value, PyObject *obj)
return 0;
}
static void
sink_gstobject(GObject *object)
{
if (GST_OBJECT_IS_FLOATING(object)) {
g_object_ref(object);
gst_object_sink(GST_OBJECT(object));
}
}
DL_EXPORT(void)
init_gst (void)
{
@ -152,9 +161,8 @@ init_gst (void)
GST_DEBUG_CATEGORY_INIT (python_debug, "python",
GST_DEBUG_FG_GREEN, "python code using gst-python");
/* _pygst_register_boxed_types (NULL); */
pygobject_register_sinkfunc(GST_TYPE_OBJECT, pygstobject_sink);
pygobject_register_sinkfunc(GST_TYPE_OBJECT, sink_gstobject);
m = Py_InitModule ("_gst", pygst_functions);
d = PyModule_GetDict (m);

View file

@ -36,129 +36,6 @@ _wrap_gst_object__get___gstrefcount__ (PyGObject * self, void *closure)
return PyInt_FromLong (GST_OBJECT_REFCOUNT_VALUE (self->obj));
}
/* < GLib 2.8 */
/* because of our gst_object_ref/_unref, we do our own GC-related
* functions:
* our own tp_traverse that checks the GstObject refcount,
* and reuse _dealloc and _clear from gobject.GObject for ours
* compare with pygtk/gobject/pygobject.c
*/
/* a define is a little evil, but it seems to generate the right code
* to allow us to do our garbage collection routines */
%%
override-slot GstObject.tp_flags
#define _wrap_gst_object_tp_flags Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC
%%
override-slot GstObject.tp_traverse
static int
_wrap_gst_object_tp_traverse (PyGObject * self, visitproc visit, void *arg)
{
int ret = 0;
GSList *tmp;
GST_LOG_OBJECT (self->obj, "gst.Object.tp_traverse, arg:%p", arg);
if (self->inst_dict) {
ret = visit (self->inst_dict, arg);
GST_LOG_OBJECT (self->obj, "visited self->inst_dict, ret %d", ret);
}
if (ret != 0)
return ret;
for (tmp = self->closures; tmp != NULL; tmp = tmp->next) {
PyGClosure *closure = tmp->data;
GST_LOG_OBJECT (self->obj, "visiting closure %p", closure);
if (closure->callback)
ret = visit (closure->callback, arg);
if (ret != 0)
return ret;
if (closure->extra_args)
ret = visit (closure->extra_args, arg);
if (ret != 0)
return ret;
if (closure->swap_data)
ret = visit (closure->swap_data, arg);
if (ret != 0)
return ret;
}
if (self->obj && GST_OBJECT_REFCOUNT_VALUE (self->obj) == 1) {
GST_DEBUG_OBJECT (self->obj,
"gst.Object.tp_traverse: GstObject refcount of %p is 1, visit",
self->obj);
ret = visit ((PyObject *) self, arg);
GST_LOG_OBJECT (self->obj,
"gst.Object.tp_traverse: GstObject %p visited, ret %d, refcount %d",
self->obj, ret, GST_OBJECT_REFCOUNT_VALUE (self->obj));
}
return ret;
}
%%
override-slot GstObject.tp_clear
int
_wrap_gst_object_tp_clear (PyGObject * self)
{
int ret;
GObject *obj = self->obj;
/* if we're a GstObject, we want to monkeypatch the GObject.tp_clear's
* g_object_unref and "replace" it with a gst_object_unref */
if (!GST_IS_OBJECT (obj))
obj = NULL;
else {
GST_DEBUG_OBJECT (obj,
"gst.Object.tp_clear, pyo %p, pyo rc %d, gsto %p, gst rc %d",
self, ((PyObject *) self)->ob_refcnt, obj,
GST_OBJECT_REFCOUNT_VALUE (obj));
g_object_ref (obj);
}
ret = PyGObject_Type.tp_clear ((PyObject *) self);
if (obj)
gst_object_unref (obj);
return ret;
}
%%
override-slot GstObject.tp_dealloc
void
_wrap_gst_object_tp_dealloc (PyGObject * self)
{
GObject *obj = self->obj;
/* if we're a GstObject, we want to monkeypatch the GObject.tp_dealloc's
* g_object_unref and "replace" it with a gst_object_unref */
if (GST_IS_OBJECT (obj)) {
GST_DEBUG_OBJECT (obj, "gst.Object.tp_dealloc, go rc %d, gsto rc %d",
obj->ref_count, GST_OBJECT_REFCOUNT_VALUE (obj));
if (GST_OBJECT_REFCOUNT_VALUE (obj) == 0) {
/* already being finalized, can't resurrect object */
obj = NULL;
self->obj = NULL;
} else {
g_object_ref (obj);
}
} else {
obj = NULL;
}
PyGObject_Type.tp_dealloc ((PyObject *) self);
if (obj)
gst_object_unref (obj);
}
%%
override-slot GstObject.tp_repr
static PyObject *

View file

@ -94,7 +94,7 @@ pad_private(GstPad *pad)
private = g_object_get_qdata (G_OBJECT (pad), padprivate);
if (private == NULL) {
private = g_new0(PyGstPadPrivate, 1);
private->pad = (PyGObject *) pygstobject_new (G_OBJECT (pad));
private->pad = (PyGObject *) pygobject_new (G_OBJECT (pad));
Py_DECREF (private->pad);
g_object_set_qdata_full (G_OBJECT (pad), padprivate, private, free_pad_private);
}
@ -131,7 +131,7 @@ probe_handler_marshal(GstPad *pad, GstMiniObject *data, gpointer user_data)
callback = PyTuple_GetItem(py_user_data, 0);
args = Py_BuildValue("(NN)",
pygstobject_new(G_OBJECT(pad)),
pygobject_new(G_OBJECT(pad)),
py_data);
len = PyTuple_Size(py_user_data);
@ -884,7 +884,7 @@ _wrap_gst_pad_get_internal_links (PyGObject * self)
ret = PyList_New(g_list_length(lst));
for (tmp = lst, i = 0 ; tmp; tmp = g_list_next(tmp), ++i) {
PyList_SetItem(ret, i, pygstobject_new(G_OBJECT(tmp->data)));
PyList_SetItem(ret, i, pygobject_new(G_OBJECT(tmp->data)));
}
g_list_free(lst);
return ret;
@ -902,7 +902,7 @@ _wrap_gst_pad_get_internal_links_default (PyGObject * self)
ret = PyList_New(g_list_length(lst));
for (tmp = lst, i = 0 ; tmp; tmp = g_list_next(tmp), ++i) {
PyList_SetItem(ret, i, pygstobject_new(G_OBJECT(tmp->data)));
PyList_SetItem(ret, i, pygobject_new(G_OBJECT(tmp->data)));
}
g_list_free(lst);
return ret;
@ -976,7 +976,7 @@ pad_block_callback_marshal(GstPad *pad, gboolean blocked, gpointer user_data)
callback = PyTuple_GetItem(py_user_data, 0);
args = Py_BuildValue("(NO)",
pygstobject_new(G_OBJECT(pad)),
pygobject_new(G_OBJECT(pad)),
blocked ? Py_True : Py_False);
{

View file

@ -65,7 +65,7 @@ _wrap_gst_tuner_list_channels(PyGObject *self)
py_list = PyList_New(0);
for (l = list; l; l = l->next) {
GstTunerChannel *channel = (GstTunerChannel*)l->data;
PyObject *py_channel = pygstobject_new(G_OBJECT(channel));
PyObject *py_channel = pygobject_new(G_OBJECT(channel));
PyList_Append(py_list, py_channel);
Py_DECREF(py_channel);
}
@ -87,7 +87,7 @@ _wrap_gst_tuner_list_norms(PyGObject *self)
py_list = PyList_New(0);
for (l = list; l; l = l->next) {
GstTunerNorm *norm = (GstTunerNorm*)l->data;
PyObject *py_norm = pygstobject_new(G_OBJECT(norm));
PyObject *py_norm = pygobject_new(G_OBJECT(norm));
PyList_Append(py_list, py_norm);
Py_DECREF(py_norm);
}
@ -109,7 +109,7 @@ _wrap_gst_mixer_list_tracks(PyGObject *self)
py_list = PyList_New(0);
for (l = list; l; l = l->next) {
GstMixerTrack *track = (GstMixerTrack*)l->data;
PyObject *py_track = pygstobject_new(G_OBJECT(track));
PyObject *py_track = pygobject_new(G_OBJECT(track));
PyList_Append(py_list, py_track);
Py_DECREF(py_track);
}
@ -131,7 +131,7 @@ _wrap_gst_color_balance_list_channels(PyGObject *self)
py_list = PyList_New(0);
for (l = list; l; l = l->next) {
GstColorBalanceChannel *channel = (GstColorBalanceChannel*)l->data;
PyObject *py_channel = pygstobject_new(G_OBJECT(channel));
PyObject *py_channel = pygobject_new(G_OBJECT(channel));
PyList_Append(py_list, py_channel);
Py_DECREF(py_channel);
}

View file

@ -43,10 +43,7 @@ pygst_iterator_iter_next(PyGstIterator *self)
PyErr_SetNone(PyExc_StopIteration);
break;
case GST_ITERATOR_OK:
if (g_type_is_a(self->iter->type, GST_TYPE_OBJECT)) {
retval = pygstobject_new(G_OBJECT(element));
pygst_object_unref (element);
} else if (g_type_is_a(self->iter->type, G_TYPE_OBJECT)) {
if (g_type_is_a(self->iter->type, G_TYPE_OBJECT)) {
retval = pygobject_new(G_OBJECT(element));
g_object_unref (element);
} else if (g_type_is_a(self->iter->type, GST_TYPE_MINI_OBJECT)) {

View file

@ -1,124 +0,0 @@
/* -*- Mode: C; ; c-file-style: "k&r"; c-basic-offset: 4 -*- */
/* gst-python
* Copyright (C) 2002 David I. Lehn
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David I. Lehn <dlehn@users.sourceforge.net>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "pygstobject.h"
#include <locale.h>
/* include this first, before NO_IMPORT_PYGOBJECT is defined */
#include <pygobject.h>
#include <gst/gst.h>
#include <gst/gstversion.h>
GST_DEBUG_CATEGORY_EXTERN (pygst_debug);
#define GST_CAT_DEFAULT pygst_debug
/* we reuse the same string for our quark so we get the same qdata;
* it might be worth it to use our own to shake out all instances
* were GObject-only calls are being used where we should be using
* gst_object_ */
static const gchar *pygobject_wrapper_id = "PyGObject::wrapper";
static GQuark pygobject_wrapper_key = 0;
/* only use on GstObject */
void
pygstobject_sink(GObject *object)
{
g_assert (GST_IS_OBJECT (object));
if (GST_OBJECT_IS_FLOATING(object)) {
gst_object_ref(GST_OBJECT(object));
gst_object_sink(GST_OBJECT(object));
}
}
/* functions used by the code generator we can call on both
* GstObject and non-GstObject GObjects
*/
/* to be called instead of pygobject_new */
PyObject *
pygstobject_new(GObject *obj)
{
PyGObject *self = NULL;
if (!GST_IS_OBJECT (obj))
return pygobject_new (obj);
GST_DEBUG_OBJECT (obj, "wrapping GstObject");
if (!pygobject_wrapper_key)
pygobject_wrapper_key = g_quark_from_static_string(pygobject_wrapper_id);
if (obj == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
/* we already have a wrapper for this object -- return it. */
self = (PyGObject *)g_object_get_qdata(obj, pygobject_wrapper_key);
if (self != NULL) {
Py_INCREF(self);
} else {
/* create wrapper */
PyTypeObject *tp = pygobject_lookup_class(G_OBJECT_TYPE(obj));
/* need to bump type refcount if created with
pygobject_new_with_interfaces(). fixes bug #141042 */
if (tp->tp_flags & Py_TPFLAGS_HEAPTYPE)
Py_INCREF(tp);
self = PyObject_GC_New(PyGObject, tp);
if (self == NULL)
return NULL;
pyg_begin_allow_threads;
self->obj = gst_object_ref(obj);
pyg_end_allow_threads;
pygstobject_sink(self->obj);
self->inst_dict = NULL;
self->weakreflist = NULL;
self->closures = NULL;
/* save wrapper pointer so we can access it later */
Py_INCREF(self);
g_object_set_qdata_full(obj, pygobject_wrapper_key, self,
pyg_destroy_notify);
PyObject_GC_Track((PyObject *)self);
}
GST_DEBUG_OBJECT (obj, "wrapped GstObject %p as PyObject %p", obj, self);
return (PyObject *)self;
}
/* to be called instead of g_object_unref */
void
pygst_object_unref(GObject *obj)
{
if (GST_IS_OBJECT (obj)) {
GST_DEBUG_OBJECT (obj, "unreffing GstObject %p", obj);
gst_object_unref (obj);
} else
g_object_unref (obj);
}

View file

@ -1,36 +0,0 @@
/* -*- Mode: C; ; c-file-style: "k&r"; c-basic-offset: 4 -*- */
/* gst-python
* Copyright (C) 2002 David I. Lehn
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David I. Lehn <dlehn@users.sourceforge.net>
*/
#ifndef _PYGSTOBJECT_H_
#define _PYGSTOBJECT_H_
#include "common.h"
G_BEGIN_DECLS
void pygstobject_sink(GObject *object);
PyObject * pygstobject_new(GObject *obj);
void pygst_object_unref(GObject *obj);
G_END_DECLS
#endif /* !_PYGSTOBJECT_H_ */