Provides Python status constants and native-error translation. More...
Classes | |
| class | _StatusFunction |
Describes a mutable ctypes status-returning function object. More... | |
| class | ApoCharmmError |
| Represents one failed apoCHARMM native operation in Python. More... | |
Functions | |
| None | check_status (int status, str context) |
Raises ApoCharmmError for a failing C ABI status. | |
| None | configure_status_function (_StatusFunction function, Sequence[object] argtypes, str context) |
Configures a ctypes function to translate nonzero C ABI statuses. | |
Provides Python status constants and native-error translation.
The public constants and ApoCharmmError are re-exported by the top-level apocharmm package. Native wrapper functions use configure_status_function() to convert nonzero C ABI statuses into one Python exception type while retaining the numeric status, operation context, and copied native diagnostic.
| None apocharmm.error.check_status | ( | int | status, |
| str | context | ||
| ) |
Raises ApoCharmmError for a failing C ABI status.
APO_STATUS_OK returns immediately without reading the native diagnostic. Every other integer causes the current thread's apo_last_error() pointer to be copied immediately. A NULL or empty C string uses the defined fallback; other bytes are decoded as UTF-8 with replacement for invalid sequences.
| [in] | status | Numeric C ABI status to inspect. Unknown nonzero values are preserved in the raised exception. |
| [in] | context | Python-facing operation description retained by the exception. |
None when status is APO_STATUS_OK. | ApoCharmmError | If status is any nonzero value. |
| None apocharmm.error.configure_status_function | ( | _StatusFunction | function, |
| Sequence[object] | argtypes, | ||
| str | context | ||
| ) |
Configures a ctypes function to translate nonzero C ABI statuses.
The function's argtypes are replaced with a new list copied from argtypes, its restype is set to ctypes.c_int, and its errcheck callback is replaced. The callback returns a successful integer unchanged and delegates every nonzero result to check_status() using the retained operation context.
| [in,out] | function | Borrowed mutable ctypes function object. The object is configured in place and is not otherwise retained. |
| [in] | argtypes | Sequence of ctypes argument declarations. The sequence is copied to a list; the declaration objects themselves are retained by that list. |
| [in] | context | Python-facing operation description captured by the installed callback for as long as the function retains that callback. |
None.function has integer status conversion and automatic ApoCharmmError translation installed.