From c45311ac3845f42488590acc83c90034066efbde Mon Sep 17 00:00:00 2001 From: John Ehresman Date: Tue, 13 Apr 2010 16:22:45 -0400 Subject: Don't pregenerate numerical constants in constants.py; adapted from a John Stower patch --- gobject/.gitignore | 3 -- gobject/Makefile.am | 13 --------- gobject/constants.py | 66 ++++++++++++++++++++++++++++++++++++++++++++ gobject/constants.py.in | 50 --------------------------------- gobject/generate-constants.c | 44 ----------------------------- gobject/gobjectmodule.c | 16 +++++++++++ 6 files changed, 82 insertions(+), 110 deletions(-) delete mode 100644 gobject/.gitignore create mode 100644 gobject/constants.py delete mode 100644 gobject/constants.py.in delete mode 100644 gobject/generate-constants.c diff --git a/gobject/.gitignore b/gobject/.gitignore deleted file mode 100644 index 5efe4c7..0000000 --- a/gobject/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Autogenerated with 'generate-constants.c'. -generate-constants -constants.py diff --git a/gobject/Makefile.am b/gobject/Makefile.am index e5d7f7b..1f9d0ac 100644 --- a/gobject/Makefile.am +++ b/gobject/Makefile.am @@ -19,19 +19,6 @@ if PLATFORM_WIN32 common_ldflags += -no-undefined endif -constants.py: generate-constants$(EXEEXT) constants.py.in - rm -f constants.py - cp $(srcdir)/constants.py.in constants.py - chmod 644 constants.py - $(top_builddir)/gobject/generate-constants$(EXEEXT) >> constants.py - chmod 444 constants.py - -generate_constants_CFLAGS = $(GLIB_CFLAGS) $(PYTHON_INCLUDES) - -noinst_PROGRAMS = generate-constants -CLEANFILES = constants.py -EXTRA_DIST = constants.py.in - _gobject_la_CFLAGS = \ -I$(top_srcdir)/glib \ $(PYTHON_INCLUDES) \ diff --git a/gobject/constants.py b/gobject/constants.py new file mode 100644 index 0000000..e02d8e9 --- /dev/null +++ b/gobject/constants.py @@ -0,0 +1,66 @@ +# -*- Mode: Python; py-indent-offset: 4 -*- +# pygobject - Python bindings for the GObject library +# Copyright (C) 2006-2007 Johan Dahlin +# +# gobject/constants.py: GObject type constants +# +# 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, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 +# USA + +import sys + +import gobject._gobject +_gobject = sys.modules['gobject._gobject'] + +# TYPE_INVALID defined in gobjectmodule.c +TYPE_NONE = _gobject.type_from_name('void') +TYPE_INTERFACE = _gobject.type_from_name('GInterface') +TYPE_CHAR = _gobject.type_from_name('gchar') +TYPE_UCHAR = _gobject.type_from_name('guchar') +TYPE_BOOLEAN = _gobject.type_from_name('gboolean') +TYPE_INT = _gobject.type_from_name('gint') +TYPE_UINT = _gobject.type_from_name('guint') +TYPE_LONG = _gobject.type_from_name('glong') +TYPE_ULONG = _gobject.type_from_name('gulong') +TYPE_INT64 = _gobject.type_from_name('gint64') +TYPE_UINT64 = _gobject.type_from_name('guint64') +TYPE_ENUM = _gobject.type_from_name('GEnum') +TYPE_FLAGS = _gobject.type_from_name('GFlags') +TYPE_FLOAT = _gobject.type_from_name('gfloat') +TYPE_DOUBLE = _gobject.type_from_name('gdouble') +TYPE_STRING = _gobject.type_from_name('gchararray') +TYPE_POINTER = _gobject.type_from_name('gpointer') +TYPE_BOXED = _gobject.type_from_name('GBoxed') +TYPE_PARAM = _gobject.type_from_name('GParam') +TYPE_OBJECT = _gobject.type_from_name('GObject') +TYPE_PYOBJECT = _gobject.type_from_name('PyObject') +TYPE_UNICHAR = TYPE_UINT + +# do a little dance to maintain API compatibility +# as these were origianally defined here, and are +# now defined in gobjectmodule.c +G_MINFLOAT = _gobject.G_MINFLOAT +G_MAXFLOAT = _gobject.G_MAXFLOAT +G_MINDOUBLE = _gobject.G_MINDOUBLE +G_MAXDOUBLE = _gobject.G_MAXDOUBLE +G_MINSHORT = _gobject.G_MINSHORT +G_MAXSHORT = _gobject.G_MAXSHORT +G_MAXUSHORT = _gobject.G_MAXUSHORT +G_MININT = _gobject.G_MININT +G_MAXINT = _gobject.G_MAXINT +G_MAXUINT = _gobject.G_MAXUINT +G_MINLONG = _gobject.G_MINLONG +G_MAXLONG = _gobject.G_MAXLONG +G_MAXULONG = _gobject.G_MAXULONG diff --git a/gobject/constants.py.in b/gobject/constants.py.in deleted file mode 100644 index 0a1eb86..0000000 --- a/gobject/constants.py.in +++ /dev/null @@ -1,50 +0,0 @@ -# -*- Mode: Python; py-indent-offset: 4 -*- -# pygobject - Python bindings for the GObject library -# Copyright (C) 2006-2007 Johan Dahlin -# -# gobject/constants.py: GObject type constants -# -# 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, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 -# USA - -import sys - -import gobject._gobject -_gobject = sys.modules['gobject._gobject'] - -# TYPE_INVALID defined in gobjectmodule.c -TYPE_NONE = _gobject.type_from_name('void') -TYPE_INTERFACE = _gobject.type_from_name('GInterface') -TYPE_CHAR = _gobject.type_from_name('gchar') -TYPE_UCHAR = _gobject.type_from_name('guchar') -TYPE_BOOLEAN = _gobject.type_from_name('gboolean') -TYPE_INT = _gobject.type_from_name('gint') -TYPE_UINT = _gobject.type_from_name('guint') -TYPE_LONG = _gobject.type_from_name('glong') -TYPE_ULONG = _gobject.type_from_name('gulong') -TYPE_INT64 = _gobject.type_from_name('gint64') -TYPE_UINT64 = _gobject.type_from_name('guint64') -TYPE_ENUM = _gobject.type_from_name('GEnum') -TYPE_FLAGS = _gobject.type_from_name('GFlags') -TYPE_FLOAT = _gobject.type_from_name('gfloat') -TYPE_DOUBLE = _gobject.type_from_name('gdouble') -TYPE_STRING = _gobject.type_from_name('gchararray') -TYPE_POINTER = _gobject.type_from_name('gpointer') -TYPE_BOXED = _gobject.type_from_name('GBoxed') -TYPE_PARAM = _gobject.type_from_name('GParam') -TYPE_OBJECT = _gobject.type_from_name('GObject') -TYPE_PYOBJECT = _gobject.type_from_name('PyObject') -TYPE_UNICHAR = TYPE_UINT - diff --git a/gobject/generate-constants.c b/gobject/generate-constants.c deleted file mode 100644 index 7789b96..0000000 --- a/gobject/generate-constants.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include - -#if PY_VERSION_HEX < 0x03000000 -# define LONGSUFFIX "L" -#else -# define LONGSUFFIX "" -#endif - -int main(void) -{ - printf("# This part is generated by generate-constants.c\n"); - printf("G_MINFLOAT = %f\n", G_MINFLOAT); - printf("G_MAXFLOAT = %f\n", G_MAXFLOAT); - printf("G_MINDOUBLE = %f\n", G_MINDOUBLE); - printf("G_MAXDOUBLE = %f\n", G_MAXDOUBLE); - printf("G_MINSHORT = %d\n", G_MINSHORT); - printf("G_MAXSHORT = %d\n", G_MAXSHORT); - printf("G_MAXUSHORT = %u\n", G_MAXUSHORT); - printf("G_MININT = %d\n", G_MININT); - printf("G_MAXINT = %d\n", G_MAXINT); - printf("G_MAXUINT = %u\n", G_MAXUINT); - printf("G_MINLONG = %ld%s\n", G_MINLONG, LONGSUFFIX); - printf("G_MAXLONG = %ld%s\n", G_MAXLONG, LONGSUFFIX); - printf("G_MAXULONG = %lu%s\n", G_MAXULONG, LONGSUFFIX); - printf("G_MININT8 = %hhd\n", G_MININT8); - printf("G_MAXINT8 = %hhd\n", G_MAXINT8); - printf("G_MAXUINT8 = %hhu\n", G_MAXUINT8); - printf("G_MININT16 = %" G_GINT16_FORMAT "\n", G_MININT16); - printf("G_MAXINT16 = %" G_GINT16_FORMAT "\n", G_MAXINT16); - printf("G_MAXUINT16 = %" G_GUINT16_FORMAT "\n", G_MAXUINT16); - printf("G_MININT32 = %" G_GINT32_FORMAT "\n", G_MININT32); - printf("G_MAXINT32 = %" G_GINT32_FORMAT "\n", G_MAXINT32); - printf("G_MAXUINT32 = %" G_GUINT32_FORMAT "\n", G_MAXUINT32); - printf("G_MININT64 = %" G_GINT64_FORMAT "%s\n", G_MININT64, LONGSUFFIX); - printf("G_MAXINT64 = %" G_GINT64_FORMAT "%s\n", G_MAXINT64, LONGSUFFIX); - printf("G_MAXUINT64 = %" G_GUINT64_FORMAT "%s\n", G_MAXUINT64, LONGSUFFIX); - printf("G_MAXSIZE = %" G_GSIZE_FORMAT "%s\n", G_MAXSIZE, LONGSUFFIX); - printf("G_MAXSSIZE = %" G_GSSIZE_FORMAT "%s\n", G_MAXSSIZE, LONGSUFFIX); - printf("G_MINOFFSET = %" G_GOFFSET_FORMAT "%s\n", G_MINOFFSET, LONGSUFFIX); - printf("G_MAXOFFSET = %" G_GOFFSET_FORMAT "%s\n", G_MAXOFFSET, LONGSUFFIX); - return 0; -} diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index 9a10be5..267546f 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -2530,6 +2530,22 @@ pygobject_register_api(PyObject *d) static void pygobject_register_constants(PyObject *m) { + /* PyFloat_ return a new ref, and add object takes the ref */ + PyModule_AddObject(m, "G_MINFLOAT", PyFloat_FromDouble(G_MINFLOAT)); + PyModule_AddObject(m, "G_MAXFLOAT", PyFloat_FromDouble(G_MAXFLOAT)); + PyModule_AddObject(m, "G_MINDOUBLE", PyFloat_FromDouble(G_MINDOUBLE)); + PyModule_AddObject(m, "G_MAXDOUBLE", PyFloat_FromDouble(G_MAXDOUBLE)); + + PyModule_AddIntConstant(m, "G_MINSHORT", G_MINSHORT); + PyModule_AddIntConstant(m, "G_MAXSHORT", G_MAXSHORT); + PyModule_AddIntConstant(m, "G_MAXUSHORT", G_MAXUSHORT); + PyModule_AddIntConstant(m, "G_MININT", G_MININT); + PyModule_AddIntConstant(m, "G_MAXINT", G_MAXINT); + PyModule_AddIntConstant(m, "G_MAXUINT", G_MAXUINT); + PyModule_AddIntConstant(m, "G_MINLONG", G_MINLONG); + PyModule_AddIntConstant(m, "G_MAXLONG", G_MAXLONG); + PyModule_AddObject(m, "G_MAXULONG", PyLong_FromUnsignedLong(G_MAXULONG)); + PyModule_AddIntConstant(m, "SIGNAL_RUN_FIRST", G_SIGNAL_RUN_FIRST); PyModule_AddIntConstant(m, "SIGNAL_RUN_LAST", G_SIGNAL_RUN_LAST); PyModule_AddIntConstant(m, "SIGNAL_RUN_CLEANUP", G_SIGNAL_RUN_CLEANUP); -- cgit