You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
A getter for errno, likely in the form fn raw_errno() -> c_int as a runtime builtin.
What is your motivation for this change?
Many, many, many POSIX functions use errno to return error codes, and checking it is necessary for proper error handling. We can't give coherent errors to the user without this. As far as I am aware, there is no way to access a C global variable from Mojo, so it needs to be a runtime builtin.
Any other details?
The reason I'm asking for raw_errno is so we can wrap the function with something that returns an enum for an easier to use "errno" function. A general version of this solution would be a way to use C ABI globals directly by symbol name, such as some kind of "extern" variable modifier.
The text was updated successfully, but these errors were encountered:
fnget_errno(self) -> C.int:
"""Get a copy of the current value of the `errno` global variable for the current thread. Returns: A copy of the current value of `errno` for the current thread."""@parameterif os_is_windows():
varerrno= stack_allocation[1, C.int]()
@parameterif static:
_ = external_call["_get_errno", C.void](errno)
else:
_ =self._lib.value().call["_get_errno", C.void](errno)
return errno[]
else:
aliasloc="__error"if os_is_macos() else"__errno_location"@parameterif static:
return external_call[loc, UnsafePointer[C.int]]()[]
else:
returnself._lib.value().call[loc, UnsafePointer[C.int]]()[]
fnset_errno(self, errno: C.int):
"""Set the `errno` global variable for the current thread. Args: errno: The value to set `errno` to."""@parameterif os_is_windows():
@parameterif static:
_ = external_call["_set_errno", C.int](errno)
else:
_ =self._lib.value().call["_set_errno", C.int](errno)
else:
aliasloc="__error"if os_is_macos() else"__errno_location"@parameterif static:
_ = external_call[loc, UnsafePointer[C.int]]()[0] = errno
else:
_ =self._lib.value().call[loc, UnsafePointer[C.int]]()[
0
] = errno
@martinvuyk This should work as a stopgap. I think this is non-portable between libcs on Linux, but that's a "later" problem. However, I'd still like the runtime builtin for portability reasons so we don't need to handle every wacky libc on Linux.
Review Mojo's priorities
What is your request?
A getter for errno, likely in the form
fn raw_errno() -> c_int
as a runtime builtin.What is your motivation for this change?
Many, many, many POSIX functions use errno to return error codes, and checking it is necessary for proper error handling. We can't give coherent errors to the user without this. As far as I am aware, there is no way to access a C global variable from Mojo, so it needs to be a runtime builtin.
Any other details?
The reason I'm asking for
raw_errno
is so we can wrap the function with something that returns an enum for an easier to use "errno" function. A general version of this solution would be a way to use C ABI globals directly by symbol name, such as some kind of "extern" variable modifier.The text was updated successfully, but these errors were encountered: