Merged the Python 3.0 support branch. The merging progress is not so smooth, so hope this commit won't make anything broken.

This is the (incomplemete) log produced by svnmerge.py:

Merged revisions 10405-10409,10420-10422,10426,10438,10445,10451,10454-10465,10467,10473-10475,10485,10488-10489,10493-10495,10497,10509-10510,10513-10514,10517,10520,10525,10528-10529,10533-10535,10554-10557,10570,10573,10593,10614,10666-10669,10673,10678,10687,10690,10704-10706,10731,10744,10750-10752,10755,10759,10770,10775-10776,10813,10819 via svnmerge from 
https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-bhy



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10834 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Haoyu Bai 2008-09-11 17:18:07 +00:00
commit 3d8ddfc442
75 changed files with 1603 additions and 246 deletions

107
Lib/python/pybuffer.i Normal file
View file

@ -0,0 +1,107 @@
/* Impelementing buffer protocol typemaps */
/* %pybuffer_mutable_binary(TYPEMAP, SIZE)
*
* Macro for functions accept mutable buffer pointer with a size.
* This can be used for both input and output. For example:
*
* %pybuffer_mutable_binary(char *buff, int size);
* void foo(char *buff, int size) {
* for(int i=0; i<size; ++i)
* buff[i]++;
* }
*/
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE)
(int res, Py_ssize_t size = 0, void *buf = 0) {
res = PyObject_AsWriteBuffer($input, &buf, &size);
if (res<0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
$1 = ($1_ltype) buf;
$2 = ($2_ltype) size;
}
%enddef
/* %pybuffer_mutable_string(TYPEMAP, SIZE)
*
* Macro for functions accept mutable zero terminated string pointer.
* This can be used for both input and output. For example:
*
* %pybuffer_mutable_string(char *str);
* void foo(char *str) {
* while(*str) {
* *str = toupper(*str);
* str++;
* }
*/
%define %pybuffer_mutable_string(TYPEMAP)
%typemap(in) (TYPEMAP)
(int res, Py_ssize_t size = 0, void *buf = 0) {
res = PyObject_AsWriteBuffer($input, &buf, &size);
if (res<0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
$1 = ($1_ltype) buf;
}
%enddef
/* pybuffer_binary(TYPEMAP, SIZE)
*
* Macro for functions accept read only buffer pointer with a size.
* This must be used for input. For example:
*
* %pybuffer_binary(char *buff, int size);
* int foo(char *buff, int size) {
* int count = 0;
* for(int i=0; i<size; ++i)
* if (0==buff[i]) count++;
* return count;
* }
*/
%define %pybuffer_binary(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE)
(int res, Py_ssize_t size = 0, const void *buf = 0) {
res = PyObject_AsReadBuffer($input, &buf, &size);
if (res<0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
$1 = ($1_ltype) buf;
$2 = ($2_ltype) size;
}
%enddef
/* %pybuffer_string(TYPEMAP, SIZE)
*
* Macro for functions accept read only zero terminated string pointer.
* This can be used for input. For example:
*
* %pybuffer_string(char *str);
* int foo(char *str) {
* int count = 0;
* while(*str) {
* if (isalnum(*str))
* count++;
* str++;
* }
*/
%define %pybuffer_string(TYPEMAP)
%typemap(in) (TYPEMAP)
(int res, Py_ssize_t size = 0, const void *buf = 0) {
res = PyObject_AsReadBuffer($input, &buf, &size);
if (res<0) {
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
$1 = ($1_ltype) buf;
}
%enddef