Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: refactor global nitialize #464

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


int main(int argc, char **argv) {
TJS_SetupArgs(argc, argv);
TJS_Initialize(argc, argv);

TJSRuntime *qrt = TJS_NewRuntime();
CHECK_NOT_NULL(qrt);
Expand Down
14 changes: 0 additions & 14 deletions src/curl-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,7 @@
"txiki.js/" STRINGIFY(TJS_VERSION_MAJOR) "." STRINGIFY(TJS_VERSION_MINOR) "." STRINGIFY(TJS_VERSION_PATCH) \
TJS_VERSION_SUFFIX

static uv_once_t curl__init_once = UV_ONCE_INIT;

static void tjs__curl_init_once(void) {
curl_global_init(CURL_GLOBAL_ALL);
}

static void tjs__curl_init(void) {
uv_once(&curl__init_once, tjs__curl_init_once);
}

CURL *tjs__curl_easy_init(CURL *curl_h) {
tjs__curl_init();

if (curl_h == NULL)
curl_h = curl_easy_init();

Expand Down Expand Up @@ -261,8 +249,6 @@ CURLM *tjs__get_curlm(JSContext *ctx) {
CHECK_NOT_NULL(qrt);

if (!qrt->curl_ctx.curlm_h) {
tjs__curl_init();

CURLM *curlm_h = curl_multi_init();
curl_multi_setopt(curlm_h, CURLMOPT_SOCKETFUNCTION, curl__handle_socket);
curl_multi_setopt(curlm_h, CURLMOPT_SOCKETDATA, qrt);
Expand Down
2 changes: 1 addition & 1 deletion src/tjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void TJS_DefaultOptions(TJSRunOptions *options);
TJSRuntime *TJS_NewRuntime(void);
TJSRuntime *TJS_NewRuntimeOptions(TJSRunOptions *options);
void TJS_FreeRuntime(TJSRuntime *qrt);
void TJS_SetupArgs(int argc, char **argv);
void TJS_Initialize(int argc, char **argv);
JSContext *TJS_GetJSContext(TJSRuntime *qrt);
TJSRuntime *TJS_GetRuntime(JSContext *ctx);
int TJS_Run(TJSRuntime *qrt);
Expand Down
6 changes: 3 additions & 3 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ void TJS_FreeRuntime(TJSRuntime *qrt) {
free(qrt);
}

void TJS_SetupArgs(int argc, char **argv) {
void TJS_Initialize(int argc, char **argv) {
curl_global_init(CURL_GLOBAL_ALL);

tjs__argc = argc;
tjs__argv = uv_setup_args(argc, argv);
if (!tjs__argv)
tjs__argv = argv;
}

JSContext *TJS_GetJSContext(TJSRuntime *qrt) {
Expand Down
Loading