python/samba: Another object.next() to next(object) py2/py3 converstion
[Samba.git] / source4 / libcli / util / pyerrors.h
blob1c91c5a9e418a7c54c841cca1c0a0f1f163f64ea
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef __PYERRORS_H__
21 #define __PYERRORS_H__
23 #define PyErr_FromWERROR(err) Py_BuildValue("(i,s)", W_ERROR_V(err), discard_const_p(char, win_errstr(err)))
25 #define PyErr_FromHRESULT(err) Py_BuildValue("(i,s)", HRES_ERROR_V(err), discard_const_p(char, hresult_errstr_const(err)))
27 #define PyErr_FromNTSTATUS(status) Py_BuildValue("(I,s)", NT_STATUS_V(status), discard_const_p(char, get_friendly_nt_error_msg(status)))
29 #define PyErr_FromString(str) Py_BuildValue("(s)", discard_const_p(char, str))
31 #define PyErr_SetWERROR(werr) \
32 PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\
33 "WERRORError"), \
34 PyErr_FromWERROR(werr))
36 #define PyErr_SetHRESULT(hresult) \
37 PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\
38 "HRESULTError"), \
39 PyErr_FromHRESULT(hresult))
41 #define PyErr_SetNTSTATUS(status) \
42 PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\
43 "NTSTATUSError"), \
44 PyErr_FromNTSTATUS(status))
46 #define PyErr_SetWERROR_and_string(werr, string) \
47 PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\
48 "WERRORError"), \
49 Py_BuildValue("(i,s)", W_ERROR_V(werr), string))
51 #define PyErr_SetHRESULT_and_string(hresult, string) \
52 PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\
53 "HRESULTError"), \
54 Py_BuildValue("(i,s)", HRES_ERROR_V(hresult), string))
56 #define PyErr_SetNTSTATUS_and_string(status, string) \
57 PyErr_SetObject(PyObject_GetAttrString(PyImport_ImportModule("samba"),\
58 "NTSTATUSError"), \
59 Py_BuildValue("(i,s)", NT_STATUS_V(status), string))
61 #define PyErr_NTSTATUS_IS_ERR_RAISE(status) \
62 if (NT_STATUS_IS_ERR(status)) { \
63 PyErr_SetNTSTATUS(status); \
64 return NULL; \
67 #define PyErr_NTSTATUS_NOT_OK_RAISE(status) \
68 if (!NT_STATUS_IS_OK(status)) { \
69 PyErr_SetNTSTATUS(status); \
70 return NULL; \
73 #define PyErr_WERROR_NOT_OK_RAISE(status) \
74 if (!W_ERROR_IS_OK(status)) { \
75 PyErr_SetWERROR(status); \
76 return NULL; \
79 #endif /* __PYERRORS_H__ */