more perl + cast/rank mechanism
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8049 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
09f0b8c5ec
commit
ba4df9e37d
3 changed files with 135 additions and 14 deletions
|
|
@ -1,15 +1,68 @@
|
|||
Version 1.3.28 (unreleased).
|
||||
===========================
|
||||
|
||||
12/21/2005: wsfulton
|
||||
[Java, C#]
|
||||
Fix incorrect code generation when the intermediary classname is changed
|
||||
in the module directive from its default. For example:
|
||||
12/22/2005: mmatus
|
||||
Add the cast and rank mechanism to dispatch overloading
|
||||
functions. The UTF supports it now, but for each language
|
||||
it must be decided how to implement and/or when to use it.
|
||||
|
||||
%module(jniclassname="myimclassnewname") "mymodule" // Java
|
||||
%module(imclassname="myimclassnewname") "mymodule" // C#
|
||||
[perl] Now perl uses the new cast and rank dispatch
|
||||
mechanism, which solves all the past problems known
|
||||
in perl, such as the old '+ 1' problem:
|
||||
|
||||
Add in new special variable $imclassname. See docs.
|
||||
int foo(int);
|
||||
|
||||
$n = 1
|
||||
$n = $n + 1
|
||||
$r = foo(n)
|
||||
|
||||
also works:
|
||||
|
||||
foo(1);
|
||||
foo("1");
|
||||
foo(1.0);
|
||||
foo("1.0");
|
||||
|
||||
but fails
|
||||
|
||||
foo("l");
|
||||
|
||||
and when overloading foo(int) and foo(double);
|
||||
|
||||
foo(1) -> foo(int)
|
||||
foo(1.0) -> foo(double)
|
||||
foo("1") -> foo(int)
|
||||
foo("1.0") -> foo(double)
|
||||
foo("l") -> error
|
||||
foo($n) -> foo(int) for good perl versions
|
||||
foo($n) -> foo(double) for old bad perl versions
|
||||
|
||||
when overloading foo(int), foo(char*) and foo(double):
|
||||
|
||||
foo(1) -> foo(int)
|
||||
foo(1.0) -> foo(double)
|
||||
foo("1") -> foo(char*)
|
||||
foo("1.0") -> foo(char*)
|
||||
foo("l") -> foo(char*)
|
||||
|
||||
Note: In perl the old dispatch mechanism was broken,
|
||||
so, we don't provide and option to enable the old one
|
||||
since, again, was really really broken.
|
||||
|
||||
See 'overload_simple_runme.pl' for more cases and tests.
|
||||
|
||||
PS: all the old known issues are declared resolved, any
|
||||
new "problem" that could be discovered is declared,
|
||||
a priori, as "features" of the new dispatch mechanism
|
||||
(until we find another solution at least).
|
||||
|
||||
|
||||
*** POTENTIAL INCOMPATIBILITY ***
|
||||
|
||||
As with the introduction of the UTF, some things could
|
||||
now start to work as expected, and people used to deal or
|
||||
workaround previous bugs related to the dispatch
|
||||
mechanism, could see now a difference in perl behavior.
|
||||
|
||||
12/21/2005: mmatus
|
||||
- The '-nodefault' flag (pragma and features) now generates
|
||||
|
|
@ -239,9 +292,7 @@ Version 1.3.28 (unreleased).
|
|||
[Java, C#]
|
||||
Typesafe enums and proper enums have an extra constructor so that enum item values that
|
||||
are initialised by another enum item value can be wrapped without having to use %javaconstvalue/
|
||||
%csconstvalue for when using %javaconst(1)/%csconst(1). Suggestion by
|
||||
Bob Marinier/Douglas Pearson.
|
||||
|
||||
%csconstvalue for when using %javaconst(1)/%csconst(1). Suggestion by Bob Marinier.
|
||||
For example:
|
||||
|
||||
typedef enum
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ SWIG_AsVal_dec(long)(SV *obj, long* val)
|
|||
|
||||
/* unsigned long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long),"header") {
|
||||
%fragment(SWIG_From_frag(unsigned long),"header",
|
||||
fragment=SWIG_AsVal_frag(double)) {
|
||||
SWIGINTERNINLINE SV *
|
||||
SWIG_From_dec(unsigned long)(unsigned long value)
|
||||
{
|
||||
|
|
@ -72,7 +73,8 @@ SWIG_From_dec(unsigned long)(unsigned long value)
|
|||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long),"header") {
|
||||
%fragment(SWIG_AsVal_frag(unsigned long),"header",
|
||||
fragment=SWIG_AsVal_frag(double)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val)
|
||||
{
|
||||
|
|
@ -88,6 +90,7 @@ SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val)
|
|||
return SWIG_OverflowError;
|
||||
}
|
||||
} else {
|
||||
int dispatch = 0;
|
||||
const char *nptr = SvPV(obj, PL_na);
|
||||
if (nptr) {
|
||||
char *endptr;
|
||||
|
|
@ -102,6 +105,23 @@ SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!dispatch) {
|
||||
double d;
|
||||
int res = SWIG_AsVal(double)(obj,&d);
|
||||
if (SWIG_IsOK(res) && (d >= 0)) {
|
||||
if (d <= ULONG_MAX) {
|
||||
double rd = rint(d);
|
||||
if (errno) {
|
||||
errno = 0;
|
||||
} else {
|
||||
if (rd == d) {
|
||||
if (val) *val = (long)(rd);
|
||||
return SWIG_AddCast(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SWIG_TypeError;
|
||||
|
|
@ -128,7 +148,10 @@ SWIG_From_dec(long long)(long long value)
|
|||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long long),"header") {
|
||||
%fragment(SWIG_AsVal_frag(long long),"header",
|
||||
fragment=SWIG_AsVal_frag(double),
|
||||
fragment="<limits.h>") {
|
||||
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(long long)(SV *obj, long long *val)
|
||||
{
|
||||
|
|
@ -136,6 +159,7 @@ SWIG_AsVal_dec(long long)(SV *obj, long long *val)
|
|||
if (val) *val = SvIV(obj);
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
int dispatch = 0;
|
||||
const char *nptr = SvPV(obj, PL_na);
|
||||
if (nptr) {
|
||||
char *endptr;
|
||||
|
|
@ -150,6 +174,23 @@ SWIG_AsVal_dec(long long)(SV *obj, long long *val)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!dispatch) {
|
||||
double d;
|
||||
int res = SWIG_AsVal(double)(obj,&d);
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (LLONG_MIN <= d && d <= LLONG_MAX) {
|
||||
double rd = rint(d);
|
||||
if (errno) {
|
||||
errno = 0;
|
||||
} else {
|
||||
if (rd == d) {
|
||||
if (val) *val = (long long)(rd);
|
||||
return SWIG_AddCast(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
|
@ -175,7 +216,9 @@ SWIG_From_dec(unsigned long long)(unsigned long long value)
|
|||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long long),"header") {
|
||||
%fragment(SWIG_AsVal_frag(unsigned long long),"header",
|
||||
fragment=SWIG_AsVal_frag(double),
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val)
|
||||
{
|
||||
|
|
@ -183,6 +226,7 @@ SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val)
|
|||
if (val) *val = SvUV(obj);
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
int dispatch = 0;
|
||||
const char *nptr = SvPV(obj, PL_na);
|
||||
if (nptr) {
|
||||
char *endptr;
|
||||
|
|
@ -197,6 +241,23 @@ SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!dispatch) {
|
||||
double d;
|
||||
int res = SWIG_AsVal(double)(obj,&d);
|
||||
if (SWIG_IsOK(res) && (d >=0 )) {
|
||||
if (d <= ULLONG_MAX) {
|
||||
double rd = rint(d);
|
||||
if (errno) {
|
||||
errno = 0;
|
||||
} else {
|
||||
if (rd == d) {
|
||||
if (val) *val = (unsigned long long)(rd);
|
||||
return SWIG_AddCast(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -321,6 +321,15 @@
|
|||
|
||||
%fragment("<limits.h>","header") %{
|
||||
#include <limits.h>
|
||||
#ifndef LLONG_MIN
|
||||
# define LLONG_MIN LONG_LONG_MIN
|
||||
#endif
|
||||
#ifndef LLONG_MAX
|
||||
# define LLONG_MAX LONG_LONG_MAX
|
||||
#endif
|
||||
#ifndef ULLONG_MAX
|
||||
# define ULLONG_MAX ULONG_LONG_MAX
|
||||
#endif
|
||||
%}
|
||||
|
||||
%fragment("<wchar.h>","header") %{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue