Macro for perlifying arrays, fix perl runtime leak
FossilOrigin-Name: 59639b62f7ebed10373fe3aa5ac234a500c14dbf428996395eee43738f156936
This commit is contained in:
parent
7390326d2c
commit
f5d4a08d3b
15 changed files with 38 additions and 147 deletions
|
@ -489,19 +489,7 @@ void content_account_favourites(PATH_ARGS)
|
|||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_BOOKMARKS, "Favorites", 0, 1);
|
||||
}
|
||||
|
||||
AV* perlify_accounts(const struct mstdnt_account* accounts, size_t len)
|
||||
{
|
||||
if (!(accounts && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_account(accounts + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
PERLIFY_MULTI(account, accounts, mstdnt_account)
|
||||
|
||||
HV* perlify_account(const struct mstdnt_account* acct)
|
||||
{
|
||||
|
|
|
@ -116,7 +116,7 @@ void cleanup_media_ids(struct session* ssn, char** media_ids)
|
|||
free(media_ids);
|
||||
}
|
||||
|
||||
HV* perlify_attachment(struct mstdnt_attachment* const attachment)
|
||||
HV* perlify_attachment(const struct mstdnt_attachment* const attachment)
|
||||
{
|
||||
if (!attachment) return NULL;
|
||||
HV* attach_hv = newHV();
|
||||
|
@ -131,19 +131,7 @@ HV* perlify_attachment(struct mstdnt_attachment* const attachment)
|
|||
return attach_hv;
|
||||
}
|
||||
|
||||
AV* perlify_attachments(struct mstdnt_attachment* const attachments, size_t len)
|
||||
{
|
||||
if (!(attachments && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_attachment(attachments + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
PERLIFY_MULTI(attachment, attachments, mstdnt_attachment)
|
||||
|
||||
void api_attachment_create(PATH_ARGS)
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ void cleanup_media_ids(struct session* ssn, char** media_ids);
|
|||
void api_attachment_create(PATH_ARGS);
|
||||
|
||||
// Perl
|
||||
HV* perlify_attachment(struct mstdnt_attachment* const attachment);
|
||||
AV* perlify_attachments(struct mstdnt_attachment* const attachments, size_t len);
|
||||
HV* perlify_attachment(const struct mstdnt_attachment* const attachment);
|
||||
AV* perlify_attachments(const struct mstdnt_attachment* const attachments, size_t len);
|
||||
|
||||
#endif // ATTACHMENTS_H
|
||||
|
|
|
@ -70,7 +70,7 @@ void content_chats(PATH_ARGS)
|
|||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
mstdnt_cleanup_chats(chats);
|
||||
mstdnt_cleanup_chats(chats, chats_len);
|
||||
Safefree(dup);
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,7 @@ void content_chat_view(PATH_ARGS)
|
|||
|
||||
mastodont_storage_cleanup(&storage);
|
||||
mastodont_storage_cleanup(&storage_chat);
|
||||
mstdnt_cleanup_chat(&chat);
|
||||
mstdnt_cleanup_messages(messages);
|
||||
Safefree(dup);
|
||||
}
|
||||
|
@ -141,19 +142,7 @@ HV* perlify_chat(const struct mstdnt_chat* chat)
|
|||
return chat_hv;
|
||||
}
|
||||
|
||||
AV* perlify_chats(const struct mstdnt_chat* chats, size_t len)
|
||||
{
|
||||
if (!(chats && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_chat(chats + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
PERLIFY_MULTI(chat, chats, mstdnt_chat)
|
||||
|
||||
HV* perlify_message(const struct mstdnt_message* message)
|
||||
{
|
||||
|
@ -171,17 +160,4 @@ HV* perlify_message(const struct mstdnt_message* message)
|
|||
return message_hv;
|
||||
}
|
||||
|
||||
AV* perlify_messages(const struct mstdnt_message* messages, size_t len)
|
||||
{
|
||||
if (!(messages && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_message(messages + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
|
||||
PERLIFY_MULTI(message, messages, mstdnt_message)
|
||||
|
|
15
src/emoji.c
15
src/emoji.c
|
@ -123,7 +123,7 @@ char* construct_emoji_picker(char* status_id, size_t* size)
|
|||
return dup;
|
||||
}
|
||||
|
||||
HV* perlify_emoji(struct mstdnt_emoji* const emoji)
|
||||
HV* perlify_emoji(const struct mstdnt_emoji* const emoji)
|
||||
{
|
||||
if (!emoji) return NULL;
|
||||
HV* emoji_hv = newHV();
|
||||
|
@ -135,16 +135,5 @@ HV* perlify_emoji(struct mstdnt_emoji* const emoji)
|
|||
return emoji_hv;
|
||||
}
|
||||
|
||||
AV* perlify_emojis(struct mstdnt_emoji* const emos, size_t len)
|
||||
{
|
||||
if (!(emos && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
PERLIFY_MULTI(emoji, emojis, mstdnt_emoji)
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_emoji(emos + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ void content_emoji_picker(PATH_ARGS);
|
|||
char* construct_emoji_picker(char* status_id, size_t* size);
|
||||
|
||||
// Perl
|
||||
HV* perlify_emoji(struct mstdnt_emoji* const emoji);
|
||||
AV* perlify_emojis(struct mstdnt_emoji* const emos, size_t len);
|
||||
HV* perlify_emoji(const struct mstdnt_emoji* const emoji);
|
||||
AV* perlify_emojis(const struct mstdnt_emoji* const emos, size_t len);
|
||||
|
||||
#endif // EMOJI_H
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <stdlib.h>
|
||||
#include "easprintf.h"
|
||||
|
||||
HV* perlify_emoji_reaction(struct mstdnt_emoji_reaction* const emoji)
|
||||
HV* perlify_emoji_reaction(const struct mstdnt_emoji_reaction* const emoji)
|
||||
{
|
||||
if (!emoji) return NULL;
|
||||
HV* emoji_hv = newHV();
|
||||
|
@ -34,16 +34,5 @@ HV* perlify_emoji_reaction(struct mstdnt_emoji_reaction* const emoji)
|
|||
return emoji_hv;
|
||||
}
|
||||
|
||||
AV* perlify_emoji_reactions(struct mstdnt_emoji_reaction* const emos, size_t len)
|
||||
{
|
||||
if (!(emos && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
PERLIFY_MULTI(emoji_reaction, emoji_reactions, mstdnt_emoji_reaction)
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_emoji_reaction(emos + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "global_perl.h"
|
||||
|
||||
// Perl
|
||||
HV* perlify_emoji_reaction(struct mstdnt_emoji_reaction* const emoji);
|
||||
AV* perlify_emoji_reactions(struct mstdnt_emoji_reaction* const emos, size_t len);
|
||||
HV* perlify_emoji_reaction(const struct mstdnt_emoji_reaction* const emoji);
|
||||
AV* perlify_emoji_reactions(const struct mstdnt_emoji_reaction* const emos, size_t len);
|
||||
|
||||
#endif // EMOJI_REACTION_H
|
||||
|
|
|
@ -46,6 +46,17 @@
|
|||
LEAVE; \
|
||||
perl_unlock()
|
||||
|
||||
#define PERLIFY_MULTI(type, types, mstype) AV* perlify_##types(const struct mstype* const types, size_t len) { \
|
||||
if (!(types && len)) return NULL; \
|
||||
AV* av = newAV(); \
|
||||
av_extend(av, len-1); \
|
||||
for (size_t i = 0; i < len; ++i) \
|
||||
av_store(av, i, newRV_noinc((SV*)perlify_##type(types + i))); \
|
||||
return av; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern PerlInterpreter* my_perl;
|
||||
extern HV* template_files;
|
||||
extern pthread_mutex_t perllock_mutex;
|
||||
|
|
13
src/lists.c
13
src/lists.c
|
@ -115,16 +115,5 @@ HV* perlify_list(const struct mstdnt_list* list)
|
|||
return list_hv;
|
||||
}
|
||||
|
||||
AV* perlify_lists(const struct mstdnt_list* lists, size_t len)
|
||||
{
|
||||
if (!(lists && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
PERLIFY_MULTI(list, lists, mstdnt_list)
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_list(lists + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ static HV* perlify_notification_pleroma(struct mstdnt_notification_pleroma* noti
|
|||
|
||||
|
||||
// Converts it into a perl struct
|
||||
HV* perlify_notification(struct mstdnt_notification* notif)
|
||||
HV* perlify_notification(const struct mstdnt_notification* const notif)
|
||||
{
|
||||
if (!notif) return NULL;
|
||||
HV* notif_hv = newHV();
|
||||
|
@ -197,20 +197,7 @@ HV* perlify_notification(struct mstdnt_notification* notif)
|
|||
return notif_hv;
|
||||
}
|
||||
|
||||
// The same as above, but for multiple
|
||||
AV* perlify_notifications(struct mstdnt_notification* notifs, size_t len)
|
||||
{
|
||||
if (!(notifs && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_notification(notifs + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
PERLIFY_MULTI(notification, notifications, mstdnt_notification)
|
||||
|
||||
void api_notifications(PATH_ARGS)
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ void content_notifications_read(PATH_ARGS);
|
|||
|
||||
void api_notifications(PATH_ARGS);
|
||||
|
||||
HV* perlify_notification(struct mstdnt_notification* notif);
|
||||
AV* perlify_notifications(struct mstdnt_notification* notif, size_t len);
|
||||
HV* perlify_notification(const struct mstdnt_notification* const notif);
|
||||
AV* perlify_notifications(const struct mstdnt_notification* const notif, size_t len);
|
||||
|
||||
#endif // NOTIFICATION_H
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "account.h"
|
||||
|
||||
// Converts it into a perl struct
|
||||
HV* perlify_scrobble(struct mstdnt_scrobble* scrobble)
|
||||
HV* perlify_scrobble(const struct mstdnt_scrobble* const scrobble)
|
||||
{
|
||||
if (!scrobble) return NULL;
|
||||
HV* scrobble_hv = newHV();
|
||||
|
@ -38,17 +38,4 @@ HV* perlify_scrobble(struct mstdnt_scrobble* scrobble)
|
|||
return scrobble_hv;
|
||||
}
|
||||
|
||||
// The same as above, but for multiple
|
||||
AV* perlify_scrobbles(struct mstdnt_scrobble* scrobble, size_t len)
|
||||
{
|
||||
if (!(scrobble && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_scrobble(scrobble + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
PERLIFY_MULTI(scrobble, scrobbles, mstdnt_scrobble)
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <mastodont.h>
|
||||
#include "global_perl.h"
|
||||
|
||||
HV* perlify_scrobble(struct mstdnt_scrobble* scrobble);
|
||||
AV* perlify_scrobbles(struct mstdnt_scrobble* scrobble, size_t len);
|
||||
HV* perlify_scrobble(const struct mstdnt_scrobble* const scrobble);
|
||||
AV* perlify_scrobbles(const struct mstdnt_scrobble* const scrobble, size_t len);
|
||||
|
||||
#endif /* SCROBBLE_H */
|
||||
|
|
15
src/status.c
15
src/status.c
|
@ -470,17 +470,4 @@ HV* perlify_status(const struct mstdnt_status* status)
|
|||
return status_hv;
|
||||
}
|
||||
|
||||
|
||||
AV* perlify_statuses(const struct mstdnt_status* statuses, size_t len)
|
||||
{
|
||||
if (!(statuses && len)) return NULL;
|
||||
AV* av = newAV();
|
||||
av_extend(av, len-1);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
av_store(av, i, newRV_inc((SV*)perlify_status(statuses + i)));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
PERLIFY_MULTI(status, statuses, mstdnt_status)
|
||||
|
|
Loading…
Reference in a new issue