Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Include/cpython/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ typedef struct {
PyObject *name;
} PyAttributeErrorObject;

#ifdef RISCOS
typedef struct {
PyException_HEAD
PyObject *errnum;
PyObject *errmsg;
} PyRISCOSErrorObject;
#endif

/* Compatibility typedefs */
typedef PyOSErrorObject PyEnvironmentErrorObject;
#ifdef MS_WINDOWS
Expand Down
5 changes: 5 additions & 0 deletions Include/osdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ extern "C" {
# define DELIM L';'
#endif

#ifdef RISCOS
# define DELIM L','
# define SEP L'.'
#endif

/* Filename separator */
#ifndef SEP
# define SEP L'/'
Expand Down
8 changes: 8 additions & 0 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5872,10 +5872,18 @@ _ssl_get_default_verify_paths_impl(PyObject *module)
if (!target) goto error; \
}

#ifdef RISCOS
// The defaults from the X509_... calls are somewhat useless.
ofile_env = Py_None; Py_INCREF(Py_None);
ofile = Py_None; Py_INCREF(Py_None);
odir_env = Py_None; Py_INCREF(Py_None);
odir = Py_None; Py_INCREF(Py_None);
#else
CONVERT(X509_get_default_cert_file_env(), ofile_env);
CONVERT(X509_get_default_cert_file(), ofile);
CONVERT(X509_get_default_cert_dir_env(), odir_env);
CONVERT(X509_get_default_cert_dir(), odir);
#endif
#undef CONVERT

return Py_BuildValue("NNNN", ofile_env, ofile, odir_env, odir);
Expand Down
4 changes: 4 additions & 0 deletions Modules/getbuildinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ Py_GetBuildInfo(void)
initialized = 1;
const char *revision = _Py_gitversion();
const char *sep = *revision ? ":" : "";
#ifdef RISCOS
const char *gitid = "riscos-1";
#else
const char *gitid = _Py_gitidentifier();
if (!(*gitid)) {
gitid = "main";
}
#endif
PyOS_snprintf(buildinfo, sizeof(buildinfo),
"%s%s%s, %.20s, %.9s", gitid, sep, revision,
DATE, TIME);
Expand Down
7 changes: 7 additions & 0 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2259,8 +2259,15 @@ pysleep(PyTime_t timeout)
#elif defined(HAVE_NANOSLEEP)
ret = nanosleep(&timeout_ts, NULL);
err = errno;
#else
#ifdef RISCOS
unsigned int end = _swi(OS_ReadMonotonicTime, _RETURN(0)) +
(timeout_tv.tv_sec * 100 + timeout_tv.tv_usec / 10000);
while ((unsigned)_swi(OS_ReadMonotonicTime, _RETURN(0)) < end) ;
ret = 0;
#else
ret = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout_tv);
#endif
err = errno;
#endif
Py_END_ALLOW_THREADS
Expand Down
70 changes: 70 additions & 0 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -4193,6 +4193,73 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning,
"Base class for warnings about resource usage.");


#ifdef RISCOS
/*
* RISC OS error.
*/

static int
RISCOSError_init(PyRISCOSErrorObject *self, PyObject *args, PyObject *kwds)
{
Py_ssize_t lenargs = PyTuple_GET_SIZE(args);

if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
return -1;

if (lenargs >= 1) {
Py_INCREF(PyTuple_GET_ITEM(args, 0));
Py_XSETREF(self->errnum, PyTuple_GET_ITEM(args, 0));
}
if (lenargs == 2) {
Py_INCREF(PyTuple_GET_ITEM(args, 1));
Py_XSETREF(self->errmsg, PyTuple_GET_ITEM(args, 1));
}
return 0;
}

static int
RISCOSError_clear(PyRISCOSErrorObject *self)
{
Py_CLEAR(self->errmsg);
Py_CLEAR(self->errnum);
return BaseException_clear((PyBaseExceptionObject *)self);
}

static void
RISCOSError_dealloc(PyRISCOSErrorObject *self)
{
_PyObject_GC_UNTRACK(self);
RISCOSError_clear(self);
Py_TYPE(self)->tp_free((PyObject *)self);
}

static int
RISCOSError_traverse(PyRISCOSErrorObject *self, visitproc visit, void *arg)
{
Py_VISIT(self->errmsg);
Py_VISIT(self->errnum);
return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
}

static PyObject *
RISCOSError_str(PyRISCOSErrorObject *self)
{
return self->errmsg;
}

static PyMemberDef RISCOSError_members[] = {
{"errmsg", _Py_T_OBJECT, offsetof(PyRISCOSErrorObject, errmsg), Py_READONLY,
PyDoc_STR("error message")},
{"errnum", _Py_T_OBJECT, offsetof(PyRISCOSErrorObject, errnum), Py_READONLY,
PyDoc_STR("error number")},
{NULL} /* Sentinel */
};

