python-2.7.17.patchset revision c7fcfd65
1From f30d4b172ebf8ec7d8db600b2ad041cc3a8c58e7 Mon Sep 17 00:00:00 2001
2From: Jerome Duval <jerome.duval@gmail.com>
3Date: Wed, 12 Mar 2014 21:17:06 +0000
4Subject: initial Haiku patch
5
6
7diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
8index b9f1c6c..7be61d3 100644
9--- a/Lib/distutils/command/install.py
10+++ b/Lib/distutils/command/install.py
11@@ -83,6 +83,35 @@ INSTALL_SCHEMES = {
12         'scripts': '$userbase/bin',
13         'data'   : '$userbase',
14         },
15+    'haiku': {
16+        'purelib': '$base/non-packaged/lib/python$py_version_short/site-packages',
17+        'platlib': '$platbase/non-packaged/lib/python$py_version_short/site-packages',
18+        'headers': '$base/non-packaged/develop/headers/python$py_version_short/$dist_name',
19+        'scripts': '$base/non-packaged/bin',
20+        'data'   : '$base/non-packaged',
21+        },
22+    'haiku_vendor': {
23+        'purelib': '$base/lib/python$py_version_short/vendor-packages',
24+        'platlib': '$platbase/lib/python$py_version_short/vendor-packages',
25+        'headers': '$base/develop/headers/python$py_version_short/$dist_name',
26+        'scripts': '$base/bin',
27+        'data'   : '$base',
28+        },
29+    'haiku_home': {
30+        'purelib': '$base/lib/python',
31+        'platlib': '$base/lib/python',
32+        'headers': '$base/develop/headers/python/$dist_name',
33+        'scripts': '$base/bin',
34+        'data'   : '$base',
35+        },
36+    'haiku_user': {
37+        'purelib': '$usersite',
38+        'platlib': '$usersite',
39+        'headers': '$userbase/develop/headers/python$py_version_short/$dist_name',
40+        'scripts': '$userbase/bin',
41+        'data'   : '$userbase',
42+        },
43+
44     }
45 
46 # The keys to an installation scheme; if any new types of files are to be
47@@ -416,10 +445,16 @@ class install (Command):
48                 raise DistutilsPlatformError(
49                     "User base directory is not specified")
50             self.install_base = self.install_platbase = self.install_userbase
51-            self.select_scheme("unix_user")
52+            if sys.platform.startswith('haiku'):
53+	            self.select_scheme("haiku_user")
54+            else:
55+	            self.select_scheme("unix_user")
56         elif self.home is not None:
57             self.install_base = self.install_platbase = self.home
58-            self.select_scheme("unix_home")
59+            if sys.platform.startswith('haiku'):
60+	            self.select_scheme("haiku_home")
61+            else:
62+	            self.select_scheme("unix_home")
63         else:
64             if self.prefix is None:
65                 if self.exec_prefix is not None:
66@@ -435,7 +470,13 @@ class install (Command):
67 
68             self.install_base = self.prefix
69             self.install_platbase = self.exec_prefix
70-            self.select_scheme("unix_prefix")
71+            if sys.platform.startswith('haiku'):
72+                if os.environ.get('HAIKU_USE_VENDOR_DIRECTORIES') == '1':
73+                    self.select_scheme("haiku_vendor")
74+                else:
75+                    self.select_scheme("haiku")
76+            else:
77+                self.select_scheme("unix_prefix")
78 
79     # finalize_unix ()
80 
81diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
82index de7da1d..8180c8e 100644
83--- a/Lib/distutils/sysconfig.py
84+++ b/Lib/distutils/sysconfig.py
85@@ -90,7 +90,8 @@ def get_python_inc(plat_specific=0, prefix=None):
86                 # Include is located in the srcdir
87                 inc_dir = os.path.join(srcdir, "Include")
88             return inc_dir
89-        return os.path.join(prefix, "include", "python" + get_python_version())
90+        inc_dir = "include" if sys.platform != "haiku1" else "develop/headers"
91+        return os.path.join(prefix, inc_dir, "python" + get_python_version())
92     elif os.name == "nt":
93         return os.path.join(prefix, "include")
94     elif os.name == "os2":
95@@ -119,12 +120,20 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
96         prefix = plat_specific and EXEC_PREFIX or PREFIX
97 
98     if os.name == "posix":
99-        libpython = os.path.join(prefix,
100-                                 "lib", "python" + get_python_version())
101-        if standard_lib:
102-            return libpython
103+        if sys.platform.startswith('haiku'):
104+            if standard_lib:
105+                return os.path.join(prefix,
106+                                    "lib", "python" + get_python_version())
107+            return os.path.join(prefix, "non-packaged",
108+                                "lib", "python" + get_python_version(),
109+                                "site-packages")
110         else:
111-            return os.path.join(libpython, "site-packages")
112+	        libpython = os.path.join(prefix,
113+	                                 "lib", "python" + get_python_version())
114+	        if standard_lib:
115+	            return libpython
116+	        else:
117+	            return os.path.join(libpython, "site-packages")
118 
119     elif os.name == "nt":
120         if standard_lib:
121diff --git a/Lib/plat-haiku1/IN.py b/Lib/plat-haiku1/IN.py
122new file mode 100644
123index 0000000..362cb41
124--- /dev/null
125+++ b/Lib/plat-haiku1/IN.py
126@@ -0,0 +1,327 @@
127+# Generated by h2py from /boot/develop/headers/be/net/netinet/in.h
128+
129+# Included from socket.h
130+
131+# Included from BeBuild.h
132+B_BEOS_VERSION_4 = 0x0400
133+B_BEOS_VERSION_4_5 = 0x0450
134+B_BEOS_VERSION_5 = 0x0500
135+B_BEOS_VERSION = B_BEOS_VERSION_5
136+B_BEOS_VERSION_MAUI = B_BEOS_VERSION_5
137+_PR2_COMPATIBLE_ = 1
138+_PR3_COMPATIBLE_ = 1
139+_R4_COMPATIBLE_ = 1
140+_R4_5_COMPATIBLE_ = 1
141+_PR2_COMPATIBLE_ = 0
142+_PR3_COMPATIBLE_ = 0
143+_R4_COMPATIBLE_ = 1
144+_R4_5_COMPATIBLE_ = 1
145+def _UNUSED(x): return x
146+
147+
148+# Included from sys/types.h
149+
150+# Included from time.h
151+
152+# Included from be_setup.h
153+def __std(ref): return ref
154+
155+__be_os = 2
156+__dest_os = __be_os
157+__MSL__ = 0x4011
158+__GLIBC__ = -2
159+__GLIBC_MINOR__ = 1
160+
161+# Included from null.h
162+NULL = (0)
163+NULL = 0L
164+
165+# Included from size_t.h
166+
167+# Included from stddef.h
168+
169+# Included from wchar_t.h
170+CLOCKS_PER_SEC = 1000
171+CLK_TCK = CLOCKS_PER_SEC
172+MAX_TIMESTR = 70
173+
174+# Included from sys/time.h
175+
176+# Included from ByteOrder.h
177+
178+# Included from endian.h
179+__LITTLE_ENDIAN = 1234
180+LITTLE_ENDIAN = __LITTLE_ENDIAN
181+__BYTE_ORDER = __LITTLE_ENDIAN
182+BYTE_ORDER = __BYTE_ORDER
183+__BIG_ENDIAN = 0
184+BIG_ENDIAN = 0
185+__BIG_ENDIAN = 4321
186+BIG_ENDIAN = __BIG_ENDIAN
187+__BYTE_ORDER = __BIG_ENDIAN
188+BYTE_ORDER = __BYTE_ORDER
189+__LITTLE_ENDIAN = 0
190+LITTLE_ENDIAN = 0
191+__PDP_ENDIAN = 3412
192+PDP_ENDIAN = __PDP_ENDIAN
193+
194+# Included from SupportDefs.h
195+
196+# Included from Errors.h
197+
198+# Included from limits.h
199+
200+# Included from float.h
201+FLT_ROUNDS = 1
202+FLT_RADIX = 2
203+FLT_MANT_DIG = 24
204+FLT_DIG = 6
205+FLT_MIN_EXP = (-125)
206+FLT_MIN_10_EXP = (-37)
207+FLT_MAX_EXP = 128
208+FLT_MAX_10_EXP = 38
209+DBL_MANT_DIG = 53
210+DBL_DIG = 15
211+DBL_MIN_EXP = (-1021)
212+DBL_MIN_10_EXP = (-308)
213+DBL_MAX_EXP = 1024
214+DBL_MAX_10_EXP = 308
215+LDBL_MANT_DIG = DBL_MANT_DIG
216+LDBL_DIG = DBL_DIG
217+LDBL_MIN_EXP = DBL_MIN_EXP
218+LDBL_MIN_10_EXP = DBL_MIN_10_EXP
219+LDBL_MAX_EXP = DBL_MAX_EXP
220+LDBL_MAX_10_EXP = DBL_MAX_10_EXP
221+CHAR_BIT = (8)
222+SCHAR_MIN = (-127-1)
223+SCHAR_MAX = (127)
224+CHAR_MIN = SCHAR_MIN
225+CHAR_MAX = SCHAR_MAX
226+MB_LEN_MAX = (1)
227+SHRT_MIN = (-32767-1)
228+SHRT_MAX = (32767)
229+LONG_MIN = (-2147483647L-1)
230+LONG_MAX = (2147483647L)
231+INT_MIN = LONG_MIN
232+INT_MAX = LONG_MAX
233+ARG_MAX = (32768)
234+ATEXIT_MAX = (32)
235+CHILD_MAX = (1024)
236+IOV_MAX = (256)
237+FILESIZEBITS = (64)
238+LINK_MAX = (1)
239+LOGIN_NAME_MAX = (32)
240+MAX_CANON = (255)
241+MAX_INPUT = (255)
242+NAME_MAX = (256)
243+NGROUPS_MAX = (32)
244+OPEN_MAX = (128)
245+PATH_MAX = (1024)
246+PIPE_MAX = (512)
247+SSIZE_MAX = (2147483647L)
248+TTY_NAME_MAX = (256)
249+TZNAME_MAX = (32)
250+SYMLINKS_MAX = (16)
251+_POSIX_ARG_MAX = (32768)
252+_POSIX_CHILD_MAX = (1024)
253+_POSIX_LINK_MAX = (1)
254+_POSIX_LOGIN_NAME_MAX = (9)
255+_POSIX_MAX_CANON = (255)
256+_POSIX_MAX_INPUT = (255)
257+_POSIX_NAME_MAX = (255)
258+_POSIX_NGROUPS_MAX = (0)
259+_POSIX_OPEN_MAX = (128)
260+_POSIX_PATH_MAX = (1024)
261+_POSIX_PIPE_BUF = (512)
262+_POSIX_SSIZE_MAX = (2147483647L)
263+_POSIX_STREAM_MAX = (8)
264+_POSIX_TTY_NAME_MAX = (256)
265+_POSIX_TZNAME_MAX = (3)
266+B_GENERAL_ERROR_BASE = LONG_MIN
267+B_OS_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x1000
268+B_APP_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x2000
269+B_INTERFACE_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x3000
270+B_MEDIA_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x4000
271+B_TRANSLATION_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x4800
272+B_MIDI_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x5000
273+B_STORAGE_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x6000
274+B_POSIX_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x7000
275+B_MAIL_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x8000
276+B_PRINT_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x9000
277+B_DEVICE_ERROR_BASE = B_GENERAL_ERROR_BASE + 0xa000
278+B_ERRORS_END = (B_GENERAL_ERROR_BASE + 0xffff)
279+E2BIG = (B_POSIX_ERROR_BASE + 1)
280+ECHILD = (B_POSIX_ERROR_BASE + 2)
281+EDEADLK = (B_POSIX_ERROR_BASE + 3)
282+EFBIG = (B_POSIX_ERROR_BASE + 4)
283+EMLINK = (B_POSIX_ERROR_BASE + 5)
284+ENFILE = (B_POSIX_ERROR_BASE + 6)
285+ENODEV = (B_POSIX_ERROR_BASE + 7)
286+ENOLCK = (B_POSIX_ERROR_BASE + 8)
287+ENOSYS = (B_POSIX_ERROR_BASE + 9)
288+ENOTTY = (B_POSIX_ERROR_BASE + 10)
289+ENXIO = (B_POSIX_ERROR_BASE + 11)
290+ESPIPE = (B_POSIX_ERROR_BASE + 12)
291+ESRCH = (B_POSIX_ERROR_BASE + 13)
292+EFPOS = (B_POSIX_ERROR_BASE + 14)
293+ESIGPARM = (B_POSIX_ERROR_BASE + 15)
294+EDOM = (B_POSIX_ERROR_BASE + 16)
295+ERANGE = (B_POSIX_ERROR_BASE + 17)
296+EPROTOTYPE = (B_POSIX_ERROR_BASE + 18)
297+EPROTONOSUPPORT = (B_POSIX_ERROR_BASE + 19)
298+EPFNOSUPPORT = (B_POSIX_ERROR_BASE + 20)
299+EAFNOSUPPORT = (B_POSIX_ERROR_BASE + 21)
300+EADDRINUSE = (B_POSIX_ERROR_BASE + 22)
301+EADDRNOTAVAIL = (B_POSIX_ERROR_BASE + 23)
302+ENETDOWN = (B_POSIX_ERROR_BASE + 24)
303+ENETUNREACH = (B_POSIX_ERROR_BASE + 25)
304+ENETRESET = (B_POSIX_ERROR_BASE + 26)
305+ECONNABORTED = (B_POSIX_ERROR_BASE + 27)
306+ECONNRESET = (B_POSIX_ERROR_BASE + 28)
307+EISCONN = (B_POSIX_ERROR_BASE + 29)
308+ENOTCONN = (B_POSIX_ERROR_BASE + 30)
309+ESHUTDOWN = (B_POSIX_ERROR_BASE + 31)
310+ECONNREFUSED = (B_POSIX_ERROR_BASE + 32)
311+EHOSTUNREACH = (B_POSIX_ERROR_BASE + 33)
312+ENOPROTOOPT = (B_POSIX_ERROR_BASE + 34)
313+ENOBUFS = (B_POSIX_ERROR_BASE + 35)
314+EINPROGRESS = (B_POSIX_ERROR_BASE + 36)
315+EALREADY = (B_POSIX_ERROR_BASE + 37)
316+EILSEQ = (B_POSIX_ERROR_BASE + 38)
317+ENOMSG = (B_POSIX_ERROR_BASE + 39)
318+ESTALE = (B_POSIX_ERROR_BASE + 40)
319+EOVERFLOW = (B_POSIX_ERROR_BASE + 41)
320+EMSGSIZE = (B_POSIX_ERROR_BASE + 42)
321+EOPNOTSUPP = (B_POSIX_ERROR_BASE + 43)
322+ENOTSOCK = (B_POSIX_ERROR_BASE + 44)
323+false = 0
324+true = 1
325+NULL = (0)
326+FALSE = 0
327+TRUE = 1
328+
329+# Included from TypeConstants.h
330+B_HOST_IS_LENDIAN = 1
331+B_HOST_IS_BENDIAN = 0
332+def B_HOST_TO_LENDIAN_DOUBLE(arg): return (double)(arg)
333+
334+def B_HOST_TO_LENDIAN_FLOAT(arg): return (float)(arg)
335+
336+def B_HOST_TO_LENDIAN_INT64(arg): return (uint64)(arg)
337+
338+def B_HOST_TO_LENDIAN_INT32(arg): return (uint32)(arg)
339+
340+def B_HOST_TO_LENDIAN_INT16(arg): return (uint16)(arg)
341+
342+def B_HOST_TO_BENDIAN_DOUBLE(arg): return __swap_double(arg)
343+
344+def B_HOST_TO_BENDIAN_FLOAT(arg): return __swap_float(arg)
345+
346+def B_HOST_TO_BENDIAN_INT64(arg): return __swap_int64(arg)
347+
348+def B_HOST_TO_BENDIAN_INT32(arg): return __swap_int32(arg)
349+
350+def B_HOST_TO_BENDIAN_INT16(arg): return __swap_int16(arg)
351+
352+def B_LENDIAN_TO_HOST_DOUBLE(arg): return (double)(arg)
353+
354+def B_LENDIAN_TO_HOST_FLOAT(arg): return (float)(arg)
355+
356+def B_LENDIAN_TO_HOST_INT64(arg): return (uint64)(arg)
357+
358+def B_LENDIAN_TO_HOST_INT32(arg): return (uint32)(arg)
359+
360+def B_LENDIAN_TO_HOST_INT16(arg): return (uint16)(arg)
361+
362+def B_BENDIAN_TO_HOST_DOUBLE(arg): return __swap_double(arg)
363+
364+def B_BENDIAN_TO_HOST_FLOAT(arg): return __swap_float(arg)
365+
366+def B_BENDIAN_TO_HOST_INT64(arg): return __swap_int64(arg)
367+
368+def B_BENDIAN_TO_HOST_INT32(arg): return __swap_int32(arg)
369+
370+def B_BENDIAN_TO_HOST_INT16(arg): return __swap_int16(arg)
371+
372+B_HOST_IS_LENDIAN = 0
373+B_HOST_IS_BENDIAN = 1
374+def B_HOST_TO_LENDIAN_DOUBLE(arg): return __swap_double(arg)
375+
376+def B_HOST_TO_LENDIAN_FLOAT(arg): return __swap_float(arg)
377+
378+def B_HOST_TO_LENDIAN_INT64(arg): return __swap_int64(arg)
379+
380+def B_HOST_TO_LENDIAN_INT32(arg): return __swap_int32(arg)
381+
382+def B_HOST_TO_LENDIAN_INT16(arg): return __swap_int16(arg)
383+
384+def B_HOST_TO_BENDIAN_DOUBLE(arg): return (double)(arg)
385+
386+def B_HOST_TO_BENDIAN_FLOAT(arg): return (float)(arg)
387+
388+def B_HOST_TO_BENDIAN_INT64(arg): return (uint64)(arg)
389+
390+def B_HOST_TO_BENDIAN_INT32(arg): return (uint32)(arg)
391+
392+def B_HOST_TO_BENDIAN_INT16(arg): return (uint16)(arg)
393+
394+def B_LENDIAN_TO_HOST_DOUBLE(arg): return __swap_double(arg)
395+
396+def B_LENDIAN_TO_HOST_FLOAT(arg): return __swap_float(arg)
397+
398+def B_LENDIAN_TO_HOST_INT64(arg): return __swap_int64(arg)
399+
400+def B_LENDIAN_TO_HOST_INT32(arg): return __swap_int32(arg)
401+
402+def B_LENDIAN_TO_HOST_INT16(arg): return __swap_int16(arg)
403+
404+def B_BENDIAN_TO_HOST_DOUBLE(arg): return (double)(arg)
405+
406+def B_BENDIAN_TO_HOST_FLOAT(arg): return (float)(arg)
407+
408+def B_BENDIAN_TO_HOST_INT64(arg): return (uint64)(arg)
409+
410+def B_BENDIAN_TO_HOST_INT32(arg): return (uint32)(arg)
411+
412+def B_BENDIAN_TO_HOST_INT16(arg): return (uint16)(arg)
413+
414+def B_SWAP_DOUBLE(arg): return __swap_double(arg)
415+
416+def B_SWAP_FLOAT(arg): return __swap_float(arg)
417+
418+def B_SWAP_INT64(arg): return __swap_int64(arg)
419+
420+def B_SWAP_INT32(arg): return __swap_int32(arg)
421+
422+def B_SWAP_INT16(arg): return __swap_int16(arg)
423+
424+def htonl(x): return B_HOST_TO_BENDIAN_INT32(x)
425+
426+def ntohl(x): return B_BENDIAN_TO_HOST_INT32(x)
427+
428+def htons(x): return B_HOST_TO_BENDIAN_INT16(x)
429+
430+def ntohs(x): return B_BENDIAN_TO_HOST_INT16(x)
431+
432+AF_INET = 1
433+INADDR_ANY = 0x00000000
434+INADDR_BROADCAST = 0xffffffff
435+INADDR_LOOPBACK = 0x7f000001
436+SOL_SOCKET = 1
437+SO_DEBUG = 1
438+SO_REUSEADDR = 2
439+SO_NONBLOCK = 3
440+SO_REUSEPORT = 4
441+MSG_OOB = 0x1
442+SOCK_DGRAM = 1
443+SOCK_STREAM = 2
444+IPPROTO_UDP = 1
445+IPPROTO_TCP = 2
446+IPPROTO_ICMP = 3
447+B_UDP_MAX_SIZE = (65536 - 1024)
448+FD_SETSIZE = 256
449+FDSETSIZE = FD_SETSIZE
450+NFDBITS = 32
451+def _FDMSKNO(fd): return ((fd) / NFDBITS)
452+
453+def _FDBITNO(fd): return ((fd) % NFDBITS)
454diff --git a/Lib/plat-haiku1/regen b/Lib/plat-haiku1/regen
455new file mode 100644
456index 0000000..d9da80c
457--- /dev/null
458+++ b/Lib/plat-haiku1/regen
459@@ -0,0 +1,7 @@
460+#! /bin/sh
461+
462+H2PY=../../Tools/scripts/h2py.py
463+HEADERS=/boot/develop/headers
464+
465+set -v
466+python $H2PY -i '(u_long)' $HEADERS/posix/netinet/in.h
467diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
468index 57c9f14..54a7ce8 100644
469--- a/Lib/test/test_fileio.py
470+++ b/Lib/test/test_fileio.py
471@@ -312,6 +312,7 @@ class OtherFileTests(unittest.TestCase):
472             self.assertEqual(f.writable(), True)
473             if sys.platform != "darwin" and \
474                'bsd' not in sys.platform and \
475+               'haiku' not in sys.platform and \
476                not sys.platform.startswith(('sunos', 'aix')):
477                 # Somehow /dev/tty appears seekable on some BSDs
478                 self.assertEqual(f.seekable(), False)
479diff --git a/Modules/resource.c b/Modules/resource.c
480index 53a6c3e..6c5f52f 100644
481--- a/Modules/resource.c
482+++ b/Modules/resource.c
483@@ -86,6 +86,7 @@ resource_getrusage(PyObject *self, PyObject *args)
484                     PyFloat_FromDouble(doubletime(ru.ru_utime)));
485     PyStructSequence_SET_ITEM(result, 1,
486                     PyFloat_FromDouble(doubletime(ru.ru_stime)));
487+#ifndef __HAIKU__
488     PyStructSequence_SET_ITEM(result, 2, PyInt_FromLong(ru.ru_maxrss));
489     PyStructSequence_SET_ITEM(result, 3, PyInt_FromLong(ru.ru_ixrss));
490     PyStructSequence_SET_ITEM(result, 4, PyInt_FromLong(ru.ru_idrss));
491@@ -100,6 +101,7 @@ resource_getrusage(PyObject *self, PyObject *args)
492     PyStructSequence_SET_ITEM(result, 13, PyInt_FromLong(ru.ru_nsignals));
493     PyStructSequence_SET_ITEM(result, 14, PyInt_FromLong(ru.ru_nvcsw));
494     PyStructSequence_SET_ITEM(result, 15, PyInt_FromLong(ru.ru_nivcsw));
495+#endif
496 
497     if (PyErr_Occurred()) {
498         Py_DECREF(result);
499diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
500index 0139754..1d4ef23 100644
501--- a/Modules/socketmodule.c
502+++ b/Modules/socketmodule.c
503@@ -4898,7 +4898,9 @@ init_socket(void)
504 #ifndef __BEOS__
505 /* We have incomplete socket support. */
506     PyModule_AddIntConstant(m, "SOCK_RAW", SOCK_RAW);
507+#ifndef __HAIKU__
508     PyModule_AddIntConstant(m, "SOCK_SEQPACKET", SOCK_SEQPACKET);
509+#endif
510 #if defined(SOCK_RDM)
511     PyModule_AddIntConstant(m, "SOCK_RDM", SOCK_RDM);
512 #endif
513diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h
514index d98e00e..2bfb3dc 100644
515--- a/Modules/socketmodule.h
516+++ b/Modules/socketmodule.h
517@@ -47,6 +47,10 @@ typedef int socklen_t;
518 #  undef AF_NETLINK
519 #endif
520 
521+#if defined(__HAIKU__)
522+#undef HAVE_BLUETOOTH_BLUETOOTH_H
523+#endif
524+
525 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
526 #include <bluetooth/bluetooth.h>
527 #include <bluetooth/rfcomm.h>
528diff --git a/Modules/spwdmodule.c b/Modules/spwdmodule.c
529index 957de58..69be5bb 100644
530--- a/Modules/spwdmodule.c
531+++ b/Modules/spwdmodule.c
532@@ -79,7 +79,9 @@ static PyObject *mkspent(struct spwd *p)
533 
534     SETS(setIndex++, p->sp_namp);
535     SETS(setIndex++, p->sp_pwdp);
536+#ifndef __HAIKU__
537     SETI(setIndex++, p->sp_lstchg);
538+#endif
539     SETI(setIndex++, p->sp_min);
540     SETI(setIndex++, p->sp_max);
541     SETI(setIndex++, p->sp_warn);
542diff --git a/Modules/timemodule.c b/Modules/timemodule.c
543index 61b8d61..5e5d93c 100644
544--- a/Modules/timemodule.c
545+++ b/Modules/timemodule.c
546@@ -1104,11 +1104,11 @@ floatsleep(double secs)
547         return -1;
548     }
549     Py_END_ALLOW_THREADS
550-#elif defined(__BEOS__)
551+#elif defined(__BEOS__) || defined(__HAIKU__)
552     /* This sleep *CAN BE* interrupted. */
553     {
554         if( secs <= 0.0 ) {
555-            return;
556+            return 0;
557         }
558 
559         Py_BEGIN_ALLOW_THREADS
560diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
561index 4b819da..46ba828 100644
562--- a/Python/bltinmodule.c
563+++ b/Python/bltinmodule.c
564@@ -19,7 +19,7 @@
565 */
566 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
567 const char *Py_FileSystemDefaultEncoding = "mbcs";
568-#elif defined(__APPLE__)
569+#elif defined(__APPLE__) || defined(__HAIKU__)
570 const char *Py_FileSystemDefaultEncoding = "utf-8";
571 #else
572 const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
573diff --git a/Tools/scripts/h2py.py b/Tools/scripts/h2py.py
574index 40b1bce..4185370 100755
575--- a/Tools/scripts/h2py.py
576+++ b/Tools/scripts/h2py.py
577@@ -50,7 +50,7 @@ except KeyError:
578         searchdirs=os.environ['INCLUDE'].split(';')
579     except KeyError:
580         try:
581-            if  sys.platform.find("beos") == 0:
582+            if  sys.platform.find("beos") == 0 or sys.platform.find("haiku1") == 0:
583                 searchdirs=os.environ['BEINCLUDES'].split(';')
584             elif sys.platform.startswith("atheos"):
585                 searchdirs=os.environ['C_INCLUDE_PATH'].split(':')
586diff --git a/configure.ac b/configure.ac
587index aecf606..206d2ec 100644
588--- a/configure.ac
589+++ b/configure.ac
590@@ -923,7 +923,7 @@ if test $enable_shared = "yes"; then
591 	  RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
592 	  INSTSONAME="$LDLIBRARY".$SOVERSION
593           ;;
594-    Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*)
595+    Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*|Haiku*)
596 	  LDLIBRARY='libpython$(VERSION).so'
597 	  BLDLIBRARY='-L. -lpython$(VERSION)'
598 	  RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
599@@ -931,6 +931,9 @@ if test $enable_shared = "yes"; then
600 	      FreeBSD*)
601 		SOVERSION=`echo $SOVERSION|cut -d "." -f 1`
602 		;;
603+	      Haiku*)
604+	    RUNSHARED=LIBRARY_PATH=`pwd`:${LIBRARY_PATH}
605+		;;
606 	  esac
607 	  INSTSONAME="$LDLIBRARY".$SOVERSION
608 	  ;;
609@@ -1029,7 +1032,7 @@ AC_PROG_MKDIR_P
610 AC_SUBST(LN)
611 if test -z "$LN" ; then
612 	case $ac_sys_system in
613-		BeOS*) LN="ln -s";;
614+		BeOS*|Haiku*) LN="ln -s";;
615 		CYGWIN*) LN="ln -s";;
616 		atheos*) LN="ln -s";;
617 		*) LN=ln;;
618@@ -2240,7 +2243,7 @@ then
619 			BLDSHARED="$LDSHARED"
620 		fi
621 		;;
622-	Linux*|GNU*|QNX*)
623+	Linux*|GNU*|QNX*|Haiku*)
624 		LDSHARED='$(CC) -shared'
625 		LDCXXSHARED='$(CXX) -shared';;
626 	BSD/OS*/4*)
627@@ -2312,7 +2315,7 @@ then
628 		 then CCSHARED="-fPIC";
629 		 else CCSHARED="+z";
630 		 fi;;
631-	Linux*|GNU*) CCSHARED="-fPIC";;
632+	Linux*|GNU*|Haiku*) CCSHARED="-fPIC";;
633 	BSD/OS*/4*) CCSHARED="-fpic";;
634 	FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) CCSHARED="-fPIC";;
635 	OpenUNIX*|UnixWare*)
636@@ -2344,7 +2347,7 @@ then
637 	    LINKFORSHARED="-Wl,-E -Wl,+s";;
638 #	    LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";;
639 	BSD/OS/4*) LINKFORSHARED="-Xlinker -export-dynamic";;
640-	Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";;
641+	Linux*|GNU*|Haiku*) LINKFORSHARED="-Xlinker -export-dynamic";;
642 	# -u libsys_s pulls in all symbols in libsys
643 	Darwin/*) 
644 		# -u _PyMac_Error is needed to pull in the mac toolbox glue,
645@@ -2459,14 +2462,16 @@ case "$ac_sys_system" in
646 esac
647 
648 # Most SVR4 platforms (e.g. Solaris) need -lsocket and -lnsl.
649-# BeOS' sockets are stashed in libnet.
650 AC_CHECK_LIB(nsl, t_open, [LIBS="-lnsl $LIBS"]) # SVR4
651 AC_CHECK_LIB(socket, socket, [LIBS="-lsocket $LIBS"], [], $LIBS) # SVR4 sockets
652 
653+# BeOS' sockets are stashed in libnet.
654+# Haiku's sockets are stashed in libnetwork.
655 case "$ac_sys_system" in
656-BeOS*)
657-AC_CHECK_LIB(net, socket, [LIBS="-lnet $LIBS"], [], $LIBS) # BeOS
658-;;
659+	BeOS*)
660+		AC_CHECK_LIB(net, socket, [LIBS="-lnet $LIBS"], [], $LIBS);;
661+	Haiku*)
662+		AC_CHECK_LIB(network, socket, [LIBS="-lnetwork $LIBS"], [], $LIBS);;
663 esac
664 
665 AC_MSG_CHECKING(for --with-libs)
666@@ -3812,7 +3817,7 @@ fi],
667 AC_SUBST(LIBM)
668 case $ac_sys_system in
669 Darwin) ;;
670-BeOS) ;;
671+BeOS|Haiku) ;;
672 *) LIBM=-lm
673 esac
674 AC_MSG_CHECKING(for --with-libm=STRING)
675diff --git a/setup.py b/setup.py
676index 33cecc6..b57b321 100644
677--- a/setup.py
678+++ b/setup.py
679@@ -541,6 +541,12 @@ class PyBuildExt(build_ext):
680             lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
681             inc_dirs += ['/system/include', '/atheos/autolnk/include']
682             inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)
683+            
684+        # Haiku-specific include and library locations
685+        if host_platform == 'haiku1':
686+            inc_dirs += ['/boot/develop/headers/posix',
687+                         '/boot/system/develop/headers']
688+            lib_dirs += ['/boot/system/develop/lib']
689 
690         # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
691         if host_platform in ['osf1', 'unixware7', 'openunix8']:
692@@ -569,7 +575,7 @@ class PyBuildExt(build_ext):
693 
694         # Check for MacOS X, which doesn't need libm.a at all
695         math_libs = ['m']
696-        if host_platform in ['darwin', 'beos']:
697+        if host_platform in ['darwin', 'beos', 'haiku1']:
698             math_libs = []
699 
700         # XXX Omitted modules: gl, pure, dl, SGI-specific modules
701@@ -812,15 +818,22 @@ class PyBuildExt(build_ext):
702                               '/usr/local/ssl/include',
703                               '/usr/contrib/ssl/include/'
704                              ]
705-        ssl_incs = find_file('openssl/ssl.h', inc_dirs,
706+        ssl_incs = find_file('openssl/ssl.h', [],
707+                             inc_dirs + search_for_ssl_incs_in
708+                             )
709+        ssl_incs_to_add = find_file('openssl/ssl.h', inc_dirs,
710                              search_for_ssl_incs_in
711                              )
712         if ssl_incs is not None:
713             krb5_h = find_file('krb5.h', inc_dirs,
714                                ['/usr/kerberos/include'])
715             if krb5_h:
716-                ssl_incs += krb5_h
717-        ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
718+                ssl_incs_to_add += krb5_h
719+        ssl_libs = find_library_file(self.compiler, 'ssl', [],
720+                                     lib_dirs + ['/usr/local/ssl/lib',
721+                                      '/usr/contrib/ssl/lib/'
722+                                     ] )
723+        ssl_libs_to_add = find_library_file(self.compiler, 'ssl', lib_dirs,
724                                      ['/usr/local/ssl/lib',
725                                       '/usr/contrib/ssl/lib/'
726                                      ] )
727@@ -828,8 +841,8 @@ class PyBuildExt(build_ext):
728         if (ssl_incs is not None and
729             ssl_libs is not None):
730             exts.append( Extension('_ssl', ['_ssl.c'],
731-                                   include_dirs = ssl_incs,
732-                                   library_dirs = ssl_libs,
733+                                   include_dirs = ssl_incs_to_add,
734+                                   library_dirs = ssl_libs_to_add,
735                                    libraries = ['ssl', 'crypto'],
736                                    depends = ['socketmodule.h']), )
737         else:
738@@ -867,8 +880,8 @@ class PyBuildExt(build_ext):
739                 # The _hashlib module wraps optimized implementations
740                 # of hash functions from the OpenSSL library.
741                 exts.append( Extension('_hashlib', ['_hashopenssl.c'],
742-                                       include_dirs = ssl_incs,
743-                                       library_dirs = ssl_libs,
744+                                       include_dirs = ssl_incs_to_add,
745+                                       library_dirs = ssl_libs_to_add,
746                                        libraries = ['ssl', 'crypto']) )
747             else:
748                 print ("warning: openssl 0x%08x is too old for _hashlib" %
749@@ -2154,7 +2167,7 @@ class PyBuildExt(build_ext):
750             ext.libraries.append('dl')
751 
752     def _detect_nis(self, inc_dirs, lib_dirs):
753-        if host_platform in {'win32', 'cygwin', 'qnx6'}:
754+        if host_platform in {'win32', 'cygwin', 'qnx6', 'haiku1'}:
755             return None
756 
757         libs = []
758-- 
7592.21.0
760
761
762From 7b55a07d0e0ae2712ab592cce0ba7c5d7bce7fa3 Mon Sep 17 00:00:00 2001
763From: Jerome Duval <jerome.duval@gmail.com>
764Date: Sat, 5 Apr 2014 21:16:40 +0000
765Subject: fix pyconfig.h path
766
767
768diff --git a/Makefile.pre.in b/Makefile.pre.in
769index 9297e7f..abbeb60 100644
770--- a/Makefile.pre.in
771+++ b/Makefile.pre.in
772@@ -109,7 +109,7 @@ BINDIR=		@bindir@
773 LIBDIR=		@libdir@
774 MANDIR=		@mandir@
775 INCLUDEDIR=	@includedir@
776-CONFINCLUDEDIR=	$(exec_prefix)/include
777+CONFINCLUDEDIR=	$(INCLUDEDIR)
778 SCRIPTDIR=	$(prefix)/lib
779 
780 # Detailed destination directories
781-- 
7822.21.0
783
784
785From 06e07e7c6df2f06f435687643b9cb6cd836bdb7f Mon Sep 17 00:00:00 2001
786From: Adrien Destugues <pulkomandy@pulkomandy.tk>
787Date: Wed, 18 Jun 2014 12:19:13 +0000
788Subject: Import missed change from the 2.6.9 patches
789
790This makes our site- and vendor- packages work properly again.
791It's sill missing the changes to addusersitepackages. This method was apparently refactored, and I don't have enough Python knowledge to redo our changes in the new code. User packages will not workas
792expected  with
793this version of Python.
794
795diff --git a/Lib/site.py b/Lib/site.py
796index 3b51e81..11fb12c 100644
797--- a/Lib/site.py
798+++ b/Lib/site.py
799@@ -287,6 +287,13 @@ def getsitepackages():
800 
801         if sys.platform in ('os2emx', 'riscos'):
802             sitepackages.append(os.path.join(prefix, "Lib", "site-packages"))
803+        elif sys.platform.startswith('haiku'):
804+            sitepackages.append(os.path.join(prefix, "non-packaged", "lib",
805+                                        "python" + sys.version[:3],
806+                                        "site-packages"))
807+            sitepackages.append(os.path.join(prefix, "lib",
808+                                        "python" + sys.version[:3],
809+                                        "vendor-packages"))
810         elif os.sep == '/':
811             sitepackages.append(os.path.join(prefix, "lib",
812                                         "python" + sys.version[:3],
813-- 
8142.21.0
815
816
817From 95f8cc6a804975272637a0588fa9755eb31163a3 Mon Sep 17 00:00:00 2001
818From: Adrien Destugues <pulkomandy@pulkomandy.tk>
819Date: Sun, 21 Sep 2014 18:59:44 +0200
820Subject: gcc2 fix.
821
822
823diff --git a/Modules/_ctypes/libffi/include/ffi_common.h b/Modules/_ctypes/libffi/include/ffi_common.h
824index 37f5a9e..37b0b25 100644
825--- a/Modules/_ctypes/libffi/include/ffi_common.h
826+++ b/Modules/_ctypes/libffi/include/ffi_common.h
827@@ -119,7 +119,7 @@ typedef signed int   SINT64 __attribute__((__mode__(__DI__)));
828 
829 typedef float FLOAT32;
830 
831-#ifndef __GNUC__
832+#if !defined(__GNUC__) || __GNUC__ < 3
833 #define __builtin_expect(x, expected_value) (x)
834 #endif
835 #define LIKELY(x)    __builtin_expect(!!(x),1)
836-- 
8372.21.0
838
839
840From fc577acd82a0a9244d8f871ba1016923dcef5df9 Mon Sep 17 00:00:00 2001
841From: Jerome Duval <jerome.duval@gmail.com>
842Date: Fri, 28 Nov 2014 16:26:28 +0000
843Subject: tarfile: let link fail and catch exception.
844
845
846diff --git a/Lib/tarfile.py b/Lib/tarfile.py
847index adf91d5..f284408 100644
848--- a/Lib/tarfile.py
849+++ b/Lib/tarfile.py
850@@ -2272,7 +2272,7 @@ class TarFile(object):
851           (platform limitation), we try to make a copy of the referenced file
852           instead of a link.
853         """
854-        if hasattr(os, "symlink") and hasattr(os, "link"):
855+        try:
856             # For systems that support symbolic and hard links.
857             if tarinfo.issym():
858                 if os.path.lexists(targetpath):
859@@ -2286,7 +2286,7 @@ class TarFile(object):
860                     os.link(tarinfo._link_target, targetpath)
861                 else:
862                     self._extract_member(self._find_link_target(tarinfo), targetpath)
863-        else:
864+        except (os.error, AttributeError):
865             try:
866                 self._extract_member(self._find_link_target(tarinfo), targetpath)
867             except KeyError:
868-- 
8692.21.0
870
871
872From 4c3a6e25aa0d2c32d5746a13108a170452255bd5 Mon Sep 17 00:00:00 2001
873From: Timothy Gu <timothygu99@gmail.com>
874Date: Sun, 11 Jan 2015 18:18:22 -0800
875Subject: Fix resource module after the initial haiku patch
876
877
878diff --git a/Modules/resource.c b/Modules/resource.c
879index 6c5f52f..73758bb 100644
880--- a/Modules/resource.c
881+++ b/Modules/resource.c
882@@ -101,6 +101,21 @@ resource_getrusage(PyObject *self, PyObject *args)
883     PyStructSequence_SET_ITEM(result, 13, PyInt_FromLong(ru.ru_nsignals));
884     PyStructSequence_SET_ITEM(result, 14, PyInt_FromLong(ru.ru_nvcsw));
885     PyStructSequence_SET_ITEM(result, 15, PyInt_FromLong(ru.ru_nivcsw));
886+#else
887+    PyStructSequence_SET_ITEM(result, 2, PyInt_FromLong(0));
888+    PyStructSequence_SET_ITEM(result, 3, PyInt_FromLong(0));
889+    PyStructSequence_SET_ITEM(result, 4, PyInt_FromLong(0));
890+    PyStructSequence_SET_ITEM(result, 5, PyInt_FromLong(0));
891+    PyStructSequence_SET_ITEM(result, 6, PyInt_FromLong(0));
892+    PyStructSequence_SET_ITEM(result, 7, PyInt_FromLong(0));
893+    PyStructSequence_SET_ITEM(result, 8, PyInt_FromLong(0));
894+    PyStructSequence_SET_ITEM(result, 9, PyInt_FromLong(0));
895+    PyStructSequence_SET_ITEM(result, 10, PyInt_FromLong(0));
896+    PyStructSequence_SET_ITEM(result, 11, PyInt_FromLong(0));
897+    PyStructSequence_SET_ITEM(result, 12, PyInt_FromLong(0));
898+    PyStructSequence_SET_ITEM(result, 13, PyInt_FromLong(0));
899+    PyStructSequence_SET_ITEM(result, 14, PyInt_FromLong(0));
900+    PyStructSequence_SET_ITEM(result, 15, PyInt_FromLong(0));
901 #endif
902 
903     if (PyErr_Occurred()) {
904-- 
9052.21.0
906
907
908From bed36c6af79128f0e54922b951320a825dc59fbd Mon Sep 17 00:00:00 2001
909From: Timothy Gu <timothygu99@gmail.com>
910Date: Sun, 11 Jan 2015 18:40:43 -0800
911Subject: resource: Fix [gs]et_rlimit() modes detection
912
913Haiku defines many of them, but they are actually empty stubs that will always
914return EINVAL. No better way of doing this.
915
916diff --git a/Modules/resource.c b/Modules/resource.c
917index 73758bb..0c396f6 100644
918--- a/Modules/resource.c
919+++ b/Modules/resource.c
920@@ -284,19 +284,19 @@ initresource(void)
921                        (PyObject*) &StructRUsageType);
922 
923     /* insert constants */
924-#ifdef RLIMIT_CPU
925+#if !defined(__HAIKU__) && defined(RLIMIT_CPU)
926     PyModule_AddIntConstant(m, "RLIMIT_CPU", RLIMIT_CPU);
927 #endif
928 
929-#ifdef RLIMIT_FSIZE
930+#if !defined(__HAIKU__) && defined(RLIMIT_FSIZE)
931     PyModule_AddIntConstant(m, "RLIMIT_FSIZE", RLIMIT_FSIZE);
932 #endif
933 
934-#ifdef RLIMIT_DATA
935+#if !defined(__HAIKU__) && defined(RLIMIT_DATA)
936     PyModule_AddIntConstant(m, "RLIMIT_DATA", RLIMIT_DATA);
937 #endif
938 
939-#ifdef RLIMIT_STACK
940+#if !defined(__HAIKU__) && defined(RLIMIT_STACK)
941     PyModule_AddIntConstant(m, "RLIMIT_STACK", RLIMIT_STACK);
942 #endif
943 
944@@ -308,31 +308,31 @@ initresource(void)
945     PyModule_AddIntConstant(m, "RLIMIT_NOFILE", RLIMIT_NOFILE);
946 #endif
947 
948-#ifdef RLIMIT_OFILE
949+#if !defined(__HAIKU__) && defined(RLIMIT_OFILE)
950     PyModule_AddIntConstant(m, "RLIMIT_OFILE", RLIMIT_OFILE);
951 #endif
952 
953-#ifdef RLIMIT_VMEM
954+#if !defined(__HAIKU__) && defined(RLIMIT_VMEM)
955     PyModule_AddIntConstant(m, "RLIMIT_VMEM", RLIMIT_VMEM);
956 #endif
957 
958-#ifdef RLIMIT_AS
959+#if !defined(__HAIKU__) && defined(RLIMIT_AS)
960     PyModule_AddIntConstant(m, "RLIMIT_AS", RLIMIT_AS);
961 #endif
962 
963-#ifdef RLIMIT_RSS
964+#if !defined(__HAIKU__) && defined(RLIMIT_RSS)
965     PyModule_AddIntConstant(m, "RLIMIT_RSS", RLIMIT_RSS);
966 #endif
967 
968-#ifdef RLIMIT_NPROC
969+#if !defined(__HAIKU__) && defined(RLIMIT_NPROC)
970     PyModule_AddIntConstant(m, "RLIMIT_NPROC", RLIMIT_NPROC);
971 #endif
972 
973-#ifdef RLIMIT_MEMLOCK
974+#if !defined(__HAIKU__) && defined(RLIMIT_MEMLOCK)
975     PyModule_AddIntConstant(m, "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK);
976 #endif
977 
978-#ifdef RLIMIT_SBSIZE
979+#if !defined(__HAIKU__) && defined(RLIMIT_SBSIZE)
980     PyModule_AddIntConstant(m, "RLIMIT_SBSIZE", RLIMIT_SBSIZE);
981 #endif
982 
983-- 
9842.21.0
985
986
987From 8687a87d528113053311ab3ebbc531224a2b00d1 Mon Sep 17 00:00:00 2001
988From: Jerome Duval <jerome.duval@gmail.com>
989Date: Tue, 26 May 2015 19:39:55 +0000
990Subject: Haiku hasn't makedev(), _PyInt_FromDev isn't defined.
991
992
993diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
994index 7a1a694..0f226a0 100644
995--- a/Modules/posixmodule.c
996+++ b/Modules/posixmodule.c
997@@ -1489,6 +1489,8 @@ _pystat_fromstructstat(STRUCT_STAT *st)
998 #endif
999 #ifdef MS_WINDOWS
1000     PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev));
1001+#elif defined(__HAIKU__)
1002+    PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong(st->st_dev));
1003 #else
1004     PyStructSequence_SET_ITEM(v, 2, _PyInt_FromDev(st->st_dev));
1005 #endif
1006-- 
10072.21.0
1008
1009
1010From 73fd37edd447798cc15dc53a00083346c1a9f788 Mon Sep 17 00:00:00 2001
1011From: Philippe Houdoin <philippe.houdoin@gmail.com>
1012Date: Tue, 23 May 2017 19:48:08 +0000
1013Subject: Implement CTypes's find_library for Haiku
1014
1015
1016diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
1017index ab10ec5..72e495b 100644
1018--- a/Lib/ctypes/util.py
1019+++ b/Lib/ctypes/util.py
1020@@ -232,6 +232,55 @@ elif os.name == "posix":
1021         def find_library(name, is64 = False):
1022             return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name))
1023 
1024+    elif sys.platform.startswith("haiku"):
1025+
1026+        def _num_version(libname):
1027+            # "libxyz.so.MAJOR.MINOR" => [ MAJOR, MINOR ]
1028+            parts = libname.split(b".")
1029+            nums = []
1030+            try:
1031+                while parts:
1032+                    nums.insert(0, int(parts.pop()))
1033+            except ValueError:
1034+                pass
1035+            return nums or [sys.maxint]
1036+
1037+        def find_library(name):
1038+            for directory in os.environ['LIBRARY_PATH'].split(os.pathsep):
1039+                if directory.startswith("%A/"):
1040+                    directory = directory.replace('%A', 
1041+                        os.path.dirname(os.path.abspath(sys.argv[0] or os.getcwd())))
1042+
1043+                if not os.path.isdir(directory):
1044+                    continue
1045+
1046+                # try direct match
1047+                fname = os.path.join(directory, name)
1048+                if os.path.isfile(fname):
1049+                    return fname
1050+
1051+                fname = os.path.join(directory, 'lib%s.so' % name)
1052+                if os.path.isfile(fname):
1053+                    return fname
1054+
1055+                # no exact matching in this directroy
1056+                # collect versioned candidates, if any
1057+                candidates = []
1058+                pattern = re.compile(r'lib%s\.so\.\S+' % re.escape(name))
1059+                for entry in os.listdir(directory):
1060+                	if not os.path.isfile(os.path.join(directory, entry)):
1061+                		continue
1062+
1063+                	if re.match(pattern, entry):
1064+                		candidates.append(os.path.join(directory, entry))
1065+
1066+                if candidates:
1067+                    # return latest version found
1068+                    candidates.sort(key=_num_version)
1069+                    return candidates[-1]
1070+
1071+            return None
1072+
1073     else:
1074 
1075         def _findSoname_ldconfig(name):
1076@@ -299,6 +348,12 @@ def test():
1077             print cdll.LoadLibrary("libcrypto.dylib")
1078             print cdll.LoadLibrary("libSystem.dylib")
1079             print cdll.LoadLibrary("System.framework/System")
1080+        elif sys.platform.startswith("haiku"):
1081+            print find_library("libbz2.so.1.0")
1082+            print find_library("tracker")
1083+            print find_library("media")
1084+            print cdll.LoadLibrary(find_library("tracker"))
1085+            print cdll.LoadLibrary("libmedia.so")
1086         else:
1087             print cdll.LoadLibrary("libm.so")
1088             print cdll.LoadLibrary("libcrypt.so")
1089-- 
10902.21.0
1091
1092
1093From fa20f098eb63bbcc688442dd0ed2de1267e889d3 Mon Sep 17 00:00:00 2001
1094From: Philippe Houdoin <philippe.houdoin@gmail.com>
1095Date: Wed, 24 May 2017 11:06:41 +0000
1096Subject: Map 'c' and 'm' libraries to libroot.so on Haiku
1097
1098
1099diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
1100index 72e495b..a2cc0a1 100644
1101--- a/Lib/ctypes/util.py
1102+++ b/Lib/ctypes/util.py
1103@@ -236,7 +236,7 @@ elif os.name == "posix":
1104 
1105         def _num_version(libname):
1106             # "libxyz.so.MAJOR.MINOR" => [ MAJOR, MINOR ]
1107-            parts = libname.split(b".")
1108+            parts = libname.split('.')
1109             nums = []
1110             try:
1111                 while parts:
1112@@ -246,6 +246,8 @@ elif os.name == "posix":
1113             return nums or [sys.maxint]
1114 
1115         def find_library(name):
1116+            if name in ('c', 'm'):
1117+                return find_library('root')        
1118             for directory in os.environ['LIBRARY_PATH'].split(os.pathsep):
1119                 if directory.startswith("%A/"):
1120                     directory = directory.replace('%A', 
1121-- 
11222.21.0
1123
1124
1125From 6e5535881d6e13810d56c3153b7c70786d08977c Mon Sep 17 00:00:00 2001
1126From: Jerome Duval <jerome.duval@gmail.com>
1127Date: Tue, 30 Apr 2019 20:39:51 +0200
1128Subject: Python/thread_pthread.h: c89 fix.
1129
1130
1131diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h
1132index 6d4b3b3..8c42fb8 100644
1133--- a/Python/thread_pthread.h
1134+++ b/Python/thread_pthread.h
1135@@ -184,6 +184,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
1136 {
1137     pthread_t th;
1138     int status;
1139+    pythread_callback *callback;
1140 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
1141     pthread_attr_t attrs;
1142 #endif
1143@@ -213,7 +214,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
1144     pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
1145 #endif
1146 
1147-    pythread_callback *callback = malloc(sizeof(pythread_callback));
1148+    callback = malloc(sizeof(pythread_callback));
1149 
1150     if (callback == NULL) {
1151         return -1;
1152-- 
11532.21.0
1154
1155
1156From 21502a9c6059d24d14924f518667f800764f5e42 Mon Sep 17 00:00:00 2001
1157From: Philipp Wolfer <phil@parolu.io>
1158Date: Mon, 23 Sep 2019 09:53:39 +0200
1159Subject: [PATCH] webbrowser: Support for default browsers on Haiku
1160
1161---
1162 Lib/webbrowser.py | 10 ++++++++++
1163 1 file changed, 10 insertions(+)
1164
1165diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py
1166index 15eeb660e2..d73749d696 100755
1167--- a/Lib/webbrowser.py
1168+++ b/Lib/webbrowser.py
1169@@ -644,6 +644,16 @@ if sys.platform == 'darwin':
1170     register("chrome", None, MacOSXOSAScript('chrome'), -1)
1171     register("MacOSX", None, MacOSXOSAScript('default'), -1)
1172 
1173+#
1174+# Platform support for Haiku
1175+#
1176+
1177+if sys.platform[:5] == "haiku":
1178+    # First try to use the default configured browser
1179+    register("haiku-default", None, GenericBrowser("open"))
1180+    # Fall back to WebPositive as the standard browser of Haiku
1181+    register("webpositive", None, BackgroundBrowser("WebPositive"))
1182+
1183 
1184 #
1185 # Platform support for OS/2
1186-- 
11872.23.0
1188
1189