From dbee141b62de1abcf220b8dd0777ec144bea8c5a Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Thu, 6 Jan 2011 15:10:41 +0000 Subject: [PATCH] Fixes for Python 2.x: 1. PyUnicode_FromString was introduced in 2.6, not 2.7. 2. When parsing optional arguments in py_magic_check, py_magic_compile and py_magic_load, the corresponding C variable, filename, must have a default value (here, NULL). --- python/py_magic.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/py_magic.c b/python/py_magic.c index b58f8f7a..65fc758d 100644 --- a/python/py_magic.c +++ b/python/py_magic.c @@ -102,7 +102,7 @@ static PyMethodDef magic_cookie_hnd_methods[] = { { "compile", py_magic_compile, METH_VARARGS, _magic_compile__doc__ }, { "load", py_magic_load, METH_VARARGS, _magic_load__doc__ }, { "errno", py_magic_errno, METH_NOARGS, _magic_errno__doc__ }, - { NULL, NULL, 0, NULL } + { NULL, NULL, 0, NULL } }; /* module level methods */ @@ -203,7 +203,7 @@ static PyTypeObject magic_cookie_type = { #endif }; -#if PY_VERSION_HEX < 0x02070000 +#if PY_VERSION_HEX < 0x02060000 #define PyUnicode_FromString(m) PyString_FromString(m) #endif @@ -320,7 +320,7 @@ static PyObject * py_magic_check(PyObject *self, PyObject *args) { magic_cookie_hnd *hnd = (magic_cookie_hnd *)self; - char *filename; + char *filename = NULL; if (!PyArg_ParseTuple(args, "|s", &filename)) return NULL; @@ -332,7 +332,7 @@ static PyObject * py_magic_compile(PyObject *self, PyObject *args) { magic_cookie_hnd *hnd = (magic_cookie_hnd *)self; - char *filename; + char *filename = NULL; if (!PyArg_ParseTuple(args, "|s", &filename)) return NULL; @@ -344,7 +344,7 @@ static PyObject * py_magic_load(PyObject *self, PyObject *args) { magic_cookie_hnd *hnd = (magic_cookie_hnd *)self; - char *filename; + char *filename = NULL; if (!PyArg_ParseTuple(args, "|s", &filename)) return NULL; -- 2.40.0