From b49346e0597c24e20dacbe75a9dc284026bd7173 Mon Sep 17 00:00:00 2001 From: nekobit Date: Thu, 18 Aug 2022 14:58:21 +0000 Subject: [PATCH] Switch to new macros FossilOrigin-Name: 9adf01fb2b7c7ee846235df49ccc874e792196a2779034bde1be4043ca9509a7 --- src/account.c | 58 +++++++-------------------------------------- src/base_page.c | 21 +++++----------- src/conversations.c | 38 +++++++---------------------- src/lists.c | 19 +++------------ src/notifications.c | 18 +++----------- src/search.c | 18 +++----------- src/timeline.c | 17 +++---------- 7 files changed, 35 insertions(+), 154 deletions(-) diff --git a/src/account.c b/src/account.c index 7ecbc39..9634b20 100644 --- a/src/account.c +++ b/src/account.c @@ -82,12 +82,7 @@ static char* accounts_page(HV* session_hv, { char* output; - perl_lock(); - dSP; - ENTER; - SAVETMPS; - PUSHMARK(SP); - + PERL_STACK_INIT; XPUSHs(newRV_noinc((SV*)session_hv)); XPUSHs(newRV_noinc((SV*)template_files)); if (acct) @@ -105,17 +100,9 @@ static char* accounts_page(HV* session_hv, if (header) mXPUSHp(header, strlen(header)); - PUTBACK; - call_pv("account::content_accounts", G_SCALAR); - SPAGAIN; + PERL_STACK_SCALAR_CALL("account::content_accounts"); - output = savesharedsvpv(POPs); - - // Clean up Perl - PUTBACK; - FREETMPS; - LEAVE; - perl_unlock(); + output = PERL_GET_STACK_EXIT; mastodont_storage_cleanup(storage); mstdnt_cleanup_accounts(accts, accts_len); @@ -232,12 +219,7 @@ static char* account_statuses_cb(HV* session_hv, mastodont_get_account_statuses(api, &m_args, acct->id, args, &storage, &statuses, &statuses_len); - perl_lock(); - dSP; - ENTER; - SAVETMPS; - PUSHMARK(SP); - + PERL_STACK_INIT; XPUSHs(newRV_noinc((SV*)session_hv)); XPUSHs(newRV_noinc((SV*)template_files)); XPUSHs(newRV_noinc((SV*)perlify_account(acct))); @@ -249,18 +231,10 @@ static char* account_statuses_cb(HV* session_hv, XPUSHs(newRV_noinc((SV*)perlify_statuses(statuses, statuses_len))); else ARG_UNDEFINED(); - PUTBACK; - call_pv("account::content_statuses", G_SCALAR); - SPAGAIN; + PERL_STACK_SCALAR_CALL("account::content_statuses"); - result = savesharedsvpv(POPs); + result = PERL_GET_STACK_EXIT; - // Clean up Perl - PUTBACK; - FREETMPS; - LEAVE; - perl_unlock(); - mastodont_storage_cleanup(&storage); mstdnt_cleanup_statuses(statuses, statuses_len); @@ -290,13 +264,7 @@ static char* account_scrobbles_cb(HV* session_hv, }; mastodont_get_scrobbles(api, &m_args, acct->id, &args, &storage, &scrobbles, &scrobbles_len); - // TODO - perl_lock(); - dSP; - ENTER; - SAVETMPS; - PUSHMARK(SP); - + PERL_STACK_INIT; XPUSHs(newRV_noinc((SV*)session_hv)); XPUSHs(newRV_noinc((SV*)template_files)); XPUSHs(newRV_noinc((SV*)perlify_account(acct))); @@ -308,17 +276,9 @@ static char* account_scrobbles_cb(HV* session_hv, XPUSHs(newRV_noinc((SV*)perlify_scrobbles(scrobbles, scrobbles_len))); else ARG_UNDEFINED(); - PUTBACK; - call_pv("account::content_scrobbles", G_SCALAR); - SPAGAIN; + PERL_STACK_SCALAR_CALL("account::content_scrobbles"); - result = savesharedsvpv(POPs); - - // Clean up Perl - PUTBACK; - FREETMPS; - LEAVE; - perl_unlock(); + result = PERL_GET_STACK_EXIT; mastodont_storage_cleanup(&storage); return result; diff --git a/src/base_page.c b/src/base_page.c index 5ff8d29..31ca2ff 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -72,12 +72,7 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session* ); } - // Init perl stack - perl_lock(); - dSP; - ENTER; - SAVETMPS; - PUSHMARK(SP); + PERL_STACK_INIT; if (page->session) mXPUSHs(newRV_inc((SV*)page->session)); @@ -94,19 +89,15 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session* else XPUSHs(&PL_sv_undef); // Run function - PUTBACK; - call_pv("base_page", G_SCALAR); - SPAGAIN; - - send_result(req, NULL, "text/html", POPp, 0); + PERL_STACK_SCALAR_CALL("base_page"); + char* dup = PERL_GET_STACK_EXIT; + + send_result(req, NULL, "text/html", dup, 0); - PUTBACK; - FREETMPS; - LEAVE; - perl_unlock(); mstdnt_cleanup_notifications(notifs, notifs_len); mastodont_storage_cleanup(&storage); + Safefree(dup); } void send_result(FCGX_Request* req, char* status, char* content_type, char* data, size_t data_len) diff --git a/src/conversations.c b/src/conversations.c index cbde683..f48a561 100644 --- a/src/conversations.c +++ b/src/conversations.c @@ -177,29 +177,18 @@ void content_chats(PATH_ARGS) mastodont_get_chats_v2(api, &m_args, &args, &storage, &chats, &chats_len); - perl_lock(); - dSP; - ENTER; - SAVETMPS; - PUSHMARK(SP); + PERL_STACK_INIT; HV* session_hv = perlify_session(ssn); XPUSHs(newRV_noinc((SV*)session_hv)); XPUSHs(newRV_noinc((SV*)template_files)); if (chats) XPUSHs(newRV_noinc((SV*)perlify_chats(chats, chats_len))); else ARG_UNDEFINED(); - // ARGS - PUTBACK; - call_pv("chat::content_chats", G_SCALAR); - SPAGAIN; + + PERL_STACK_SCALAR_CALL("chat::content_chats"); // Duplicate so we can free the TMPs - char* dup = savesharedsvpv(POPs); - - PUTBACK; - FREETMPS; - LEAVE; - perl_unlock(); + char* dup = PERL_GET_STACK_EXIT; struct base_page b = { .category = BASE_CAT_CHATS, @@ -240,11 +229,7 @@ void content_chat_view(PATH_ARGS) int chat_code = mastodont_get_chat(api, &m_args, data[0], &storage_chat, &chat); - perl_lock(); - dSP; - ENTER; - SAVETMPS; - PUSHMARK(SP); + PERL_STACK_INIT; HV* session_hv = perlify_session(ssn); XPUSHs(newRV_noinc((SV*)session_hv)); XPUSHs(newRV_noinc((SV*)template_files)); @@ -254,18 +239,11 @@ void content_chat_view(PATH_ARGS) if (messages) XPUSHs(newRV_noinc((SV*)perlify_messages(messages, messages_len))); else ARG_UNDEFINED(); - // ARGS - PUTBACK; - call_pv("chat::construct_chat", G_SCALAR); - SPAGAIN; + + PERL_STACK_SCALAR_CALL("chat::construct_chat"); // Duplicate so we can free the TMPs - char* dup = savesharedsvpv(POPs); - - PUTBACK; - FREETMPS; - LEAVE; - perl_unlock(); + char* dup = PERL_GET_STACK_EXIT; struct base_page b = { .category = BASE_CAT_CHATS, diff --git a/src/lists.c b/src/lists.c index e0e5d14..50503f0 100644 --- a/src/lists.c +++ b/src/lists.c @@ -55,29 +55,16 @@ void content_lists(PATH_ARGS) mastodont_get_lists(api, &m_args, &storage, &lists, &lists_len); - // Call perl - perl_lock(); - dSP; - ENTER; - SAVETMPS; - PUSHMARK(SP); - + PERL_STACK_INIT; HV* session_hv = perlify_session(ssn); XPUSHs(newRV_noinc((SV*)session_hv)); XPUSHs(newRV_noinc((SV*)template_files)); XPUSHs(newRV_noinc((SV*)perlify_lists(lists, lists_len))); - // ARGS - PUTBACK; - call_pv("lists::content_lists", G_SCALAR); - SPAGAIN; + PERL_STACK_SCALAR_CALL("lists::content_lists"); // Duplicate so we can free the TMPs - char* dup = savesharedsvpv(POPs); - PUTBACK; - FREETMPS; - LEAVE; - perl_unlock(); + char* dup = PERL_GET_STACK_EXIT; struct base_page b = { .category = BASE_CAT_LISTS, diff --git a/src/notifications.c b/src/notifications.c index db85bda..ce843a9 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -216,13 +216,7 @@ void content_notifications(PATH_ARGS) if (keystr(ssn->cookies.logged_in)) mastodont_get_notifications(api, &m_args, &args, &storage, ¬ifs, ¬ifs_len); - // Call perl - perl_lock(); - dSP; - ENTER; - SAVETMPS; - PUSHMARK(SP); - + PERL_STACK_INIT; HV* session_hv = perlify_session(ssn); XPUSHs(newRV_noinc((SV*)session_hv)); XPUSHs(newRV_noinc((SV*)template_files)); @@ -230,16 +224,10 @@ void content_notifications(PATH_ARGS) XPUSHs(newRV_noinc((SV*)perlify_notifications(notifs, notifs_len))); // ARGS - PUTBACK; - call_pv("notifications::content_notifications", G_SCALAR); - SPAGAIN; + PERL_STACK_SCALAR_CALL("notifications::content_notifications"); // Duplicate so we can free the TMPs - char* dup = savesharedsvpv(POPs); - PUTBACK; - FREETMPS; - LEAVE; - perl_unlock(); + char* dup = PERL_GET_STACK_EXIT; struct base_page b = { .category = BASE_CAT_NOTIFICATIONS, diff --git a/src/search.c b/src/search.c index 2700790..89a5f2b 100644 --- a/src/search.c +++ b/src/search.c @@ -85,28 +85,16 @@ void content_search_all(PATH_ARGS) mastodont_search(api, &m_args, keystr(ssn->query.query), &storage, &args, &results); - perl_lock(); - dSP; - ENTER; - SAVETMPS; - PUSHMARK(SP); + PERL_STACK_INIT; HV* session_hv = perlify_session(ssn); XPUSHs(newRV_noinc((SV*)session_hv)); XPUSHs(newRV_noinc((SV*)template_files)); XPUSHs(newRV_noinc((SV*)perlify_search_results(&results))); - // ARGS - PUTBACK; - call_pv("search::content_search", G_SCALAR); - SPAGAIN; + PERL_STACK_SCALAR_CALL("search::content_search"); // Duplicate so we can free the TMPs - char* dup = savesharedsvpv(POPs); - - PUTBACK; - FREETMPS; - LEAVE; - perl_unlock(); + char* dup = PERL_GET_STACK_EXIT; struct base_page b = { .category = BASE_CAT_NONE, diff --git a/src/timeline.c b/src/timeline.c index d326c91..2f57909 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -46,11 +46,7 @@ void content_timeline(FCGX_Request* req, int show_post_box, int fake_timeline) { - perl_lock(); - dSP; - ENTER; - SAVETMPS; - PUSHMARK(SP); + PERL_STACK_INIT; HV* session_hv = perlify_session(ssn); XPUSHs(newRV_noinc((SV*)session_hv)); XPUSHs(newRV_noinc((SV*)template_files)); @@ -66,17 +62,10 @@ void content_timeline(FCGX_Request* req, mXPUSHi(show_post_box); mXPUSHi(fake_timeline); - PUTBACK; - call_pv("timeline::content_timeline", G_SCALAR); - SPAGAIN; + PERL_STACK_SCALAR_CALL("timeline::content_timeline"); // Duplicate to free temps - char* dup = savesharedsvpv(POPs); - - PUTBACK; - FREETMPS; - LEAVE; - perl_unlock(); + char* dup = PERL_GET_STACK_EXIT; struct base_page b = { .category = cat,