1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

add GString to Perl

This commit is contained in:
Ailin Nemui 2021-08-13 17:31:49 +02:00
parent 1602b506a6
commit 425178e793
2 changed files with 38 additions and 3 deletions

View File

@ -19,6 +19,8 @@ while (<>) {
s/GList \* of ([^,]*)s/glistptr_\1/g; s/GList \* of ([^,]*)s/glistptr_\1/g;
s/GSList of ([^,]*)s/gslist_\1/g; s/GSList of ([^,]*)s/gslist_\1/g;
s/GString \*[^,]*/gstring/g;
s/char \*[^,]*/string/g; s/char \*[^,]*/string/g;
s/ulong \*[^,]*/ulongptr/g; s/ulong \*[^,]*/ulongptr/g;
s/int \*[^,]*/intptr/g; s/int \*[^,]*/intptr/g;

View File

@ -86,6 +86,7 @@ void perl_signal_args_to_c(void (*callback)(void *, int, void **), void *cb_arg,
unsigned long v_ulong; unsigned long v_ulong;
GSList *v_gslist; GSList *v_gslist;
GList *v_glist; GList *v_glist;
GString *v_gstring;
} saved_args[SIGNAL_MAX_ARGUMENTS]; } saved_args[SIGNAL_MAX_ARGUMENTS];
AV *aargs; AV *aargs;
void *p[SIGNAL_MAX_ARGUMENTS]; void *p[SIGNAL_MAX_ARGUMENTS];
@ -146,6 +147,12 @@ void perl_signal_args_to_c(void (*callback)(void *, int, void **), void *cb_arg,
} else if (g_strcmp0(rec->args[n], "intptr") == 0) { } else if (g_strcmp0(rec->args[n], "intptr") == 0) {
saved_args[n].v_int = SvIV(SvRV(arg)); saved_args[n].v_int = SvIV(SvRV(arg));
c_arg = &saved_args[n].v_int; c_arg = &saved_args[n].v_int;
} else if (g_strcmp0(rec->args[n], "gstring") == 0) {
char *pv;
size_t len;
pv = SvPV(SvRV(arg), len);
c_arg = saved_args[n].v_gstring = g_string_new_len(pv, len);
} else if (strncmp(rec->args[n], "glistptr_", 9) == 0) { } else if (strncmp(rec->args[n], "glistptr_", 9) == 0) {
GList *gl; GList *gl;
int is_str; int is_str;
@ -220,6 +227,16 @@ void perl_signal_args_to_c(void (*callback)(void *, int, void **), void *cb_arg,
SV *t = SvRV(arg); SV *t = SvRV(arg);
SvIOK_only(t); SvIOK_only(t);
SvIV_set(t, saved_args[n].v_int); SvIV_set(t, saved_args[n].v_int);
} else if (g_strcmp0(rec->args[n], "gstring") == 0) {
GString *str;
SV *t;
str = saved_args[n].v_gstring;
t = SvRV(arg);
SvPOK_only(t);
sv_setpvn(t, str->str, str->len);
g_string_free(str, TRUE);
} else if (strncmp(rec->args[n], "gslist_", 7) == 0) { } else if (strncmp(rec->args[n], "gslist_", 7) == 0) {
g_slist_free(saved_args[n].v_gslist); g_slist_free(saved_args[n].v_gslist);
} else if (strncmp(rec->args[n], "glistptr_", 9) == 0) { } else if (strncmp(rec->args[n], "glistptr_", 9) == 0) {
@ -306,7 +323,10 @@ static void perl_call_signal(PERL_SCRIPT_REC *script, SV *func,
perlarg = newSViv(*(unsigned long *) arg); perlarg = newSViv(*(unsigned long *) arg);
else if (g_strcmp0(rec->args[n], "intptr") == 0) else if (g_strcmp0(rec->args[n], "intptr") == 0)
saved_args[n] = perlarg = newRV_noinc(newSViv(*(int *) arg)); saved_args[n] = perlarg = newRV_noinc(newSViv(*(int *) arg));
else if (g_strcmp0(rec->args[n], "formatnum_args") == 0 && n >= 3) { else if (g_strcmp0(rec->args[n], "gstring") == 0) {
GString *str = arg;
saved_args[n] = perlarg = newRV_noinc(newSVpvn(str->str, str->len));
} else if (g_strcmp0(rec->args[n], "formatnum_args") == 0 && n >= 3) {
const THEME_REC *theme; const THEME_REC *theme;
const MODULE_THEME_REC *rec; const MODULE_THEME_REC *rec;
const FORMAT_REC *formats; const FORMAT_REC *formats;
@ -415,6 +435,19 @@ static void perl_call_signal(PERL_SCRIPT_REC *script, SV *func,
if (g_strcmp0(rec->args[n], "intptr") == 0) { if (g_strcmp0(rec->args[n], "intptr") == 0) {
int *val = arg; int *val = arg;
*val = SvIV(SvRV(saved_args[n])); *val = SvIV(SvRV(saved_args[n]));
} else if (g_strcmp0(rec->args[n], "gstring") == 0) {
SV *os, *ns;
GString *str = arg;
os = sv_2mortal(newSVpvn(str->str, str->len));
ns = SvRV(saved_args[n]);
if (sv_cmp(os, ns) != 0) {
size_t len;
char *pv = SvPV(ns, len);
g_string_truncate(str, 0);
g_string_append_len(str, pv, len);
}
} else if (strncmp(rec->args[n], "glistptr_", 9) == 0) { } else if (strncmp(rec->args[n], "glistptr_", 9) == 0) {
GList **ret = arg; GList **ret = arg;
GList *out = NULL; GList *out = NULL;