summaryrefslogtreecommitdiff
path: root/moz/patches/dtoa.patch
blob: fce3be38b10b61ce8df24df27220341b731f1d16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
--- misc/mozilla/nsprpub/pr/src/misc/prdtoa.c	20 Mar 2009 03:41:21 -0000	4.7
+++ misc/build/mozilla/nsprpub/pr/src/misc/prdtoa.c	15 Sep 2009 00:10:20 -0000
@@ -169,17 +169,22 @@ void _PR_CleanupDtoa(void)
  *	Llong, #define #ULLong to be the corresponding unsigned type.
  * #define KR_headers for old-style C function headers.
  * #define Bad_float_h if your system lacks a float.h or if it does not
  *	define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
  *	FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
  * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
  *	if memory is available and otherwise does something you deem
  *	appropriate.  If MALLOC is undefined, malloc will be invoked
- *	directly -- and assumed always to succeed.
+ *	directly -- and assumed always to succeed.  Similarly, if you
+ *	want something other than the system's free() to be called to
+ *	recycle memory acquired from MALLOC, #define FREE to be the
+ *	name of the alternate routine.  (FREE or free is only called in
+ *	pathological cases, e.g., in a dtoa call after a dtoa return in
+ *	mode 3 with thousands of digits requested.)
  * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making
  *	memory allocations from a private pool of memory when possible.
  *	When used, the private pool is PRIVATE_MEM bytes long:  2304 bytes,
  *	unless #defined to be a different length.  This default length
  *	suffices to get rid of MALLOC calls except for unusual cases,
  *	such as decimal-to-binary conversion of a very long string of
  *	digits.  The longest string dtoa can return is about 751 bytes
  *	long.  For conversions by strtod of strings of 800 digits and
@@ -553,17 +558,17 @@ extern double rnd_prod(double, double), 
 #endif
 #endif /* NO_LONG_LONG */
 
 #ifndef MULTIPLE_THREADS
 #define ACQUIRE_DTOA_LOCK(n)	/*nothing*/
 #define FREE_DTOA_LOCK(n)	/*nothing*/
 #endif
 
-#define Kmax 15
+#define Kmax 7
 
  struct
 Bigint {
 	struct Bigint *next;
 	int k, maxwds, sign, wds;
 	ULong x[1];
 	};
 
