Bug 379165: Simplifing JS_DimpHeap while fixing BeOS build problems. r=brendan
--- a/js/jsd/jsd_xpc.cpp
+++ b/js/jsd/jsd_xpc.cpp
@@ -2718,21 +2718,18 @@ jsdService::DumpHeap(const char* fileNam
return NS_ERROR_NOT_IMPLEMENTED;
#else
nsresult rv = NS_OK;
FILE *file = fileName ? fopen(fileName, "w") : stdout;
if (!file) {
rv = NS_ERROR_FAILURE;
} else {
JSContext *cx = JSD_GetDefaultJSContext (mCx);
- if (!JS_DumpHeap(cx, NULL, 0, NULL, (size_t)-1, NULL,
- NS_REINTERPRET_CAST(JSPrintfFormater, &fprintf),
- file)) {
+ if (!JS_DumpHeap(cx, file, NULL, 0, NULL, (size_t)-1, NULL))
rv = NS_ERROR_FAILURE;
- }
if (file != stdout)
fclose(file);
}
return rv;
#endif
}
NS_IMETHODIMP
--- a/js/src/js.c
+++ b/js/src/js.c
@@ -1410,19 +1410,18 @@ DumpHeap(JSContext *cx, JSObject *obj, u
dumpFile = fopen(fileName, "w");
if (!dumpFile) {
fprintf(gErrFile, "dumpHeap: can't open %s: %s\n",
fileName, strerror(errno));
return JS_FALSE;
}
}
- ok = JS_DumpHeap(cx, startThing, startTraceKind, thingToFind,
- maxDepth, thingToIgnore,
- (JSPrintfFormater)fprintf, dumpFile);
+ ok = JS_DumpHeap(cx, dumpFile, startThing, startTraceKind, thingToFind,
+ maxDepth, thingToIgnore);
if (dumpFile != stdout)
fclose(dumpFile);
return ok;
not_traceable_arg:
fprintf(gErrFile,
"dumpHeap: argument %u is not null or a heap-allocated thing\n",
(unsigned)(vp - argv));
--- a/js/src/jsapi.c
+++ b/js/src/jsapi.c
@@ -2161,27 +2161,26 @@ DumpNotify(JSTracer *trc, void *thing, u
JS_ASSERT(!*dtrc->lastNodep);
*dtrc->lastNodep = node;
dtrc->lastNodep = &node->next;
}
/* Dump node and the chain that leads to thing it contains. */
static JSBool
-DumpNode(JSDumpingTracer *dtrc, JSHeapDumpNode *node,
- JSPrintfFormater format, void *closure)
+DumpNode(JSDumpingTracer *dtrc, FILE* fp, JSHeapDumpNode *node)
{
JSHeapDumpNode *prev, *following;
size_t chainLimit;
JSBool ok;
enum { MAX_PARENTS_TO_PRINT = 10 };
JS_PrintTraceThingInfo(dtrc->buffer, sizeof dtrc->buffer,
&dtrc->base, node->thing, node->kind, JS_TRUE);
- if (format(closure, "%p %-22s via ", node->thing, dtrc->buffer) < 0)
+ if (fprintf(fp, "%p %-22s via ", node->thing, dtrc->buffer) < 0)
return JS_FALSE;
/*
* We need to print the parent chain in the reverse order. To do it in
* O(N) time where N is the chain length we first reverse the chain while
* searching for the top and then print each node while restoring the
* chain order.
*/
@@ -2190,56 +2189,55 @@ DumpNode(JSDumpingTracer *dtrc, JSHeapDu
for (;;) {
following = node->parent;
node->parent = prev;
prev = node;
node = following;
if (!node)
break;
if (chainLimit == 0) {
- if (format(closure, "...") < 0)
+ if (fputs("...", fp) < 0)
return JS_FALSE;
break;
}
--chainLimit;
}
node = prev;
prev = following;
ok = JS_TRUE;
do {
/* Loop must continue even when !ok to restore the parent chain. */
if (ok) {
if (!prev) {
/* Print edge from some runtime root or startThing. */
- if (format(closure, "%s", node->edgeName) < 0)
+ if (fputs(node->edgeName, fp) < 0)
ok = JS_FALSE;
} else {
JS_PrintTraceThingInfo(dtrc->buffer, sizeof dtrc->buffer,
&dtrc->base, prev->thing, prev->kind,
JS_FALSE);
- if (format(closure, "(%p %s).%s",
+ if (fprintf(fp, "(%p %s).%s",
prev->thing, dtrc->buffer, node->edgeName) < 0) {
ok = JS_FALSE;
}
}
}
following = node->parent;
node->parent = prev;
prev = node;
node = following;
} while (node);
- return ok && format(closure, "\n") >= 0;
+ return ok && putc('\n', fp) >= 0;
}
JS_PUBLIC_API(JSBool)
-JS_DumpHeap(JSContext *cx, void* startThing, uint32 startKind,
- void *thingToFind, size_t maxDepth, void *thingToIgnore,
- JSPrintfFormater format, void *closure)
+JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, uint32 startKind,
+ void *thingToFind, size_t maxDepth, void *thingToIgnore)
{
JSDumpingTracer dtrc;
JSHeapDumpNode *node, *children, *next, *parent;
size_t depth;
JSBool thingToFindWasTraced;
if (maxDepth == 0)
return JS_TRUE;
@@ -2272,17 +2270,17 @@ JS_DumpHeap(JSContext *cx, void* startTh
thingToFindWasTraced = thingToFind && thingToFind == startThing;
for (;;) {
/*
* Loop must continue even when !dtrc.ok to free all nodes allocated
* so far.
*/
if (dtrc.ok) {
if (thingToFind == NULL || thingToFind == node->thing)
- dtrc.ok = DumpNode(&dtrc, node, format, closure);
+ dtrc.ok = DumpNode(&dtrc, fp, node);
/* Descend into children. */
if (dtrc.ok &&
depth < maxDepth &&
(thingToFind != node->thing || !thingToFindWasTraced)) {
dtrc.parentNode = node;
children = NULL;
dtrc.lastNodep = &children;
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -1011,35 +1011,36 @@ JS_TraceChildren(JSTracer *trc, void *th
extern JS_PUBLIC_API(void)
JS_TraceRuntime(JSTracer *trc);
#ifdef DEBUG
extern JS_PUBLIC_API(void)
JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc,
void *thing, uint32 kind, JSBool includeDetails);
+
/*
- * DEBUG-only method to dump an object graph of heap-allocated things.
+ * DEBUG-only method to dump the object graph of heap-allocated things.
*
- * start: when non-null, dump only things reachable from start thing. Otherwise
- * dump all things rechable from runtime roots.
- * startKind: trace kind of start if start is not null. Must be 0 when start
- * is null.
- * thingToFind: dump only paths in the object graph leading to thingToFind
- * when non-null.
- * maxDepth: the upper bound on the number of edges to descend from the graph
- * roots.
- * thingToIgnore: thing to ignore during graph traversal when non-null.
- * format: callback to format the dump output.
- * closure: an argument to pass to formater.
+ * fp: file for the dump output.
+ * start: when non-null, dump only things reachable from start
+ * thing. Otherwise dump all things reachable from the
+ * runtime roots.
+ * startKind: trace kind of start if start is not null. Must be 0 when
+ * start is null.
+ * thingToFind: dump only paths in the object graph leading to thingToFind
+ * when non-null.
+ * maxDepth: the upper bound on the number of edges to descend from the
+ * graph roots.
+ * thingToIgnore: thing to ignore during the graph traversal when non-null.
*/
extern JS_PUBLIC_API(JSBool)
-JS_DumpHeap(JSContext *cx, void* startThing, uint32 startKind,
- void *thingToFind, size_t maxDepth, void *thingToIgnore,
- JSPrintfFormater format, void *closure);
+JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, uint32 startKind,
+ void *thingToFind, size_t maxDepth, void *thingToIgnore);
+
#endif
/*
* Garbage collector API.
*/
extern JS_PUBLIC_API(void)
JS_GC(JSContext *cx);
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -710,23 +710,11 @@ typedef JSBool
* a window object in the DOM level 0). If there are no principals associated
* with obj, return null. Therefore null does not mean an error was reported;
* in no event should an error be reported or an exception be thrown by this
* callback's implementation.
*/
typedef JSPrincipals *
(* JS_DLL_CALLBACK JSObjectPrincipalsFinder)(JSContext *cx, JSObject *obj);
-/*
- * Output formated arguments as specified by format string. See fprintf/sprintf
- * documentation for specification of format. Return the number of characters
- * printed or -1 if an error occur.
- */
-typedef int
-(* JS_DLL_CALLBACK JSPrintfFormater)(void *closure, const char *format, ...)
-#if defined __GNUC__
- __attribute__ ((format (printf, 2, 3)))
-#endif
-;
-
JS_END_EXTERN_C
#endif /* jspubtd_h___ */
--- a/js/src/xpconnect/shell/xpcshell.cpp
+++ b/js/src/xpconnect/shell/xpcshell.cpp
@@ -380,19 +380,18 @@ DumpHeap(JSContext *cx, JSObject *obj, u
dumpFile = fopen(fileName, "w");
if (!dumpFile) {
fprintf(gErrFile, "dumpHeap: can't open %s: %s\n",
fileName, strerror(errno));
return JS_FALSE;
}
}
- ok = JS_DumpHeap(cx, startThing, startTraceKind, thingToFind,
- maxDepth, thingToIgnore,
- (JSPrintfFormater)fprintf, dumpFile);
+ ok = JS_DumpHeap(cx, dumpFile, startThing, startTraceKind, thingToFind,
+ maxDepth, thingToIgnore);
if (dumpFile != gOutFile)
fclose(dumpFile);
return ok;
not_traceable_arg:
fprintf(gErrFile,
"dumpHeap: argument %u is not null or a heap-allocated thing\n",
(unsigned)(vp - argv));
--- a/js/src/xpconnect/src/nsXPConnect.cpp
+++ b/js/src/xpconnect/src/nsXPConnect.cpp
@@ -332,20 +332,18 @@ nsXPConnect::ReleaseXPConnectSingleton()
if(dumpName)
{
FILE* dumpFile = (*dumpName == '\0' ||
strcmp(dumpName, "stdout") == 0)
? stdout
: fopen(dumpName, "w");
if(dumpFile)
{
- JS_DumpHeap(ccx, nsnull, 0, nsnull,
- NS_STATIC_CAST(size_t, -1), nsnull,
- NS_REINTERPRET_CAST(JSPrintfFormater, fprintf),
- dumpFile);
+ JS_DumpHeap(ccx, dumpFile, nsnull, 0, nsnull,
+ NS_STATIC_CAST(size_t, -1), nsnull);
if(dumpFile != stdout)
fclose(dumpFile);
}
}
}
#endif
#ifdef XPC_DUMP_AT_SHUTDOWN
// NOTE: to see really interesting stuff turn on the prlog stuff.