From 175d10665472e6f4090d707e3b89255814c932b1 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Mon, 8 Jun 2015 18:14:08 +0200 Subject: Use a named tuple for returning multiple values >>> v = Gtk.Button().get_alignment() >>> v (xalign=0.5, yalign=0.5) >>> v.xalign 0.5 For each GICallable a new gi._gi.ResultTuple subclass is created which knows the return value names of that callable and displays them in __repr__, __dir__ and allows to access tuple items by name. The subclass is cached in PyGICallableCache. To reduce the number of small tuple allocations use a free list similar to the one used for pure tuples in CPython. https://bugzilla.gnome.org/show_bug.cgi?id=727374 --- gi/pygi-resulttuple.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 gi/pygi-resulttuple.h (limited to 'gi/pygi-resulttuple.h') diff --git a/gi/pygi-resulttuple.h b/gi/pygi-resulttuple.h new file mode 100644 index 00000000..3f63ca0c --- /dev/null +++ b/gi/pygi-resulttuple.h @@ -0,0 +1,34 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * vim: tabstop=4 shiftwidth=4 expandtab + * + * Copyright (C) 2015 Christoph Reiter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef __PYGI_RESULTTUPLE_H__ +#define __PYGI_RESULTTUPLE_H__ + +#include "Python.h" + +int +pygi_resulttuple_register_types (PyObject *d); + +PyTypeObject * +pygi_resulttuple_new_type (PyObject *tuple_names); + +PyObject* +pygi_resulttuple_new (PyTypeObject *subclass, Py_ssize_t len); + +#endif /* __PYGI_RESULTTUPLE_H__ */ -- cgit v1.2.1