# HG changeset patch # User Yuya Nishihara # Date 2016-08-07 01:06:56 # Node ID 155f0cc3f81354f3dd43607b885c7b46b738824e # Parent 5e2365698d448c2a1d75f6a58e11ec65f66a0266 mpatch: raise MemoryError instead of mpatchError if lalloc() failed MemoryError is handled differently in dispatch._runcatch(). Since mpatch_errors[] isn't that useful now, I've changed it to a simple switch statement. diff --git a/mercurial/mpatch.c b/mercurial/mpatch.c --- a/mercurial/mpatch.c +++ b/mercurial/mpatch.c @@ -27,9 +27,6 @@ #include "compat.h" #include "mpatch.h" -char *mpatch_errors[] = {NULL, "invalid patch", "patch cannot be decoded", - "no memory"}; - static struct mpatch_flist *lalloc(ssize_t size) { struct mpatch_flist *a = NULL; diff --git a/mercurial/mpatch.h b/mercurial/mpatch.h --- a/mercurial/mpatch.h +++ b/mercurial/mpatch.h @@ -1,8 +1,6 @@ #ifndef _HG_MPATCH_H_ #define _HG_MPATCH_H_ -extern char *mpatch_errors[]; - #define MPATCH_ERR_NO_MEM -3 #define MPATCH_ERR_CANNOT_BE_DECODED -2 #define MPATCH_ERR_INVALID_PATCH -1 diff --git a/mercurial/mpatch_module.c b/mercurial/mpatch_module.c --- a/mercurial/mpatch_module.c +++ b/mercurial/mpatch_module.c @@ -33,6 +33,21 @@ static char mpatch_doc[] = "Efficient binary patching."; static PyObject *mpatch_Error; +static void setpyerr(int r) +{ + switch (r) { + case MPATCH_ERR_NO_MEM: + PyErr_NoMemory(); + break; + case MPATCH_ERR_CANNOT_BE_DECODED: + PyErr_SetString(mpatch_Error, "patch cannot be decoded"); + break; + case MPATCH_ERR_INVALID_PATCH: + PyErr_SetString(mpatch_Error, "invalid patch"); + break; + } +} + struct mpatch_flist *cpygetitem(void *bins, ssize_t pos) { const char *buffer; @@ -47,7 +62,7 @@ struct mpatch_flist *cpygetitem(void *bi return NULL; if ((r = mpatch_decode(buffer, blen, &res)) < 0) { if (!PyErr_Occurred()) - PyErr_SetString(mpatch_Error, mpatch_errors[-r]); + setpyerr(r); return NULL; } return res; @@ -102,7 +117,7 @@ patches(PyObject *self, PyObject *args) cleanup: mpatch_lfree(patch); if (!result && !PyErr_Occurred()) - PyErr_SetString(mpatch_Error, mpatch_errors[-r]); + setpyerr(r); return result; }