Commit 417945c1 authored by Olivier Aubert's avatar Olivier Aubert

python bindings, vlc_mediacontrol.c: use PyObject_DEL + cache

vlcInstance reference in MediaControl object (patch by Jan David Mol)
parent 17ce364a
...@@ -42,7 +42,6 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) ...@@ -42,7 +42,6 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
if( PyArg_ParseTuple( args, "O", &py_param ) ) if( PyArg_ParseTuple( args, "O", &py_param ) )
{ {
Py_INCREF( py_param );
if( PyObject_TypeCheck( py_param, &vlcInstance_Type ) == 1 ) if( PyObject_TypeCheck( py_param, &vlcInstance_Type ) == 1 )
{ {
p_instance = ((vlcInstance*)py_param)->p_instance; p_instance = ((vlcInstance*)py_param)->p_instance;
...@@ -51,6 +50,7 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) ...@@ -51,6 +50,7 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{ {
Py_ssize_t i_index; Py_ssize_t i_index;
Py_INCREF( py_param );
if( ! PySequence_Check( py_param ) ) if( ! PySequence_Check( py_param ) )
{ {
PyErr_SetString( PyExc_TypeError, "Parameter must be a vlc.Instance or a sequence of strings." ); PyErr_SetString( PyExc_TypeError, "Parameter must be a vlc.Instance or a sequence of strings." );
...@@ -74,8 +74,8 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) ...@@ -74,8 +74,8 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
i_index ) ) ) ); i_index ) ) ) );
} }
ppsz_args[i_size] = NULL; ppsz_args[i_size] = NULL;
Py_DECREF( py_param );
} }
Py_DECREF( py_param );
} }
else else
{ {
...@@ -89,10 +89,14 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) ...@@ -89,10 +89,14 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
if( p_instance ) if( p_instance )
{ {
self->mc = mediacontrol_new_from_instance( p_instance, exception ); self->mc = mediacontrol_new_from_instance( p_instance, exception );
Py_INCREF( py_param );
self->vlc_instance = py_param;
} }
else else
{ {
self->mc = mediacontrol_new( i_size, ppsz_args, exception ); self->mc = mediacontrol_new( i_size, ppsz_args, exception );
self->vlc_instance = PyObject_New( vlcInstance, &vlcInstance_Type );
self->vlc_instance->p_instance = mediacontrol_get_libvlc_instance( SELF->mc );
} }
MC_EXCEPT; MC_EXCEPT;
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
...@@ -104,7 +108,8 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) ...@@ -104,7 +108,8 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
static void static void
MediaControl_dealloc( PyObject *self ) MediaControl_dealloc( PyObject *self )
{ {
PyMem_DEL( self ); Py_DECREF( SELF->vlc_instance );
PyObject_DEL( self );
} }
static PyObject * static PyObject *
...@@ -112,10 +117,8 @@ MediaControl_get_vlc_instance( PyObject *self, PyObject *args ) ...@@ -112,10 +117,8 @@ MediaControl_get_vlc_instance( PyObject *self, PyObject *args )
{ {
vlcInstance *p_ret; vlcInstance *p_ret;
p_ret = PyObject_New( vlcInstance, &vlcInstance_Type ); p_ret = SELF->vlc_instance;
if( !p_ret ) Py_INCREF( p_ret );
return NULL;
p_ret->p_instance = mediacontrol_get_libvlc_instance( SELF->mc );
return ( PyObject * )p_ret; return ( PyObject * )p_ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment