##// END OF EJS Templates
mpatch: raise MemoryError instead of mpatchError if lalloc() failed...
Yuya Nishihara -
r29749:155f0cc3 default
parent child Browse files
Show More
@@ -27,9 +27,6 b''
27 27 #include "compat.h"
28 28 #include "mpatch.h"
29 29
30 char *mpatch_errors[] = {NULL, "invalid patch", "patch cannot be decoded",
31 "no memory"};
32
33 30 static struct mpatch_flist *lalloc(ssize_t size)
34 31 {
35 32 struct mpatch_flist *a = NULL;
@@ -1,8 +1,6 b''
1 1 #ifndef _HG_MPATCH_H_
2 2 #define _HG_MPATCH_H_
3 3
4 extern char *mpatch_errors[];
5
6 4 #define MPATCH_ERR_NO_MEM -3
7 5 #define MPATCH_ERR_CANNOT_BE_DECODED -2
8 6 #define MPATCH_ERR_INVALID_PATCH -1
@@ -33,6 +33,21 b''
33 33 static char mpatch_doc[] = "Efficient binary patching.";
34 34 static PyObject *mpatch_Error;
35 35
36 static void setpyerr(int r)
37 {
38 switch (r) {
39 case MPATCH_ERR_NO_MEM:
40 PyErr_NoMemory();
41 break;
42 case MPATCH_ERR_CANNOT_BE_DECODED:
43 PyErr_SetString(mpatch_Error, "patch cannot be decoded");
44 break;
45 case MPATCH_ERR_INVALID_PATCH:
46 PyErr_SetString(mpatch_Error, "invalid patch");
47 break;
48 }
49 }
50
36 51 struct mpatch_flist *cpygetitem(void *bins, ssize_t pos)
37 52 {
38 53 const char *buffer;
@@ -47,7 +62,7 b' struct mpatch_flist *cpygetitem(void *bi'
47 62 return NULL;
48 63 if ((r = mpatch_decode(buffer, blen, &res)) < 0) {
49 64 if (!PyErr_Occurred())
50 PyErr_SetString(mpatch_Error, mpatch_errors[-r]);
65 setpyerr(r);
51 66 return NULL;
52 67 }
53 68 return res;
@@ -102,7 +117,7 b' patches(PyObject *self, PyObject *args)'
102 117 cleanup:
103 118 mpatch_lfree(patch);
104 119 if (!result && !PyErr_Occurred())
105 PyErr_SetString(mpatch_Error, mpatch_errors[-r]);
120 setpyerr(r);
106 121 return result;
107 122 }
108 123
General Comments 0
You need to be logged in to leave comments. Login now