mercurial/osutil.c
changeset 11359 4eaacccbb2ca
parent 10282 08a0f04b56bd
child 13273 764441ecbf2e
--- a/mercurial/osutil.c	Tue Jun 15 19:49:56 2010 -0300
+++ b/mercurial/osutil.c	Tue Jun 15 19:49:56 2010 -0300
@@ -23,6 +23,8 @@
 #include <unistd.h>
 #endif
 
+#include "util.h"
+
 /* some platforms lack the PATH_MAX definition (eg. GNU/Hurd) */
 #ifndef PATH_MAX
 #define PATH_MAX 4096
@@ -95,8 +97,7 @@
 }
 
 static PyTypeObject listdir_stat_type = {
-	PyObject_HEAD_INIT(NULL)
-	0,                         /*ob_size*/
+	PyVarObject_HEAD_INIT(NULL, 0)
 	"osutil.stat",             /*tp_name*/
 	sizeof(struct listdir_stat), /*tp_basicsize*/
 	0,                         /*tp_itemsize*/
@@ -392,7 +393,7 @@
 	wantstat = statobj && PyObject_IsTrue(statobj);
 
 	if (skipobj && skipobj != Py_None) {
-		skip = PyString_AsString(skipobj);
+		skip = PyBytes_AsString(skipobj);
 		if (!skip)
 			return NULL;
 	}
@@ -486,12 +487,13 @@
 	}
 
 	fd = _open_osfhandle((intptr_t)handle, flags);
+
 	if (fd == -1) {
 		CloseHandle(handle);
 		PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
 		goto bail;
 	}
-
+#ifndef IS_PY3K
 	fp = _fdopen(fd, fpmode);
 	if (fp == NULL) {
 		_close(fd);
@@ -506,6 +508,11 @@
 	}
 
 	PyFile_SetBufSize(file_obj, bufsize);
+#else
+	file_obj = PyFile_FromFd(fd, name, mode, bufsize, NULL, NULL, NULL, 1);
+	if (file_obj == NULL)
+		goto bail;
+#endif
 bail:
 	PyMem_Free(name);
 	return file_obj;
@@ -525,6 +532,23 @@
 	{NULL, NULL}
 };
 
+#ifdef IS_PY3K
+static struct PyModuleDef osutil_module = {
+	PyModuleDef_HEAD_INIT,
+	"osutil",
+	osutil_doc,
+	-1,
+	methods
+};
+
+PyMODINIT_FUNC PyInit_osutil(void)
+{
+	if (PyType_Ready(&listdir_stat_type) < 0)
+		return NULL;
+
+	return PyModule_Create(&osutil_module);
+}
+#else
 PyMODINIT_FUNC initosutil(void)
 {
 	if (PyType_Ready(&listdir_stat_type) == -1)
@@ -532,3 +556,4 @@
 
 	Py_InitModule3("osutil", methods, osutil_doc);
 }
+#endif