summaryrefslogtreecommitdiff
path: root/gi/pygi-resulttuple.h
diff options
context:
space:
mode:
authorChristoph Reiter <creiter@src.gnome.org>2015-06-08 18:14:08 +0200
committerChristoph Reiter <creiter@src.gnome.org>2015-10-27 09:30:45 +0100
commit175d10665472e6f4090d707e3b89255814c932b1 (patch)
tree9686dacb6aa22489ebe62832cb85fb5447fed396 /gi/pygi-resulttuple.h
parentb1788c9a445c8a820121c42260bcbdbc3ae8dfba (diff)
downloadpygobject-175d10665472e6f4090d707e3b89255814c932b1.tar.gz
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
Diffstat (limited to 'gi/pygi-resulttuple.h')
-rw-r--r--gi/pygi-resulttuple.h34
1 files changed, 34 insertions, 0 deletions
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 <reiter.christoph@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#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__ */