@@ -581,27 +586,28 @@ Balloc
 {
 	int x;
 	Bigint *rv;
 #ifndef Omit_Private_Memory
 	unsigned int len;
 #endif
 
 	ACQUIRE_DTOA_LOCK(0);
-	if (rv = freelist[k]) {
+	/* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */
+	/* but this case seems very unlikely. */
+	if (k <= Kmax && (rv = freelist[k]))
 		freelist[k] = rv->next;
-		}
 	else {
 		x = 1 << k;
 #ifdef Omit_Private_Memory
 		rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
 #else
 		len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
 			/sizeof(double);
-		if (pmem_next - private_mem + len <= PRIVATE_mem) {
+		if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
 			rv = (Bigint*)pmem_next;
 			pmem_next += len;
 			}
 		else
 			rv = (Bigint*)MALLOC(len*sizeof(double));
 #endif
 		rv->k = k;
 		rv->maxwds = x;
@@ -615,20 +621,28 @@ Balloc
 Bfree
 #ifdef KR_headers
 	(v) Bigint *v;
 #else
 	(Bigint *v)
 #endif
 {
 	if (v) {
-		ACQUIRE_DTOA_LOCK(0);
-		v->next = freelist[v->k];
-		freelist[v->k] = v;
-		FREE_DTOA_LOCK(0);
+		if (v->k > Kmax)
+#ifdef FREE
+			FREE((void*)v);
+#else
+			free((void*)v);
+#endif
+		else {
+			ACQUIRE_DTOA_LOCK(0);
+			v->next = freelist[v->k];
+			freelist[v->k] = v;
+			FREE_DTOA_LOCK(0);
+			}
 		}
 	}
 
 #define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \
 y->wds*sizeof(Long) + 2*sizeof(int))
 
  static Bigint *
 multadd
--- misc/mozilla/js/src/jsdtoa.c	2 Sep 2007 22:20:41 -0000	3.41
+++ misc/build/mozilla/js/src/jsdtoa.c	18 Sep 2009 16:15:13 -0000
@@ -145,17 +145,22 @@
  *  and if "unsigned Llong" does not work as an unsigned version of
  *  Llong, #define #ULLong to be the corresponding unsigned type.
  * #define Bad_float_h if your system lacks a float.h or if it does not
  *  define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
  *  FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
  * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
  *  if memory is available and otherwise does something you deem
  *  appropriate.  If MALLOC is undefined, malloc will be invoked
- *  directly -- and assumed always to succeed.
+ *  directly -- and assumed always to succeed.  Similarly, if you
+ *  want something other than the system's free() to be called to
+ *  recycle memory acquired from MALLOC, #define FREE to be the
+ *  name of the alternate routine.  (FREE or free is only called in
+ *  pathological cases, e.g., in a dtoa call after a dtoa return in
+ *  mode 3 with thousands of digits requested.)
  * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making
  *  memory allocations from a private pool of memory when possible.
  *  When used, the private pool is PRIVATE_MEM bytes long: 2000 bytes,
  *  unless #defined to be a different length.  This default length
  *  suffices to get rid of MALLOC calls except for unusual cases,
  *  such as decimal-to-binary conversion of a very long string of
  *  digits.
  * #define INFNAN_CHECK on IEEE systems to cause strtod to check for
@@ -320,17 +325,17 @@ static PRLock *freelist_lock;
     JS_END_MACRO
 #define RELEASE_DTOA_LOCK() PR_Unlock(freelist_lock)
 #else
 #undef MULTIPLE_THREADS
 #define ACQUIRE_DTOA_LOCK()   /*nothing*/
 #define RELEASE_DTOA_LOCK()   /*nothing*/
 #endif
 
-#define Kmax 15
+#define Kmax 7
 
 struct Bigint {
     struct Bigint *next;  /* Free list link */
     int32 k;              /* lg2(maxwds) */
     int32 maxwds;         /* Number of words allocated for x */
     int32 sign;           /* Zero if positive, 1 if negative.  Ignored by most Bigint routines! */
     int32 wds;            /* Actual number of words.  If value is nonzero, the most significant word must be nonzero. */
     ULong x[1];           /* wds words of number in little endian order */
@@ -400,26 +405,26 @@ static Bigint *Balloc(int32 k)
 
 #ifdef ENABLE_OOM_TESTING
     if (++allocationNum == desiredFailure) {
         printf("Forced Failing Allocation number %d\n", allocationNum);
         return NULL;
     }
 #endif
 
-    if ((rv = freelist[k]) != NULL)
+    if (k <= Kmax && (rv = freelist[k]) != NULL)
         freelist[k] = rv->next;
     if (rv == NULL) {
         x = 1 << k;
 #ifdef Omit_Private_Memory
         rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
 #else
         len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
             /sizeof(double);
-        if (pmem_next - private_mem + len <= PRIVATE_mem) {
+        if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
             rv = (Bigint*)pmem_next;
             pmem_next += len;
             }
         else
             rv = (Bigint*)MALLOC(len*sizeof(double));
 #endif
         if (!rv)
             return NULL;
@@ -428,18 +433,26 @@ static Bigint *Balloc(int32 k)
     }
     rv->sign = rv->wds = 0;
     return rv;
 }
 
 static void Bfree(Bigint *v)
 {
     if (v) {
-        v->next = freelist[v->k];
-        freelist[v->k] = v;
+        if (v->k > Kmax)
+#ifdef FREE
+                FREE((void*)v);
+#else
+                free((void*)v);
+#endif
+        else {
+                v->next = freelist[v->k];
+                freelist[v->k] = v;
+        }
     }
 }
 
 #define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \
                           y->wds*sizeof(Long) + 2*sizeof(int32))
 
 /* Return b*m + a.  Deallocate the old b.  Both a and m must be between 0 and
  * 65535 inclusive.  NOTE: old b is deallocated on memory failure.
--- misc/mozilla/js/src/jsdtoa.c	22 Sep 2009 06:16:27 -0000	3.42
+++ misc/build/mozilla/js/src/jsdtoa.c	15 Oct 2009 10:34:38 -0000
@@ -405,19 +405,19 @@ static Bigint *Balloc(int32 k)
 
 #ifdef ENABLE_OOM_TESTING
     if (++allocationNum == desiredFailure) {
         printf("Forced Failing Allocation number %d\n", allocationNum);
         return NULL;
     }
 #endif
 
-    if (k <= Kmax && (rv = freelist[k]) != NULL)
+    if (k <= Kmax && (rv = freelist[k]))
         freelist[k] = rv->next;
-    if (rv == NULL) {
+    else {
         x = 1 << k;
 #ifdef Omit_Private_Memory
         rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
 #else
         len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
             /sizeof(double);
         if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
             rv = (Bigint*)pmem_next;