From 682f6e0813c297fc221be5dcb190df69606eec4b Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 12 Oct 2022 19:30:55 +0000 Subject: [PATCH] Undef in main FossilOrigin-Name: bad68ecf59eb93817413d54d47c7ca5a5bdb6b36dba0c9163dc7299b26c31f7a --- Makefile | 4 ++-- perl/main.pl | 7 +++++-- src/about.c | 6 +++--- src/base_page.c | 19 +++++++------------ src/global_perl.h | 10 +++++----- src/notifications.c | 8 ++++---- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index bee0cf0..df99da1 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ CC ?= cc GIT ?= git MASTODONT_DIR = mastodont-c/ MASTODONT = $(MASTODONT_DIR)libmastodont.a -CFLAGS += -Wall -I $(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-ignored-qualifiers -I/usr/include/ -I $(MASTODONT_DIR)/libs $(shell pkg-config --cflags libcurl libpcre2-8) `perl -MExtUtils::Embed -e ccopts` -LDFLAGS += -L$(MASTODONT_DIR) -lmastodont $(shell pkg-config --libs libcurl libpcre2-8) -lfcgi -lpthread `perl -MExtUtils::Embed -e ldopts` +CFLAGS += -Wall -I $(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-ignored-qualifiers -I/usr/include/ -I $(MASTODONT_DIR)/libs $(shell pkg-config --cflags libcurl libpcre2-8) `perl -MExtUtils::Embed -e ccopts` -DDEBUGGING_MSTATS +LDFLAGS += -L$(MASTODONT_DIR) -lmastodont $(shell pkg-config --libs libcurl libpcre2-8) -lfcgi -lpthread `perl -MExtUtils::Embed -e ldopts` -DDEBUGGING_MSTATS SRC = $(wildcard src/*.c) OBJ = $(patsubst %.c,%.o,$(SRC)) HEADERS = $(wildcard src/*.h) config.h diff --git a/perl/main.pl b/perl/main.pl index 66a3468..db7e643 100644 --- a/perl/main.pl +++ b/perl/main.pl @@ -47,6 +47,9 @@ sub base_page notification => \&generate_notification, ); - to_template(\%vars, \$data->{'main.tt'}); + my $ret = to_template(\%vars, \$data->{'main.tt'}); + undef($notifs); + undef($main); + undef($ssn); + return $ret; } - diff --git a/src/about.c b/src/about.c index 79228c8..e522f2c 100644 --- a/src/about.c +++ b/src/about.c @@ -25,10 +25,9 @@ void content_about(PATH_ARGS) PERL_STACK_INIT; HV* session_hv = perlify_session(ssn); XPUSHs(newRV_noinc((SV*)session_hv)); - XPUSHs(newRV_noinc((SV*)template_files)); + XPUSHs(newRV_inc((SV*)template_files)); PERL_STACK_SCALAR_CALL("meta::about"); - char* dup = PERL_GET_STACK_EXIT; struct base_page b = { @@ -39,7 +38,8 @@ void content_about(PATH_ARGS) }; render_base_page(&b, req, ssn, api); - Safefree(dup); + free(dup); +// sv_free(session_hv); } diff --git a/src/base_page.c b/src/base_page.c index 9af03e2..494493b 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -84,26 +84,21 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session* } else ARG_UNDEFINED(); - SvREFCNT_dec(pl_notifs_rv); - SvREFCNT_dec(pl_notifs); - SvREFCNT_dec(content); - SvREFCNT_dec(real_ssn); - - av_undef(pl_notifs); - sv_set_undef(pl_notifs_rv); - sv_set_undef(real_ssn); - sv_set_undef(content); - // Run function PERL_STACK_SCALAR_CALL("base_page"); char* dup = PERL_GET_STACK_EXIT; send_result(req, NULL, "text/html", dup, 0); - free(page->content); + /* av_clear(pl_notifs); */ + /* av_undef(pl_notifs); */ + /* sv_free(pl_notifs_rv); */ + //hv_undef(real_ssn); + //sv_free(content); + mstdnt_cleanup_notifications(notifs, notifs_len); mastodont_storage_cleanup(&storage); - Safefree(dup); + free(dup); } void send_result(FCGX_Request* req, char* status, char* content_type, char* data, size_t data_len) diff --git a/src/global_perl.h b/src/global_perl.h index d30fe98..7c23ad6 100644 --- a/src/global_perl.h +++ b/src/global_perl.h @@ -23,9 +23,9 @@ #include // hv_stores(ssn_hv, "id", newSVpv(acct->id, 0)); -#define hvstores_str(hv, key, val) if (val) { hv_stores((hv), key, sv_2mortal(newSVpv((val), 0))); } -#define hvstores_int(hv, key, val) hv_stores((hv), key, sv_2mortal(newSViv((val)))) -#define hvstores_ref(hv, key, val) if (val) { hv_stores((hv), key, sv_2mortal(newRV_noinc((SV*)(val)))); } +#define hvstores_str(hv, key, val) if (val) { hv_stores((hv), key, Perl_newSVpv_share(aTHX_ (val), 0)); } +#define hvstores_int(hv, key, val) hv_stores((hv), key, newSViv((val))) +#define hvstores_ref(hv, key, val) if (val) { hv_stores((hv), key, newRV_noinc((SV*)(val))); } /* Seeing all this shit littered in Treebird's code made me decide to write some macros */ #define PERL_STACK_INIT perl_lock(); \ @@ -49,8 +49,8 @@ if (!(types && len)) return NULL; \ AV* av = newAV(); \ for (size_t i = 0; i < len; ++i) \ - av_push(av, sv_2mortal(newRV_noinc((SV*)sv_2mortal(perlify_##type(types + i))))); \ - return sv_2mortal(av); \ + av_push(av, newRV_noinc((SV*)perlify_##type(types + i))); \ + return av; \ } diff --git a/src/notifications.c b/src/notifications.c index 42f685b..2cf923f 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -191,11 +191,11 @@ HV* perlify_notification(const struct mstdnt_notification* const notif) hvstores_int(notif_hv, "created_at", notif->created_at); hvstores_str(notif_hv, "emoji", notif->emoji); hvstores_str(notif_hv, "type", mstdnt_notification_t_to_str(notif->type)); - hvstores_ref(notif_hv, "account", sv_2mortal(perlify_account(notif->account))); - hvstores_ref(notif_hv, "pleroma", sv_2mortal(perlify_notification_pleroma(notif->pleroma))); -hvstores_ref(notif_hv, "status", sv_2mortal(perlify_status(notif->status))); + hvstores_ref(notif_hv, "account", perlify_account(notif->account)); + hvstores_ref(notif_hv, "pleroma", perlify_notification_pleroma(notif->pleroma)); + hvstores_ref(notif_hv, "status", perlify_status(notif->status)); - return (HV*)sv_2mortal((SV*)notif_hv); + return notif_hv; } PERLIFY_MULTI(notification, notifications, mstdnt_notification)