pyperl patch

James Gregory <[email protected]> Mon, 08 Sep 2003 15:59:14 +1000
Newsgroups gmane.comp.web.zope.perl
Message-ID <[email protected]>
--=-Q0IkhRt00hSlYGkhuFp5
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi all,

I've recently spent some time tinkering with the pyperl code base in
order to get it to build and run on my Mandrake Cooker system running
perl-5.8.1-0.RC4.1mdk and python-2.3-2mdk. The patch probably needs a
bit of work before being rolled into the base line (I was sure that I
just needed to define PERL_CORE and it would all work, but it seemed to
resist my attempts to do this. Fortunately it was only 4 or so #defines
missing, so it's not too bad). One positive result of my patch is that
the dlhack.c file now has some slightly better error reporting (it only
attempts to dlopen files that exist, and uses dlerror in the message
returned to python rather than the generic "perl2.so does not exist").

Enough rambling. The patch is attached. Hopefully someone will find this
helpful.

James.


--=-Q0IkhRt00hSlYGkhuFp5
Content-Disposition: attachment; filename=pyperl-perl581-compile.patch
Content-Type: text/x-patch; name=pyperl-perl581-compile.patch;
	charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

diff -ruN pyperl-1.0.1/dlhack.c pyperl-1.0.1-patched/dlhack.c
--- pyperl-1.0.1/dlhack.c	2001-03-07 06:36:16.000000000 +1100
+++ pyperl-1.0.1-patched/dlhack.c	2003-09-05 17:12:12.000000000 +1000
@@ -1,50 +1,71 @@
 #include <Python.h>
 #include <dlfcn.h>
 
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
 /* This is a fake perl module that will look for the real thing ('perl2.so')
  * in sys.path and then load this one with the RTLD_GLOBAL set in order to
  * make the symbols available for extension modules that perl might load.
  */
 
-extern void initperl()
-{
+extern void initperl() {
     void* handle;
+	char *error, *tmp;
     int i, npath, len;
     char buf[1024];
+    int buflen = 1024;
 
     PyObject *path = PySys_GetObject("path");
     if (path == NULL || !PyList_Check(path)) {
-	PyErr_SetString(PyExc_ImportError,
-			"sys.path must be a list of directory names");
-	return;
+		PyErr_SetString(PyExc_ImportError, "sys.path must be a list of directory names");
+		return;
     }
 
     npath = PyList_Size(path);
-    for (i = 0; i < npath; i++) {
-	PyObject *v = PyList_GetItem(path, i);
-	if (!PyString_Check(v))
-	    continue;
-	len = PyString_Size(v);
-	if (len + 10 >= sizeof(buf))
-	    continue; /* Too long */
-	strcpy(buf, PyString_AsString(v));
-	if (buf[0] != '/')
-	    continue; /* Not absolute */
-	if (strlen(buf) != len)
-	    continue; /* v contains '\0' */
-	strcpy(buf+len, "/perl2.so");
-
-	handle = dlopen(buf, RTLD_NOW | RTLD_GLOBAL);
-	if (handle) {
-	    void (*f)() = dlsym(handle, "initperl2");
-	    if (f) {
-		f();
-	    }
-	    else {
-		PyErr_SetString(PyExc_ImportError, "initperl2 entry point not found");
-	    }
-	    return;
+
+	for (i = 0; i < npath; i++) {
+		PyObject *v = PyList_GetItem(path, i);
+		if (!PyString_Check(v)) continue;
+
+		len = PyString_Size(v);
+		if (len + 10 >= sizeof(buf)) {
+			continue; /* Too long */
+		}
+
+		strcpy(buf, PyString_AsString(v));
+		if (buf[0] != '/') {
+			continue; /* Not absolute */
+		}
+
+		if (strlen(buf) != len) {
+			continue; /* v contains '\0' */
+		}
+
+		strcpy(buf+len, "/perl2.so");
+
+		/* only bother with dlopen()ing files that exist. 0 is success. */
+		if (*buf && access (buf, F_OK | R_OK) == 0) {
+			handle = dlopen(buf, RTLD_NOW | RTLD_GLOBAL);
+			error = dlerror();
+			if (!error && handle) {
+				void (*f)() = dlsym(handle, "initperl2");
+				if (f) {
+					f();
+				} else {
+					PyErr_SetString(PyExc_ImportError, "initperl2 entry point not found");
+				}
+				return;
+			}
+		}
 	}
+
+	/* If we get to here, the return in the previous block was never reached.
+	 * We must have a "terminal" error. */
+    if (error != NULL) {
+		PyErr_SetString(PyExc_ImportError, error);
+    } else {
+		PyErr_SetString(PyExc_ImportError, "perl2.so not found");
     }
-    PyErr_SetString(PyExc_ImportError, "perl2.so not found");
 }
diff -ruN pyperl-1.0.1/Python-Object/Object.xs pyperl-1.0.1-patched/Python-Object/Object.xs
--- pyperl-1.0.1/Python-Object/Object.xs	2001-03-07 06:36:16.000000000 +1100
+++ pyperl-1.0.1-patched/Python-Object/Object.xs	2003-09-04 19:55:50.000000000 +1000
@@ -12,6 +12,11 @@
 #include "../thrd_ctx.h"
 #include "../pyo.h"
 
+#define SvOK_off(sv)            (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC|    \
+                                                  SVf_IVisUV|SVf_UTF8), \
+                                                        SvOOK_off(sv))
+
+
 /* so we can use different typemaps for borrowed/owned obj refs */
 typedef PyObject NewPyObject;
 typedef PyObject NewPyObjectX;
diff -ruN pyperl-1.0.1/svrv_object.c pyperl-1.0.1-patched/svrv_object.c
--- pyperl-1.0.1/svrv_object.c	2001-03-07 06:36:16.000000000 +1100
+++ pyperl-1.0.1-patched/svrv_object.c	2003-09-08 15:15:22.000000000 +1000
@@ -492,7 +492,7 @@
     
     diff = newlen - len;
     if (newlen && !AvREAL(av) && AvREIFY(av))
-	av_reify(av);
+	Perl_av_reify(PERL_GET_THX, av);
 
 #ifdef SPLICE_DEBUG
     printf("splice(offset=%d, len=%d, diff=%d, after=%d, fill=%d, max=%d, pre=%d)\n",
diff -ruN pyperl-1.0.1/try_perlapi.pl pyperl-1.0.1-patched/try_perlapi.pl
--- pyperl-1.0.1/try_perlapi.pl	2001-03-07 06:36:16.000000000 +1100
+++ pyperl-1.0.1-patched/try_perlapi.pl	2003-09-08 15:12:11.000000000 +1000
@@ -16,6 +16,8 @@
 
 print C <<EOT;
 
+#define cxinc()           Perl_cxinc(PERL_GET_THX)
+
 #include <EXTERN.h>
 #include <perl.h>
 #include <Python.h>
@@ -50,7 +52,7 @@
     ENTER;
     SAVETMPS;
 
-    push_return(Nullop);
+    Perl_push_return(PERL_GET_THX, Nullop);
     PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), PL_stack_sp);
     PUSHEVAL(cx, 0, 0);
     PL_eval_root = PL_op;
@@ -71,7 +73,7 @@
 
         POPBLOCK(cx,newpm);
         POPEVAL(cx);
-        pop_return();
+        Perl_pop_return(PERL_GET_THX);
         PL_curpm = newpm;
     }
 

--=-Q0IkhRt00hSlYGkhuFp5
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Zope-perl maillist  -  [email protected]
http://mail.zope.org/mailman/listinfo/zope-perl

--=-Q0IkhRt00hSlYGkhuFp5--