Conversation
This module replaced the built-in errno module rather than extending it, and the values it defines are the Linux/x86 ones. errno is an extensible built-in, so a file on sys.path wins outright: installing this package left errno.ETIMEDOUT at 110 on a port whose headers say 145 (Linux/mips) or 60 (macOS), while the number OSError carries still came from those headers. errno.errorcode disappeared with it. Found on an OpenWrt mips target, where the package is installed into /usr/lib/micropython, which is on the default sys.path. Import the built-in module at the end of the file, under its u-prefixed name so that the import does not find this file again. Placed last it overrides the table above, which stays as the fallback for the names the built-in module does not provide. Drop EAFNOSUPPORT. It is not in the default MICROPY_PY_ERRNO_LIST, so the value here is the one that gets used, and 97 is right only for Linux/x86: newlib has 106, Linux/mips 124, macOS 47. What is left in the table is codes 1 to 34, which glibc, musl, newlib and py/mperrno.h agree on, and four codes the default list supplies anyway. Signed-off-by: Kirill Lukonin (Evil Wireless Man) <klukonin@gmail.com>
|
I'm just a simple Windows guy, so I'm sure I do not understand all the intricacies of the different error codes for the same error on one platform, but I do wonder if this proposed changes makes it simpler or harder from a MicroPython module perspective ? How do you intend that this makes it possible for a MicroPython module to know which error to check for? |
|
Good question from a Windows guy))) try:
s.connect(addr)
except OSError as e:
if e.args[0] == errno.ETIMEDOUT:
print("TIMEOUT!!!")The name is the portable part. The number behind it is not, and supplying it is What this package does today is overwrite that with the Linux/x86 numbers,
After this change the package stops overriding those names. The one thing a module must not do is write the number instead of the name. |
|
One finding from digging into this, and one question I would rather The finding. The obvious "fix it properly" move is to expose more of Windows is also a fourth distinct numbering, worth recording next to the So IMHO the workable shape is a per-port list. The question. Given that, is The one case that genuinely needs it is firmware that cannot be rebuilt, where |
python-stdlib/errnoreplaces the built-inerrnomodule instead of extendingit, and hardcodes the Linux/x86 values.
errnois an extensible built-in, so a file found onsys.pathwins outright.Installing this package leaves
errno.ETIMEDOUTat 110 on a port whose systemheaders say 145 (Linux/mips) or 60 (macOS), while the number
OSErrorcarriesstill comes from those headers — so
e.args[0] == errno.ETIMEDOUTsilentlystops matching.
errno.errorcodedisappears at the same time, which is whatmp_errno_to_str()looks names up in.The fix is one import, at the end of the file, which is what makes it work
without per-name guards: the built-in values override the table, and the table
only fills the gaps. The
u-prefixed name reaches the built-in module directly(
py/objmodule.c), so the import does not find this file again.os.py,time.pyandbinascii.pyalready use this pattern at the top of the file,having nothing to fall back to.
EAFNOSUPPORTis removed: it is not in the defaultMICROPY_PY_ERRNO_LIST, sothe value here is the one used, and 97 is right only for Linux/x86 (newlib 106,
Linux/mips 124, macOS 47). This does mean
errno.EAFNOSUPPORTraisesAttributeErroron a stock x86 build where it used to be correct — a loudfailure in place of a silent wrong answer. The companion PR below brings it
back from the built-in module on every platform.