[Python-checkins] CVS: python/dist/src/Modules _codecsmodule.c,2.1,2.2

Guido van Rossum python-dev@python.org
Tue, 28 Mar 2000 15:30:01 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Modules
In directory eric:/home/guido/hp/mal/py-patched/Modules

Modified Files:
	_codecsmodule.c 
Log Message:
Marc-Andre Lemburg:

The attached patch set includes a workaround to get Python with
Unicode compile on BSDI 4.x (courtesy Thomas Wouters; the cause
is a bug in the BSDI wchar.h header file) and Python interfaces
for the MBCS codec donated by Mark Hammond.

Also included are some minor corrections w/r to the docs of
the new "es" and "es#" parser markers (use PyMem_Free() instead
of free(); thanks to Mark Hammond for finding these).

The unicodedata tests are now in a separate file
(test_unicodedata.py) to avoid problems if the module cannot
be found.



Index: _codecsmodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/_codecsmodule.c,v
retrieving revision 2.1
retrieving revision 2.2
diff -C2 -r2.1 -r2.2
*** _codecsmodule.c	2000/03/10 23:09:23	2.1
--- _codecsmodule.c	2000/03/28 20:29:58	2.2
***************
*** 287,290 ****
--- 287,310 ----
  }
  
+ #ifdef MS_WIN32
+ 
+ static PyObject *
+ mbcs_decode(PyObject *self,
+ 	    PyObject *args)
+ {
+     const char *data;
+     int size;
+     const char *errors = NULL;
+     
+     if (!PyArg_ParseTuple(args, "t#|z:mbcs_decode",
+ 			  &data, &size, &errors))
+ 	return NULL;
+ 
+     return codec_tuple(PyUnicode_DecodeMBCS(data, size, errors),
+ 		       size);
+ }
+ 
+ #endif /* MS_WIN32 */
+ 
  /* --- Encoder ------------------------------------------------------------ */
  
***************
*** 492,495 ****
--- 512,537 ----
  }
  
+ #ifdef MS_WIN32
+ 
+ static PyObject *
+ mbcs_encode(PyObject *self,
+ 	    PyObject *args)
+ {
+     PyObject *str;
+     const char *errors = NULL;
+ 
+     if (!PyArg_ParseTuple(args, "U|z:mbcs_encode",
+ 			  &str, &errors))
+ 	return NULL;
+ 
+     return codec_tuple(PyUnicode_EncodeMBCS(
+ 			       PyUnicode_AS_UNICODE(str), 
+ 			       PyUnicode_GET_SIZE(str),
+ 			       errors),
+ 		       PyUnicode_GET_SIZE(str));
+ }
+ 
+ #endif /* MS_WIN32 */
+ 
  /* --- Module API --------------------------------------------------------- */
  
***************
*** 520,523 ****
--- 562,569 ----
      {"readbuffer_encode",	readbuffer_encode,		1},
      {"charbuffer_encode",	charbuffer_encode,		1},
+ #ifdef MS_WIN32
+     {"mbcs_encode", 		mbcs_encode,			1},
+     {"mbcs_decode", 		mbcs_decode,			1},
+ #endif
      {NULL, NULL}		/* sentinel */
  };