From 34192f9bf9a22d47796ad78487a1964a0c68a86a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 2 Apr 2019 18:04:45 +0530 Subject: [PATCH] py3: More fixes for chmlib wrapper --- src/calibre/utils/chm/swig_chm.c | 12 ++++++++---- src/calibre/utils/chm/swig_chm.i | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/calibre/utils/chm/swig_chm.c b/src/calibre/utils/chm/swig_chm.c index 9929e6c0de..2d1f30f95a 100644 --- a/src/calibre/utils/chm/swig_chm.c +++ b/src/calibre/utils/chm/swig_chm.c @@ -1,7 +1,8 @@ /* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (http://www.swig.org). * Version 3.0.12 - * swig -Wall -python -builtin -modern -O swig_chm.i + * + * swig -Wall -python -builtin -modern -O -o swig_chm.c swig_chm.i * * This file is not intended to be easily readable and contains a number of * coding conventions designed to improve portability and efficiency. Do not make @@ -3819,7 +3820,7 @@ int dummy_enumerator (struct chmFile *h, py_h = SWIG_NewPointerObj((void *) h, SWIGTYPE_p_chmFile, 0); py_ui = SWIG_NewPointerObj((void *) ui, SWIGTYPE_p_chmUnitInfo, 0); - py_c = PyCObject_AsVoidPtr(context); + py_c = PyCapsule_GetPointer(context, NULL); /* Time to call the callback */ arglist = Py_BuildValue("(OOO)", py_h, py_ui, py_c); @@ -4799,6 +4800,7 @@ SWIGINTERN PyObject *_wrap_chm_retrieve_object(PyObject *self, PyObject *args) { resultobj = t_output_helper(resultobj,o); + free(arg3); } @@ -4837,9 +4839,10 @@ SWIGINTERN PyObject *_wrap_chm_enumerate(PyObject *self, PyObject *args) { arg3 = dummy_enumerator; } { - if (!(arg4 = PyCObject_FromVoidPtr(swig_obj[3], NULL))) goto fail; + if (!(arg4 = PyCapsule_New(swig_obj[3], NULL, NULL))) goto fail; } result = (int)chm_enumerate(arg1,arg2,arg3,arg4); + Py_XDECREF(arg4); resultobj = SWIG_From_int((int)(result)); return resultobj; fail: @@ -4885,9 +4888,10 @@ SWIGINTERN PyObject *_wrap_chm_enumerate_dir(PyObject *self, PyObject *args) { arg4 = dummy_enumerator; } { - if (!(arg5 = PyCObject_FromVoidPtr(swig_obj[4], NULL))) goto fail; + if (!(arg5 = PyCapsule_New(swig_obj[4], NULL, NULL))) goto fail; } result = (int)chm_enumerate_dir(arg1,(char const *)arg2,arg3,arg4,arg5); + Py_XDECREF(arg5); resultobj = SWIG_From_int((int)(result)); if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); return resultobj; diff --git a/src/calibre/utils/chm/swig_chm.i b/src/calibre/utils/chm/swig_chm.i index 9e24f829bb..f9b4191cf4 100644 --- a/src/calibre/utils/chm/swig_chm.i +++ b/src/calibre/utils/chm/swig_chm.i @@ -55,7 +55,7 @@ int dummy_enumerator (struct chmFile *h, py_h = SWIG_NewPointerObj((void *) h, SWIGTYPE_p_chmFile, 0); py_ui = SWIG_NewPointerObj((void *) ui, SWIGTYPE_p_chmUnitInfo, 0); - py_c = PyCObject_AsVoidPtr(context); + py_c = PyCapsule_GetPointer(context, NULL); /* Time to call the callback */ arglist = Py_BuildValue("(OOO)", py_h, py_ui, py_c); @@ -83,7 +83,7 @@ int dummy_enumerator (struct chmFile *h, } %typemap(in) void *context { - if (!($1 = PyCObject_FromVoidPtr($input, NULL))) goto fail; + if (!($1 = PyCapsule_New($input, NULL, NULL))) goto fail; } %typemap(in, numinputs=0) struct chmUnitInfo *OutValue (struct chmUnitInfo *temp = (struct chmUnitInfo *) calloc(1, sizeof(struct chmUnitInfo))) { @@ -122,7 +122,7 @@ int dummy_enumerator (struct chmFile *h, %typemap(argout,fragment="t_output_helper") unsigned char *OUTPUT { PyObject *o; - o = PyString_FromStringAndSize($1, arg5); + o = PyBytes_FromStringAndSize((const char*)$1, arg5); $result = t_output_helper($result,o); #ifdef __cplusplus delete [] $1;