[Python-checkins] r85596 - python/branches/py3k/Modules/_multiprocessing/multiprocessing.c

gregory.p.smith python-checkins at python.org
Sun Oct 17 04:14:36 CEST 2010


Author: gregory.p.smith
Date: Sun Oct 17 04:14:36 2010
New Revision: 85596

Log:
Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
as (~0U) on NetBSD which was causing it to appear as -1 when used as
a signed int for _multprocessing.SemLock.SEM_VALUE_MAX.  This works
around the problem by substituting INT_MAX on systems where it appears
negative when used as an int.


Modified:
   python/branches/py3k/Modules/_multiprocessing/multiprocessing.c

Modified: python/branches/py3k/Modules/_multiprocessing/multiprocessing.c
==============================================================================
--- python/branches/py3k/Modules/_multiprocessing/multiprocessing.c	(original)
+++ python/branches/py3k/Modules/_multiprocessing/multiprocessing.c	Sun Oct 17 04:14:36 2010
@@ -269,8 +269,19 @@
     if (PyType_Ready(&SemLockType) < 0)
         return NULL;
     Py_INCREF(&SemLockType);
-    PyDict_SetItemString(SemLockType.tp_dict, "SEM_VALUE_MAX",
-                         Py_BuildValue("i", SEM_VALUE_MAX));
+    {
+        PyObject *py_sem_value_max;
+        /* Some systems define SEM_VALUE_MAX as an unsigned value that
+         * causes it to be negative when used as an int (NetBSD). */
+        if ((int)(SEM_VALUE_MAX) < 0)
+            py_sem_value_max = PyLong_FromLong(INT_MAX);
+        else
+            py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX);
+        if (py_sem_value_max == NULL)
+            return NULL;
+        PyDict_SetItemString(SemLockType.tp_dict, "SEM_VALUE_MAX",
+                             py_sem_value_max);
+    }
     PyModule_AddObject(module, "SemLock", (PyObject*)&SemLockType);
 #endif
 


More information about the Python-checkins mailing list