ComplexExtendsException(PyExc_Exception, RISCOSError, RISCOSError,
0, 0, RISCOSError_members, 0,
RISCOSError_str, "RISC OS error.");
#endif


#ifdef MS_WINDOWS
#include <winsock2.h>
Expand Down Expand Up @@ -4341,6 +4408,9 @@ static struct static_exception static_exceptions[] = {
ITEM(UnicodeDecodeError),
ITEM(UnicodeEncodeError),
ITEM(UnicodeTranslateError),
#ifdef RISCOS
ITEM(RISCOSError), // base: Exception
#endif
#undef ITEM
};

Expand Down
13 changes: 13 additions & 0 deletions Programs/_freeze_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#include "pycore_fileutils.h" // _Py_stat_struct
#include <pycore_import.h>

#ifdef RISCOS
#include <unixlib/local.h>
int __riscosify_control = __RISCOSIFY_NO_PROCESS |
__RISCOSIFY_NO_SUFFIX |
__RISCOSIFY_NO_REVERSE_SUFFIX;
#endif

#include <stdio.h>
#include <stdlib.h> // malloc()
#include <sys/types.h>
Expand Down Expand Up @@ -79,12 +86,18 @@ read_text(const char *inpath)
}

struct _Py_stat_struct stat;
#ifdef RISCOS
fseek(infile, 0, SEEK_END);
size_t text_size = ftell(infile);
fseek(infile, 0, SEEK_SET);
#else
if (_Py_fstat_noraise(fileno(infile), &stat)) {
fprintf(stderr, "cannot fstat '%s'\n", inpath);
fclose(infile);
return NULL;
}
size_t text_size = (size_t)stat.st_size;
#endif

char *text = (char *) malloc(text_size + 1);
if (text == NULL) {
Expand Down
7 changes: 7 additions & 0 deletions Programs/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

#include "Python.h"

#ifdef RISCOS
#include <unixlib/local.h>
int __riscosify_control = __RISCOSIFY_NO_PROCESS |
__RISCOSIFY_NO_SUFFIX |
__RISCOSIFY_NO_REVERSE_SUFFIX;
#endif

#ifdef MS_WINDOWS
int
wmain(int argc, wchar_t **argv)
Expand Down
19 changes: 18 additions & 1 deletion Python/dynload_shlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "pycore_interp.h" // _PyInterpreterState.dlopenflags
#include "pycore_pystate.h" // _PyInterpreterState_GET()

#ifdef RISCOS
#include <unixlib/local.h>
#endif

#include <sys/types.h>
#include <sys/stat.h>

Expand Down Expand Up @@ -37,7 +41,10 @@
*/

const char *_PyImport_DynLoadFiletab[] = {
#ifdef __CYGWIN__
#if defined(RISCOS)
"/so",
"/" SOABI "/so",
#elif defined(__CYGWIN__)
".dll",
#else /* !__CYGWIN__ */
"." SOABI ".so",
Expand All @@ -59,14 +66,18 @@ _PyImport_FindSharedFuncptr(const char *prefix,
dl_funcptr p;
void *handle;
char funcname[258];
#ifndef RISCOS
char pathbuf[260];
#endif
int dlopenflags=0;

#ifndef RISCOS
if (strchr(pathname, '/') == NULL) {
/* Prefix bare filename with "./" */
PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname);
pathname = pathbuf;
}
#endif

PyOS_snprintf(funcname, sizeof(funcname),
LEAD_UNDERSCORE "%.20s_%.200s", prefix, shortname);
Expand All @@ -79,7 +90,13 @@ _PyImport_FindSharedFuncptr(const char *prefix,

dlopenflags = _PyImport_GetDLOpenFlags(_PyInterpreterState_GET());

#ifdef RISCOS
char* unixpath = __unixify(pathname, 0x0, 0, 0, -1);
handle = dlopen(unixpath, dlopenflags);
free(unixpath);
#else
handle = dlopen(pathname, dlopenflags);
#endif

if (handle == NULL) {
PyObject *mod_name;
Expand Down
9 changes: 9 additions & 0 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,14 @@ config_init_hash_seed(PyConfig *config)
}


#ifdef RISCOS
#warning config_wstr_to_int hardcoded to return 0
static int
config_wstr_to_int(const wchar_t *wstr, int *result)
{
return 0;
}
#else
static int
config_wstr_to_int(const wchar_t *wstr, int *result)
{
Expand All @@ -1811,6 +1819,7 @@ config_wstr_to_int(const wchar_t *wstr, int *result)
*result = (int)value;
return 0;
}
#endif

static PyStatus
config_read_gil(PyConfig *config, size_t len, wchar_t first_char)
Expand Down
Loading
Loading