diff options
author | John Ehresman <jpe@wingware.com> | 2010-04-13 16:22:45 -0400 |
---|---|---|
committer | John Ehresman <jpe@wingware.com> | 2010-04-15 12:16:49 -0400 |
commit | c45311ac3845f42488590acc83c90034066efbde (patch) | |
tree | 9081a4c9d8dc7f504c508843117bb889a60568be | |
parent | 2e1c1f48b9ada382f99206789360f0d39f89bcb5 (diff) | |
download | pygobject-c45311ac3845f42488590acc83c90034066efbde.tar.gz pygobject-c45311ac3845f42488590acc83c90034066efbde.tar.xz pygobject-c45311ac3845f42488590acc83c90034066efbde.zip |
Don't pregenerate numerical constants in constants.py; adapted from a John Stower patch
-rw-r--r-- | gobject/.gitignore | 3 | ||||
-rw-r--r-- | gobject/Makefile.am | 13 | ||||
-rw-r--r-- | gobject/constants.py (renamed from gobject/constants.py.in) | 16 | ||||
-rw-r--r-- | gobject/generate-constants.c | 44 | ||||
-rw-r--r-- | gobject/gobjectmodule.c | 16 |
5 files changed, 32 insertions, 60 deletions
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.in b/gobject/constants.py index 0a1eb86..e02d8e9 100644 --- a/gobject/constants.py.in +++ b/gobject/constants.py @@ -48,3 +48,19 @@ 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/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 <stdio.h> -#include <glib.h> -#include <Python.h> - -#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); |