summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%google.com <devnull@localhost>2009-10-03 01:17:42 +0000
committerwtc%google.com <devnull@localhost>2009-10-03 01:17:42 +0000
commita8f4bb8ec1bfebc84c55af8a8e6ea7eef8f267eb (patch)
treed9c6b000e42dc07a6c5f1c661f392e5cc4deb1d7
parent8d22374fbcf52f4660c560e81a0e32e5e558a9c3 (diff)
downloadnspr-hg-a8f4bb8ec1bfebc84c55af8a8e6ea7eef8f267eb.tar.gz
Bug 516396: Merge rev. 4.8 from the trunk.
Backported two changes from dtoa.c upstream made on 2009-03-01 and 2009-04-19. Here is an excerpt from the 'changes' file describing these changes: dtoa.c and gdtoa/gdtoaimp.h and gdtoa/misc.c: reduce Kmax, and use MALLOC and FREE or free for huge blocks, which are possible only in pathological cases, such as dtoa calls in mode 3 with thousands of digits requested, or strtod() calls with thousand of digits. For the latter case, I have an alternate approach that runs much faster and uses less memory, but finding time to get it ready for distribution may take a while. dtoa.c, gdtoa/misc.c: do not attempt to allocate large memory blocks from the private memory pool (which was an unlikely event, but a bug). Tag: NSPR_4_7_BRANCH
-rw-r--r--pr/src/misc/prdtoa.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/pr/src/misc/prdtoa.c b/pr/src/misc/prdtoa.c
index 2af610eb..1ec52daf 100644
--- a/pr/src/misc/prdtoa.c
+++ b/pr/src/misc/prdtoa.c
@@ -175,7 +175,12 @@ void _PR_CleanupDtoa(void)
* #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,
@@ -543,7 +548,7 @@ extern double rnd_prod(double, double), rnd_quot(double, double);
#define FREE_DTOA_LOCK(n) /*nothing*/
#endif
-#define Kmax 15
+#define Kmax 7
struct
Bigint {
@@ -571,9 +576,10 @@ Balloc
#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
@@ -581,7 +587,7 @@ Balloc
#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;
}
@@ -605,10 +611,18 @@ Bfree
#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);
+ }
}
}