summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--ext/bigdecimal/bigdecimal.c44
-rw-r--r--ext/bigdecimal/bigdecimal.h12
-rw-r--r--ext/bigdecimal/bigdecimal_en.html9
-rw-r--r--ext/bigdecimal/bigdecimal_ja.html7
-rw-r--r--lib/cgi.rb4
6 files changed, 38 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index 9be0d54490..5dc18b16d4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Feb 9 15:46:09 2007 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/bigdecimal: Synchronize with trunk. Better function
+ prototypes, removal of a useless method `!=', and document
+ updates.
+
Tue Feb 06 22:06:45 2007 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/nkf-utf8/{nkf.c,utf8tbl.c}:
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 370f5ecd50..5a26ea79d9 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -224,14 +224,14 @@ GetVpValue(VALUE v, int must)
#ifdef ENABLE_NUMERIC_STRING
case T_STRING:
SafeStringValue(v);
- return VpCreateRbObject(strlen(RSTRING(v)->ptr) + VpBaseFig() + 1,
- RSTRING(v)->ptr);
+ return VpCreateRbObject(strlen(RSTRING_PTR(v)) + VpBaseFig() + 1,
+ RSTRING_PTR(v));
#endif /* ENABLE_NUMERIC_STRING */
case T_BIGNUM:
bg = rb_big2str(v, 10);
- return VpCreateRbObject(strlen(RSTRING(bg)->ptr) + VpBaseFig() + 1,
- RSTRING(bg)->ptr);
+ return VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1,
+ RSTRING_PTR(bg));
default:
goto SomeOneMayDoIt;
}
@@ -240,7 +240,7 @@ SomeOneMayDoIt:
if(must) {
rb_raise(rb_eTypeError, "%s can't be coerced into BigDecimal",
rb_special_const_p(v)?
- RSTRING(rb_inspect(v))->ptr:
+ RSTRING_PTR(rb_inspect(v)):
rb_obj_classname(v)
);
}
@@ -332,7 +332,7 @@ BigDecimal_load(VALUE self, VALUE str)
unsigned long m=0;
SafeStringValue(str);
- pch = RSTRING(str)->ptr;
+ pch = RSTRING_PTR(str);
/* First get max prec */
while((*pch)!=(unsigned char)'\0' && (ch=*pch++)!=(unsigned char)':') {
if(!ISDIGIT(ch)) {
@@ -474,7 +474,7 @@ VpNewRbClass(U_LONG mx, char *str, VALUE klass)
}
VP_EXPORT Real *
-VpCreateRbObject(U_LONG mx, char *str)
+VpCreateRbObject(U_LONG mx, const char *str)
{
Real *pv = VpAlloc(mx,str);
pv->obj = (VALUE)Data_Wrap_Struct(rb_cBigDecimal, 0, BigDecimal_delete, pv);
@@ -781,17 +781,6 @@ BigDecimal_eq(VALUE self, VALUE r)
return BigDecimalCmp(self, r, '=');
}
-/* Returns true if the values are not equal in value. Values may be coerced
- * to perform the comparison:
- *
- * BigDecimal.new('1.0') != 1.0 -> false
- */
-static VALUE
-BigDecimal_ne(VALUE self, VALUE r)
-{
- return BigDecimalCmp(self, r, '!');
-}
-
/* call-seq:
* a < b
*
@@ -1276,7 +1265,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self)
{
ENTER(5);
Real *c, *a;
- int iLoc;
+ int iLoc = 0;
U_LONG mx;
VALUE vLoc;
VALUE vRound;
@@ -1510,7 +1499,7 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self)
if(rb_scan_args(argc,argv,"01",&f)==1) {
if(TYPE(f)==T_STRING) {
SafeStringValue(f);
- psz = RSTRING(f)->ptr;
+ psz = RSTRING_PTR(f);
if(*psz==' ') {
fPlus = 1; psz++;
} else if(*psz=='+') {
@@ -1687,7 +1676,7 @@ BigDecimal_global_new(int argc, VALUE *argv, VALUE self)
mf = GetPositiveInt(nFig);
}
SafeStringValue(iniValue);
- GUARD_OBJ(pv,VpCreateRbObject(mf, RSTRING(iniValue)->ptr));
+ GUARD_OBJ(pv,VpCreateRbObject(mf, RSTRING_PTR(iniValue)));
return ToValue(pv);
}
@@ -1718,7 +1707,7 @@ BigDecimal_new(int argc, VALUE *argv, VALUE self)
mf = GetPositiveInt(nFig);
}
SafeStringValue(iniValue);
- GUARD_OBJ(pv,VpNewRbClass(mf, RSTRING(iniValue)->ptr,self));
+ GUARD_OBJ(pv,VpNewRbClass(mf, RSTRING_PTR(iniValue),self));
return ToValue(pv);
}
@@ -1939,7 +1928,6 @@ Init_bigdecimal(void)
rb_define_method(rb_cBigDecimal, "==", BigDecimal_eq, 1);
rb_define_method(rb_cBigDecimal, "===", BigDecimal_eq, 1);
rb_define_method(rb_cBigDecimal, "eql?", BigDecimal_eq, 1);
- rb_define_method(rb_cBigDecimal, "!=", BigDecimal_ne, 1);
rb_define_method(rb_cBigDecimal, "<", BigDecimal_lt, 1);
rb_define_method(rb_cBigDecimal, "<=", BigDecimal_le, 1);
rb_define_method(rb_cBigDecimal, ">", BigDecimal_gt, 1);
@@ -2187,7 +2175,7 @@ VpIsNegDoubleZero(double v)
}
VP_EXPORT int
-VpException(unsigned short f,char *str,int always)
+VpException(unsigned short f, const char *str,int always)
{
VALUE exc;
int fatal=0;
@@ -2329,7 +2317,7 @@ NaN:
* returns number of chars needed to represent vp in specified format.
*/
VP_EXPORT U_LONG
-VpNumOfChars(Real *vp,char *pszFmt)
+VpNumOfChars(Real *vp,const char *pszFmt)
{
S_INT ex;
U_LONG nc;
@@ -2432,7 +2420,7 @@ VpInit(U_LONG BaseVal)
}
VP_EXPORT Real *
-VpOne()
+VpOne(void)
{
return VpConstOne;
}
@@ -2482,7 +2470,7 @@ overflow:
* NULL be returned if memory allocation is failed,or any error.
*/
VP_EXPORT Real *
-VpAlloc(U_LONG mx, char *szVal)
+VpAlloc(U_LONG mx, const char *szVal)
{
U_LONG i, ni, ipn, ipf, nf, ipe, ne, nalloc;
char v,*psz;
@@ -3897,7 +3885,7 @@ VpToFString(Real *a,char *psz,int fFmt,int fPlus)
* ne ... number of characters in exp_chr[],not including '+/-'.
*/
VP_EXPORT int
-VpCtoV(Real *a, char *int_chr, U_LONG ni, char *frac, U_LONG nf, char *exp_chr, U_LONG ne)
+VpCtoV(Real *a, const char *int_chr, U_LONG ni, const char *frac, U_LONG nf, const char *exp_chr, U_LONG ne)
{
U_LONG i, j, ind_a, ma, mi, me;
U_LONG loc;
diff --git a/ext/bigdecimal/bigdecimal.h b/ext/bigdecimal/bigdecimal.h
index aabc551a76..4f77feab00 100644
--- a/ext/bigdecimal/bigdecimal.h
+++ b/ext/bigdecimal/bigdecimal.h
@@ -105,7 +105,7 @@ typedef struct {
VP_EXPORT Real *
VpNewRbClass(U_LONG mx,char *str,VALUE klass);
-VP_EXPORT Real *VpCreateRbObject(U_LONG mx,char *str);
+VP_EXPORT Real *VpCreateRbObject(U_LONG mx,const char *str);
VP_EXPORT U_LONG VpBaseFig(void);
VP_EXPORT U_LONG VpDblFig(void);
@@ -126,13 +126,13 @@ VP_EXPORT int VpIsRoundMode(unsigned long n);
VP_EXPORT unsigned long VpGetRoundMode(void);
VP_EXPORT unsigned long VpSetRoundMode(unsigned long n);
-VP_EXPORT int VpException(unsigned short f,char *str,int always);
+VP_EXPORT int VpException(unsigned short f,const char *str,int always);
VP_EXPORT int VpIsNegDoubleZero(double v);
-VP_EXPORT U_LONG VpNumOfChars(Real *vp,char *pszFmt);
+VP_EXPORT U_LONG VpNumOfChars(Real *vp,const char *pszFmt);
VP_EXPORT U_LONG VpInit(U_LONG BaseVal);
VP_EXPORT void *VpMemAlloc(U_LONG mb);
VP_EXPORT void VpFree(Real *pv);
-VP_EXPORT Real *VpAlloc(U_LONG mx, char *szVal);
+VP_EXPORT Real *VpAlloc(U_LONG mx, const char *szVal);
VP_EXPORT int VpAsgn(Real *c,Real *a,int isw);
VP_EXPORT int VpAddSub(Real *c,Real *a,Real *b,int operation);
VP_EXPORT int VpMult(Real *c,Real *a,Real *b);
@@ -143,7 +143,7 @@ VP_EXPORT void VpSzMantissa(Real *a,char *psz);
VP_EXPORT int VpToSpecialString(Real *a,char *psz,int fPlus);
VP_EXPORT void VpToString(Real *a,char *psz,int fFmt,int fPlus);
VP_EXPORT void VpToFString(Real *a,char *psz,int fFmt,int fPlus);
-VP_EXPORT int VpCtoV(Real *a,char *int_chr,U_LONG ni,char *frac,U_LONG nf,char *exp_chr,U_LONG ne);
+VP_EXPORT int VpCtoV(Real *a,const char *int_chr,U_LONG ni,const char *frac,U_LONG nf,const char *exp_chr,U_LONG ne);
VP_EXPORT int VpVtoD(double *d,S_LONG *e,Real *m);
VP_EXPORT void VpDtoV(Real *m,double d);
VP_EXPORT void VpItoV(Real *m,S_INT ival);
@@ -155,7 +155,7 @@ VP_EXPORT void VpFrac(Real *y,Real *x);
VP_EXPORT int VpPower(Real *y,Real *x,S_INT n);
/* VP constants */
-VP_EXPORT Real *VpOne();
+VP_EXPORT Real *VpOne(void);
/*
* ------------------
diff --git a/ext/bigdecimal/bigdecimal_en.html b/ext/bigdecimal/bigdecimal_en.html
index 02c88df43e..c2b86faef6 100644
--- a/ext/bigdecimal/bigdecimal_en.html
+++ b/ext/bigdecimal/bigdecimal_en.html
@@ -379,7 +379,7 @@ after every n digits for readability.
<CODE><PRE>
BigDecimal("0.1234567890123456789").to_s(10) # ==> "0.1234567890 123456789E0"
</PRE></CODE>
-n can be an string representing a positive integer number.
+n can be a string representing a positive integer number.
<CODE><PRE>
BigDecimal("0.1234567890123456789").to_s("10") # ==> "0.1234567890 123456789E0"
</PRE></CODE>
@@ -678,10 +678,9 @@ structure.
</DL>
<H3>Disadvantage of decimal representation</H3>
-Advantages stated so far can also be disadvantages if the input from outside is
- represented in binary.
-Translation error from decimal to binary or vice versa is inevitable.
-So,translation from Float(binary) to BigDecimal(decimal) is not alway done exactly.
+Because most computers have no internal decimal representaion.
+Once you use BigDecimal,you need to keep using it without
+considering computation cost if exact computation is required.
<H4>Which is the first input?</H4>
Because most people uses decimal notatin for numeric data representation,
diff --git a/ext/bigdecimal/bigdecimal_ja.html b/ext/bigdecimal/bigdecimal_ja.html
index 8fd95a6fe3..37bbcbbb09 100644
--- a/ext/bigdecimal/bigdecimal_ja.html
+++ b/ext/bigdecimal/bigdecimal_ja.html
@@ -676,10 +676,11 @@ exponent=1、sign=2 なら数値が 1234.56784321 であるのは見れば直ぐに分かります。
<H3>10進のデメリット</H3>
実は今までのメリットは、そのままデメリットにもなります。
-そもそも、10進を2進、2進を10進に変換するような操作は変換誤差
+そもそも、10進を2進に変換するような操作は変換誤差
を伴う場合を回避することはできません。
-既に計算機内部に取り込まれた2進数値を BigDecimal の内部表現に
-変換するときには誤差が避けられない場合があります。
+大概のコンピュータは10進の内部表現を持っていないので、
+BigDecimal を利用して誤差無しの計算をする場合は、計算速度
+を無視しても最後まで BigDecimal を使用続ける必要があります。
<H3>最初は何か?</H3>
自分で計算するときにわざわざ2進数を使う人は極めてまれです。
diff --git a/lib/cgi.rb b/lib/cgi.rb
index 38407da5cc..94d92e25ae 100644
--- a/lib/cgi.rb
+++ b/lib/cgi.rb
@@ -1037,8 +1037,8 @@ class CGI
body.rewind
- /Content-Disposition:.* filename="?([^\";]*)"?/ni.match(head)
- filename = ($1 or "")
+ /Content-Disposition:.* filename=(?:"((?:\\.|[^\"])*)"|([^;]*))/ni.match(head)
+ filename = ($1 or $2 or "")
if /Mac/ni.match(env_table['HTTP_USER_AGENT']) and
/Mozilla/ni.match(env_table['HTTP_USER_AGENT']) and
(not /MSIE/ni.match(env_table['HTTP_USER_AGENT']))