forked from cory/tildefriends
Use a custom allocator for everything.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3892 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
#include "file.js.h"
|
||||
|
||||
#include "mem.h"
|
||||
#include "task.h"
|
||||
#include "util.js.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <uv.h>
|
||||
@ -60,7 +60,7 @@ static const int k_file_read_max = 8 * 1024 * 1024;
|
||||
static void _file_async_close_callback(uv_fs_t* req)
|
||||
{
|
||||
uv_fs_req_cleanup(req);
|
||||
free(req);
|
||||
tf_free(req);
|
||||
}
|
||||
|
||||
static void _file_read_read_callback(uv_fs_t* req)
|
||||
@ -90,7 +90,7 @@ static void _file_read_read_callback(uv_fs_t* req)
|
||||
if (result < 0)
|
||||
{
|
||||
uv_fs_req_cleanup(req);
|
||||
free(fsreq);
|
||||
tf_free(fsreq);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ static void _file_read_open_callback(uv_fs_t* req)
|
||||
if (result < 0)
|
||||
{
|
||||
uv_fs_req_cleanup(req);
|
||||
free(fsreq);
|
||||
tf_free(fsreq);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,7 +121,7 @@ static void _file_read_open_callback(uv_fs_t* req)
|
||||
{
|
||||
tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(req->result)));
|
||||
uv_fs_req_cleanup(req);
|
||||
free(req);
|
||||
tf_free(req);
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ static JSValue _file_read_file(JSContext* context, JSValueConst this_val, int ar
|
||||
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
fs_req_t* req = malloc(sizeof(fs_req_t) + k_file_read_max);
|
||||
fs_req_t* req = tf_malloc(sizeof(fs_req_t) + k_file_read_max);
|
||||
*req = (fs_req_t)
|
||||
{
|
||||
.fs =
|
||||
@ -146,7 +146,7 @@ static JSValue _file_read_file(JSContext* context, JSValueConst this_val, int ar
|
||||
{
|
||||
tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result)));
|
||||
uv_fs_req_cleanup(&req->fs);
|
||||
free(req);
|
||||
tf_free(req);
|
||||
}
|
||||
JS_FreeCString(context, file_name);
|
||||
return promise_value;
|
||||
@ -171,7 +171,7 @@ static void _file_write_write_callback(uv_fs_t* req)
|
||||
if (result < 0)
|
||||
{
|
||||
uv_fs_req_cleanup(req);
|
||||
free(fsreq);
|
||||
tf_free(fsreq);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ static void _file_write_open_callback(uv_fs_t* req)
|
||||
if (result < 0)
|
||||
{
|
||||
uv_fs_req_cleanup(req);
|
||||
free(fsreq);
|
||||
tf_free(fsreq);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -202,7 +202,7 @@ static void _file_write_open_callback(uv_fs_t* req)
|
||||
{
|
||||
tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(req->result)));
|
||||
uv_fs_req_cleanup(req);
|
||||
free(req);
|
||||
tf_free(req);
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ static JSValue _file_write_file(JSContext* context, JSValueConst this_val, int a
|
||||
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
fs_req_t* req = malloc(sizeof(fs_req_t) + size);
|
||||
fs_req_t* req = tf_malloc(sizeof(fs_req_t) + size);
|
||||
*req = (fs_req_t)
|
||||
{
|
||||
.fs =
|
||||
@ -263,7 +263,7 @@ static void _file_async_callback(uv_fs_t* req)
|
||||
{
|
||||
tf_task_reject_promise(task, promise, JS_NewInt32(context, req->result));
|
||||
}
|
||||
free(req);
|
||||
tf_free(req);
|
||||
}
|
||||
|
||||
static JSValue _file_rename_file(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
@ -273,7 +273,7 @@ static JSValue _file_rename_file(JSContext* context, JSValueConst this_val, int
|
||||
const char* new_name = JS_ToCString(context, argv[1]);
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
uv_fs_t* req = malloc(sizeof(uv_fs_t));
|
||||
uv_fs_t* req = tf_malloc(sizeof(uv_fs_t));
|
||||
*req = (uv_fs_t)
|
||||
{
|
||||
.data = (void*)(intptr_t)promise,
|
||||
@ -294,7 +294,7 @@ static JSValue _file_unlink_file(JSContext* context, JSValueConst this_val, int
|
||||
const char* file_name = JS_ToCString(context, argv[0]);
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
uv_fs_t* req = malloc(sizeof(uv_fs_t));
|
||||
uv_fs_t* req = tf_malloc(sizeof(uv_fs_t));
|
||||
*req = (uv_fs_t)
|
||||
{
|
||||
.data = (void*)(intptr_t)promise,
|
||||
@ -315,7 +315,7 @@ JSValue _file_make_directory(JSContext* context, JSValueConst this_val, int argc
|
||||
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
uv_fs_t* req = malloc(sizeof(uv_fs_t));
|
||||
uv_fs_t* req = tf_malloc(sizeof(uv_fs_t));
|
||||
*req = (uv_fs_t)
|
||||
{
|
||||
.data = (void*)(intptr_t)promise,
|
||||
@ -336,7 +336,7 @@ JSValue _file_remove_directory(JSContext* context, JSValueConst this_val, int ar
|
||||
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
uv_fs_t* req = malloc(sizeof(uv_fs_t));
|
||||
uv_fs_t* req = tf_malloc(sizeof(uv_fs_t));
|
||||
*req = (uv_fs_t)
|
||||
{
|
||||
.data = (void*)(intptr_t)promise,
|
||||
@ -357,7 +357,7 @@ JSValue _file_stat(JSContext* context, JSValueConst this_val, int argc, JSValueC
|
||||
promiseid_t promise = -1;
|
||||
JSValue promise_value = tf_task_allocate_promise(task, &promise);
|
||||
|
||||
file_stat_t* data = malloc(sizeof(file_stat_t));
|
||||
file_stat_t* data = tf_malloc(sizeof(file_stat_t));
|
||||
data->_task = task;
|
||||
data->_promise = promise;
|
||||
data->_request.data = data;
|
||||
@ -368,7 +368,7 @@ JSValue _file_stat(JSContext* context, JSValueConst this_val, int argc, JSValueC
|
||||
{
|
||||
tf_task_reject_promise(task, promise, JS_NewInt32(context, result));
|
||||
uv_fs_req_cleanup(&data->_request);
|
||||
free(data);
|
||||
tf_free(data);
|
||||
}
|
||||
JS_FreeCString(context, path);
|
||||
return promise_value;
|
||||
@ -399,5 +399,5 @@ static void _file_on_stat_complete(uv_fs_t* request)
|
||||
JS_FreeValue(context, result);
|
||||
}
|
||||
uv_fs_req_cleanup(request);
|
||||
free(data);
|
||||
tf_free(data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user