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

View file

@ -17,3 +17,4 @@ clean::
rm -f $(TARGET).py
check: all
$(MAKE) -f $(TOP)/Makefile python_run

View file

@ -17,6 +17,7 @@ extern int gcd(int x, int y);
%typemap(in,fragment="t_output_helper") (int argc, char *argv[]) {
int i;
int l;
if (!PyList_Check($input)) {
SWIG_exception(SWIG_ValueError, "Expecting a list");
}
@ -27,11 +28,21 @@ extern int gcd(int x, int y);
$2 = (char **) malloc(($1+1)*sizeof(char *));
for (i = 0; i < $1; i++) {
PyObject *s = PyList_GetItem($input,i);
if (!PyString_Check(s)) {
%#if PY_VERSION_HEX >= 0x03000000
if (!PyUnicode_Check(s))
%#else
if (!PyString_Check(s))
%#endif
{
free($2);
SWIG_exception(SWIG_ValueError, "List items must be strings");
}
%#if PY_VERSION_HEX >= 0x03000000
$2[i] = PyUnicode_AsStringAndSize(s, &l);
%#else
$2[i] = PyString_AsString(s);
%#endif
}
$2[i] = 0;
}
@ -39,12 +50,21 @@ extern int gcd(int x, int y);
extern int gcdmain(int argc, char *argv[]);
%typemap(in) (char *bytes, int len) {
%#if PY_VERSION_HEX >= 0x03000000
if (!PyUnicode_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a string");
return NULL;
}
$1 = PyUnicode_AsStringAndSize($input, &$2);
%#else
if (!PyString_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a string");
return NULL;
}
$1 = PyString_AsString($input);
$2 = PyString_Size($input);
%#endif
}
extern int count(char *bytes, int len, char c);
@ -56,9 +76,15 @@ extern int count(char *bytes, int len, char c);
so that we don't violate it's mutability */
%typemap(in) (char *str, int len) {
%#if PY_VERSION_HEX >= 0x03000000
$2 = PyUnicode_GetSize($input);
$1 = (char *) malloc($2+1);
memmove($1,PyUnicode_AsString($input),$2);
%#else
$2 = PyString_Size($input);
$1 = (char *) malloc($2+1);
memmove($1,PyString_AsString($input),$2);
%#endif
}
/* Return the mutated string as a new object. The t_output_helper
@ -67,7 +93,11 @@ extern int count(char *bytes, int len, char c);
%typemap(argout) (char *str, int len) {
PyObject *o;
%#if PY_VERSION_HEX >= 0x03000000
o = PyUnicode_FromStringAndSize($1,$2);
%#else
o = PyString_FromStringAndSize($1,$2);
%#endif
$result = t_output_helper($result,o);
free($1);
}