~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to debian/patches/149_bignum_to_s.patch

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
--- ruby-1.8.5/bignum.c 7 Oct 2006 15:48:44 -0000       1.100.2.24
2
 
+++ ruby-1.8.5/bignum.c 30 Oct 2006 10:31:01 -0000      1.100.2.28
3
 
@@ -614,15 +614,16 @@
4
 
 
5
 
 const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
6
 
 VALUE
7
 
-rb_big2str(x, base)
8
 
+rb_big2str0(x, base, trim)
9
 
     VALUE x;
10
 
     int base;
11
 
+    int trim;
12
 
 {
13
 
     volatile VALUE t;
14
 
     BDIGIT *ds;
15
 
     long i, j, hbase;
16
 
     VALUE ss;
17
 
-    char *s, c;
18
 
+    char *s;
19
 
 
20
 
     if (FIXNUM_P(x)) {
21
 
        return rb_fix2str(x, base);
22
 
@@ -635,7 +636,7 @@
23
 
     switch (base) {
24
 
       case 2: break;
25
 
       case 3:
26
 
-       j = j * 647L / 1024;
27
 
+       j = j * 53L / 84 + 1;
28
 
        break;
29
 
       case 4: case 5: case 6: case 7:
30
 
        j /= 2;
31
 
@@ -644,7 +645,7 @@
32
 
        j /= 3;
33
 
        break;
34
 
       case 10: case 11: case 12: case 13: case 14: case 15:
35
 
-       j = j * 241L / 800;
36
 
+       j = j * 28L / 93 + 1;
37
 
        break;
38
 
       case 16: case 17: case 18: case 19: case 20: case 21:
39
 
       case 22: case 23: case 24: case 25: case 26: case 27:
40
 
@@ -658,7 +659,7 @@
41
 
        rb_raise(rb_eArgError, "illegal radix %d", base);
42
 
        break;
43
 
     }
44
 
-    j += 2;
45
 
+    j++;                       /* space for sign */
46
 
 
47
 
     hbase = base * base;
48
 
 #if SIZEOF_BDIGITS > 2
49
 
@@ -667,11 +668,11 @@
50
 
 
51
 
     t = rb_big_clone(x);
52
 
     ds = BDIGITS(t);
53
 
-    ss = rb_str_new(0, j);
54
 
+    ss = rb_str_new(0, j+1);
55
 
     s = RSTRING(ss)->ptr;
56
 
 
57
 
     s[0] = RBIGNUM(x)->sign ? '+' : '-';
58
 
-    while (i && j) {
59
 
+    while (i && j > 1) {
60
 
        long k = i;
61
 
        BDIGIT_DBL num = 0;
62
 
 
63
 
@@ -680,23 +681,36 @@
64
 
            ds[k] = (BDIGIT)(num / hbase);
65
 
            num %= hbase;
66
 
        }
67
 
-       if (ds[i-1] == 0) i--;
68
 
+       if (trim && ds[i-1] == 0) i--;
69
 
        k = SIZEOF_BDIGITS;
70
 
        while (k--) {
71
 
-           c = (char)(num % base);
72
 
-           s[--j] = ruby_digitmap[(int)c];
73
 
+           s[--j] = ruby_digitmap[num % base];
74
 
            num /= base;
75
 
-           if (i == 0 && num == 0) break;
76
 
+           if (!trim && j < 1) break;
77
 
+           if (trim && i == 0 && num == 0) break;
78
 
        }
79
 
     }
80
 
-    while (s[j] == '0') j++;
81
 
-    RSTRING(ss)->len -= RBIGNUM(x)->sign?j:j-1;
82
 
-    memmove(RBIGNUM(x)->sign?s:s+1, s+j, RSTRING(ss)->len);
83
 
+    if (trim) {while (s[j] == '0') j++;}
84
 
+    i = RSTRING(ss)->len - j;
85
 
+    if (RBIGNUM(x)->sign) {
86
 
+       memmove(s, s+j, i);
87
 
+       RSTRING(ss)->len = i-1;
88
 
+    }
89
 
+    else {
90
 
+       memmove(s+1, s+j, i);
91
 
+       RSTRING(ss)->len = i;
92
 
+    }
93
 
     s[RSTRING(ss)->len] = '\0';
94
 
 
95
 
     return ss;
96
 
 }
97
 
 
98
 
+VALUE
99
 
+rb_big2str(VALUE x, int base)
100
 
+{
101
 
+    return rb_big2str0(x, base, Qtrue);
102
 
+}
103
 
+
104
 
 /*
105
 
  *  call-seq:
106
 
  *     big.to_s(base=10)   =>  string
107
 
--- ruby-1.8.5/intern.h 14 Sep 2006 07:25:54 -0000      1.139.2.20
108
 
+++ ruby-1.8.5/intern.h 30 Oct 2006 02:24:08 -0000      1.139.2.21
109
 
@@ -70,6 +70,7 @@
110
 
 VALUE rb_cstr2inum _((const char*, int));
111
 
 VALUE rb_str2inum _((VALUE, int));
112
 
 VALUE rb_big2str _((VALUE, int));
113
 
+VALUE rb_big2str0 _((VALUE, int, int));
114
 
 long rb_big2long _((VALUE));
115
 
 #define rb_big2int(x) rb_big2long(x)
116
 
 unsigned long rb_big2ulong _((VALUE));
117
 
--- ruby-1.8.5/sprintf.c        28 Jul 2006 16:27:42 -0000      1.34.2.19
118
 
+++ ruby-1.8.5/sprintf.c        30 Oct 2006 02:24:08 -0000      1.34.2.20
119
 
@@ -627,7 +627,7 @@
120
 
                    val = rb_big_clone(val);
121
 
                    rb_big_2comp(val);
122
 
                }
123
 
-               tmp1 = tmp = rb_big2str(val, base);
124
 
+               tmp1 = tmp = rb_big2str0(val, base, RBIGNUM(val)->sign);
125
 
                s = RSTRING(tmp)->ptr;
126
 
                if (*s == '-') {
127
 
                    if (base == 10) {