Merge from trunk
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@13053 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
commit
7444913fda
59 changed files with 955 additions and 692 deletions
|
|
@ -91,31 +91,31 @@ private class SwigExceptionHelper {
|
|||
&setNoSuchElementException);
|
||||
}
|
||||
|
||||
static void setException(const char* message) {
|
||||
static void setException(char* message) {
|
||||
auto exception = new object.Exception(tango.stdc.stringz.fromStringz(message).dup);
|
||||
exception.next = SwigPendingException.retrieve();
|
||||
SwigPendingException.set(exception);
|
||||
}
|
||||
|
||||
static void setIllegalArgumentException(const char* message) {
|
||||
static void setIllegalArgumentException(char* message) {
|
||||
auto exception = new tango.core.Exception.IllegalArgumentException(tango.stdc.stringz.fromStringz(message).dup);
|
||||
exception.next = SwigPendingException.retrieve();
|
||||
SwigPendingException.set(exception);
|
||||
}
|
||||
|
||||
static void setIllegalElementException(const char* message) {
|
||||
static void setIllegalElementException(char* message) {
|
||||
auto exception = new tango.core.Exception.IllegalElementException(tango.stdc.stringz.fromStringz(message).dup);
|
||||
exception.next = SwigPendingException.retrieve();
|
||||
SwigPendingException.set(exception);
|
||||
}
|
||||
|
||||
static void setIOException(const char* message) {
|
||||
static void setIOException(char* message) {
|
||||
auto exception = new tango.core.Exception.IOException(tango.stdc.stringz.fromStringz(message).dup);
|
||||
exception.next = SwigPendingException.retrieve();
|
||||
SwigPendingException.set(exception);
|
||||
}
|
||||
|
||||
static void setNoSuchElementException(const char* message) {
|
||||
static void setNoSuchElementException(char* message) {
|
||||
auto exception = new tango.core.Exception.NoSuchElementException(tango.stdc.stringz.fromStringz(message).dup);
|
||||
exception.next = SwigPendingException.retrieve();
|
||||
SwigPendingException.set(exception);
|
||||
|
|
@ -174,7 +174,7 @@ private:
|
|||
alias tango.core.Thread.ThreadLocal!(object.Exception) ThreadLocalData;
|
||||
static ThreadLocalData m_sPendingException;
|
||||
}
|
||||
alias void function(const char* message) SwigExceptionCallback;
|
||||
alias void function(char* message) SwigExceptionCallback;
|
||||
%}
|
||||
#else
|
||||
%pragma(d) imdmoduleimports=%{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -33,6 +33,15 @@ extern "C" {
|
|||
# define lua_rawlen lua_objlen
|
||||
#endif
|
||||
|
||||
|
||||
/* lua_pushglobaltable is the recommended "future-proof" way to get
|
||||
the global table for Lua 5.2 and later. Here we define
|
||||
lua_pushglobaltable ourselves for Lua versions before 5.2. */
|
||||
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
|
||||
# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
|
||||
#endif
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* global swig types
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
@ -469,6 +478,39 @@ SWIGINTERN int SWIG_Lua_class_destruct(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* the class.__tostring method called by the interpreter and print */
|
||||
SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L)
|
||||
{
|
||||
/* there should be 1 param passed in
|
||||
(1) userdata (not the metatable) */
|
||||
assert(lua_isuserdata(L,1)); /* just in case */
|
||||
unsigned long userData = (unsigned long)lua_touserdata(L,1); /* get the userdata address for later */
|
||||
lua_getmetatable(L,1); /* get the meta table */
|
||||
assert(lua_istable(L,-1)); /* just in case */
|
||||
|
||||
lua_getfield(L, -1, ".type");
|
||||
const char* className = lua_tostring(L, -1);
|
||||
|
||||
char output[256];
|
||||
sprintf(output, "<%s userdata: %lX>", className, userData);
|
||||
|
||||
lua_pushstring(L, (const char*)output);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* to manually disown some userdata */
|
||||
SWIGINTERN int SWIG_Lua_class_disown(lua_State* L)
|
||||
{
|
||||
/* there should be 1 params passed in
|
||||
(1) userdata (not the meta table) */
|
||||
swig_lua_userdata* usr;
|
||||
assert(lua_isuserdata(L,-1)); /* just in case */
|
||||
usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
|
||||
|
||||
usr->own = 0; /* clear our ownership */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* gets the swig class registry (or creates it) */
|
||||
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L)
|
||||
{
|
||||
|
|
@ -594,11 +636,15 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss)
|
|||
/* add a table called ".fn" */
|
||||
lua_pushstring(L,".fn");
|
||||
lua_newtable(L);
|
||||
/* add manual disown method */
|
||||
SWIG_Lua_add_function(L,"__disown",SWIG_Lua_class_disown);
|
||||
lua_rawset(L,-3);
|
||||
/* add accessor fns for using the .get,.set&.fn */
|
||||
SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
|
||||
SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
|
||||
SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
|
||||
/* add tostring method for better output */
|
||||
SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
|
||||
/* add it */
|
||||
lua_rawset(L,-3); /* metatable into registry */
|
||||
lua_pop(L,1); /* tidy stack (remove registry) */
|
||||
|
|
|
|||
|
|
@ -30,11 +30,7 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
|
|||
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
|
||||
int i;
|
||||
/* start with global table */
|
||||
#ifdef LUA_RIDX_GLOBALS
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
|
||||
#else
|
||||
lua_pushvalue(L,LUA_GLOBALSINDEX);
|
||||
#endif
|
||||
lua_pushglobaltable (L);
|
||||
/* SWIG's internal initalisation */
|
||||
SWIG_InitializeModule((void*)L);
|
||||
SWIG_PropagateClientData();
|
||||
|
|
|
|||
|
|
@ -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++; %}
|
||||
|
||||
|
|
|
|||
|
|
@ -424,7 +424,8 @@ namespace Swig {
|
|||
if (ndim==1 && c.columns()!=1) ndim = c.columns();
|
||||
|
||||
dim_vector d;
|
||||
d.resize(ndim);
|
||||
d.resize(ndim < 2 ? 2 : ndim);
|
||||
d(0) = d(1) = 1;
|
||||
|
||||
// Fill in dim_vector
|
||||
for (int k=0;k<ndim;k++) {
|
||||
|
|
@ -440,7 +441,8 @@ namespace Swig {
|
|||
Array<int> a = out.int_vector_value();
|
||||
if (error_state) return dim_vector(1,1);
|
||||
dim_vector d;
|
||||
d.resize(a.numel());
|
||||
d.resize(a.numel() < 2 ? 2 : a.numel());
|
||||
d(0) = d(1) = 1;
|
||||
for (int k=0;k<a.numel();k++) {
|
||||
d.elem(k) = a(k);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,7 +171,9 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
|
|||
// exiting without explicitly clearing the variable causes octave to segfault.
|
||||
#if OCTAVE_API_VERSION_NUMBER>=37
|
||||
octave_value_list SWIG_atexit_func(const octave_value_list &args, int nargout) {
|
||||
symbol_table::clear_global_pattern("*");
|
||||
string_vector vars = symbol_table::global_variable_names();
|
||||
for (int i = 0; i < vars.length(); i++)
|
||||
symbol_table::clear_global(vars[i]);
|
||||
symbol_table::clear_functions();
|
||||
return octave_value();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ SWIG_AsVal_dec(bool)(SV *obj, bool* val)
|
|||
if (val) *val = false;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (val) *val = SvTRUE(obj);
|
||||
if (val) *val = SvTRUE(obj) ? true : false;
|
||||
return SWIG_AddCast(SWIG_OK);
|
||||
}
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ SWIG_From_dec(long long)(long long value)
|
|||
{
|
||||
SV *sv;
|
||||
if (value >= IV_MIN && value <= IV_MAX)
|
||||
sv = newSViv(value);
|
||||
sv = newSViv((IV)(value));
|
||||
else {
|
||||
//sv = newSVpvf("%lld", value); doesn't work in non 64bit Perl
|
||||
char temp[256];
|
||||
|
|
@ -248,7 +248,7 @@ SWIG_From_dec(unsigned long long)(unsigned long long value)
|
|||
{
|
||||
SV *sv;
|
||||
if (value <= UV_MAX)
|
||||
sv = newSVuv(value);
|
||||
sv = newSVuv((UV)(value));
|
||||
else {
|
||||
//sv = newSVpvf("%llu", value); doesn't work in non 64bit Perl
|
||||
char temp[256];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -272,7 +274,7 @@ namespace swig {
|
|||
typename Sequence::const_iterator it = sb;
|
||||
while (it!=se) {
|
||||
sequence->push_back(*it);
|
||||
for (typename Sequence::size_type c=0; c<step && it!=se; ++c)
|
||||
for (Py_ssize_t c=0; c<step && it!=se; ++c)
|
||||
it++;
|
||||
}
|
||||
return sequence;
|
||||
|
|
@ -287,7 +289,7 @@ namespace swig {
|
|||
typename Sequence::const_reverse_iterator it = sb;
|
||||
while (it!=se) {
|
||||
sequence->push_back(*it);
|
||||
for (typename Sequence::size_type c=0; c<-step && it!=se; ++c)
|
||||
for (Py_ssize_t c=0; c<-step && it!=se; ++c)
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
|
@ -337,7 +339,7 @@ namespace swig {
|
|||
std::advance(it,ii);
|
||||
for (size_t rc=0; rc<replacecount; ++rc) {
|
||||
*it++ = *isit++;
|
||||
for (typename Sequence::size_type c=0; c<(step-1); ++c)
|
||||
for (Py_ssize_t c=0; c<(step-1); ++c)
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
|
@ -355,7 +357,7 @@ namespace swig {
|
|||
std::advance(it,size-ii-1);
|
||||
for (size_t rc=0; rc<replacecount; ++rc) {
|
||||
*it++ = *isit++;
|
||||
for (typename Sequence::size_type c=0; c<(-step-1); ++c)
|
||||
for (Py_ssize_t c=0; c<(-step-1); ++c)
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
|
@ -383,7 +385,7 @@ namespace swig {
|
|||
it = self->erase(it);
|
||||
if (it==self->end())
|
||||
break;
|
||||
for (typename Sequence::size_type c=0; c<(step-1); ++c)
|
||||
for (Py_ssize_t c=0; c<(step-1); ++c)
|
||||
it++;
|
||||
delcount--;
|
||||
}
|
||||
|
|
@ -399,7 +401,7 @@ namespace swig {
|
|||
self->erase((++it).base());
|
||||
if (it==self->rend())
|
||||
break;
|
||||
for (typename Sequence::size_type c=0; c<(-step-1); ++c)
|
||||
for (Py_ssize_t c=0; c<(-step-1); ++c)
|
||||
it++;
|
||||
delcount--;
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type)
|
||||
#define PyInt_Check(x) PyLong_Check(x)
|
||||
#define PyInt_AsLong(x) PyLong_AsLong(x)
|
||||
#define PyInt_AsUnsignedLongMask(x) PyLong_AsUnsignedLongMask(x)
|
||||
#define PyInt_FromLong(x) PyLong_FromLong(x)
|
||||
#define PyString_Check(name) PyBytes_Check(name)
|
||||
#define PyString_FromString(x) PyUnicode_FromString(x)
|
||||
|
|
|
|||
|
|
@ -100,12 +100,13 @@ SWIGINTERN int
|
|||
SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val)
|
||||
{
|
||||
if (PyInt_Check(obj)) {
|
||||
unsigned long v = PyInt_AsUnsignedLongMask(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
long v = PyInt_AsLong(obj);
|
||||
if (v >= 0) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
PyErr_Clear();
|
||||
} else if (PyLong_Check(obj)) {
|
||||
unsigned long v = PyLong_AsUnsignedLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
%include <rstdcommon.swg>
|
||||
%include <std/std_common.i>
|
||||
|
||||
|
||||
/*
|
||||
Generate the traits for a 'primitive' type, such as 'double',
|
||||
for which the SWIG_AsVal and SWIG_From methods are already defined.
|
||||
*/
|
||||
|
||||
%define %traits_ptypen(Type...)
|
||||
%fragment(SWIG_Traits_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(Type),
|
||||
fragment=SWIG_From_frag(Type),
|
||||
fragment="StdTraits") {
|
||||
fragment=SWIG_AsVal_frag(Type),
|
||||
fragment=SWIG_From_frag(Type),
|
||||
fragment="StdTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<Type > {
|
||||
typedef value_category category;
|
||||
|
|
@ -27,6 +32,39 @@ namespace swig {
|
|||
}
|
||||
%enddef
|
||||
|
||||
/* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums
|
||||
is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit
|
||||
instantiations required using %template). The STL containers define the 'front' method and the typemap
|
||||
below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the
|
||||
standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from
|
||||
required in the generated code for enums. */
|
||||
|
||||
%define %traits_enum(Type...)
|
||||
%fragment("SWIG_Traits_enum_"{Type},"header",
|
||||
fragment=SWIG_AsVal_frag(int),
|
||||
fragment=SWIG_From_frag(int),
|
||||
fragment="StdTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits_asval<Type > {
|
||||
typedef Type value_type;
|
||||
static int asval(SEXP obj, value_type *val) {
|
||||
return SWIG_AsVal(int)(obj, (int *)val);
|
||||
}
|
||||
};
|
||||
template <> struct traits_from<Type > {
|
||||
typedef Type value_type;
|
||||
static SEXP from(const value_type& val) {
|
||||
return SWIG_From(int)((int)val);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
%typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%}
|
||||
%enddef
|
||||
|
||||
|
||||
%include <std/std_common.i>
|
||||
|
||||
//
|
||||
// Generates the traits for all the known primitive
|
||||
// C++ types (int, double, ...)
|
||||
|
|
|
|||
|
|
@ -192,7 +192,6 @@
|
|||
struct traits_asptr < std::vector<T> > {
|
||||
static int asptr(SEXP obj, std::vector<T> **val) {
|
||||
std::vector<T> *p;
|
||||
Rprintf("my asptr\n");
|
||||
int res = SWIG_R_ConvertPtr(obj, (void**)&p, type_info< std::vector<T> >(), 0);
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val) *val = p;
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
|
|||
downcast methods. */
|
||||
if (obj != Qnil) {
|
||||
VALUE value = rb_iv_get(obj, "@__swigtype__");
|
||||
char* type_name = RSTRING_PTR(value);
|
||||
const char* type_name = RSTRING_PTR(value);
|
||||
|
||||
if (strcmp(type->name, type_name) == 0) {
|
||||
return obj;
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@ namespace std {
|
|||
|
||||
#ifdef __cplusplus
|
||||
%typemap(memberin) char * {
|
||||
if ($1) delete [] $1;
|
||||
delete [] $1;
|
||||
if ($input) {
|
||||
$1 = ($1_type) (new char[strlen((const char *)$input)+1]);
|
||||
strcpy((char *)$1, (const char *)$input);
|
||||
|
|
@ -376,7 +376,7 @@ namespace std {
|
|||
}
|
||||
}
|
||||
%typemap(globalin) char * {
|
||||
if ($1) delete [] $1;
|
||||
delete [] $1;
|
||||
if ($input) {
|
||||
$1 = ($1_type) (new char[strlen((const char *)$input)+1]);
|
||||
strcpy((char *)$1, (const char *)$input);
|
||||
|
|
@ -394,7 +394,7 @@ namespace std {
|
|||
}
|
||||
#else
|
||||
%typemap(memberin) char * {
|
||||
if ($1) free((char *)$1);
|
||||
free($1);
|
||||
if ($input) {
|
||||
$1 = ($1_type) malloc(strlen((const char *)$input)+1);
|
||||
strcpy((char *)$1, (const char *)$input);
|
||||
|
|
@ -411,7 +411,7 @@ namespace std {
|
|||
}
|
||||
}
|
||||
%typemap(globalin) char * {
|
||||
if ($1) free((char *)$1);
|
||||
free($1);
|
||||
if ($input) {
|
||||
$1 = ($1_type) malloc(strlen((const char *)$input)+1);
|
||||
strcpy((char *)$1, (const char *)$input);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue