forked from cory/tildefriends
		
	Trace more things. Add a CORS header for /mem so I can make an app to examine it. Fix a memory leak. Fix tf_realloc(NULL, 0).
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4187 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		@@ -840,7 +840,11 @@ loadSettings().then(function() {
 | 
			
		||||
			return response.end(data);
 | 
			
		||||
		} else if (match = /^\/mem$/.exec(request.uri)) {
 | 
			
		||||
			let data = JSON.stringify(getAllocations(), null, 2);
 | 
			
		||||
			response.writeHead(200, {"Content-Type": "application/json; charset=utf-8", "Content-Length": data.length.toString()});
 | 
			
		||||
			response.writeHead(200, {
 | 
			
		||||
				"Content-Type": "application/json; charset=utf-8",
 | 
			
		||||
				"Content-Length": data.length.toString(),
 | 
			
		||||
				"Access-Control-Allow-Origin": "*",
 | 
			
		||||
			});
 | 
			
		||||
			return response.end(data);
 | 
			
		||||
		} else if (request.uri == "/robots.txt") {
 | 
			
		||||
			return blobHandler(request, response, null, request.uri);
 | 
			
		||||
 
 | 
			
		||||
@@ -218,6 +218,11 @@ static void* _tf_alloc(int64_t* total, size_t size)
 | 
			
		||||
 | 
			
		||||
static void* _tf_realloc(int64_t* total, void* ptr, size_t size)
 | 
			
		||||
{
 | 
			
		||||
	if (!ptr && !size)
 | 
			
		||||
	{
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void* buffer[32];
 | 
			
		||||
	int count = 0;
 | 
			
		||||
	size_t overhead = sizeof(size_t);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								src/task.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								src/task.c
									
									
									
									
									
								
							@@ -322,8 +322,10 @@ static const char* _task_loadFile(const char* fileName)
 | 
			
		||||
JSValue _tf_task_exit(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
 | 
			
		||||
{
 | 
			
		||||
	tf_task_t* task = JS_GetContextOpaque(context);
 | 
			
		||||
	tf_trace_begin(task->_trace, __func__);
 | 
			
		||||
	int exitCode = 0;
 | 
			
		||||
	JS_ToInt32(task->_context, &exitCode, argv[0]);
 | 
			
		||||
	tf_trace_end(task->_trace);
 | 
			
		||||
	exit(exitCode);
 | 
			
		||||
	return JS_UNDEFINED;
 | 
			
		||||
}
 | 
			
		||||
@@ -628,7 +630,10 @@ JSValue _tf_task_get_parent(JSContext* context, JSValueConst this_val, int argc,
 | 
			
		||||
static JSValue _tf_task_version(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
 | 
			
		||||
{
 | 
			
		||||
	tf_task_t* task = JS_GetContextOpaque(context);
 | 
			
		||||
	return JS_NewString(task->_context, k_version);
 | 
			
		||||
	tf_trace_begin(task->_trace, __func__);
 | 
			
		||||
	JSValue result = JS_NewString(task->_context, k_version);
 | 
			
		||||
	tf_trace_end(task->_trace);
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exportid_t tf_task_export_function(tf_task_t* task, tf_taskstub_t* to, JSValue function)
 | 
			
		||||
@@ -697,15 +702,18 @@ static JSValue _tf_task_trace(JSContext* context, JSValueConst this_val, int arg
 | 
			
		||||
		return JS_UNDEFINED;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tf_trace_begin(task->_trace, __func__);
 | 
			
		||||
	char* trace = tf_trace_export(task->_trace);
 | 
			
		||||
	JSValue result = JS_NewString(context, trace);
 | 
			
		||||
	tf_free(trace);
 | 
			
		||||
	tf_trace_end(task->_trace);
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
 | 
			
		||||
{
 | 
			
		||||
	tf_task_t* task = JS_GetContextOpaque(context);
 | 
			
		||||
	tf_trace_begin(task->_trace, __func__);
 | 
			
		||||
	JSValue result = JS_NewObject(context);
 | 
			
		||||
	JS_SetPropertyStr(context, result, "child_count", JS_NewInt32(context, task->_child_count));
 | 
			
		||||
	JS_SetPropertyStr(context, result, "import_count", JS_NewInt32(context, task->_import_count));
 | 
			
		||||
@@ -742,6 +750,7 @@ static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int
 | 
			
		||||
		JS_SetPropertyStr(context, result, "requests", JS_NewInt32(context, ssb_stats.request_count));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tf_trace_end(task->_trace);
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -785,6 +794,7 @@ static void _tf_backtrace_error(void* data, const char* message, int error)
 | 
			
		||||
static JSValue _tf_task_getDebug(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
 | 
			
		||||
{
 | 
			
		||||
	tf_task_t* task = JS_GetContextOpaque(context);
 | 
			
		||||
	tf_trace_begin(task->_trace, __func__);
 | 
			
		||||
	JSValue result = JS_NewObject(context);
 | 
			
		||||
 | 
			
		||||
	JSValue promises = JS_NewArray(context);
 | 
			
		||||
@@ -820,12 +830,14 @@ static JSValue _tf_task_getDebug(JSContext* context, JSValueConst this_val, int
 | 
			
		||||
			JS_SetPropertyUint32(context, promises, j++, entry);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tf_trace_end(task->_trace);
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static JSValue _tf_task_getAllocations(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
 | 
			
		||||
{
 | 
			
		||||
	tf_task_t* task = JS_GetContextOpaque(context);
 | 
			
		||||
	tf_trace_begin(task->_trace, __func__);
 | 
			
		||||
	JSValue result = JS_NewObject(context);
 | 
			
		||||
 | 
			
		||||
	int count = 0;
 | 
			
		||||
@@ -843,22 +855,28 @@ static JSValue _tf_task_getAllocations(JSContext* context, JSValueConst this_val
 | 
			
		||||
		tf_free((void*)stack);
 | 
			
		||||
		JS_SetPropertyUint32(context, allocations, i, allocation);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tf_free(allocation_info);
 | 
			
		||||
	tf_trace_end(task->_trace);
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static JSValue _tf_task_disconnectionsDebug(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
 | 
			
		||||
{
 | 
			
		||||
	tf_task_t* task = JS_GetContextOpaque(context);
 | 
			
		||||
	return tf_ssb_get_disconnection_debug(task->_ssb, context);
 | 
			
		||||
	tf_trace_begin(task->_trace, __func__);
 | 
			
		||||
	JSValue result = tf_ssb_get_disconnection_debug(task->_ssb, context);
 | 
			
		||||
	tf_trace_end(task->_trace);
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static JSValue _tf_task_getFile(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
 | 
			
		||||
{
 | 
			
		||||
	tf_task_t* task = JS_GetContextOpaque(context);
 | 
			
		||||
	tf_trace_begin(task->_trace, __func__);
 | 
			
		||||
	const char* name = JS_ToCString(context, argv[0]);
 | 
			
		||||
	JSValue result = JS_GetPropertyStr(context, task->_loadedFiles, name);
 | 
			
		||||
	JS_FreeCString(context, name);
 | 
			
		||||
	tf_trace_end(task->_trace);
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -312,6 +312,7 @@ static JSValue _util_sha1_digest(JSContext* context, JSValueConst this_val, int
 | 
			
		||||
	const char* value = JS_ToCStringLen(context, &length, argv[0]);
 | 
			
		||||
	unsigned char digest[SHA_DIGEST_LENGTH] = { 0 };
 | 
			
		||||
	SHA1((const unsigned char*)value, length, digest);
 | 
			
		||||
	JS_FreeCString(context, value);
 | 
			
		||||
	return JS_NewArrayBufferCopy(context, digest, sizeof(digest));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user