You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2009/09/21 20:35:46 UTC
svn commit: r817364 - in /lucene/lucy/trunk/perl/xs: XSBind.c XSBind.h
Author: marvin
Date: Mon Sep 21 18:35:46 2009
New Revision: 817364
URL: http://svn.apache.org/viewvc?rev=817364&view=rev
Log:
Add code to enable overloading in Perl bindings for classes such as Err.
Modified:
lucene/lucy/trunk/perl/xs/XSBind.c
lucene/lucy/trunk/perl/xs/XSBind.h
Modified: lucene/lucy/trunk/perl/xs/XSBind.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/xs/XSBind.c?rev=817364&r1=817363&r2=817364&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/xs/XSBind.c (original)
+++ lucene/lucy/trunk/perl/xs/XSBind.c Mon Sep 21 18:35:46 2009
@@ -294,6 +294,39 @@
}
void
+XSBind_enable_overload(void *pobj)
+{
+ SV *perl_obj = (SV*)pobj;
+ HV *stash = SvSTASH(SvRV(perl_obj));
+ char *package_name = HvNAME(stash);
+ size_t size = strlen(package_name);
+
+ /* This code is informed by the following snippet from Perl_sv_bless, from
+ * sv.c:
+ *
+ * if (Gv_AMG(stash))
+ * SvAMAGIC_on(sv);
+ * else
+ * (void)SvAMAGIC_off(sv);
+ *
+ * Gv_AMupdate is undocumented. It is extracted from the Gv_AMG macro,
+ * also undocumented, defined in sv.h:
+ *
+ * #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
+ *
+ * The purpose of the code is to turn on overloading for the class in
+ * question. It seems that as soon as overloading is on for any class,
+ * anywhere, that PL_amagic_generation goes positive and stays positive,
+ * so that Gv_AMupdate gets called with every bless() invocation. Since
+ * we need overloading for Doc and all its subclasses, we skip the check
+ * and just update every time.
+ */
+ stash = gv_stashpvn((char*)package_name, size, true);
+ Gv_AMupdate(stash);
+ SvAMAGIC_on(perl_obj);
+}
+
+void
XSBind_allot_params(SV** stack, chy_i32_t start, chy_i32_t num_stack_elems,
char* params_hash_name, ...)
{
Modified: lucene/lucy/trunk/perl/xs/XSBind.h
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/xs/XSBind.h?rev=817364&r1=817363&r2=817364&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/xs/XSBind.h (original)
+++ lucene/lucy/trunk/perl/xs/XSBind.h Mon Sep 21 18:35:46 2009
@@ -111,6 +111,11 @@
SV*
lucy_XSBind_cb_to_sv(const lucy_CharBuf *cb);
+/** Turn on overloading for the supplied Perl object and its class.
+ */
+void
+lucy_XSBind_enable_overload(void *pobj);
+
/** Process hash-style params passed to an XS subroutine. The varargs must
* come batched in groups of three: an SV**, the name of the parameter, and
* length of the paramter name. A NULL pointer terminates the list: