Index: lang/python24/Makefile =================================================================== RCS file: /home/pcvs/ports/lang/python24/Makefile,v retrieving revision 1.170 diff -u -r1.170 Makefile --- lang/python24/Makefile 26 Nov 2009 14:04:19 -0000 1.170 +++ lang/python24/Makefile 24 Jun 2010 20:01:51 -0000 @@ -7,7 +7,7 @@ PORTNAME= python24 PORTVERSION= 2.4.5 -PORTREVISION= 5 +PORTREVISION= 6 CATEGORIES= lang python ipv6 MASTER_SITES= ${PYTHON_MASTER_SITES} MASTER_SITE_SUBDIR= ${PYTHON_MASTER_SITE_SUBDIR} Index: lang/python24/files/patch-Modules-fcntlmodule.c =================================================================== RCS file: lang/python24/files/patch-Modules-fcntlmodule.c diff -N lang/python24/files/patch-Modules-fcntlmodule.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/python24/files/patch-Modules-fcntlmodule.c 24 Jun 2010 20:01:51 -0000 @@ -0,0 +1,69 @@ +--- Modules/fcntlmodule.c.orig 2006-09-27 15:17:32.000000000 -0400 ++++ Modules/fcntlmodule.c 2010-06-24 15:50:49.000000000 -0400 +@@ -95,7 +95,19 @@ fcntl_ioctl(PyObject *self, PyObject *ar + { + #define IOCTL_BUFSZ 1024 + int fd; ++#if defined(__APPLE__) || defined(__DragonFlyBSD__) || defined(__FreeBSD__) || \ ++ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) ++#define IOCTL_ULONG 1 ++#endif ++#ifdef IOCTL_ULONG ++ unsigned long code; ++#else ++ /* In PyArg_ParseTuple below, use the unsigned int 'I' format for ++ the signed int 'code' variable, because Python turns 0x8000000 ++ into a large positive number (PyLong, or PyInt on 64-bit ++ platforms,) whereas C expects it to be a negative int */ + int code; ++#endif + int arg; + int ret; + char *str; +@@ -103,7 +115,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + int mutate_arg = 0; + char buf[IOCTL_BUFSZ+1]; /* argument plus NUL byte */ + +- if (PyArg_ParseTuple(args, "O&iw#|i:ioctl", ++#ifdef IOCTL_ULONG ++ if (PyArg_ParseTuple(args, "O&kw#|i:ioctl", ++#else ++ if (PyArg_ParseTuple(args, "O&Iw#|i:ioctl", ++#endif + conv_descriptor, &fd, &code, + &str, &len, &mutate_arg)) { + char *arg; +@@ -164,7 +180,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + } + + PyErr_Clear(); +- if (PyArg_ParseTuple(args, "O&is#:ioctl", ++#ifdef IOCTL_ULONG ++ if (PyArg_ParseTuple(args, "O&ks#:ioctl", ++#else ++ if (PyArg_ParseTuple(args, "O&Is#:ioctl", ++#endif + conv_descriptor, &fd, &code, &str, &len)) { + if (len > IOCTL_BUFSZ) { + PyErr_SetString(PyExc_ValueError, +@@ -186,7 +206,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + PyErr_Clear(); + arg = 0; + if (!PyArg_ParseTuple(args, +- "O&i|i;ioctl requires a file or file descriptor," ++#ifdef IOCTL_ULONG ++ "O&k|i;ioctl requires a file or file descriptor," ++#else ++ "O&I|i;ioctl requires a file or file descriptor," ++#endif + " an integer and optionally a integer or buffer argument", + conv_descriptor, &fd, &code, &arg)) { + return NULL; +@@ -204,6 +228,7 @@ fcntl_ioctl(PyObject *self, PyObject *ar + } + return PyInt_FromLong((long)ret); + #undef IOCTL_BUFSZ ++#undef IOCTL_ULONG + } + + PyDoc_STRVAR(ioctl_doc, Index: lang/python25/Makefile =================================================================== RCS file: /home/pcvs/ports/lang/python25/Makefile,v retrieving revision 1.159 diff -u -r1.159 Makefile --- lang/python25/Makefile 2 Feb 2010 22:00:24 -0000 1.159 +++ lang/python25/Makefile 24 Jun 2010 20:01:51 -0000 @@ -6,6 +6,7 @@ PORTNAME= python25 PORTVERSION= 2.5.5 +PORTREVISION= 1 CATEGORIES= lang python ipv6 MASTER_SITES= ${PYTHON_MASTER_SITES} MASTER_SITE_SUBDIR= ${PYTHON_MASTER_SITE_SUBDIR} Index: lang/python25/files/patch-Lib-test-test_ioctl.py =================================================================== RCS file: lang/python25/files/patch-Lib-test-test_ioctl.py diff -N lang/python25/files/patch-Lib-test-test_ioctl.py --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/python25/files/patch-Lib-test-test_ioctl.py 24 Jun 2010 20:01:51 -0000 @@ -0,0 +1,27 @@ +--- Lib/test/test_ioctl.py.orig 2008-08-03 20:45:34.000000000 -0400 ++++ Lib/test/test_ioctl.py 2010-06-24 13:26:52.000000000 -0400 +@@ -44,21 +44,12 @@ class IoctlTests(unittest.TestCase): + raise TestSkipped('pty module required') + mfd, sfd = pty.openpty() + try: +- if termios.TIOCSWINSZ < 0: +- set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ +- set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffffL +- else: +- set_winsz_opcode_pos = termios.TIOCSWINSZ +- set_winsz_opcode_maybe_neg, = struct.unpack("i", +- struct.pack("I", termios.TIOCSWINSZ)) +- ++ set_winsz_opcode = termios.TIOCSWINSZ + # We're just testing that these calls do not raise exceptions. + saved_winsz = fcntl.ioctl(mfd, termios.TIOCGWINSZ, "\0"*8) + our_winsz = struct.pack("HHHH",80,25,0,0) +- # test both with a positive and potentially negative ioctl code +- new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz) +- new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz) +- fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, saved_winsz) ++ new_winsz = fcntl.ioctl(mfd, set_winsz_opcode, our_winsz) ++ fcntl.ioctl(mfd, set_winsz_opcode, saved_winsz) + finally: + os.close(mfd) + os.close(sfd) Index: lang/python25/files/patch-Modules-fcntlmodule.c =================================================================== RCS file: lang/python25/files/patch-Modules-fcntlmodule.c diff -N lang/python25/files/patch-Modules-fcntlmodule.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/python25/files/patch-Modules-fcntlmodule.c 24 Jun 2010 20:01:51 -0000 @@ -0,0 +1,80 @@ +--- Modules/fcntlmodule.c.orig 2008-08-03 20:45:34.000000000 -0400 ++++ Modules/fcntlmodule.c 2010-06-24 15:55:56.000000000 -0400 +@@ -97,20 +97,19 @@ fcntl_ioctl(PyObject *self, PyObject *ar + { + #define IOCTL_BUFSZ 1024 + int fd; +- /* In PyArg_ParseTuple below, we use the unsigned non-checked 'I' +- format for the 'code' parameter because Python turns 0x8000000 +- into either a large positive number (PyLong or PyInt on 64-bit +- platforms) or a negative number on others (32-bit PyInt) +- whereas the system expects it to be a 32bit bit field value +- regardless of it being passed as an int or unsigned long on +- various platforms. See the termios.TIOCSWINSZ constant across +- platforms for an example of thise. +- +- If any of the 64bit platforms ever decide to use more than 32bits +- in their unsigned long ioctl codes this will break and need +- special casing based on the platform being built on. +- */ +- unsigned int code; ++#if defined(__APPLE__) || defined(__DragonFlyBSD__) || defined(__FreeBSD__) || \ ++ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) ++#define IOCTL_ULONG 1 ++#endif ++#ifdef IOCTL_ULONG ++ unsigned long code; ++#else ++ /* In PyArg_ParseTuple below, use the unsigned int 'I' format for ++ the signed int 'code' variable, because Python turns 0x8000000 ++ into a large positive number (PyLong, or PyInt on 64-bit ++ platforms,) whereas C expects it to be a negative int */ ++ int code; ++#endif + int arg; + int ret; + char *str; +@@ -118,7 +117,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + int mutate_arg = 1; + char buf[IOCTL_BUFSZ+1]; /* argument plus NUL byte */ + ++#ifdef IOCTL_ULONG ++ if (PyArg_ParseTuple(args, "O&kw#|i:ioctl", ++#else + if (PyArg_ParseTuple(args, "O&Iw#|i:ioctl", ++#endif + conv_descriptor, &fd, &code, + &str, &len, &mutate_arg)) { + char *arg; +@@ -169,7 +172,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + } + + PyErr_Clear(); ++#ifdef IOCTL_ULONG ++ if (PyArg_ParseTuple(args, "O&ks#:ioctl", ++#else + if (PyArg_ParseTuple(args, "O&Is#:ioctl", ++#endif + conv_descriptor, &fd, &code, &str, &len)) { + if (len > IOCTL_BUFSZ) { + PyErr_SetString(PyExc_ValueError, +@@ -191,7 +198,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + PyErr_Clear(); + arg = 0; + if (!PyArg_ParseTuple(args, ++#ifdef IOCTL_ULONG ++ "O&k|i;ioctl requires a file or file descriptor," ++#else + "O&I|i;ioctl requires a file or file descriptor," ++#endif + " an integer and optionally an integer or buffer argument", + conv_descriptor, &fd, &code, &arg)) { + return NULL; +@@ -209,6 +220,7 @@ fcntl_ioctl(PyObject *self, PyObject *ar + } + return PyInt_FromLong((long)ret); + #undef IOCTL_BUFSZ ++#undef IOCTL_ULONG + } + + PyDoc_STRVAR(ioctl_doc, Index: lang/python26/Makefile =================================================================== RCS file: /home/pcvs/ports/lang/python26/Makefile,v retrieving revision 1.166 diff -u -r1.166 Makefile --- lang/python26/Makefile 12 May 2010 12:13:06 -0000 1.166 +++ lang/python26/Makefile 24 Jun 2010 20:01:51 -0000 @@ -6,6 +6,7 @@ PORTNAME= python26 PORTVERSION= 2.6.5 +PORTREVISION= 1 CATEGORIES= lang python ipv6 MASTER_SITES= ${PYTHON_MASTER_SITES} MASTER_SITE_SUBDIR= ${PYTHON_MASTER_SITE_SUBDIR} Index: lang/python26/files/patch-Lib-test-test_ioctl.py =================================================================== RCS file: lang/python26/files/patch-Lib-test-test_ioctl.py diff -N lang/python26/files/patch-Lib-test-test_ioctl.py --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/python26/files/patch-Lib-test-test_ioctl.py 24 Jun 2010 20:01:51 -0000 @@ -0,0 +1,23 @@ +--- Lib/test/test_ioctl.py.orig 2008-05-24 05:36:45.000000000 -0400 ++++ Lib/test/test_ioctl.py 2010-06-24 13:29:31.000000000 -0400 +@@ -44,18 +44,9 @@ class IoctlTests(unittest.TestCase): + raise TestSkipped('pty module required') + mfd, sfd = pty.openpty() + try: +- if termios.TIOCSWINSZ < 0: +- set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ +- set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffffL +- else: +- set_winsz_opcode_pos = termios.TIOCSWINSZ +- set_winsz_opcode_maybe_neg, = struct.unpack("i", +- struct.pack("I", termios.TIOCSWINSZ)) +- ++ set_winsz_opcode = termios.TIOCSWINSZ + our_winsz = struct.pack("HHHH",80,25,0,0) +- # test both with a positive and potentially negative ioctl code +- new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz) +- new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz) ++ new_winsz = fcntl.ioctl(mfd, set_winsz_opcode, our_winsz) + finally: + os.close(mfd) + os.close(sfd) Index: lang/python26/files/patch-Modules-fcntlmodule.c =================================================================== RCS file: lang/python26/files/patch-Modules-fcntlmodule.c diff -N lang/python26/files/patch-Modules-fcntlmodule.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/python26/files/patch-Modules-fcntlmodule.c 24 Jun 2010 20:01:51 -0000 @@ -0,0 +1,104 @@ +--- Modules/fcntlmodule.c.orig 2009-05-24 11:41:43.000000000 -0400 ++++ Modules/fcntlmodule.c 2010-06-24 15:57:47.000000000 -0400 +@@ -34,7 +34,11 @@ fcntl_fcntl(PyObject *self, PyObject *ar + { + int fd; + int code; ++#if defined(__linux__) + long arg; ++#else ++ int arg; ++#endif + int ret; + char *str; + Py_ssize_t len; +@@ -61,7 +65,11 @@ fcntl_fcntl(PyObject *self, PyObject *ar + PyErr_Clear(); + arg = 0; + if (!PyArg_ParseTuple(args, ++#if defined(__linux__) + "O&i|l;fcntl requires a file or file descriptor," ++#else ++ "O&i|i;fcntl requires a file or file descriptor," ++#endif + " an integer and optionally a third integer or a string", + conv_descriptor, &fd, &code, &arg)) { + return NULL; +@@ -97,20 +105,19 @@ fcntl_ioctl(PyObject *self, PyObject *ar + { + #define IOCTL_BUFSZ 1024 + int fd; +- /* In PyArg_ParseTuple below, we use the unsigned non-checked 'I' +- format for the 'code' parameter because Python turns 0x8000000 +- into either a large positive number (PyLong or PyInt on 64-bit +- platforms) or a negative number on others (32-bit PyInt) +- whereas the system expects it to be a 32bit bit field value +- regardless of it being passed as an int or unsigned long on +- various platforms. See the termios.TIOCSWINSZ constant across +- platforms for an example of thise. +- +- If any of the 64bit platforms ever decide to use more than 32bits +- in their unsigned long ioctl codes this will break and need +- special casing based on the platform being built on. +- */ +- unsigned int code; ++#if defined(__APPLE__) || defined(__DragonFlyBSD__) || defined(__FreeBSD__) || \ ++ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) ++#define IOCTL_ULONG 1 ++#endif ++#ifdef IOCTL_ULONG ++ unsigned long code; ++#else ++ /* In PyArg_ParseTuple below, use the unsigned int 'I' format for ++ the signed int 'code' variable, because Python turns 0x8000000 ++ into a large positive number (PyLong, or PyInt on 64-bit ++ platforms,) whereas C expects it to be a negative int */ ++ int code; ++#endif + int arg; + int ret; + char *str; +@@ -118,7 +125,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + int mutate_arg = 1; + char buf[IOCTL_BUFSZ+1]; /* argument plus NUL byte */ + ++#ifdef IOCTL_ULONG ++ if (PyArg_ParseTuple(args, "O&kw#|i:ioctl", ++#else + if (PyArg_ParseTuple(args, "O&Iw#|i:ioctl", ++#endif + conv_descriptor, &fd, &code, + &str, &len, &mutate_arg)) { + char *arg; +@@ -169,7 +180,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + } + + PyErr_Clear(); ++#ifdef IOCTL_ULONG ++ if (PyArg_ParseTuple(args, "O&ks#:ioctl", ++#else + if (PyArg_ParseTuple(args, "O&Is#:ioctl", ++#endif + conv_descriptor, &fd, &code, &str, &len)) { + if (len > IOCTL_BUFSZ) { + PyErr_SetString(PyExc_ValueError, +@@ -191,7 +206,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + PyErr_Clear(); + arg = 0; + if (!PyArg_ParseTuple(args, ++#ifdef IOCTL_ULONG ++ "O&k|i;ioctl requires a file or file descriptor," ++#else + "O&I|i;ioctl requires a file or file descriptor," ++#endif + " an integer and optionally an integer or buffer argument", + conv_descriptor, &fd, &code, &arg)) { + return NULL; +@@ -209,6 +228,7 @@ fcntl_ioctl(PyObject *self, PyObject *ar + } + return PyInt_FromLong((long)ret); + #undef IOCTL_BUFSZ ++#undef IOCTL_ULONG + } + + PyDoc_STRVAR(ioctl_doc, Index: lang/python31/Makefile =================================================================== RCS file: /home/pcvs/ports/lang/python31/Makefile,v retrieving revision 1.166 diff -u -r1.166 Makefile --- lang/python31/Makefile 12 May 2010 12:13:06 -0000 1.166 +++ lang/python31/Makefile 24 Jun 2010 20:01:52 -0000 @@ -6,6 +6,7 @@ PORTNAME= python31 PORTVERSION= 3.1.2 +PORTREVISION= 1 CATEGORIES= lang python ipv6 MASTER_SITES= ${PYTHON_MASTER_SITES} MASTER_SITE_SUBDIR= ${PYTHON_MASTER_SITE_SUBDIR} Index: lang/python31/files/patch-Lib-test-test_fcntl.py =================================================================== RCS file: lang/python31/files/patch-Lib-test-test_fcntl.py diff -N lang/python31/files/patch-Lib-test-test_fcntl.py --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/python31/files/patch-Lib-test-test_fcntl.py 24 Jun 2010 20:01:52 -0000 @@ -0,0 +1,11 @@ +--- Lib/test/test_fcntl.py.orig 2009-05-24 11:46:13.000000000 -0400 ++++ Lib/test/test_fcntl.py 2010-06-24 13:56:52.000000000 -0400 +@@ -29,7 +29,7 @@ + if sys.platform in ('netbsd1', 'netbsd2', 'netbsd3', + 'Darwin1.2', 'darwin', + 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5', +- 'freebsd6', 'freebsd7', 'freebsd8', ++ 'freebsd6', 'freebsd7', 'freebsd8', 'freebsd9', + 'bsdos2', 'bsdos3', 'bsdos4', + 'openbsd', 'openbsd2', 'openbsd3', 'openbsd4'): + if struct.calcsize('l') == 8: Index: lang/python31/files/patch-Lib-test-test_ioctl.py =================================================================== RCS file: lang/python31/files/patch-Lib-test-test_ioctl.py diff -N lang/python31/files/patch-Lib-test-test_ioctl.py --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/python31/files/patch-Lib-test-test_ioctl.py 24 Jun 2010 20:01:52 -0000 @@ -0,0 +1,23 @@ +--- Lib/test/test_ioctl.py.orig 2009-08-13 04:51:18.000000000 -0400 ++++ Lib/test/test_ioctl.py 2010-06-24 13:35:29.000000000 -0400 +@@ -41,18 +41,9 @@ class IoctlTests(unittest.TestCase): + raise unittest.SkipTest('pty module required') + mfd, sfd = pty.openpty() + try: +- if termios.TIOCSWINSZ < 0: +- set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ +- set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffff +- else: +- set_winsz_opcode_pos = termios.TIOCSWINSZ +- set_winsz_opcode_maybe_neg, = struct.unpack("i", +- struct.pack("I", termios.TIOCSWINSZ)) +- ++ set_winsz_opcode = termios.TIOCSWINSZ + our_winsz = struct.pack("HHHH",80,25,0,0) +- # test both with a positive and potentially negative ioctl code +- new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz) +- new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz) ++ new_winsz = fcntl.ioctl(mfd, set_winsz_opcode, our_winsz) + finally: + os.close(mfd) + os.close(sfd) Index: lang/python31/files/patch-Lib-test-test_socket.py =================================================================== RCS file: lang/python31/files/patch-Lib-test-test_socket.py diff -N lang/python31/files/patch-Lib-test-test_socket.py --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/python31/files/patch-Lib-test-test_socket.py 24 Jun 2010 20:01:52 -0000 @@ -0,0 +1,11 @@ +--- Lib/test/test_socket.py.orig 2009-10-04 10:54:52.000000000 -0400 ++++ Lib/test/test_socket.py 2010-06-24 13:57:37.000000000 -0400 +@@ -337,7 +337,7 @@ + # I've ordered this by protocols that have both a tcp and udp + # protocol, at least for modern Linuxes. + if sys.platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6', +- 'freebsd7', 'freebsd8', 'darwin'): ++ 'freebsd7', 'freebsd8', 'freebsd9', 'darwin'): + # avoid the 'echo' service on this platform, as there is an + # assumption breaking non-standard port/protocol entry + services = ('daytime', 'qotd', 'domain') Index: lang/python31/files/patch-Modules-fcntlmodule.c =================================================================== RCS file: lang/python31/files/patch-Modules-fcntlmodule.c diff -N lang/python31/files/patch-Modules-fcntlmodule.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lang/python31/files/patch-Modules-fcntlmodule.c 24 Jun 2010 20:01:52 -0000 @@ -0,0 +1,104 @@ +--- Modules/fcntlmodule.c.orig 2009-05-24 11:46:13.000000000 -0400 ++++ Modules/fcntlmodule.c 2010-06-24 16:00:48.000000000 -0400 +@@ -34,7 +34,11 @@ fcntl_fcntl(PyObject *self, PyObject *ar + { + int fd; + int code; ++#if defined(__linux__) + long arg; ++#else ++ int arg; ++#endif + int ret; + char *str; + Py_ssize_t len; +@@ -61,7 +65,11 @@ fcntl_fcntl(PyObject *self, PyObject *ar + PyErr_Clear(); + arg = 0; + if (!PyArg_ParseTuple(args, ++#if defined(__linux__) + "O&i|l;fcntl requires a file or file descriptor," ++#else ++ "O&i|i;fcntl requires a file or file descriptor," ++#endif + " an integer and optionally a third integer or a string", + conv_descriptor, &fd, &code, &arg)) { + return NULL; +@@ -97,20 +105,19 @@ fcntl_ioctl(PyObject *self, PyObject *ar + { + #define IOCTL_BUFSZ 1024 + int fd; +- /* In PyArg_ParseTuple below, we use the unsigned non-checked 'I' +- format for the 'code' parameter because Python turns 0x8000000 +- into either a large positive number (PyLong or PyInt on 64-bit +- platforms) or a negative number on others (32-bit PyInt) +- whereas the system expects it to be a 32bit bit field value +- regardless of it being passed as an int or unsigned long on +- various platforms. See the termios.TIOCSWINSZ constant across +- platforms for an example of thise. +- +- If any of the 64bit platforms ever decide to use more than 32bits +- in their unsigned long ioctl codes this will break and need +- special casing based on the platform being built on. +- */ +- unsigned int code; ++#if defined(__APPLE__) || defined(__DragonFlyBSD__) || defined(__FreeBSD__) || \ ++ defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) ++#define IOCTL_ULONG 1 ++#endif ++#ifdef IOCTL_ULONG ++ unsigned long code; ++#else ++ /* In PyArg_ParseTuple below, use the unsigned int 'I' format for ++ the signed int 'code' variable, because Python turns 0x8000000 ++ into a large positive number (PyLong, or PyInt on 64-bit ++ platforms,) whereas C expects it to be a negative int */ ++ int code; ++#endif + int arg; + int ret; + Py_buffer pstr; +@@ -119,7 +126,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + int mutate_arg = 1; + char buf[IOCTL_BUFSZ+1]; /* argument plus NUL byte */ + ++#ifdef IOCTL_ULONG ++ if (PyArg_ParseTuple(args, "O&kw*|i:ioctl", ++#else + if (PyArg_ParseTuple(args, "O&Iw*|i:ioctl", ++#endif + conv_descriptor, &fd, &code, + &pstr, &mutate_arg)) { + char *arg; +@@ -174,7 +185,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + } + + PyErr_Clear(); ++#ifdef IOCTL_ULONG ++ if (PyArg_ParseTuple(args, "O&ks*:ioctl", ++#else + if (PyArg_ParseTuple(args, "O&Is*:ioctl", ++#endif + conv_descriptor, &fd, &code, &pstr)) { + str = pstr.buf; + len = pstr.len; +@@ -201,7 +216,11 @@ fcntl_ioctl(PyObject *self, PyObject *ar + PyErr_Clear(); + arg = 0; + if (!PyArg_ParseTuple(args, ++#ifdef IOCTL_ULONG ++ "O&k|i;ioctl requires a file or file descriptor," ++#else + "O&I|i;ioctl requires a file or file descriptor," ++#endif + " an integer and optionally an integer or buffer argument", + conv_descriptor, &fd, &code, &arg)) { + return NULL; +@@ -219,6 +238,7 @@ fcntl_ioctl(PyObject *self, PyObject *ar + } + return PyLong_FromLong((long)ret); + #undef IOCTL_BUFSZ ++#undef IOCTL_ULONG + } + + PyDoc_STRVAR(ioctl_doc,