Skip to content

Commit

Permalink
Merge pull request #324 from steve-s/ss/improve-hpy-ext-usability
Browse files Browse the repository at this point in the history
Minor usability improvements in hpy.universal
  • Loading branch information
steve-s authored May 25, 2022
2 parents f859692 + 665ed4c commit 41989b8
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions hpy/universal/src/hpymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
#include "hpy_debug.h"

#ifdef PYPY_VERSION
# error "Cannot build hpy.univeral on top of PyPy. PyPy comes with its own version of it"
# error "Cannot build hpy.universal on top of PyPy. PyPy comes with its own version of it"
#endif
#ifdef GRAALVM_PYTHON
# error "Cannot build hpy.universal on top of GraalPython. GraalPython comes with its own version of it"
#endif

typedef HPy (*InitFuncPtr)(HPyContext *ctx);

static PyObject *set_debug(PyObject *self, PyObject *args)
{
// TODO
Py_RETURN_NONE;
}

static const char *prefix = "HPyInit";

static HPyContext * get_context(int debug)
Expand Down Expand Up @@ -101,17 +98,23 @@ static PyObject *do_load(PyObject *name_unicode, PyObject *path, int debug)
if (mylib == NULL) {
const char *error = dlerror();
if (error == NULL)
error = "unknown dlopen() error";
PyErr_Format(PyExc_RuntimeError, "dlopen: %s", error);
error = "no error message provided by the system";
PyErr_Format(PyExc_RuntimeError,
"Error during loading of the HPy extension module at path "
"'%s'. Error message from dlopen/WinAPI: %s", soname, error);
goto error;
}

void *initfn = dlsym(mylib, init_name);
if (initfn == NULL) {
const char *error = dlerror();
if (error == NULL)
error = "unknown dlsym() error";
PyErr_Format(PyExc_RuntimeError, "dlsym: %s", error);
error = "no error message provided by the system";
PyErr_Format(PyExc_RuntimeError,
"Error during loading of the HPy extension module at "
"path '%s' while trying to find symbol '%s'. Did you use"
"the HPy_MODINIT macro to register your module? Error "
"message from dlsym/WinAPI: %s", soname, init_name, error);
goto error;
}

Expand Down Expand Up @@ -152,7 +155,6 @@ static PyObject *get_version(PyObject *self, PyObject *ignored)
}

static PyMethodDef HPyMethods[] = {
{"set_debug", (PyCFunction)set_debug, METH_O, "TODO"},
{"load", (PyCFunction)load, METH_VARARGS | METH_KEYWORDS, "Load a .hpy.so"},
{"get_version", (PyCFunction)get_version, METH_NOARGS, "Return a tuple ('version', 'git revision')"},
{NULL, NULL, 0, NULL}
Expand Down

0 comments on commit 41989b8

Please sign in to comment.