>From d2e9366a75241f9b4bdda1e383985d4c4db6b61a Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Sat, 30 Aug 2025 19:44:21 +0100
Subject: [PATCH] perl: Use the modglobal interpreter slot for context data

The Xpv slot was obsolete and removed in Perl 5.41.3:

  https://github.com/Perl/perl5/commit/079a9d4ad36ef1a5b3d792b63137d406168df0e9

Use the Perl hash in the modglobal slot instead. From the perlapi
document:

  "PL_modglobal" is a general purpose, interpreter global HV for use by
  extensions that need to keep information on a per-interpreter basis.
  In a pinch, it can also be used as a symbol table for extensions to
  share data among each other.  It is a good idea to use keys prefixed
  by the package name of the extension that owns the data.

  On threaded perls, each thread has an independent copy of this variable;
  each initialized at creation time with the current value of the creating
  thread's copy.

Bug-Debian: https://bugs.debian.org/1112517
---
 libfungwbind/perl/fungw_perl.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libfungwbind/perl/fungw_perl.c b/libfungwbind/perl/fungw_perl.c
index a8580bc..66f6626 100644
--- a/libfungwbind/perl/fungw_perl.c
+++ b/libfungwbind/perl/fungw_perl.c
@@ -32,7 +32,8 @@
    struct, but in return the init function can't create variables or
    in the interpreter before parsing a script; this workaround abuses
    an unused field (as of perl 5.26.2). */
-#define perl_user_data IXpv
+#define perl_user_data_hash Imodglobal
+#define perl_user_data_key "fungw::_context"
 
 typedef struct {
 	PerlInterpreter *interp;
@@ -93,7 +94,8 @@ static SV *fgws_perl_arg2sv(fgw_ctx_t *fctx, perl_ctx_t *ctx, fgw_arg_t *arg)
 /* API: the script is calling an fgw function */
 static XS(fgws_perl_call_fgw)
 {
-	perl_ctx_t *ctx = (perl_ctx_t *)my_perl->perl_user_data;
+	SV **svp = hv_fetchs(my_perl->perl_user_data_hash, perl_user_data_key, 0);
+	perl_ctx_t *ctx = INT2PTR(perl_ctx_t *, SvIV(*svp));
 	fgw_func_t *func;
 	GV *gv;
 	SV *func_name_sv;
@@ -237,7 +239,8 @@ static XS(fgws_perl_func_reg)
 {
 	dXSARGS;
 	const char *name;
-	perl_ctx_t *ctx = (perl_ctx_t *)my_perl->perl_user_data;
+	SV **svp = hv_fetchs(my_perl->perl_user_data_hash, perl_user_data_key, 0);
+	perl_ctx_t *ctx = INT2PTR(perl_ctx_t *, SvIV(*svp));
 	fgw_func_t *func;
 
 	SP -= items;
@@ -283,7 +286,7 @@ static int fgws_perl_init(fgw_obj_t *obj, const char *filename, const char *opts
 	PERL_SET_CONTEXT(ctx->interp);
 	perl_construct(ctx->interp);
 	obj->script_data = ctx;
-	ctx->interp->perl_user_data = (void *)ctx;
+	hv_stores(ctx->interp->perl_user_data_hash, perl_user_data_key, newSViv(PTR2IV(ctx)));
 	ctx->obj = obj;
 	ctx->freg_delay = 1;
 
-- 
2.49.0

