mirror of https://github.com/KLayout/klayout.git
Also provide 'void to self' return values for Python.
This commit is contained in:
parent
5608327899
commit
a20f0d5891
|
|
@ -686,6 +686,15 @@ property_name_from_id (int mid, PyObject *self)
|
|||
return cls_decl->name () + "." + mt->property_name (mid);
|
||||
}
|
||||
|
||||
static gsi::ArgType create_void_type ()
|
||||
{
|
||||
gsi::ArgType at;
|
||||
at.init<void> ();
|
||||
return at;
|
||||
}
|
||||
|
||||
static gsi::ArgType s_void_type = create_void_type ();
|
||||
|
||||
static PyObject *
|
||||
get_return_value (PYAObjectBase *self, gsi::SerialArgs &retlist, const gsi::MethodBase *meth, tl::Heap &heap)
|
||||
{
|
||||
|
|
@ -696,6 +705,12 @@ get_return_value (PYAObjectBase *self, gsi::SerialArgs &retlist, const gsi::Meth
|
|||
gsi::IterAdaptorAbstractBase *iter = (gsi::IterAdaptorAbstractBase *) retlist.read<gsi::IterAdaptorAbstractBase *> (heap);
|
||||
ret = (PyObject *) PYAIteratorObject::create (self ? self->py_object () : 0, iter, &meth->ret_type ());
|
||||
|
||||
} else if (meth->ret_type () == s_void_type && self != 0) {
|
||||
|
||||
// simple, yet magical :)
|
||||
ret = self->py_object ();
|
||||
Py_INCREF (ret);
|
||||
|
||||
} else {
|
||||
|
||||
ret = pop_arg (meth->ret_type (), retlist, self, heap).release ();
|
||||
|
|
|
|||
|
|
@ -728,6 +728,17 @@ class DBPolygonTests(unittest.TestCase):
|
|||
self.assertEqual(str(p1), "(21,42;21,62;41,62;41,42)")
|
||||
self.assertEqual(str(pp), "(21,42;21,62;41,62;41,42)")
|
||||
|
||||
def test_voidMethodsReturnSelf(self):
|
||||
|
||||
hull = [ pya.Point(0, 0), pya.Point(6000, 0),
|
||||
pya.Point(6000, 3000), pya.Point(0, 3000) ]
|
||||
hole1 = [ pya.Point(1000, 1000), pya.Point(2000, 1000),
|
||||
pya.Point(2000, 2000), pya.Point(1000, 2000) ]
|
||||
hole2 = [ pya.Point(3000, 1000), pya.Point(4000, 1000),
|
||||
pya.Point(4000, 2000), pya.Point(3000, 2000) ]
|
||||
poly = pya.Polygon(hull).insert_hole(hole1).insert_hole(hole2)
|
||||
self.assertEqual(str(poly), "(0,0;0,3000;6000,3000;6000,0/1000,1000;2000,1000;2000,2000;1000,2000/3000,1000;4000,1000;4000,2000;3000,2000)")
|
||||
|
||||
# run unit tests
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(DBPolygonTests)
|
||||
|
|
|
|||
Loading…
Reference in New Issue