-
Notifications
You must be signed in to change notification settings - Fork 58
/
wrapperbuilder.py
48 lines (41 loc) · 1.85 KB
/
wrapperbuilder.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright 2012 David Malcolm <dmalcolm@redhat.com>
# Copyright 2012 Red Hat, Inc.
#
# This is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
# Shared code for gcc-python-plugin's generate-*-c.py, where the code
# is specific to gcc-python-plugin
from cpybuilder import PyTypeObject, with_gcc_extensions
def indent(lines):
return '\n'.join(' %s' % line for line in lines.splitlines())
class PyGccWrapperTypeObject(PyTypeObject):
"""
A PyTypeObject that's also a PyGccWrapperTypeObject
(with metaclass PyGccWrapperMeta_TypeObj)
"""
def __init__(self, *args, **kwargs):
PyTypeObject.__init__(self, *args, **kwargs)
self.ob_type = '&PyGccWrapperMeta_TypeObj'
def c_defn(self):
result = '\n'
result += 'PyGccWrapperTypeObject %(identifier)s = {\n' % self.__dict__
result += self.c_src_field_value('wrtp_base',
'{\n .ht_type = {\n%s}' % indent(indent(self.c_initializer())))
result += ' },\n'
result += self.c_src_field_value('wrtp_mark',
'PyGcc_WrtpMarkFor%s' % self.struct_name,
cast='wrtp_marker')
result += '};\n'
result +='\n'
return result