guile: fix multimap example
- fix compiler warning - fix guile 2 deprecation warnings - minor cleanup of generated code
This commit is contained in:
parent
7b9c302fa1
commit
95bfa86ae9
1 changed files with 30 additions and 21 deletions
|
|
@ -15,43 +15,52 @@ extern int squareCubed (int n, int *OUTPUT);
|
||||||
|
|
||||||
extern int gcd(int x, int y);
|
extern int gcd(int x, int y);
|
||||||
|
|
||||||
%typemap(in) (int argc, char *argv[]) {
|
%typemap(in) (int argc, char *argv[]) %{
|
||||||
int i;
|
scm_t_array_handle handle;
|
||||||
SCM *v;
|
size_t i;
|
||||||
if (!(SCM_NIMP($input) && SCM_VECTORP($input))) {
|
ssize_t inc;
|
||||||
|
const SCM *v;
|
||||||
|
if (!(SCM_NIMP($input) && scm_is_vector($input))) {
|
||||||
SWIG_exception(SWIG_ValueError, "Expecting a vector");
|
SWIG_exception(SWIG_ValueError, "Expecting a vector");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$1 = SCM_LENGTH($input);
|
v = scm_vector_elements($input, &handle, &$1, &inc);
|
||||||
if ($1 == 0) {
|
if ($1 == 0) {
|
||||||
SWIG_exception(SWIG_ValueError, "Vector must contain at least 1 element");
|
SWIG_exception(SWIG_ValueError, "Vector must contain at least 1 element");
|
||||||
}
|
}
|
||||||
$2 = (char **) malloc(($1+1)*sizeof(char *));
|
$2 = (char **) malloc(($1+1)*sizeof(char *));
|
||||||
v = SCM_VELTS($input);
|
for (i = 0; i < $1; i++, v +=inc ) {
|
||||||
for (i = 0; i < $1; i++) {
|
if (!(SCM_NIMP(*v) && scm_is_string(*v))) {
|
||||||
if (!(SCM_NIMP(v[i]) && SCM_STRINGP(v[i]))) {
|
free($2);
|
||||||
free($2);
|
|
||||||
SWIG_exception(SWIG_ValueError, "Vector items must be strings");
|
SWIG_exception(SWIG_ValueError, "Vector items must be strings");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$2[i] = SCM_CHARS(v[i]);
|
$2[i] = scm_to_locale_string(*v);
|
||||||
}
|
}
|
||||||
$2[i] = 0;
|
$2[i] = 0;
|
||||||
}
|
scm_array_handle_release (&handle);
|
||||||
|
%}
|
||||||
|
|
||||||
%typemap(freearg) (int argc, char *argv[]) {
|
%typemap(freearg) (int argc, char *argv[]) %{
|
||||||
free($2);
|
for (i = 0; i < $1; i++) {
|
||||||
}
|
free($2[i]);
|
||||||
|
}
|
||||||
|
free($2);
|
||||||
|
%}
|
||||||
|
|
||||||
extern int gcdmain(int argc, char *argv[]);
|
extern int gcdmain(int argc, char *argv[]);
|
||||||
|
|
||||||
%typemap(in) (char *bytes, int len) {
|
%typemap(in) (char *bytes, int len) %{
|
||||||
if (!(SCM_NIMP($input) && SCM_STRINGP($input))) {
|
if (!(SCM_NIMP($input) && scm_is_string($input))) {
|
||||||
SWIG_exception(SWIG_ValueError, "Expecting a string");
|
SWIG_exception(SWIG_ValueError, "Expecting a string");
|
||||||
}
|
}
|
||||||
$1 = SCM_CHARS($input);
|
$1 = scm_to_locale_string($input);
|
||||||
$2 = SCM_LENGTH($input);
|
$2 = scm_c_string_length($input);
|
||||||
}
|
%}
|
||||||
|
|
||||||
|
%typemap(freearg) (char *bytes, int len) %{
|
||||||
|
free($1);
|
||||||
|
%}
|
||||||
|
|
||||||
extern int count(char *bytes, int len, char c);
|
extern int count(char *bytes, int len, char c);
|
||||||
|
|
||||||
|
|
@ -67,7 +76,7 @@ extern int count(char *bytes, int len, char c);
|
||||||
|
|
||||||
%typemap(argout) (char *str, int len) {
|
%typemap(argout) (char *str, int len) {
|
||||||
SWIG_APPEND_VALUE(scm_from_locale_stringn($1,$2));
|
SWIG_APPEND_VALUE(scm_from_locale_stringn($1,$2));
|
||||||
if ($1) scm_must_free($1);
|
if ($1) SWIG_free($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void capitalize(char *str, int len);
|
extern void capitalize(char *str, int len);
|
||||||
|
|
@ -78,7 +87,7 @@ extern void capitalize(char *str, int len);
|
||||||
%typemap(check) (double cx, double cy) {
|
%typemap(check) (double cx, double cy) {
|
||||||
double a = $1*$1 + $2*$2;
|
double a = $1*$1 + $2*$2;
|
||||||
if (a > 1.0) {
|
if (a > 1.0) {
|
||||||
SWIG_exception(SWIG_ValueError,"$1_name and $2_name must be in unit circle");
|
SWIG_exception(SWIG_ValueError,"$1_name and $2_name must be in unit circle");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue