Skip to content

Commit

Permalink
Merge pull request #121 from hpyproject/feature/add-exception-and-war…
Browse files Browse the repository at this point in the history
…ning-constants

Add exception and warning constants
  • Loading branch information
hodgestar committed Nov 17, 2020
2 parents 4a0d4ff + c4554cd commit 62f48e1
Show file tree
Hide file tree
Showing 11 changed files with 708 additions and 22 deletions.
5 changes: 5 additions & 0 deletions hpy/devel/include/common/autogen_impl.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions hpy/devel/include/cpython/hpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,77 @@ typedef Py_hash_t HPy_hash_t;

// this should maybe autogenerated from public_api.h
typedef struct _HPyContext_s {
/* Constants */
HPy h_None;
HPy h_True;
HPy h_False;
/* Exceptions */
HPy h_BaseException;
HPy h_Exception;
HPy h_StopAsyncIteration;
HPy h_StopIteration;
HPy h_GeneratorExit;
HPy h_ArithmeticError;
HPy h_LookupError;
HPy h_AssertionError;
HPy h_AttributeError;
HPy h_BufferError;
HPy h_EOFError;
HPy h_FloatingPointError;
HPy h_OSError;
HPy h_ImportError;
HPy h_ModuleNotFoundError;
HPy h_IndexError;
HPy h_KeyError;
HPy h_KeyboardInterrupt;
HPy h_MemoryError;
HPy h_NameError;
HPy h_OverflowError;
HPy h_RuntimeError;
HPy h_RecursionError;
HPy h_NotImplementedError;
HPy h_SyntaxError;
HPy h_IndentationError;
HPy h_TabError;
HPy h_ReferenceError;
HPy h_SystemError;
HPy h_SystemExit;
HPy h_TypeError;
HPy h_UnboundLocalError;
HPy h_UnicodeError;
HPy h_UnicodeEncodeError;
HPy h_UnicodeDecodeError;
HPy h_UnicodeTranslateError;
HPy h_ValueError;
HPy h_ZeroDivisionError;
HPy h_BlockingIOError;
HPy h_BrokenPipeError;
HPy h_ChildProcessError;
HPy h_ConnectionError;
HPy h_ConnectionAbortedError;
HPy h_ConnectionRefusedError;
HPy h_ConnectionResetError;
HPy h_FileExistsError;
HPy h_FileNotFoundError;
HPy h_InterruptedError;
HPy h_IsADirectoryError;
HPy h_NotADirectoryError;
HPy h_PermissionError;
HPy h_ProcessLookupError;
HPy h_TimeoutError;
/* Warnings */
HPy h_Warning;
HPy h_UserWarning;
HPy h_DeprecationWarning;
HPy h_PendingDeprecationWarning;
HPy h_SyntaxWarning;
HPy h_RuntimeWarning;
HPy h_FutureWarning;
HPy h_ImportWarning;
HPy h_UnicodeWarning;
HPy h_BytesWarning;
HPy h_ResourceWarning;
/* Types */
HPy h_BaseObjectType;
HPy h_TypeType;
HPy h_LongType;
Expand Down Expand Up @@ -81,15 +143,77 @@ _HPyGetContext(void) {
if (HPy_IsNull(ctx->h_None)) {
// XXX: we need to find a better way to check whether the ctx is
// initialized or not
/* Constants */
ctx->h_None = _py2h(Py_None);
ctx->h_True = _py2h(Py_True);
ctx->h_False = _py2h(Py_False);
/* Exceptions */
ctx->h_BaseException = _py2h(PyExc_BaseException);
ctx->h_Exception = _py2h(PyExc_Exception);
ctx->h_StopAsyncIteration = _py2h(PyExc_StopAsyncIteration);
ctx->h_StopIteration = _py2h(PyExc_StopIteration);
ctx->h_GeneratorExit = _py2h(PyExc_GeneratorExit);
ctx->h_ArithmeticError = _py2h(PyExc_ArithmeticError);
ctx->h_LookupError = _py2h(PyExc_LookupError);
ctx->h_AssertionError = _py2h(PyExc_AssertionError);
ctx->h_AttributeError = _py2h(PyExc_AttributeError);
ctx->h_BufferError = _py2h(PyExc_BufferError);
ctx->h_EOFError = _py2h(PyExc_EOFError);
ctx->h_FloatingPointError = _py2h(PyExc_FloatingPointError);
ctx->h_OSError = _py2h(PyExc_OSError);
ctx->h_ImportError = _py2h(PyExc_ImportError);
ctx->h_ModuleNotFoundError = _py2h(PyExc_ModuleNotFoundError);
ctx->h_IndexError = _py2h(PyExc_IndexError);
ctx->h_KeyError = _py2h(PyExc_KeyError);
ctx->h_KeyboardInterrupt = _py2h(PyExc_KeyboardInterrupt);
ctx->h_MemoryError = _py2h(PyExc_MemoryError);
ctx->h_NameError = _py2h(PyExc_NameError);
ctx->h_OverflowError = _py2h(PyExc_OverflowError);
ctx->h_RuntimeError = _py2h(PyExc_RuntimeError);
ctx->h_RecursionError = _py2h(PyExc_RecursionError);
ctx->h_NotImplementedError = _py2h(PyExc_NotImplementedError);
ctx->h_SyntaxError = _py2h(PyExc_SyntaxError);
ctx->h_IndentationError = _py2h(PyExc_IndentationError);
ctx->h_TabError = _py2h(PyExc_TabError);
ctx->h_ReferenceError = _py2h(PyExc_ReferenceError);
ctx->h_SystemError = _py2h(PyExc_SystemError);
ctx->h_SystemExit = _py2h(PyExc_SystemExit);
ctx->h_TypeError = _py2h(PyExc_TypeError);
ctx->h_UnboundLocalError = _py2h(PyExc_UnboundLocalError);
ctx->h_UnicodeError = _py2h(PyExc_UnicodeError);
ctx->h_UnicodeEncodeError = _py2h(PyExc_UnicodeEncodeError);
ctx->h_UnicodeDecodeError = _py2h(PyExc_UnicodeDecodeError);
ctx->h_UnicodeTranslateError = _py2h(PyExc_UnicodeTranslateError);
ctx->h_ValueError = _py2h(PyExc_ValueError);
ctx->h_ZeroDivisionError = _py2h(PyExc_ZeroDivisionError);
ctx->h_BlockingIOError = _py2h(PyExc_BlockingIOError);
ctx->h_BrokenPipeError = _py2h(PyExc_BrokenPipeError);
ctx->h_ChildProcessError = _py2h(PyExc_ChildProcessError);
ctx->h_ConnectionError = _py2h(PyExc_ConnectionError);
ctx->h_ConnectionAbortedError = _py2h(PyExc_ConnectionAbortedError);
ctx->h_ConnectionRefusedError = _py2h(PyExc_ConnectionRefusedError);
ctx->h_ConnectionResetError = _py2h(PyExc_ConnectionResetError);
ctx->h_FileExistsError = _py2h(PyExc_FileExistsError);
ctx->h_FileNotFoundError = _py2h(PyExc_FileNotFoundError);
ctx->h_InterruptedError = _py2h(PyExc_InterruptedError);
ctx->h_IsADirectoryError = _py2h(PyExc_IsADirectoryError);
ctx->h_NotADirectoryError = _py2h(PyExc_NotADirectoryError);
ctx->h_PermissionError = _py2h(PyExc_PermissionError);
ctx->h_ProcessLookupError = _py2h(PyExc_ProcessLookupError);
ctx->h_TimeoutError = _py2h(PyExc_TimeoutError);
/* Warnings */
ctx->h_Warning = _py2h(PyExc_Warning);
ctx->h_UserWarning = _py2h(PyExc_UserWarning);
ctx->h_DeprecationWarning = _py2h(PyExc_DeprecationWarning);
ctx->h_PendingDeprecationWarning = _py2h(PyExc_PendingDeprecationWarning);
ctx->h_SyntaxWarning = _py2h(PyExc_SyntaxWarning);
ctx->h_RuntimeWarning = _py2h(PyExc_RuntimeWarning);
ctx->h_FutureWarning = _py2h(PyExc_FutureWarning);
ctx->h_ImportWarning = _py2h(PyExc_ImportWarning);
ctx->h_UnicodeWarning = _py2h(PyExc_UnicodeWarning);
ctx->h_BytesWarning = _py2h(PyExc_BytesWarning);
ctx->h_ResourceWarning = _py2h(PyExc_ResourceWarning);
/* Types */
ctx->h_BaseObjectType = _py2h((PyObject *)&PyBaseObject_Type);
ctx->h_TypeType = _py2h((PyObject *)&PyType_Type);
ctx->h_LongType = _py2h((PyObject *)&PyLong_Type);
Expand Down
59 changes: 59 additions & 0 deletions hpy/devel/include/universal/autogen_ctx.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions hpy/devel/include/universal/autogen_trampolines.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions hpy/tools/autogen/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def _visit_hpyslot_slot(self, node):
'HPy_SetItem_i': None,
'HPy_SetItem_s': None,
'HPy_Length': 'PyObject_Length',
'HPy_Call': 'PyObject_Call',
'_HPy_Cast': None,
'HPy_FromPyObject': None,
'HPy_AsPyObject': None,
Expand Down
68 changes: 68 additions & 0 deletions hpy/tools/autogen/public_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,82 @@ typedef int HPyTracker;

/* HPy public API */

/* Constants */
HPy h_None;
HPy h_True;
HPy h_False;

/* Exceptions */
HPy h_BaseException;
HPy h_Exception;
HPy h_StopAsyncIteration;
HPy h_StopIteration;
HPy h_GeneratorExit;
HPy h_ArithmeticError;
HPy h_LookupError;
HPy h_AssertionError;
HPy h_AttributeError;
HPy h_BufferError;
HPy h_EOFError;
HPy h_FloatingPointError;
HPy h_OSError;
HPy h_ImportError;
HPy h_ModuleNotFoundError;
HPy h_IndexError;
HPy h_KeyError;
HPy h_KeyboardInterrupt;
HPy h_MemoryError;
HPy h_NameError;
HPy h_OverflowError;
HPy h_RuntimeError;
HPy h_RecursionError;
HPy h_NotImplementedError;
HPy h_SyntaxError;
HPy h_IndentationError;
HPy h_TabError;
HPy h_ReferenceError;
HPy h_SystemError;
HPy h_SystemExit;
HPy h_TypeError;
HPy h_UnboundLocalError;
HPy h_UnicodeError;
HPy h_UnicodeEncodeError;
HPy h_UnicodeDecodeError;
HPy h_UnicodeTranslateError;
HPy h_ValueError;
HPy h_ZeroDivisionError;
HPy h_BlockingIOError;
HPy h_BrokenPipeError;
HPy h_ChildProcessError;
HPy h_ConnectionError;
HPy h_ConnectionAbortedError;
HPy h_ConnectionRefusedError;
HPy h_ConnectionResetError;
HPy h_FileExistsError;
HPy h_FileNotFoundError;
HPy h_InterruptedError;
HPy h_IsADirectoryError;
HPy h_NotADirectoryError;
HPy h_PermissionError;
HPy h_ProcessLookupError;
HPy h_TimeoutError;
// EnvironmentError, IOError and WindowsError are intentionally omitted (they
// are all aliases of OSError since Python 3.3).

/* Warnings */
HPy h_Warning;
HPy h_UserWarning;
HPy h_DeprecationWarning;
HPy h_PendingDeprecationWarning;
HPy h_SyntaxWarning;
HPy h_RuntimeWarning;
HPy h_FutureWarning;
HPy h_ImportWarning;
HPy h_UnicodeWarning;
HPy h_BytesWarning;
HPy h_ResourceWarning;

/* Types */
HPy h_BaseObjectType; /* built-in 'object' */
HPy h_TypeType; /* built-in 'type' */
HPy h_LongType; /* built-in 'int' */
Expand Down Expand Up @@ -99,6 +166,7 @@ HPy HPy_InPlaceOr(HPyContext ctx, HPy h1, HPy h2);

/* pyerrors.h */
void HPyErr_SetString(HPyContext ctx, HPy h_type, const char *message);
void HPyErr_SetObject(HPyContext ctx, HPy h_type, HPy h_value);
/* note: HPyErr_Occurred() returns a flag 0-or-1, instead of a 'PyObject *' */
int HPyErr_Occurred(HPyContext ctx);
HPy HPyErr_NoMemory(HPyContext ctx);
Expand Down
Loading

0 comments on commit 62f48e1

Please sign in to comment.