File: gda-arg-types.py

package info (click to toggle)
gnome-python-extras 2.19.1-3.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,640 kB
  • ctags: 736
  • sloc: sh: 8,856; ansic: 5,031; xml: 1,319; python: 769; makefile: 460
file content (26 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import argtypes

class GValueArg(argtypes.ArgType):
    def write_param(self, ptype, pname, pdflt, pnull, info):
        info.varlist.add('GValue', pname + ' = { 0 }')
        info.varlist.add('PyObject', '*py_' + pname)
        info.codebefore.append('    pygda_value_from_pyobject(&%s, py_%s);\n' % (pname, pname))
        info.codeafter.append('    if(G_IS_VALUE(&%s)) g_value_unset(&%s);\n' % (pname, pname))
        info.arglist.append('&' + pname)
        info.add_parselist('O', ['&py_' + pname], [pname])

    def write_return(self, ptype, ownsreturn, info):
        if(ptype == 'const-GValue*'):
            info.varlist.add('const GValue', '*ret')
        else:
            info.varlist.add('GValue', '*ret')
        info.varlist.add('PyObject', '*pyret')

        info.codeafter.append('    pyret = pygda_value_as_pyobject(ret, TRUE);\n')
        if ownsreturn:
            info.codeafter.append('    if(G_IS_VALUE(ret)) g_value_unset(ret);\n')
        info.codeafter.append('    return pyret;')

arg = GValueArg()
argtypes.matcher.register('GValue*', arg)
argtypes.matcher.register('const-GValue*', arg)