ia64/xen-unstable
changeset 13238:abcd545e7f4c
Fix the error handling in acm.policy.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | Ewan Mellor <ewan@xensource.com> |
---|---|
date | Tue Jan 02 13:32:35 2007 +0000 (2007-01-02) |
parents | 7cd6c032689e |
children | 71eadf04a1f9 |
files | tools/python/xen/lowlevel/acm/acm.c |
line diff
1.1 --- a/tools/python/xen/lowlevel/acm/acm.c Tue Jan 02 13:04:01 2007 +0000 1.2 +++ b/tools/python/xen/lowlevel/acm/acm.c Tue Jan 02 13:32:35 2007 +0000 1.3 @@ -35,6 +35,8 @@ 1.4 fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ 1.5 errno, strerror(errno)) 1.6 1.7 +static PyObject *acm_error_obj; 1.8 + 1.9 /* generic shared function */ 1.10 void * __getssid(int domid, uint32_t *buflen) 1.11 { 1.12 @@ -80,28 +82,26 @@ static PyObject *policy(PyObject * self, 1.13 { 1.14 /* out */ 1.15 char *policyreference; 1.16 - PyObject *ret = NULL; 1.17 + PyObject *ret; 1.18 void *ssid_buffer; 1.19 uint32_t buf_len; 1.20 1.21 if (!PyArg_ParseTuple(args, "", NULL)) { 1.22 - goto out1; 1.23 + return NULL; 1.24 } 1.25 ssid_buffer = __getssid(0, &buf_len); 1.26 - if (ssid_buffer == NULL) { 1.27 - goto out1; 1.28 - } else if (buf_len < sizeof(struct acm_ssid_buffer)) { 1.29 - goto out2; 1.30 - } else { 1.31 + if (ssid_buffer == NULL || buf_len < sizeof(struct acm_ssid_buffer)) { 1.32 + free(ssid_buffer); 1.33 + return PyErr_SetFromErrno(acm_error_obj); 1.34 + } 1.35 + else { 1.36 struct acm_ssid_buffer *ssid = (struct acm_ssid_buffer *)ssid_buffer; 1.37 policyreference = (char *)(ssid_buffer + ssid->policy_reference_offset 1.38 + sizeof (struct acm_policy_reference_buffer)); 1.39 + ret = Py_BuildValue("s", policyreference); 1.40 + free(ssid_buffer); 1.41 + return ret; 1.42 } 1.43 - ret = Py_BuildValue("s", policyreference); 1.44 - out2: 1.45 - free(ssid_buffer); 1.46 - out1: 1.47 - return ret; 1.48 } 1.49 1.50 1.51 @@ -213,5 +213,8 @@ static PyMethodDef acmMethods[] = { 1.52 /* inits */ 1.53 PyMODINIT_FUNC initacm(void) 1.54 { 1.55 - Py_InitModule("acm", acmMethods); 1.56 + PyObject *m = Py_InitModule("acm", acmMethods); 1.57 + acm_error_obj = PyErr_NewException("acm.Error", PyExc_RuntimeError, NULL); 1.58 + Py_INCREF(acm_error_obj); 1.59 + PyModule_AddObject(m, "Error", acm_error_obj); 1.60 }