Show More
@@ -27,9 +27,6 b'' | |||||
27 | #include "compat.h" |
|
27 | #include "compat.h" | |
28 | #include "mpatch.h" |
|
28 | #include "mpatch.h" | |
29 |
|
29 | |||
30 | char *mpatch_errors[] = {NULL, "invalid patch", "patch cannot be decoded", |
|
|||
31 | "no memory"}; |
|
|||
32 |
|
||||
33 | static struct mpatch_flist *lalloc(ssize_t size) |
|
30 | static struct mpatch_flist *lalloc(ssize_t size) | |
34 | { |
|
31 | { | |
35 | struct mpatch_flist *a = NULL; |
|
32 | struct mpatch_flist *a = NULL; |
@@ -1,8 +1,6 b'' | |||||
1 | #ifndef _HG_MPATCH_H_ |
|
1 | #ifndef _HG_MPATCH_H_ | |
2 | #define _HG_MPATCH_H_ |
|
2 | #define _HG_MPATCH_H_ | |
3 |
|
3 | |||
4 | extern char *mpatch_errors[]; |
|
|||
5 |
|
||||
6 | #define MPATCH_ERR_NO_MEM -3 |
|
4 | #define MPATCH_ERR_NO_MEM -3 | |
7 | #define MPATCH_ERR_CANNOT_BE_DECODED -2 |
|
5 | #define MPATCH_ERR_CANNOT_BE_DECODED -2 | |
8 | #define MPATCH_ERR_INVALID_PATCH -1 |
|
6 | #define MPATCH_ERR_INVALID_PATCH -1 |
@@ -33,6 +33,21 b'' | |||||
33 | static char mpatch_doc[] = "Efficient binary patching."; |
|
33 | static char mpatch_doc[] = "Efficient binary patching."; | |
34 | static PyObject *mpatch_Error; |
|
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 | struct mpatch_flist *cpygetitem(void *bins, ssize_t pos) |
|
51 | struct mpatch_flist *cpygetitem(void *bins, ssize_t pos) | |
37 | { |
|
52 | { | |
38 | const char *buffer; |
|
53 | const char *buffer; | |
@@ -47,7 +62,7 b' struct mpatch_flist *cpygetitem(void *bi' | |||||
47 | return NULL; |
|
62 | return NULL; | |
48 | if ((r = mpatch_decode(buffer, blen, &res)) < 0) { |
|
63 | if ((r = mpatch_decode(buffer, blen, &res)) < 0) { | |
49 | if (!PyErr_Occurred()) |
|
64 | if (!PyErr_Occurred()) | |
50 | PyErr_SetString(mpatch_Error, mpatch_errors[-r]); |
|
65 | setpyerr(r); | |
51 | return NULL; |
|
66 | return NULL; | |
52 | } |
|
67 | } | |
53 | return res; |
|
68 | return res; | |
@@ -102,7 +117,7 b' patches(PyObject *self, PyObject *args)' | |||||
102 | cleanup: |
|
117 | cleanup: | |
103 | mpatch_lfree(patch); |
|
118 | mpatch_lfree(patch); | |
104 | if (!result && !PyErr_Occurred()) |
|
119 | if (!result && !PyErr_Occurred()) | |
105 | PyErr_SetString(mpatch_Error, mpatch_errors[-r]); |
|
120 | setpyerr(r); | |
106 | return result; |
|
121 | return result; | |
107 | } |
|
122 | } | |
108 |
|
123 |
General Comments 0
You need to be logged in to leave comments.
Login now