Modified the "varin" typemap for a dimensionless char array to generate

a warning message, and to raise an exception if the typemap is actually
invoked at runtime. This is needed to avoid problems for the case when
wrapping an extern char[] declaration, where the array size is truly
unknown.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6151 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Lyle Johnson 2004-08-26 01:48:40 +00:00
commit d34102d40b

View file

@ -1,4 +1,5 @@
/* --- Input Values --- */ /* --- Input Values --- */
%typemap(in) char * "$1 = StringValuePtr($input);"; %typemap(in) char * "$1 = StringValuePtr($input);";
%typemap(in) char [ANY] "$1 = StringValuePtr($input);"; %typemap(in) char [ANY] "$1 = StringValuePtr($input);";
@ -59,9 +60,10 @@
#endif /* __cplusplus */ #endif /* __cplusplus */
/* Special case for string array variables */ /* Special case for string array variables */
%typemap(varin) char[] { %typemap(varin,
size_t size = sizeof($1); warning="462:Unable to set variable of type char []") char[]
strncpy($1,StringValuePtr($input),size); {
rb_raise(rb_eTypeError, "C/C++ variable '$name' is read-only.");
} }
%typemap(varin) char[ANY] "strncpy($1,StringValuePtr($input),$1_dim0);"; %typemap(varin) char[ANY] "strncpy($1,StringValuePtr($input),$1_dim0);";