2008-05-24 21:38:33 +02:00
/*
Unix SMB / CIFS implementation .
Samba utility functions
Copyright ( C ) Jelmer Vernooij < jelmer @ samba . org > 2008
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef __PYERRORS_H__
# define __PYERRORS_H__
2008-05-24 22:13:32 +02:00
# define PyErr_FromWERROR(err) Py_BuildValue("(i,s)", W_ERROR_V(err), discard_const_p(char, win_errstr(err)))
2014-04-07 15:47:02 +02:00
# define PyErr_FromHRESULT(err) Py_BuildValue("(i,s)", HRES_ERROR_V(err), discard_const_p(char, hresult_errstr_const(err)))
2017-09-06 09:27:02 +02:00
# define PyErr_FromNTSTATUS(status) Py_BuildValue("(I,s)", NT_STATUS_V(status), discard_const_p(char, get_friendly_nt_error_msg(status)))
2008-05-24 22:13:32 +02:00
2010-02-25 16:16:33 +11:00
# define PyErr_FromString(str) Py_BuildValue("(s)", discard_const_p(char, str))
2016-11-01 15:23:58 +13:00
# define PyErr_SetWERROR(werr) \
PyErr_SetObject ( PyObject_GetAttrString ( PyImport_ImportModule ( " samba " ) , \
" WERRORError " ) , \
PyErr_FromWERROR ( werr ) )
# define PyErr_SetHRESULT(hresult) \
PyErr_SetObject ( PyObject_GetAttrString ( PyImport_ImportModule ( " samba " ) , \
" HRESULTError " ) , \
PyErr_FromHRESULT ( hresult ) )
2008-05-24 21:38:33 +02:00
# define PyErr_SetNTSTATUS(status) \
2016-11-01 15:23:58 +13:00
PyErr_SetObject ( PyObject_GetAttrString ( PyImport_ImportModule ( " samba " ) , \
" NTSTATUSError " ) , \
PyErr_FromNTSTATUS ( status ) )
2008-05-24 21:38:33 +02:00
2016-11-01 16:03:09 +13:00
# 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 ) )
2008-12-18 15:32:58 +00:00
# define PyErr_NTSTATUS_IS_ERR_RAISE(status) \
if ( NT_STATUS_IS_ERR ( status ) ) { \
PyErr_SetNTSTATUS ( status ) ; \
return NULL ; \
}
2012-08-06 10:41:31 +02:00
# define PyErr_NTSTATUS_NOT_OK_RAISE(status) \
if ( ! NT_STATUS_IS_OK ( status ) ) { \
PyErr_SetNTSTATUS ( status ) ; \
return NULL ; \
}
2012-08-06 10:39:19 +02:00
# define PyErr_WERROR_NOT_OK_RAISE(status) \
2008-12-18 15:32:58 +00:00
if ( ! W_ERROR_IS_OK ( status ) ) { \
PyErr_SetWERROR ( status ) ; \
return NULL ; \
}
2008-05-24 21:38:33 +02:00
# endif /* __PYERRORS_H__ */