From: <pj...@us...> - 2010-04-18 05:46:31
|
Revision: 7035 http://jython.svn.sourceforge.net/jython/?rev=7035&view=rev Author: pjenvey Date: 2010-04-18 05:46:24 +0000 (Sun, 18 Apr 2010) Log Message: ----------- constantine now has accurate Windows errnos so we actually have to map the missing errnos to the WSA equivalents like CPython does. and update to constantine-0.8-2355d07 for more WSA errnos Modified Paths: -------------- trunk/jython/extlibs/constantine.jar trunk/jython/src/org/python/modules/errno.java Modified: trunk/jython/extlibs/constantine.jar =================================================================== (Binary files differ) Modified: trunk/jython/src/org/python/modules/errno.java =================================================================== --- trunk/jython/src/org/python/modules/errno.java 2010-04-18 00:59:01 UTC (rev 7034) +++ trunk/jython/src/org/python/modules/errno.java 2010-04-18 05:46:24 UTC (rev 7035) @@ -3,6 +3,8 @@ import com.kenai.constantine.Constant; import com.kenai.constantine.ConstantSet; +import com.kenai.constantine.Platform; +import com.kenai.constantine.platform.Errno; import org.python.core.ClassDictInit; import org.python.core.Py; import org.python.core.PyDictionary; @@ -32,9 +34,12 @@ public static final PyObject errorcode = new PyDictionary(); public static void classDictInit(PyObject dict) { - for (Constant constant : ConstantSet.getConstantSet("Errno")) { - addCode(dict, constant.name(), constant.value(), constant.toString()); + if (Platform.OS.equals("windows")) { + initWindows(dict); + } else { + initPosix(dict); } + // XXX: necessary? addCode(dict, "ESOCKISBLOCKING", 20000, "Socket is in blocking mode"); addCode(dict, "EGETADDRINFOFAILED", 20001, "getaddrinfo failed"); @@ -43,6 +48,44 @@ dict.__setitem__("classDictInit", null); } + /** + * Setup errnos for Windows. + * + * Windows replaced the BSD/POSIX socket errnos with its own Winsock equivalents + * (e.g. EINVAL -> WSAEINVAL). We painstakenly map the missing constants to their WSA + * equivalent values and expose the WSA constants on their own. + */ + private static void initWindows(PyObject dict) { + // the few POSIX errnos Windows defines + ConstantSet winErrnos = ConstantSet.getConstantSet("Errno"); + // WSA errnos (and other Windows LastErrors) + ConstantSet lastErrors = ConstantSet.getConstantSet("LastError"); + + // Fill the gaps by searching through every possible constantine Errno first + // checking if it's defined on Windows, then falling back to the WSA prefixed + // version if it exists + Constant constant; + for (Constant errno : Errno.values()) { + String errnoName = errno.name(); + if ((constant = winErrnos.getConstant(errnoName)) != null + || (constant = lastErrors.getConstant("WSA" + errnoName)) != null) { + addCode(dict, errnoName, constant.value(), constant.toString()); + } + } + // Then provide the WSA names + for (Constant lastError : lastErrors) { + if (lastError.name().startsWith("WSA")) { + addCode(dict, lastError.name(), lastError.value(), lastError.toString()); + } + } + } + + private static void initPosix(PyObject dict) { + for (Constant constant : ConstantSet.getConstantSet("Errno")) { + addCode(dict, constant.name(), constant.value(), constant.toString()); + } + } + private static void addCode(PyObject dict, String name, int code, String message) { PyObject nameObj = Py.newString(name); PyObject codeObj = Py.newInteger(code); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |