merge rev 13009-13025 (up to swig-2.0.6) from trunk to gsoc2008-cherylfoil
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@13045 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
commit
ce1891a6c3
18 changed files with 186 additions and 100 deletions
|
|
@ -23,7 +23,8 @@
|
|||
%typemap(jtype) char **STRING_ARRAY "String[]"
|
||||
%typemap(jstype) char **STRING_ARRAY "String[]"
|
||||
%typemap(in) char **STRING_ARRAY (jint size) {
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
if ($input) {
|
||||
size = JCALL1(GetArrayLength, jenv, $input);
|
||||
#ifdef __cplusplus
|
||||
$1 = new char*[size+1];
|
||||
|
|
@ -31,51 +32,56 @@
|
|||
$1 = (char **)calloc(size+1, sizeof(char *));
|
||||
#endif
|
||||
for (i = 0; i<size; i++) {
|
||||
jstring j_string = (jstring)JCALL2(GetObjectArrayElement, jenv, $input, i);
|
||||
const char *c_string = JCALL2(GetStringUTFChars, jenv, j_string, 0);
|
||||
jstring j_string = (jstring)JCALL2(GetObjectArrayElement, jenv, $input, i);
|
||||
const char *c_string = JCALL2(GetStringUTFChars, jenv, j_string, 0);
|
||||
#ifdef __cplusplus
|
||||
$1[i] = new char [strlen(c_string)+1];
|
||||
$1[i] = new char [strlen(c_string)+1];
|
||||
#else
|
||||
$1[i] = (char *)calloc(strlen(c_string)+1, sizeof(const char *));
|
||||
$1[i] = (char *)calloc(strlen(c_string)+1, sizeof(const char *));
|
||||
#endif
|
||||
strcpy($1[i], c_string);
|
||||
JCALL2(ReleaseStringUTFChars, jenv, j_string, c_string);
|
||||
JCALL1(DeleteLocalRef, jenv, j_string);
|
||||
strcpy($1[i], c_string);
|
||||
JCALL2(ReleaseStringUTFChars, jenv, j_string, c_string);
|
||||
JCALL1(DeleteLocalRef, jenv, j_string);
|
||||
}
|
||||
$1[i] = 0;
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(freearg) char **STRING_ARRAY {
|
||||
int i;
|
||||
for (i=0; i<size$argnum-1; i++)
|
||||
int i;
|
||||
for (i=0; i<size$argnum-1; i++)
|
||||
#ifdef __cplusplus
|
||||
delete[] $1[i];
|
||||
delete[] $1;
|
||||
delete[] $1[i];
|
||||
delete[] $1;
|
||||
#else
|
||||
free($1[i]);
|
||||
free($1);
|
||||
free($1[i]);
|
||||
free($1);
|
||||
#endif
|
||||
}
|
||||
|
||||
%typemap(out) char **STRING_ARRAY {
|
||||
if ($1) {
|
||||
int i;
|
||||
int len=0;
|
||||
jstring temp_string;
|
||||
const jclass clazz = JCALL1(FindClass, jenv, "java/lang/String");
|
||||
|
||||
while ($1[len]) len++;
|
||||
jresult = JCALL3(NewObjectArray, jenv, len, clazz, NULL);
|
||||
while ($1[len]) len++;
|
||||
$result = JCALL3(NewObjectArray, jenv, len, clazz, NULL);
|
||||
/* exception checking omitted */
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
temp_string = JCALL1(NewStringUTF, jenv, *$1++);
|
||||
JCALL3(SetObjectArrayElement, jenv, jresult, i, temp_string);
|
||||
JCALL3(SetObjectArrayElement, jenv, $result, i, temp_string);
|
||||
JCALL1(DeleteLocalRef, jenv, temp_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(javain) char **STRING_ARRAY "$javainput"
|
||||
%typemap(javaout) char **STRING_ARRAY {
|
||||
%typemap(javaout) char **STRING_ARRAY {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +117,7 @@
|
|||
|
||||
%typemap(argout) char **STRING_OUT {
|
||||
jstring jnewstring = NULL;
|
||||
if($1) {
|
||||
if ($1) {
|
||||
jnewstring = JCALL1(NewStringUTF, jenv, *$1);
|
||||
}
|
||||
JCALL3(SetObjectArrayElement, jenv, $input, 0, jnewstring);
|
||||
|
|
@ -134,11 +140,11 @@
|
|||
%typemap(jtype) char *BYTE "byte[]"
|
||||
%typemap(jstype) char *BYTE "byte[]"
|
||||
%typemap(in) char *BYTE {
|
||||
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
|
||||
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
|
||||
}
|
||||
|
||||
%typemap(argout) char *BYTE {
|
||||
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
|
||||
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
|
||||
}
|
||||
|
||||
%typemap(javain) char *BYTE "$javainput"
|
||||
|
|
|
|||
23
Lib/lua/factory.i
Normal file
23
Lib/lua/factory.i
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
A modification of factory.swg from the generic UTL library.
|
||||
*/
|
||||
|
||||
%include <typemaps/swigmacros.swg>
|
||||
|
||||
%define %_factory_dispatch(Type)
|
||||
if (!dcast) {
|
||||
Type *dobj = dynamic_cast<Type *>($1);
|
||||
if (dobj) {
|
||||
dcast = 1;
|
||||
SWIG_NewPointerObj(L, dobj, $descriptor(Type *), $owner); SWIG_arg++;
|
||||
}
|
||||
}%enddef
|
||||
|
||||
%define %factory(Method,Types...)
|
||||
%typemap(out) Method {
|
||||
int dcast = 0;
|
||||
%formacro(%_factory_dispatch, Types)
|
||||
if (!dcast) {
|
||||
SWIG_NewPointerObj(L, $1, $descriptor, $owner); SWIG_arg++;
|
||||
}
|
||||
}%enddef
|
||||
|
|
@ -557,7 +557,8 @@ ptr=nil -- the iMath* will be GC'ed as normal
|
|||
*/
|
||||
|
||||
%typemap(in,numinputs=0) SWIGTYPE** OUTPUT ($*ltype temp)
|
||||
%{ $1 = &temp; %}
|
||||
%{ temp = ($*ltype)0;
|
||||
$1 = &temp; %}
|
||||
%typemap(argout) SWIGTYPE** OUTPUT
|
||||
%{SWIG_NewPointerObj(L,*$1,$*descriptor,1); SWIG_arg++; %}
|
||||
|
||||
|
|
|
|||
|
|
@ -188,8 +188,9 @@ namespace swig {
|
|||
}
|
||||
|
||||
namespace swig {
|
||||
template <class Difference>
|
||||
inline size_t
|
||||
check_index(ptrdiff_t i, size_t size, bool insert = false) {
|
||||
check_index(Difference i, size_t size, bool insert = false) {
|
||||
if ( i < 0 ) {
|
||||
if ((size_t) (-i) <= size)
|
||||
return (size_t) (i + size);
|
||||
|
|
@ -201,37 +202,38 @@ namespace swig {
|
|||
throw std::out_of_range("index out of range");
|
||||
}
|
||||
|
||||
template <class Difference>
|
||||
void
|
||||
slice_adjust(ptrdiff_t i, ptrdiff_t j, ptrdiff_t step, size_t size, ptrdiff_t &ii, ptrdiff_t &jj, bool insert = false) {
|
||||
slice_adjust(Difference i, Difference j, Py_ssize_t step, size_t size, Difference &ii, Difference &jj, bool insert = false) {
|
||||
if (step == 0) {
|
||||
throw std::invalid_argument("slice step cannot be zero");
|
||||
} else if (step > 0) {
|
||||
// Required range: 0 <= i < size, 0 <= j < size
|
||||
if (i < 0) {
|
||||
ii = 0;
|
||||
} else if (i < (ptrdiff_t)size) {
|
||||
} else if (i < (Difference)size) {
|
||||
ii = i;
|
||||
} else if (insert && (i >= (ptrdiff_t)size)) {
|
||||
ii = (ptrdiff_t)size;
|
||||
} else if (insert && (i >= (Difference)size)) {
|
||||
ii = (Difference)size;
|
||||
}
|
||||
if ( j < 0 ) {
|
||||
jj = 0;
|
||||
} else {
|
||||
jj = (j < (ptrdiff_t)size) ? j : (ptrdiff_t)size;
|
||||
jj = (j < (Difference)size) ? j : (Difference)size;
|
||||
}
|
||||
} else {
|
||||
// Required range: -1 <= i < size-1, -1 <= j < size-1
|
||||
if (i < -1) {
|
||||
ii = -1;
|
||||
} else if (i < (ptrdiff_t) size) {
|
||||
} else if (i < (Difference) size) {
|
||||
ii = i;
|
||||
} else if (i >= (ptrdiff_t)(size-1)) {
|
||||
ii = (ptrdiff_t)(size-1);
|
||||
} else if (i >= (Difference)(size-1)) {
|
||||
ii = (Difference)(size-1);
|
||||
}
|
||||
if (j < -1) {
|
||||
jj = -1;
|
||||
} else {
|
||||
jj = (j < (ptrdiff_t)size ) ? j : (ptrdiff_t)(size-1);
|
||||
jj = (j < (Difference)size ) ? j : (Difference)(size-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -329,7 +331,7 @@ namespace swig {
|
|||
size_t replacecount = (jj - ii + step - 1) / step;
|
||||
if (is.size() != replacecount) {
|
||||
char msg[1024];
|
||||
sprintf(msg, "attempt to assign sequence of size %d to extended slice of size %d", is.size(), replacecount);
|
||||
sprintf(msg, "attempt to assign sequence of size %lu to extended slice of size %lu", (unsigned long)is.size(), (unsigned long)replacecount);
|
||||
throw std::invalid_argument(msg);
|
||||
}
|
||||
typename Sequence::const_iterator isit = is.begin();
|
||||
|
|
@ -347,7 +349,7 @@ namespace swig {
|
|||
size_t replacecount = (ii - jj - step - 1) / -step;
|
||||
if (is.size() != replacecount) {
|
||||
char msg[1024];
|
||||
sprintf(msg, "attempt to assign sequence of size %d to extended slice of size %d", is.size(), replacecount);
|
||||
sprintf(msg, "attempt to assign sequence of size %lu to extended slice of size %lu", (unsigned long)is.size(), (unsigned long)replacecount);
|
||||
throw std::invalid_argument(msg);
|
||||
}
|
||||
typename Sequence::const_iterator isit = is.begin();
|
||||
|
|
@ -797,8 +799,7 @@ namespace swig
|
|||
return swig::getslice(self, i, j, 1);
|
||||
}
|
||||
|
||||
void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence())
|
||||
throw (std::out_of_range, std::invalid_argument) {
|
||||
void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence()) throw (std::out_of_range, std::invalid_argument) {
|
||||
swig::setslice(self, i, j, 1, v);
|
||||
}
|
||||
|
||||
|
|
@ -821,41 +822,46 @@ namespace swig
|
|||
SWIG_Error(SWIG_TypeError, "Slice object expected.");
|
||||
return NULL;
|
||||
}
|
||||
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
|
||||
return swig::getslice(self, i, j, step);
|
||||
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
|
||||
Sequence::difference_type id = i;
|
||||
Sequence::difference_type jd = j;
|
||||
return swig::getslice(self, id, jd, step);
|
||||
}
|
||||
|
||||
void __setitem__(PySliceObject *slice, const Sequence& v)
|
||||
throw (std::out_of_range, std::invalid_argument) {
|
||||
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(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
|
||||
swig::setslice(self, i, j, step, v);
|
||||
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
|
||||
Sequence::difference_type id = i;
|
||||
Sequence::difference_type jd = j;
|
||||
swig::setslice(self, id, jd, step, v);
|
||||
}
|
||||
|
||||
void __setitem__(PySliceObject *slice)
|
||||
throw (std::out_of_range, std::invalid_argument) {
|
||||
void __setitem__(PySliceObject *slice) 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(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
|
||||
swig::delslice(self, i, j, step);
|
||||
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
|
||||
Sequence::difference_type id = i;
|
||||
Sequence::difference_type jd = j;
|
||||
swig::delslice(self, id, jd, step);
|
||||
}
|
||||
|
||||
void __delitem__(PySliceObject *slice)
|
||||
throw (std::out_of_range, std::invalid_argument) {
|
||||
void __delitem__(PySliceObject *slice) 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(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
|
||||
swig::delslice(self, i, j, step);
|
||||
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
|
||||
Sequence::difference_type id = i;
|
||||
Sequence::difference_type jd = j;
|
||||
swig::delslice(self, id, jd, step);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue