mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
Added 'keeprefcount' argument for function/method parameters in order to cope with functions/methods that decrement t...
Original commit message from CVS: * codegen/argtypes.py: * codegen/codegen.py: * codegen/definitions.py: * gst/arg-types.py: Added 'keeprefcount' argument for function/method parameters in order to cope with functions/methods that decrement the refcount of the given parameter * gst/gst.defs: Added 'keeprefcount' for buffer argument of gst_pad_push() wrapper.
This commit is contained in:
parent
9d7ce16b6a
commit
16bb9b838e
6 changed files with 59 additions and 35 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2005-10-05 Edward Hervey <edward@fluendo.com>
|
||||
|
||||
* codegen/argtypes.py:
|
||||
* codegen/codegen.py:
|
||||
* codegen/definitions.py:
|
||||
* gst/arg-types.py:
|
||||
Added 'keeprefcount' argument for function/method parameters in order to
|
||||
cope with functions/methods that decrement the refcount of the given
|
||||
parameter
|
||||
* gst/gst.defs:
|
||||
Added 'keeprefcount' for buffer argument of gst_pad_push() wrapper.
|
||||
|
||||
2005-10-05 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* gst/__init__.py:
|
||||
|
|
|
@ -84,7 +84,7 @@ class NoneArg(ArgType):
|
|||
' return Py_None;')
|
||||
|
||||
class StringArg(ArgType):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
if pdflt != 'NULL': pdflt = '"' + pdflt + '"'
|
||||
info.varlist.add('char', '*' + pname + ' = ' + pdflt)
|
||||
|
@ -115,7 +115,7 @@ class StringArg(ArgType):
|
|||
|
||||
class UCharArg(ArgType):
|
||||
# allows strings with embedded NULLs.
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add('guchar', '*' + pname + ' = "' + pdflt + '"')
|
||||
else:
|
||||
|
@ -130,7 +130,7 @@ class UCharArg(ArgType):
|
|||
[pname])
|
||||
|
||||
class CharArg(ArgType):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add('char', pname + " = '" + pdflt + "'")
|
||||
else:
|
||||
|
@ -149,7 +149,7 @@ class GUniCharArg(ArgType):
|
|||
'#endif\n'
|
||||
' py_ret = (Py_UNICODE)ret;\n'
|
||||
' return PyUnicode_FromUnicode(&py_ret, 1);\n')
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add('gunichar', pname + " = '" + pdflt + "'")
|
||||
else:
|
||||
|
@ -163,7 +163,7 @@ class GUniCharArg(ArgType):
|
|||
|
||||
|
||||
class IntArg(ArgType):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add('int', pname + ' = ' + pdflt)
|
||||
else:
|
||||
|
@ -175,7 +175,7 @@ class IntArg(ArgType):
|
|||
info.codeafter.append(' return PyInt_FromLong(ret);')
|
||||
|
||||
class UIntArg(ArgType):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add(ptype, pname + ' = ' + pdflt)
|
||||
else:
|
||||
|
@ -193,7 +193,7 @@ class SizeArg(ArgType):
|
|||
else:
|
||||
llp64 = False
|
||||
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add(ptype, pname + ' = ' + pdflt)
|
||||
else:
|
||||
|
@ -217,7 +217,7 @@ class SSizeArg(ArgType):
|
|||
else:
|
||||
llp64 = False
|
||||
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add(ptype, pname + ' = ' + pdflt)
|
||||
else:
|
||||
|
@ -235,7 +235,7 @@ class SSizeArg(ArgType):
|
|||
info.codeafter.append(' return PyLong_FromLong(ret);\n')
|
||||
|
||||
class LongArg(ArgType):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add(ptype, pname + ' = ' + pdflt)
|
||||
else:
|
||||
|
@ -252,7 +252,7 @@ class BoolArg(IntArg):
|
|||
info.codeafter.append(' return PyBool_FromLong(ret);\n')
|
||||
|
||||
class TimeTArg(ArgType):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add('time_t', pname + ' = ' + pdflt)
|
||||
else:
|
||||
|
@ -267,7 +267,7 @@ class ULongArg(ArgType):
|
|||
dflt = ' if (py_%(name)s)\n' \
|
||||
' %(name)s = PyLong_AsUnsignedLong(py_%(name)s);\n'
|
||||
before = ' %(name)s = PyLong_AsUnsignedLong(py_%(name)s);\n'
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add('gulong', pname + ' = ' + pdflt)
|
||||
info.codebefore.append(self.dflt % {'name':pname})
|
||||
|
@ -282,7 +282,7 @@ class ULongArg(ArgType):
|
|||
info.codeafter.append(' return PyLong_FromUnsignedLong(ret);')
|
||||
|
||||
class Int64Arg(ArgType):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add('gint64', pname + ' = ' + pdflt)
|
||||
else:
|
||||
|
@ -297,7 +297,7 @@ class UInt64Arg(ArgType):
|
|||
dflt = ' if (py_%(name)s)\n' \
|
||||
' %(name)s = PyLong_AsUnsignedLongLong(py_%(name)s);\n'
|
||||
before = ' %(name)s = PyLong_AsUnsignedLongLong(py_%(name)s);\n'
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add('guint64', pname + ' = ' + pdflt)
|
||||
info.codebefore.append(self.dflt % {'name':pname})
|
||||
|
@ -313,7 +313,7 @@ class UInt64Arg(ArgType):
|
|||
|
||||
|
||||
class DoubleArg(ArgType):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add('double', pname + ' = ' + pdflt)
|
||||
else:
|
||||
|
@ -341,7 +341,7 @@ class FileArg(ArgType):
|
|||
' }\n')
|
||||
dflt = (' if (py_%(name)s)\n'
|
||||
' %(name)s = PyFile_AsFile(py_%(name)s);\n')
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pnull:
|
||||
if pdflt:
|
||||
info.varlist.add('FILE', '*' + pname + ' = ' + pdflt)
|
||||
|
@ -376,7 +376,7 @@ class EnumArg(ArgType):
|
|||
def __init__(self, enumname, typecode):
|
||||
self.enumname = enumname
|
||||
self.typecode = typecode
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add(self.enumname, pname + ' = ' + pdflt)
|
||||
else:
|
||||
|
@ -396,7 +396,7 @@ class FlagsArg(ArgType):
|
|||
def __init__(self, flagname, typecode):
|
||||
self.flagname = flagname
|
||||
self.typecode = typecode
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add(self.flagname, pname + ' = ' + pdflt)
|
||||
default = "py_%s && " % (pname,)
|
||||
|
@ -436,7 +436,7 @@ class ObjectArg(ArgType):
|
|||
self.objname = objname
|
||||
self.cast = string.replace(typecode, '_TYPE_', '_', 1)
|
||||
self.parent = parent
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pnull:
|
||||
if pdflt:
|
||||
info.varlist.add(self.objname, '*' + pname + ' = ' + pdflt)
|
||||
|
@ -504,7 +504,7 @@ class MiniObjectArg(ArgType):
|
|||
self.objname = objname
|
||||
self.cast = string.replace(typecode, '_TYPE_', '_', 1)
|
||||
self.parent = parent
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pnull:
|
||||
if pdflt:
|
||||
info.varlist.add(self.objname, '*' + pname + ' = ' + pdflt)
|
||||
|
@ -534,6 +534,8 @@ class MiniObjectArg(ArgType):
|
|||
info.arglist.append('%s(%s->obj)' % (self.cast, pname))
|
||||
info.add_parselist('O!', ['&Py%s_Type' % self.objname,
|
||||
'&' + pname], [pname])
|
||||
if keeprefcount:
|
||||
info.codebefore.append(' gst_mini_object_ref(GST_MINI_OBJECT(%s));\n' % pname)
|
||||
def write_return(self, ptype, ownsreturn, info):
|
||||
if ptype[-1] == '*': ptype = ptype[:-1]
|
||||
info.varlist.add(ptype, '*ret')
|
||||
|
@ -564,7 +566,7 @@ class BoxedArg(ArgType):
|
|||
def __init__(self, ptype, typecode):
|
||||
self.typename = ptype
|
||||
self.typecode = typecode
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pnull:
|
||||
info.varlist.add(self.typename, '*' + pname + ' = NULL')
|
||||
info.varlist.add('PyObject', '*py_' + pname + ' = Py_None')
|
||||
|
@ -615,7 +617,7 @@ class CustomBoxedArg(ArgType):
|
|||
self.getter = getter
|
||||
self.checker = 'Py' + ptype + '_Check'
|
||||
self.new = new
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pnull:
|
||||
info.varlist.add(ptype[:-1], '*' + pname + ' = NULL')
|
||||
info.varlist.add('PyObject', '*py_' + pname + ' = Py_None')
|
||||
|
@ -653,7 +655,7 @@ class PointerArg(ArgType):
|
|||
def __init__(self, ptype, typecode):
|
||||
self.typename = ptype
|
||||
self.typecode = typecode
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pnull:
|
||||
info.varlist.add(self.typename, '*' + pname + ' = NULL')
|
||||
info.varlist.add('PyObject', '*py_' + pname + ' = Py_None')
|
||||
|
@ -687,7 +689,7 @@ class AtomArg(IntArg):
|
|||
atom = (' %(name)s = pygdk_atom_from_pyobject(py_%(name)s);\n'
|
||||
' if (PyErr_Occurred())\n'
|
||||
' return NULL;\n')
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
info.varlist.add('GdkAtom', pname + ' = ' + pdflt)
|
||||
info.varlist.add('PyObject', '*py_' + pname + ' = NULL')
|
||||
|
@ -705,7 +707,7 @@ class AtomArg(IntArg):
|
|||
class GTypeArg(ArgType):
|
||||
gtype = (' if ((%(name)s = pyg_type_from_object(py_%(name)s)) == 0)\n'
|
||||
' return NULL;\n')
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
info.varlist.add('GType', pname)
|
||||
info.varlist.add('PyObject', '*py_' + pname + ' = NULL')
|
||||
info.codebefore.append(self.gtype % {'name': pname})
|
||||
|
@ -719,7 +721,7 @@ class GTypeArg(ArgType):
|
|||
class GErrorArg(ArgType):
|
||||
handleerror = (' if (pyg_error_check(&%(name)s))\n'
|
||||
' return NULL;\n')
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
info.varlist.add('GError', '*' + pname + ' = NULL')
|
||||
info.arglist.append('&' + pname)
|
||||
info.codeafter.append(self.handleerror % { 'name': pname })
|
||||
|
@ -742,7 +744,7 @@ class GtkTreePathArg(ArgType):
|
|||
' gtk_tree_path_free(%(name)s);\n')
|
||||
def __init__(self):
|
||||
pass
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pnull:
|
||||
info.varlist.add('GtkTreePath', '*' + pname + ' = NULL')
|
||||
info.varlist.add('PyObject', '*py_' + pname + ' = Py_None')
|
||||
|
@ -783,7 +785,7 @@ class GdkRectanglePtrArg(ArgType):
|
|||
' %(name)s = &%(name)s_rect;\n'
|
||||
' else\n'
|
||||
' return NULL;\n')
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pnull:
|
||||
info.varlist.add('GdkRectangle', pname + '_rect = { 0, 0, 0, 0 }')
|
||||
info.varlist.add('GdkRectangle', '*' + pname)
|
||||
|
@ -804,7 +806,7 @@ class GdkRectangleArg(ArgType):
|
|||
info.codeafter.append(' return pyg_boxed_new(GDK_TYPE_RECTANGLE, &ret, TRUE, TRUE);')
|
||||
|
||||
class PyObjectArg(ArgType):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
info.varlist.add('PyObject', '*' + pname)
|
||||
info.add_parselist('O', ['&' + pname], [pname])
|
||||
info.arglist.append(pname)
|
||||
|
@ -852,6 +854,7 @@ class ArgMatcher:
|
|||
self.register('GdkBitmap*', oa)
|
||||
def register_miniobject(self, ptype, parent, typecode):
|
||||
oa = MiniObjectArg(ptype, parent, typecode)
|
||||
self.register(ptype, oa) # in case I forget the * in the .defs
|
||||
self.register(ptype+'*', oa)
|
||||
def register_boxed(self, ptype, typecode):
|
||||
if self.argtypes.has_key(ptype): return
|
||||
|
|
|
@ -280,7 +280,7 @@ class Wrapper:
|
|||
info.add_parselist('|', [], [])
|
||||
handler = argtypes.matcher.get(param.ptype)
|
||||
handler.write_param(param.ptype, param.pname, param.pdflt,
|
||||
param.pnull, info)
|
||||
param.pnull, param.keeprefcount, info)
|
||||
|
||||
substdict['setreturn'] = ''
|
||||
if handle_return:
|
||||
|
|
|
@ -7,11 +7,12 @@ def get_valid_scheme_definitions(defs):
|
|||
|
||||
# New Parameter class, wich emulates a tuple for compatibility reasons
|
||||
class Parameter(object):
|
||||
def __init__(self, ptype, pname, pdflt, pnull, prop=None):
|
||||
def __init__(self, ptype, pname, pdflt, pnull, prop=None, keeprefcount=False):
|
||||
self.ptype = ptype
|
||||
self.pname = pname
|
||||
self.pdflt = pdflt
|
||||
self.pnull = pnull
|
||||
self.keeprefcount = keeprefcount
|
||||
|
||||
def __len__(self): return 4
|
||||
def __getitem__(self, i):
|
||||
|
@ -340,13 +341,17 @@ class MethodDefBase(Definition):
|
|||
pname = parg[1]
|
||||
pdflt = None
|
||||
pnull = 0
|
||||
keeprefcount = False
|
||||
for farg in parg[2:]:
|
||||
assert isinstance(farg, tuple)
|
||||
if farg[0] == 'default':
|
||||
pdflt = farg[1]
|
||||
elif farg[0] == 'null-ok':
|
||||
pnull = 1
|
||||
self.params.append(Parameter(ptype, pname, pdflt, pnull))
|
||||
elif farg[0] == 'keep-refcount':
|
||||
keeprefcount = True
|
||||
self.params.append(Parameter(ptype, pname, pdflt, pnull,
|
||||
keeprefcount=keeprefcount))
|
||||
elif arg[0] == 'varargs':
|
||||
self.varargs = arg[1] in ('t', '#t')
|
||||
elif arg[0] == 'deprecated':
|
||||
|
@ -448,12 +453,16 @@ class FunctionDef(Definition):
|
|||
pname = parg[1]
|
||||
pdflt = None
|
||||
pnull = 0
|
||||
keeprefcount = False
|
||||
for farg in parg[2:]:
|
||||
if farg[0] == 'default':
|
||||
pdflt = farg[1]
|
||||
elif farg[0] == 'null-ok':
|
||||
pnull = 1
|
||||
self.params.append(Parameter(ptype, pname, pdflt, pnull))
|
||||
elif farg[0] == 'keep-refcount':
|
||||
keeprefcount = True
|
||||
self.params.append(Parameter(ptype, pname, pdflt, pnull,
|
||||
keeprefcount = keeprefcount))
|
||||
elif arg[0] == 'properties':
|
||||
if self.is_constructor_of is None:
|
||||
print >> sys.stderr, "Warning: (properties ...) "\
|
||||
|
|
|
@ -50,7 +50,7 @@ class XmlNodeArg(ArgType):
|
|||
' PyTuple_SetItem(xargs, 0, o);\n'
|
||||
' return PyInstance_New(xobj, xargs, PyDict_New());\n')
|
||||
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
info.varlist.add('PyObject', '*xml = _gst_get_libxml2_module()')
|
||||
info.varlist.add('PyObject', '*o')
|
||||
info.varlist.add('PyObject', '*xobj')
|
||||
|
@ -90,7 +90,7 @@ class GstCapsArg(ArgType):
|
|||
after = (' if (%(name)s && %(name)s_is_copy)\n'
|
||||
' gst_caps_unref (%(name)s);\n')
|
||||
|
||||
def write_param(self, ptype, pname, pdflt, pnull, info):
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if ptype == 'const-GstCaps*':
|
||||
self.write_const_param(pname, pdflt, pnull, info)
|
||||
elif ptype == 'GstCaps*':
|
||||
|
|
|
@ -3358,7 +3358,7 @@
|
|||
(c-name "gst_pad_push")
|
||||
(return-type "GstFlowReturn")
|
||||
(parameters
|
||||
'("GstBuffer*" "buffer")
|
||||
'("GstBuffer*" "buffer" (keep-refcount))
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue