[pygobject/py3k: 12/20] Don't pregenerate numerical constants in constants.py; adapted from a John Stower patch



commit c45311ac3845f42488590acc83c90034066efbde
Author: John Ehresman <jpe wingware com>
Date:   Tue Apr 13 16:22:45 2010 -0400

    Don't pregenerate numerical constants in constants.py; adapted from a John Stower patch

 gobject/.gitignore                        |    3 --
 gobject/Makefile.am                       |   13 --------
 gobject/{constants.py.in => constants.py} |   16 ++++++++++
 gobject/generate-constants.c              |   44 -----------------------------
 gobject/gobjectmodule.c                   |   16 ++++++++++
 5 files changed, 32 insertions(+), 60 deletions(-)
---
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
similarity index 78%
rename from gobject/constants.py.in
rename to 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/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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]