pyerrors: Add PyErr_Set{WERROR,HRESULT,NTSTATUS}_and_string()
authorAndrew Bartlett <abartlet@samba.org>
Tue, 1 Nov 2016 03:03:09 +0000 (16:03 +1300)
committerGarming Sam <garming@samba.org>
Fri, 4 Nov 2016 03:41:19 +0000 (04:41 +0100)
This varient allows control of the text explaination string

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12398

source4/libcli/util/pyerrors.h

index 9228c340ea72b3d2cc1dcaf8ffc89d8e1681a806..c3b307646bac3bb346cc25cc3df45a42a37b528c 100644 (file)
                                               "NTSTATUSError"),        \
                        PyErr_FromNTSTATUS(status))
 
                                               "NTSTATUSError"),        \
                        PyErr_FromNTSTATUS(status))
 
+#define PyErr_SetWERROR_and_string(werr, string) \
+        PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\
+                                              "WERRORError"),  \
+                       Py_BuildValue("(i,s)", W_ERROR_V(werr), string))
+
+#define PyErr_SetHRESULT_and_string(hresult, string) \
+        PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\
+                                              "HRESULTError"), \
+                       Py_BuildValue("(i,s)", HRES_ERROR_V(hresult), string))
+
+#define PyErr_SetNTSTATUS_and_string(status, string)                           \
+        PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\
+                                              "NTSTATUSError"),        \
+                       Py_BuildValue("(i,s)", NT_STATUS_V(status), string))
+
 #define PyErr_NTSTATUS_IS_ERR_RAISE(status) \
        if (NT_STATUS_IS_ERR(status)) { \
                PyErr_SetNTSTATUS(status); \
 #define PyErr_NTSTATUS_IS_ERR_RAISE(status) \
        if (NT_STATUS_IS_ERR(status)) { \
                PyErr_SetNTSTATUS(status); \