Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03be7f5

Browse files
committed
Changes by jack so the generated modules export their types
to Python.
1 parent a755e68 commit 03be7f5

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

Tools/bgen/bgen/bgenModule.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ def __init__(self, name, prefix = None,
1414
self.initstuff = initstuff
1515
self.finalstuff = finalstuff
1616
self.variablestuff = variablestuff
17+
self.typeobjects = []
1718

1819
def addobject(self, od):
1920
self.generators.append(od)
21+
self.typeobjects.append(od)
2022

2123
def generate(self):
2224
OutHeader1("Module " + self.name)
@@ -66,6 +68,8 @@ def createModuleVariables(self):
6668
Output("""Py_FatalError("can't initialize %s.Error");""",
6769
self.name)
6870
DedentLevel()
71+
for tp in self.typeobjects:
72+
tp.outputTypeObjectInitializer()
6973
if self.variablestuff:
7074
Output("%s", self.variablestuff)
7175
Output()

Tools/bgen/bgen/bgenObjectDefinition.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ def outputTypeObject(self):
170170
Output("(setattrfunc) %s_setattr, /*tp_setattr*/", self.prefix)
171171
DedentLevel()
172172
Output("};")
173+
174+
def outputTypeObjectInitializer(self):
175+
Output("""%s.ob_type = &PyType_Type;""", self.typename);
176+
Output("""Py_INCREF(&%s);""", self.typename);
177+
Output("""if (PyDict_SetItemString(d, "%sType", (PyObject *)&%s) != 0)""",
178+
self.name, self.typename);
179+
IndentLevel()
180+
Output("""Py_FatalError("can't initialize %sType");""",
181+
self.name)
182+
DedentLevel()
183+
173184

174185

175186
class GlobalObjectDefinition(ObjectDefinition):

Tools/bgen/bgen/bgenlocations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
#
44

55
# Where to find the Universal Header include files:
6-
INCLUDEDIR="Sap:CW8 Gold:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:"
6+
MWERKSDIR="Moes:Metrowerks:Metrowerks CodeWarrior:"
7+
INCLUDEDIR=MWERKSDIR + "MacOS Support:Headers:Universal Headers:"
78

89
# Where to put the python definitions file:
9-
TOOLBOXDIR="Moes:Development:Jack:Python 1.3:Mac:Lib:toolbox:"
10+
TOOLBOXDIR="Moes:Development:Jack:Python:Mac:Lib:toolbox:"
1011

1112
# Creator for C files:
1213
CREATOR="CWIE"

0 commit comments

Comments
 (0)