Skip to content

Commit

Permalink
Added RISC OS support.
Browse files Browse the repository at this point in the history
RISC OS builds of Python come with a swi module. Who knew?
Documentation is absurdly poor, but I managed. It works even with the
unofficial 2.7 port that guy did for the Raspberry Pi.
  • Loading branch information
Cairnarvon committed Feb 12, 2013
1 parent a8a9820 commit bf61a57
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
11 changes: 0 additions & 11 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ the time of the first reset, last reset, and number of resets), but the Palm OS
is 2426 pages. I'll find it eventually.
## RISC OS
Unless someone gets a Python with `ctypes` working, we may have to write an
extension and include extensive manual build instructions. I don't imagine
`distutils` would cope very well.
I'm not even sure the current method would work with `ctypes`; `_swi` could be
a compiler extension and not part of `CLib`. RISC OS is so painful to work with
I haven't even checked.
## Symbian
```cpp
Expand Down
9 changes: 4 additions & 5 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ the others on which it is therefore expected to work as well.
+------------------+--------+--------------------------+---------------------+
| ReactOS 0.3.14 || :func:`_uptime_windows` | |
+------------------+--------+--------------------------+---------------------+
| RISC OS 5.19 | ✗ [*]_ | :func:`_uptime_riscos` | RISC OS in general |
| RISC OS 5.19 | | :func:`_uptime_riscos` | RISC OS in general |
+------------------+--------+--------------------------+---------------------+
| Syllable Desktop | ✗ [*]_ | :func:`_uptime_syllable` | AtheOS |
| 0.6.7 | | | |
Expand All @@ -84,9 +84,6 @@ the others on which it is therefore expected to work as well.
| Windows XP SP 3 || :func:`_uptime_windows` | |
+------------------+--------+--------------------------+---------------------+

.. [*] Our current method relies on :mod:`ctypes`, and RISC OS doesn't seem to
have a version of Python available that has a working one.
.. [*] Not even the :command:`uptime` that ships with Syllable Desktop is able
to determine the system uptime on that platform.
Expand Down Expand Up @@ -231,13 +228,15 @@ uptime

.. function:: _uptime_riscos

RISC OS-specific uptime. This uses :c:func:`_kernel_swi` to perform the
RISC OS-specific uptime. This uses the :mod:`swi` module to perform the
software interrupt :c:data:`OS_ReadMonotonicTime`, which returns the uptime
in centiseconds. This will overflow after about eight months on 32-bit
systems (2.9 billion years on 64-bit). If this can be detected, the function
will return :const:`None` rather than rely on assumptions regarding signed
overflow.

This function does not require a working :mod:`ctypes`.

.. versionadded:: 1.4

.. function:: _uptime_solaris
Expand Down
29 changes: 11 additions & 18 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
import sys
import time

try:
# RISC OS only.
import swi
except ImportError:
pass

try:
from uptime._posix import _uptime_posix
except ImportError:
Expand Down Expand Up @@ -164,28 +170,15 @@ def _uptime_plan9():

def _uptime_riscos():
"""Returns uptime in seconds or None, on RISC OS."""
# Apparently the only way to get at the uptime is through a software
# interrupt. In C, this is done through _kernel_swi.
try:
libc = ctypes.CDLL('CLib')
libc._kernel_swi.argtypes = [ctypes.c_int,
ctypes.POINTER(ctypes.c_int * 10),
ctypes.POINTER(ctypes.c_int * 10)]
up = swi.swi('OS_ReadMonotonicTime', ';i')
if up < 0:
# Overflows after about eight months on 32-bit.
return None
return up / 100.
except:
return None

OS_ReadMonotonicTime = 0x42 # All sources seem to agree.
r = (ctypes.c_int * 10)() # typedef struct {
# int r[10];
# } _kernel_swi_regs;
libc._kernel_swi(OS_ReadMonotonicTime, ctypes.byref(r), ctypes.byref(r))

if r[0] < 0:
# Overflows after about eight months on 32-bit.
return None
else:
return r[0] / 100.

def _uptime_solaris():
"""Returns uptime in seconds or None, on Solaris."""
global __boottime
Expand Down

0 comments on commit bf61a57

Please sign in to comment.