changeset 11549:935c83ce9172

inotify: Port of the C module to py3k. This patch accomplishes the port of the inotify C module to py3k by #including mercurial's util.h file, and by defining the necessary boilerplate code required by py3k through conditional compilation.
author Renato Cunha <renatoc@gmail.com>
date Fri, 02 Jul 2010 16:22:59 -0300
parents dd2f356e1f6f
children 14e90cc3a296
files hgext/inotify/linux/_inotify.c
diffstat 1 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/inotify/linux/_inotify.c	Fri Jul 02 16:21:46 2010 -0300
+++ b/hgext/inotify/linux/_inotify.c	Fri Jul 02 16:22:59 2010 -0300
@@ -15,6 +15,8 @@
 #include <sys/ioctl.h>
 #include <unistd.h>
 
+#include <util.h>
+
 /* Variables used in the event string representation */
 static PyObject *join;
 static PyObject *er_wm;
@@ -394,8 +396,7 @@
 }
 
 static PyTypeObject event_type = {
-	PyObject_HEAD_INIT(NULL)
-	0,                         /*ob_size*/
+	PyVarObject_HEAD_INIT(NULL, 0)
 	"_inotify.event",             /*tp_name*/
 	sizeof(struct event), /*tp_basicsize*/
 	0,                         /*tp_itemsize*/
@@ -600,6 +601,35 @@
 	{NULL},
 };
 
+#ifdef IS_PY3K
+static struct PyModuleDef _inotify_module = {
+	PyModuleDef_HEAD_INIT,
+	"_inotify",
+	doc,
+	-1,
+	methods
+};
+
+PyMODINIT_FUNC PyInit__inotify(void)
+{
+	PyObject *mod, *dict;
+
+	mod = PyModule_Create(&_inotify_module);
+
+	if (mod == NULL)
+		return NULL;
+
+	if (!init_globals())
+		return;
+
+	dict = PyModule_GetDict(mod);
+
+	if (dict)
+		define_consts(dict);
+
+	return mod;
+}
+#else
 void init_inotify(void)
 {
 	PyObject *mod, *dict;
@@ -617,3 +647,4 @@
 	if (dict)
 		define_consts(dict);
 }
+#endif