home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pytho152.zip / emx / src / Python / Python-1.5.2.diff
Encoding:
Text File  |  2000-08-10  |  20.1 KB  |  716 lines

  1. diff -ur Python-1.5.2.org/Include/osdefs.h Python-1.5.2/Include/osdefs.h
  2. --- Python-1.5.2.org/Include/osdefs.h    Fri Dec  5 21:39:24 1997
  3. +++ Python-1.5.2/Include/osdefs.h    Thu Aug 10 14:50:48 2000
  4. @@ -49,7 +49,7 @@
  5.  #if defined(MS_WINDOWS) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__DJGPP__) || defined(PYOS_OS2)
  6.  #define SEP '\\'
  7.  #define ALTSEP '/'
  8. -#define MAXPATHLEN 256
  9. +#define MAXPATHLEN 260
  10.  #define DELIM ';'
  11.  #endif
  12.  #endif
  13. diff -ur Python-1.5.2.org/Lib/test/test_signal.py Python-1.5.2/Lib/test/test_signal.py
  14. --- Python-1.5.2.org/Lib/test/test_signal.py    Sat Nov 22 21:50:24 1997
  15. +++ Python-1.5.2/Lib/test/test_signal.py    Thu Aug 10 14:50:48 2000
  16. @@ -4,6 +4,7 @@
  17.  import os
  18.  import sys
  19.  
  20. +# In fact, the OS/2 port compiled with EMX+GCC works okay, but for other's sake...
  21.  if sys.platform[:3] in ('win', 'os2'):
  22.      raise ImportError, "Can't test signal on %s" % sys.platform[:3]
  23.  
  24. diff -ur Python-1.5.2.org/Modules/posixmodule.c Python-1.5.2/Modules/posixmodule.c
  25. --- Python-1.5.2.org/Modules/posixmodule.c    Wed Apr  7 15:49:40 1999
  26. +++ Python-1.5.2/Modules/posixmodule.c    Thu Aug 10 14:50:48 2000
  27. @@ -54,6 +54,10 @@
  28.  #define  INCL_DOSPROCESS
  29.  #define  INCL_NOPMAPI
  30.  #include <os2.h>
  31. +#if defined (PYCC_GCC)
  32. +#include <ctype.h>
  33. +#include <io.h>
  34. +#endif
  35.  #endif
  36.  
  37.  #include <sys/types.h>
  38. @@ -112,6 +116,9 @@
  39.  #define HAVE_SYSTEM    1
  40.  #else /* 16-bit Windows */
  41.  #endif /* !MS_WIN32 */
  42. +#else
  43. +#if defined (PYOS_OS2) && defined (PYCC_GCC)
  44. +/* Everything needed is defined in PC/os2emx/config.h */
  45.  #else            /* all other compilers */
  46.  /* Unix functions that the configure script doesn't check for */
  47.  #define HAVE_EXECV      1
  48. @@ -129,6 +136,7 @@
  49.  #define HAVE_SYSTEM    1
  50.  #define HAVE_WAIT       1
  51.  #define HAVE_TTYNAME    1
  52. +#endif /* PYOS_OS2 && PYCC_GCC */
  53.  #endif  /* _MSC_VER */
  54.  #endif  /* __BORLANDC__ */
  55.  #endif  /* ! __WATCOMC__ || __QNX__ */
  56. @@ -603,7 +611,6 @@
  57.      PyObject *self;
  58.      PyObject *args;
  59.  {
  60. -    PyObject *file;
  61.      int id;
  62.      char *ret;
  63.  
  64. @@ -912,7 +919,7 @@
  65.      if (srchcnt > 0) { /* If Directory is NOT Totally Empty, */
  66.          do {
  67.              if (ep.achName[0] == '.'
  68. -            && (ep.achName[1] == '\0' || ep.achName[1] == '.' && ep.achName[2] == '\0'))
  69. +            && (ep.achName[1] == '\0' || (ep.achName[1] == '.' && ep.achName[2] == '\0')))
  70.                  continue; /* Skip Over "." and ".." Names */
  71.  
  72.              strcpy(namebuf, ep.achName);
  73. @@ -1824,7 +1831,7 @@
  74.  "popen(command [, mode='r' [, bufsize]]) -> pipe\n\
  75.  Open a pipe to/from a command returning a file object.";
  76.  
  77. -#if defined(PYOS_OS2)
  78. +#if defined(PYOS_OS2) && !defined (PYCC_GCC)
  79.  static int
  80.  async_system(const char *command)
  81.  {
  82. @@ -2046,7 +2053,7 @@
  83.      PyObject *self;
  84.      PyObject *args;
  85.  {
  86. -    int pid, sts;
  87. +    int pid;
  88.  #ifdef UNION_WAIT
  89.      union wait status;
  90.  #define status_i (status.w_status)
  91. @@ -3349,7 +3356,7 @@
  92.      case 40: ver = "4.00"; break;
  93.      case 50: ver = "5.00"; break;
  94.      default:
  95. -        sprintf(tmp, "%d-%d", values[QSV_VERSION_MAJOR],
  96. +        sprintf(tmp, "%ld-%ld", values[QSV_VERSION_MAJOR],
  97.                                values[QSV_VERSION_MINOR]);
  98.          ver = &tmp[0];
  99.      }
  100. diff -ur Python-1.5.2.org/Modules/readline.c Python-1.5.2/Modules/readline.c
  101. --- Python-1.5.2.org/Modules/readline.c    Fri Jan 29 21:55:02 1999
  102. +++ Python-1.5.2/Modules/readline.c    Thu Aug 10 14:50:48 2000
  103. @@ -233,6 +233,8 @@
  104.  setup_readline()
  105.  {
  106.      rl_readline_name = "python";
  107. +    /* Allow $if term= in .inputrc to work */
  108. +        rl_terminal_name = getenv ("TERM");
  109.      /* Force rebind of TAB to insert-tab */
  110.      rl_bind_key('\t', rl_insert);
  111.      /* Bind both ESC-TAB and ESC-ESC to the completion function */
  112. diff -ur Python-1.5.2.org/Modules/selectmodule.c Python-1.5.2/Modules/selectmodule.c
  113. --- Python-1.5.2.org/Modules/selectmodule.c    Fri Dec  4 18:50:04 1998
  114. +++ Python-1.5.2/Modules/selectmodule.c    Thu Aug 10 14:50:48 2000
  115. @@ -50,7 +50,7 @@
  116.  
  117.  #include <sys/types.h>
  118.  
  119. -#if defined(PYOS_OS2)
  120. +#if defined(PYOS_OS2) && !defined (PYCC_GCC)
  121.  #include <sys/time.h>
  122.  #include <utils.h>
  123.  #endif
  124. diff -ur Python-1.5.2.org/Modules/signalmodule.c Python-1.5.2/Modules/signalmodule.c
  125. --- Python-1.5.2.org/Modules/signalmodule.c    Mon Dec 21 19:32:38 1998
  126. +++ Python-1.5.2/Modules/signalmodule.c    Thu Aug 10 14:50:48 2000
  127. @@ -50,7 +50,7 @@
  128.  #define SIG_ERR ((RETSIGTYPE (*)())-1)
  129.  #endif
  130.  
  131. -#if defined(PYOS_OS2)
  132. +#if defined (PYOS_OS2) && !defined (PYCC_GCC)
  133.  #define NSIG 12
  134.  #include <process.h>
  135.  #endif
  136. diff -ur Python-1.5.2.org/Modules/socketmodule.c Python-1.5.2/Modules/socketmodule.c
  137. --- Python-1.5.2.org/Modules/socketmodule.c    Tue Apr 13 04:07:32 1999
  138. +++ Python-1.5.2/Modules/socketmodule.c    Thu Aug 10 14:50:48 2000
  139. @@ -185,7 +185,7 @@
  140.  #define FORCE_ANSI_FUNC_DEFS
  141.  #endif
  142.  
  143. -#if defined(PYOS_OS2)
  144. +#if defined(PYOS_OS2) && !defined (PYCC_GCC)
  145.  #define close soclose
  146.  #define NO_DUP /* Sockets are Not Actual File Handles under OS/2 */
  147.  #define FORCE_ANSI_FUNC_DEFS
  148. @@ -254,7 +254,7 @@
  149.      else
  150.  #endif
  151.  
  152. -#if defined(PYOS_OS2)
  153. +#if defined(PYOS_OS2) && !defined (PYCC_GCC)
  154.      if (sock_errno() != NO_ERROR) {
  155.          APIRET rc;
  156.          ULONG  msglen;
  157. @@ -662,7 +662,7 @@
  158.                  (void *)(&block), sizeof( int ) );
  159.  #else
  160.  #ifndef MS_WINDOWS
  161. -#ifdef PYOS_OS2
  162. +#if defined (PYOS_OS2) && !defined (PYCC_GCC)
  163.      block = !block;
  164.      ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block));
  165.  #else /* !PYOS_OS2 */
  166. @@ -1121,7 +1121,7 @@
  167.      Py_BEGIN_ALLOW_THREADS
  168.      n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags,
  169.  #ifndef MS_WINDOWS
  170. -#if defined(PYOS_OS2)
  171. +#if defined (PYOS_OS2) && !defined (PYCC_GCC)
  172.               (struct sockaddr *)addrbuf, &addrlen
  173.  #else
  174.               (ANY *)addrbuf, &addrlen
  175. @@ -1866,27 +1866,24 @@
  176.  
  177.  /* Additional initialization and cleanup for OS/2 */
  178.  
  179. -static void
  180. -OS2cleanup()
  181. -{
  182. -    /* No cleanup is necessary for OS/2 Sockets */
  183. -}
  184. -
  185.  static int
  186.  OS2init()
  187.  {
  188. +#if !defined (PYCC_GCC)
  189.      char reason[64];
  190.      int rc = sock_init();
  191.  
  192. -    if (rc == 0) {
  193. -        atexit(OS2cleanup);
  194. +    if (rc == 0)
  195.          return 1; /* Indicate Success */
  196. -    }
  197.  
  198.      sprintf(reason, "OS/2 TCP/IP Error# %d", sock_errno());
  199.      PyErr_SetString(PyExc_ImportError, reason);
  200.  
  201.      return 0;  /* Indicate Failure */
  202. +#else
  203. +    /* no need to initialize sockets under OS/2 with GCC/EMX */
  204. +    return 1;
  205. +#endif
  206.  }
  207.  
  208.  #endif /* PYOS_OS2 */
  209. @@ -1984,7 +1981,7 @@
  210.          return;
  211.      m = Py_InitModule3("_socket", PySocket_methods, module_doc);
  212.  #else
  213. -#if defined(__TOS_OS2__)
  214. +#if defined(PYOS_OS2)
  215.      if (!OS2init())
  216.          return;
  217.      m = Py_InitModule3("_socket", PySocket_methods, module_doc);
  218. diff -ur Python-1.5.2.org/Modules/timemodule.c Python-1.5.2/Modules/timemodule.c
  219. --- Python-1.5.2.org/Modules/timemodule.c    Mon Apr  5 21:54:14 1999
  220. +++ Python-1.5.2/Modules/timemodule.c    Thu Aug 10 16:05:16 2000
  221. @@ -53,7 +53,7 @@
  222.  #include <unistd.h>
  223.  #endif
  224.  
  225. -#if defined(HAVE_SELECT) && !defined(__BEOS__)
  226. +#if defined(HAVE_SELECT) && !defined(__BEOS__) && !defined(__EMX__)
  227.  #include "myselect.h"
  228.  #else
  229.  #include "mytime.h"
  230. @@ -87,6 +87,12 @@
  231.  #undef HAVE_CLOCK /* We have our own version down below */
  232.  #endif /* MS_WIN32 */
  233.  
  234. +#ifdef PYOS_OS2
  235. +#define INCL_DOS
  236. +#define INCL_ERRORS
  237. +#include <os2.h>
  238. +#endif
  239. +
  240.  #if defined(PYCC_VACPP)
  241.  #include <sys/time.h>
  242.  #endif
  243. @@ -409,7 +415,10 @@
  244.  #endif /* HAVE_STRFTIME */
  245.  
  246.  #ifdef HAVE_STRPTIME
  247. -/* extern char *strptime(); /* Enable this if it's not declared in <time.h> */
  248. +
  249. +#if 0
  250. +extern char *strptime(); /* Enable this if it's not declared in <time.h> */
  251. +#endif
  252.  
  253.  static PyObject *
  254.  time_strptime(self, args)
  255. @@ -741,7 +750,7 @@
  256.  #endif /* MPW */
  257.  {
  258.  /* XXX Should test for MS_WIN32 first! */
  259. -#if defined(HAVE_SELECT) && !defined(__BEOS__)
  260. +#if defined(HAVE_SELECT) && !defined(__BEOS__) && !defined(__EMX__)
  261.      struct timeval t;
  262.      double frac;
  263.      frac = fmod(secs, 1.0);
  264. diff -ur Python-1.5.2.org/Objects/fileobject.c Python-1.5.2/Objects/fileobject.c
  265. --- Python-1.5.2.org/Objects/fileobject.c    Sat Apr 10 15:48:22 1999
  266. +++ Python-1.5.2/Objects/fileobject.c    Thu Aug 10 14:50:48 2000
  267. @@ -60,6 +60,10 @@
  268.  #define NO_FOPEN_ERRNO
  269.  #endif
  270.  
  271. +#if defined (PYOS_OS2) && defined (PYCC_GCC)
  272. +#include <io.h>
  273. +#endif
  274. +
  275.  #define BUF(v) PyString_AS_STRING((PyStringObject *)v)
  276.  
  277.  #include <errno.h>
  278. diff -ur Python-1.5.2.org/Objects/floatobject.c Python-1.5.2/Objects/floatobject.c
  279. --- Python-1.5.2.org/Objects/floatobject.c    Fri Mar 19 20:59:40 1999
  280. +++ Python-1.5.2/Objects/floatobject.c    Thu Aug 10 14:50:48 2000
  281. @@ -685,7 +685,8 @@
  282.                      PyFloat_AsString(buf, p);
  283.                      fprintf(stderr,
  284.                   "#   <float at %lx, refcnt=%d, val=%s>\n",
  285. -                        p, p->ob_refcnt, buf);
  286. +                        (long unsigned int)p,
  287. +                        p->ob_refcnt, buf);
  288.                  }
  289.              }
  290.              list = list->next;
  291. diff -ur Python-1.5.2.org/Objects/intobject.c Python-1.5.2/Objects/intobject.c
  292. --- Python-1.5.2.org/Objects/intobject.c    Fri Mar 19 20:30:38 1999
  293. +++ Python-1.5.2/Objects/intobject.c    Thu Aug 10 14:50:50 2000
  294. @@ -893,7 +893,8 @@
  295.                  if (PyInt_Check(p) && p->ob_refcnt != 0)
  296.                      fprintf(stderr,
  297.                  "#   <int at %lx, refcnt=%d, val=%ld>\n",
  298. -                        p, p->ob_refcnt, p->ob_ival);
  299. +                        (long unsigned int)p,
  300. +                        p->ob_refcnt, p->ob_ival);
  301.              }
  302.              list = list->next;
  303.          }
  304. diff -ur Python-1.5.2.org/PC/getpathp.c Python-1.5.2/PC/getpathp.c
  305. --- Python-1.5.2.org/PC/getpathp.c    Tue Aug 11 20:35:56 1998
  306. +++ Python-1.5.2/PC/getpathp.c    Thu Aug 10 14:50:50 2000
  307. @@ -40,6 +40,11 @@
  308.  extern BOOL PyWin_IsWin32s();
  309.  #endif
  310.  
  311. +#if defined (PYOS_OS2)
  312. +#define INCL_DOS
  313. +#include <os2.h>
  314. +#endif
  315. +
  316.  #include <sys/types.h>
  317.  #include <sys/stat.h>
  318.  #include <string.h>
  319. @@ -275,12 +280,21 @@
  320.  get_progpath()
  321.  {
  322.      extern char *Py_GetProgramName();
  323. +    extern void Py_SetProgramName(char *);
  324.      char *path = getenv("PATH");
  325.      char *prog = Py_GetProgramName();
  326.  
  327.  #ifdef MS_WIN32
  328.      if (GetModuleFileName(NULL, progpath, MAXPATHLEN))
  329.          return;
  330. +#endif
  331. +#if defined (PYOS_OS2)
  332. +    {
  333. +        PPIB pib;
  334. +        if ((DosGetInfoBlocks (NULL, &pib) == 0)
  335. +         && (DosQueryModuleName (pib->pib_hmte, sizeof (progpath), progpath) == 0))
  336. +            return;
  337. +    }
  338.  #endif
  339.      if (prog == NULL || *prog == '\0')
  340.          prog = "python";
  341. diff -ur Python-1.5.2.org/PC/os2vacpp/getpathp.c Python-1.5.2/PC/os2vacpp/getpathp.c
  342. --- Python-1.5.2.org/PC/os2vacpp/getpathp.c    Mon Jul 27 13:49:04 1998
  343. +++ Python-1.5.2/PC/os2vacpp/getpathp.c    Thu Aug 10 14:50:50 2000
  344. @@ -344,6 +344,7 @@
  345.      get_progpath();
  346.      strcpy(argv0_path, progpath);
  347.      reduce(argv0_path);
  348. +
  349.      if (pythonhome == NULL || *pythonhome == '\0') {
  350.          if (search_for_prefix(argv0_path, LANDMARK))
  351.              pythonhome = prefix;
  352. @@ -486,7 +487,7 @@
  353.      if (!module_search_path)
  354.          calculate_path();
  355.  
  356. -    return prefix;
  357. +    return Py_GetPath;
  358.  }
  359.  
  360.  char *
  361. diff -ur Python-1.5.2.org/Python/fmod.c Python-1.5.2/Python/fmod.c
  362. --- Python-1.5.2.org/Python/fmod.c    Fri Oct 25 14:43:04 1996
  363. +++ Python-1.5.2/Python/fmod.c    Thu Aug 10 14:50:50 2000
  364. @@ -36,6 +36,9 @@
  365.  #include "mymath.h"
  366.  #include <errno.h>
  367.  
  368. +/* BUG WARNING: fmod (-10,1) returns -1!!! */
  369. +/* if someone cares to fix it, please do */
  370. +
  371.  double
  372.  fmod(double x, double y)
  373.  {
  374. diff -ur Python-1.5.2.org/Python/importdl.c Python-1.5.2/Python/importdl.c
  375. --- Python-1.5.2.org/Python/importdl.c    Wed Jan 27 17:53:10 1999
  376. +++ Python-1.5.2/Python/importdl.c    Thu Aug 10 14:50:50 2000
  377. @@ -589,8 +589,8 @@
  378.          if (rc != NO_ERROR) {
  379.              char errBuf[256];
  380.              sprintf(errBuf,
  381. -                "DLL load failed, rc = %d, problem '%s': %s",
  382. -                rc, failreason);
  383. +                "%s: DLL load failed, rc = %ld, problem '%s'",
  384. +                pathname, rc, failreason);
  385.              PyErr_SetString(PyExc_ImportError, errBuf);
  386.              return NULL;
  387.          }
  388. diff -ur Python-1.5.2.org/Python/strtod.c Python-1.5.2/Python/strtod.c
  389. --- Python-1.5.2.org/Python/strtod.c    Wed Apr  7 16:07:22 1999
  390. +++ Python-1.5.2/Python/strtod.c    Thu Aug 10 14:50:50 2000
  391. @@ -1,4 +1,5 @@
  392.  #include "config.h"
  393. +#include <stdio.h>
  394.  
  395.  /* comp.sources.misc strtod(), as posted in comp.lang.tcl,
  396.     with bugfix for "123000.0" and acceptance of space after 'e' sign nuked.
  397. @@ -79,7 +80,7 @@
  398.      dp = buffer;    
  399.      *dp++ = '0'; *dp++ = '.';
  400.      buforg = dp, buflim = buffer+48;
  401. -    for (save = sp; c = *sp; sp++)
  402. +    for (save = sp; (c = *sp); sp++)
  403.          if (c == '.') {
  404.          if (dotseen) break;
  405.          dotseen++;
  406. diff -ur Python-1.5.2.org/Python/thread_os2.h Python-1.5.2/Python/thread_os2.h
  407. --- Python-1.5.2.org/Python/thread_os2.h    Mon Dec 21 19:32:32 1998
  408. +++ Python-1.5.2/Python/thread_os2.h    Thu Aug 10 15:48:26 2000
  409. @@ -38,8 +38,15 @@
  410.  
  411.  #include "process.h"
  412.  
  413. -long PyThread_get_thread_ident(void);
  414. +#ifdef __EMX__
  415. +#  include <sys/builtin.h>
  416. +#  include <sys/fmutex.h>
  417. +#endif
  418.  
  419. +/*
  420. +#undef dprintf
  421. +#define dprintf(args) printf args
  422. +*/
  423.  
  424.  /*
  425.   * Initialization of the C package, should not be needed.
  426. @@ -53,156 +60,197 @@
  427.   */
  428.  int PyThread_start_new_thread(void (*func)(void *), void *arg)
  429.  {
  430. -  int aThread;
  431. -  int success = 1;
  432. +    int aThread;
  433. +    int success = 1;
  434.  
  435. -  aThread = _beginthread(func,NULL,65536,arg);
  436. +    aThread = _beginthread(func,NULL,65536,arg);
  437.  
  438. -  if( aThread == -1 ) {
  439. -    success = 0;
  440. -    fprintf(stderr,"aThread failed == %d",aThread);
  441. -    dprintf(("_beginthread failed. return %ld\n", errno));
  442. -  }
  443. +    if (aThread == -1)
  444. +    {
  445. +        success = 0;
  446. +        fprintf(stderr,"aThread failed == %d",aThread);
  447. +        dprintf (("_beginthread failed. return %d\n", errno));
  448. +    }
  449.  
  450. -  return success;
  451. +    return success;
  452.  }
  453.  
  454.  long PyThread_get_thread_ident(void)
  455.  {
  456. -  PPIB pib;
  457. -  PTIB tib;
  458. +#if defined (PYCC_GCC)
  459. +    if (!initialized)
  460. +        PyThread_init_thread();
  461. +    return _gettid ();
  462. +#else
  463. +    PPIB pib;
  464. +    PTIB tib;
  465.  
  466. -  if (!initialized)
  467. -    PyThread_init_thread();
  468. +    if (!initialized)
  469. +        PyThread_init_thread();
  470.          
  471. -  DosGetInfoBlocks(&tib,&pib);
  472. -  return tib->tib_ptib2->tib2_ultid;
  473. +    DosGetInfoBlocks(&tib,&pib);
  474. +    return tib->tib_ptib2->tib2_ultid;
  475. +#endif
  476.  }
  477.  
  478.  static void do_PyThread_exit_thread(int no_cleanup)
  479.  {
  480. -  dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident()));
  481. -  if (!initialized)
  482. -    if (no_cleanup)
  483. -      _exit(0);
  484. -    else
  485. -      exit(0);
  486. -  _endthread();
  487. +    dprintf (("%ld: PyThread_exit_thread(%d)\n", PyThread_get_thread_ident(), no_cleanup));
  488. +    if (!initialized)
  489. +    {
  490. +        if (no_cleanup)
  491. +            _exit(0);
  492. +        else
  493. +            exit(0);
  494. +    }
  495. +    _endthread();
  496.  }
  497.  
  498.  void PyThread_exit_thread(void)
  499.  {
  500. -  do_PyThread_exit_thread(0);
  501. +    dprintf (("%ld: PyThread_exit_thread()\n", PyThread_get_thread_ident()));
  502. +    do_PyThread_exit_thread(0);
  503.  }
  504.  
  505.  void PyThread__exit_thread(void)
  506.  {
  507. -  do_PyThread_exit_thread(1);
  508. +    dprintf (("%ld: PyThread__exit_thread()\n", PyThread_get_thread_ident()));
  509. +    do_PyThread_exit_thread(1);
  510.  }
  511.  
  512.  #ifndef NO_EXIT_PROG
  513.  static void do_PyThread_exit_prog(int status, int no_cleanup)
  514.  {
  515. -  dprintf(("PyThread_exit_prog(%d) called\n", status));
  516. -  if (!initialized)
  517. -    if (no_cleanup)
  518. -      _exit(status);
  519. -    else
  520. -      exit(status);
  521. +    dprintf(("PyThread_exit_prog(%d) called\n", status));
  522. +    if (!initialized)
  523. +        if (no_cleanup)
  524. +            _exit(status);
  525. +        else
  526. +            exit(status);
  527.  }
  528.  
  529.  void PyThread_exit_prog(int status)
  530.  {
  531. -  do_PyThread_exit_prog(status, 0);
  532. +    do_PyThread_exit_prog(status, 0);
  533.  }
  534.  
  535.  void PyThread__exit_prog _P1(int status)
  536.  {
  537. -  do_PyThread_exit_prog(status, 1);
  538. +    do_PyThread_exit_prog(status, 1);
  539.  }
  540.  #endif /* NO_EXIT_PROG */
  541.  
  542.  /*
  543.   * Lock support. It has too be implemented as semaphores.
  544. - * I [Dag] tried to implement it with mutex but I could find a way to
  545. - * tell whether a thread already own the lock or not.
  546. + * With gcc/emx use fast RAM semaphores; this has several advantages:
  547. + *    - EMX fast semaphores are not owned by threads: this means
  548. + *      secondary acquirement of same lock will result in normal
  549. + *      "wait-to-be-released" operation, in contrast to OS/2
  550. + *      mutex semaphores which work different way.
  551. + *    - Because of same reason releasing a lock from other thread
  552. + *      works okay (as expected by Python) while with HMTX it doesn't.
  553. + *    - Signals works okay during semaphore wait. This particularily
  554. + *      means you can Ctrl-C your bugs.
  555.   */
  556.  PyThread_type_lock PyThread_allocate_lock(void)
  557.  {
  558. -  HMTX   aLock;
  559. -  APIRET rc;
  560. -
  561. -  dprintf(("PyThread_allocate_lock called\n"));
  562. -  if (!initialized)
  563. -    PyThread_init_thread();
  564. +#ifdef __EMX__
  565. +    _fmutex *sem = malloc (sizeof (_fmutex));
  566. +    if (!initialized)
  567. +        PyThread_init_thread ();
  568. +    dprintf (("%ld: PyThread_allocate_lock() -> %lx\n", PyThread_get_thread_ident(), (long)sem));
  569. +    if (_fmutex_create (sem, 0))
  570. +    {
  571. +        free (sem);
  572. +        sem = NULL;
  573. +    }
  574. +    return (PyThread_type_lock)sem;
  575. +#else
  576. +    HMTX   aLock;
  577. +
  578. +    if (!initialized)
  579. +        PyThread_init_thread();
  580.  
  581. -  DosCreateMutexSem(NULL,  /* Sem name      */
  582. -                    &aLock, /* the semaphone */
  583. -                    0,     /* shared ?      */
  584. -                    0);    /* initial state */  
  585. +    DosCreateMutexSem (NULL, &aLock, 0, 0);
  586.  
  587. -  dprintf(("%ld: PyThread_allocate_lock() -> %lx\n", PyThread_get_thread_ident(), (long)aLock));
  588. +    dprintf(("%ld: PyThread_allocate_lock() -> %lx\n", PyThread_get_thread_ident(), (long)aLock));
  589.  
  590. -  return (PyThread_type_lock) aLock;
  591. +    return (PyThread_type_lock) aLock;
  592. +#endif
  593.  }
  594.  
  595.  void PyThread_free_lock(PyThread_type_lock aLock)
  596.  {
  597. -  dprintf(("%ld: PyThread_free_lock(%lx) called\n", PyThread_get_thread_ident(),(long)aLock));
  598. -
  599. -  DosCloseMutexSem((HMTX)aLock);
  600. +    dprintf (("%ld: PyThread_free_lock(%lx)\n", PyThread_get_thread_ident(),(long)aLock));
  601. +#ifdef __EMX__
  602. +    _fmutex_close ((_fmutex *)aLock);
  603. +    free ((_fmutex *)aLock);
  604. +#else
  605. +    DosCloseMutexSem((HMTX)aLock);
  606. +#endif
  607.  }
  608.  
  609.  /*
  610.   * Return 1 on success if the lock was acquired
  611. - *
  612. - * and 0 if the lock was not acquired. This means a 0 is returned
  613. - * if the lock has already been acquired by this thread!
  614.   */
  615.  int PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag)
  616.  {
  617. -  int   success = 1;
  618. -  ULONG rc, count;
  619. -  PID   pid = 0;
  620. -  TID   tid = 0;
  621. -
  622. -  dprintf(("%ld: PyThread_acquire_lock(%lx, %d) called\n", PyThread_get_thread_ident(),
  623. -           (long)aLock, waitflag));
  624. -
  625. -  DosQueryMutexSem((HMTX)aLock,&pid,&tid,&count);
  626. -  if( tid == PyThread_get_thread_ident() ) { /* if we own this lock */
  627. -    success = 0;
  628. -  } else {
  629. -    rc = DosRequestMutexSem((HMTX) aLock,
  630. +#ifdef __EMX__
  631. +    dprintf (("%ld: PyThread_acquire_lock(%lx, %d)\n", PyThread_get_thread_ident(),    (long)aLock, waitflag));
  632. +    if (_fmutex_request ((_fmutex *)aLock, waitflag ? 0 : _FMR_NOWAIT))
  633. +        return 0;
  634. +    return 1;
  635. +#else
  636. +    int   success = 1;
  637. +    ULONG rc, count;
  638. +    PID   pid = 0;
  639. +    TID   tid = 0;
  640. +
  641. +    dprintf (("%ld: PyThread_acquire_lock(%lx, %d)\n", PyThread_get_thread_ident(),    (long)aLock, waitflag));
  642. +
  643. +    DosQueryMutexSem((HMTX)aLock,&pid,&tid,&count);
  644. +    if (tid == PyThread_get_thread_ident ())
  645. +    { /* if we own this lock */
  646. +        success = 0;
  647. +    }
  648. +    else
  649. +    {
  650. +        rc = DosRequestMutexSem((HMTX) aLock,
  651.                              (waitflag == 1 ? SEM_INDEFINITE_WAIT : 0));
  652.      
  653. -    if( rc != 0) {
  654. -      success = 0;                /* We failed */
  655. +        if( rc != 0)
  656. +            success = 0;                /* We failed */
  657.      }
  658. -  }
  659.  
  660. -  dprintf(("%ld: PyThread_acquire_lock(%lx, %d) -> %d\n",
  661. -           PyThread_get_thread_ident(),(long)aLock, waitflag, success));
  662. +    dprintf(("%ld: PyThread_acquire_lock(%lx, %d) -> %d\n",
  663. +        PyThread_get_thread_ident(),(long)aLock, waitflag, success));
  664.  
  665. -  return success;
  666. +    return success;
  667. +#endif
  668.  }
  669.  
  670.  void PyThread_release_lock(PyThread_type_lock aLock)
  671.  {
  672. -  dprintf(("%ld: PyThread_release_lock(%lx) called\n", PyThread_get_thread_ident(),(long)aLock));
  673. -
  674. -  if ( DosReleaseMutexSem( (HMTX) aLock ) != 0 ) {
  675. -    dprintf(("%ld: Could not PyThread_release_lock(%lx) error: %l\n",
  676. -             PyThread_get_thread_ident(), (long)aLock, GetLastError()));
  677. -  }
  678. +#ifdef __EMX__
  679. +    dprintf(("%ld: PyThread_release_lock(%lx)\n", PyThread_get_thread_ident(), (long)aLock));
  680. +    _fmutex_release ((_fmutex *)aLock);
  681. +#else
  682. +    int rc;
  683. +    dprintf(("%ld: PyThread_release_lock(%lx)\n", PyThread_get_thread_ident(), (long)aLock));
  684. +
  685. +    rc = DosReleaseMutexSem ((HMTX) aLock);
  686. +    if (rc)
  687. +        dprintf (("%ld: Could not PyThread_release_lock(%lx) error: %d\n",
  688. +            PyThread_get_thread_ident(), (long)aLock, rc));
  689. +#endif
  690.  }
  691.  
  692.  /*
  693. - * Semaphore support.
  694. + * Semaphore support: not implemented since semaphores are not used
  695.   */
  696.  PyThread_type_sema PyThread_allocate_sema(int value)
  697.  {
  698. -  return (PyThread_type_sema) 0;
  699. +    return (PyThread_type_sema) 0;
  700.  }
  701.  
  702.  void PyThread_free_sema(PyThread_type_sema aSemaphore)
  703. @@ -212,10 +260,10 @@
  704.  
  705.  int PyThread_down_sema(PyThread_type_sema aSemaphore, int waitflag)
  706.  {
  707. -  return -1;
  708. +    return -1;
  709.  }
  710.  
  711.  void PyThread_up_sema(PyThread_type_sema aSemaphore)
  712.  {
  713. -  dprintf(("%ld: PyThread_up_sema(%lx)\n", PyThread_get_thread_ident(), (long)aSemaphore));
  714. +    dprintf(("%ld: PyThread_up_sema(%lx)\n", PyThread_get_thread_ident(), (long)aSemaphore));
  715.  }
  716.