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

@ -116,6 +116,17 @@ namespace std {
bool res;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
res = PyObject_Compare(v, w) < 0;
/* This may fall into a case of inconsistent
eg. ObjA > ObjX > ObjB
but ObjA < ObjB
*/
if( PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_TypeError) )
{
/* Objects can't be compared, this mostly occured in Python 3.0 */
/* Compare their ptr directly for a workaround */
res = (v < w);
PyErr_Clear();
}
SWIG_PYTHON_THREAD_END_BLOCK;
return res;
}
@ -597,6 +608,11 @@ namespace swig
return !(self->empty());
}
/* Alias for Python 3 compatibility */
bool __bool__() const {
return !(self->empty());
}
size_type __len__() const {
return self->size();
}
@ -618,6 +634,14 @@ namespace swig
return x;
}
/* typemap for slice object support */
%typemap(in) PySliceObject* {
$1 = (PySliceObject *) $input;
}
%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) PySliceObject* {
$1 = PySlice_Check($input);
}
Sequence* __getslice__(difference_type i, difference_type j) throw (std::out_of_range) {
return swig::getslice(self, i, j);
}
@ -634,6 +658,43 @@ namespace swig
void __delitem__(difference_type i) throw (std::out_of_range) {
self->erase(swig::getpos(self,i));
}
/* Overloaded methods for Python 3 compatibility
* (Also useful in Python 2.x)
*/
Sequence* __getitem__(PySliceObject *slice) throw (std::out_of_range) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return NULL;
}
PySlice_GetIndices(slice, self->size(), &i, &j, &step);
return swig::getslice(self, i, j);
}
void __setitem__(PySliceObject *slice, const Sequence& v)
throw (std::out_of_range, std::invalid_argument) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(slice, self->size(), &i, &j, &step);
swig::setslice(self, i, j, v);
}
void __delitem__(PySliceObject *slice)
throw (std::out_of_range) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(slice, self->size(), &i, &j, &step);
swig::delslice(self, i,j);
}
}
%enddef