[KoCo-CVS] [Commit] cjkcodecs/src codeccommon.h multibytecodec.c multibytecodec_compat.h
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-06-06 06:27:42
|
perky 03/06/05 23:27:42 Modified: src codeccommon.h multibytecodec.c multibytecodec_compat.h Log: Get python2.1 compatibility Revision Changes Path 1.12 +2 -1 cjkcodecs/src/codeccommon.h Index: codeccommon.h =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/codeccommon.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- codeccommon.h 2 Jun 2003 09:24:50 -0000 1.11 +++ codeccommon.h 6 Jun 2003 06:27:41 -0000 1.12 @@ -26,11 +26,12 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: codeccommon.h,v 1.11 2003/06/02 09:24:50 perky Exp $ + * $Id: codeccommon.h,v 1.12 2003/06/06 06:27:41 perky Exp $ */ #include "Python.h" #include "multibytecodec.h" +#include "multibytecodec_compat.h" #include "cjkcommon.h" #define ENCMAP(encoding) \ 1.16 +34 -7 cjkcodecs/src/multibytecodec.c Index: multibytecodec.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/multibytecodec.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- multibytecodec.c 6 Jun 2003 05:57:53 -0000 1.15 +++ multibytecodec.c 6 Jun 2003 06:27:41 -0000 1.16 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: multibytecodec.c,v 1.15 2003/06/06 05:57:53 perky Exp $ + * $Id: multibytecodec.c,v 1.16 2003/06/06 06:27:41 perky Exp $ */ #include "Python.h" @@ -659,6 +659,8 @@ PyObject_Del(self); } +OLD_GETATTR_DEF(multibytecodec) + static PyTypeObject MultibyteCodec_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ @@ -668,7 +670,7 @@ /* methods */ (destructor)multibytecodec_dealloc, /* tp_dealloc */ 0, /* tp_print */ - 0, /* tp_getattr */ + GETATTR_FUNC(multibytecodec), /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_compare */ 0, /* tp_repr */ @@ -678,11 +680,12 @@ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ + GETATTRO_FUNC(multibytecodec), /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ 0, /* tp_doc */ +#ifndef OLD_STYLE_TYPE 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -690,6 +693,7 @@ 0, /* tp_iter */ 0, /* tp_iterext */ multibytecodec_methods, /* tp_methods */ +#endif }; static PyObject * @@ -917,6 +921,8 @@ PyObject_Del(self); } +OLD_GETATTR_DEF(mbstreamreader) + static PyTypeObject MultibyteStreamReader_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ @@ -926,7 +932,7 @@ /* methods */ (destructor)mbstreamreader_dealloc, /* tp_dealloc */ 0, /* tp_print */ - 0, /* tp_getattr */ + GETATTR_FUNC(mbstreamreader), /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_compare */ 0, /* tp_repr */ @@ -936,11 +942,12 @@ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ + GETATTRO_FUNC(mbstreamreader), /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ 0, /* tp_doc */ +#ifndef OLD_STYLE_TYPE 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -948,6 +955,7 @@ 0, /* tp_iter */ 0, /* tp_iterext */ mbstreamreader_methods, /* tp_methods */ +#endif }; static int @@ -1101,6 +1109,8 @@ {NULL, NULL}, }; +OLD_GETATTR_DEF(mbstreamwriter) + static PyTypeObject MultibyteStreamWriter_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ @@ -1110,7 +1120,7 @@ /* methods */ (destructor)mbstreamwriter_dealloc, /* tp_dealloc */ 0, /* tp_print */ - 0, /* tp_getattr */ + GETATTR_FUNC(mbstreamwriter), /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_compare */ 0, /* tp_repr */ @@ -1120,11 +1130,12 @@ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ + GETATTRO_FUNC(mbstreamwriter), /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ 0, /* tp_doc */ +#ifndef OLD_STYLE_TYPE 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -1132,13 +1143,25 @@ 0, /* tp_iter */ 0, /* tp_iterext */ mbstreamwriter_methods, /* tp_methods */ +#endif }; static PyObject * +#ifndef NO_METH_O __create_codec(PyObject *ignore, PyObject *arg) +#else +__create_codec(PyObject *ignore, PyObject *args) +#endif { MultibyteCodecObject *self; +#ifdef NO_METH_O + PyObject *arg; + + if (!PyArg_ParseTuple(args, "O:__create_codec", &arg)) + return NULL; +#endif + if (!PyCObject_Check(arg)) { PyErr_SetString(PyExc_ValueError, "argument type invalid"); return NULL; @@ -1209,7 +1232,11 @@ } static struct PyMethodDef __methods[] = { +#ifndef NO_METH_O {"__create_codec", (PyCFunction)__create_codec, METH_O}, +#else + {"__create_codec", (PyCFunction)__create_codec, METH_VARARGS}, +#endif {NULL, NULL}, }; 1.2 +15 -3 cjkcodecs/src/multibytecodec_compat.h Index: multibytecodec_compat.h =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/multibytecodec_compat.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- multibytecodec_compat.h 6 Jun 2003 05:57:53 -0000 1.1 +++ multibytecodec_compat.h 6 Jun 2003 06:27:42 -0000 1.2 @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: multibytecodec_compat.h,v 1.1 2003/06/06 05:57:53 perky Exp $ + * $Id: multibytecodec_compat.h,v 1.2 2003/06/06 06:27:42 perky Exp $ */ /* We don't support 2.0 and older */ @@ -48,9 +48,21 @@ #if PY_VERSION_HEX < 0x02020000 # define Py_USING_UNICODE 1 # define Py_UNICODE_SIZE 2 -# define NO_PYSTRING_FROMFORMAT 1 -# define OLD_STYLE_TYPE 1 # define METH_NOARGS METH_VARARGS +# define NO_METH_O 1 +# define OLD_STYLE_TYPE 1 +# define OLD_GETATTR_DEF(prefix) \ + static PyObject * \ + prefix##_getattr(PyObject *self, char *name) \ + { \ + return Py_FindMethod(prefix##_methods, self, name); \ + } +# define GETATTR_FUNC(prefix) prefix##_getattr +# define GETATTRO_FUNC(prefix) 0 +#else +# define OLD_GETATTR_DEF(prefix) +# define GETATTR_FUNC(prefix) 0 +# define GETATTRO_FUNC(prefix) PyObject_GenericGetAttr #endif /* |