[libinline-python-perl] 01/05: Imported Upstream version 0.48

Tony Mancill tmancill at moszumanska.debian.org
Fri Apr 10 05:56:29 UTC 2015


This is an automated email from the git hooks/post-receive script.

tmancill pushed a commit to branch master
in repository libinline-python-perl.

commit 6e3406d78e6c22af9228f1a45cd3cd89e5961cbb
Author: tony mancill <tmancill at debian.org>
Date:   Thu Apr 9 21:41:55 2015 -0700

    Imported Upstream version 0.48
---
 Changes         |  8 ++++++++
 MANIFEST        |  1 +
 META.json       |  4 ++--
 META.yml        |  4 ++--
 Python.pm       |  2 +-
 Python.pod      |  8 ++++----
 Python.xs       |  4 ++++
 perlmodule.c    | 14 ++++++++++----
 py2pl.c         | 47 +++++++++++++++++++++++++++++++----------------
 py2pl.h         |  1 +
 t/02testpl.t    |  4 ++--
 t/28exception.t | 28 +++++++++++++++++++++++++++-
 t/32boolean.t   | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 t/33reinit.t    | 10 ++++++++++
 14 files changed, 151 insertions(+), 32 deletions(-)

diff --git a/Changes b/Changes
index 385bea0..de6de1c 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,13 @@
 Revision history for Perl extension Inline::Python.
 
+0.48 Sat  Jan 24 10:00:00 CET 2015 (Stefan Seifert)
+	- Fix compatibility with perl < 5.14
+	- Allow shutting down Python
+
+0.47 Thu  Jan 22 19:35:00 CET 2015 (Stefan Seifert)
+	- Translate Perl exceptions into Python exceptions and make them catchable.
+	- fix some POD errors by Gregor Herrmann
+
 0.46 Sun  Dec 07 12:30:00 CET 2014 (Stefan Seifert)
 	- Python 3 support by Laurent Mazuel!
 	- Correcting KeyError to AttributeError in __getattr__ by Laurent Mazuel
diff --git a/MANIFEST b/MANIFEST
index 480e901..39a67cc 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -44,6 +44,7 @@ t/29named_params.t
 t/30floats.t
 t/31stringification.t
 t/32boolean.t
+t/33reinit.t
 t/cmp.t
 TESTED
 ToDo
diff --git a/META.json b/META.json
index 66f9cb4..629a4e1 100644
--- a/META.json
+++ b/META.json
@@ -4,7 +4,7 @@
       "Neil Watkiss <NEILW at cpan.org>"
    ],
    "dynamic_config" : 1,
-   "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142690",
+   "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.143240",
    "license" : [
       "perl_5"
    ],
@@ -48,5 +48,5 @@
          "web" : "http://github.com/niner/inline-python-pm"
       }
    },
-   "version" : "0.46"
+   "version" : "0.48"
 }
diff --git a/META.yml b/META.yml
index 3dfe4a4..ce5ed0a 100644
--- a/META.yml
+++ b/META.yml
@@ -7,7 +7,7 @@ build_requires:
 configure_requires:
   ExtUtils::MakeMaker: '0'
 dynamic_config: 1
-generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142690'
+generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.143240'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -25,4 +25,4 @@ requires:
   Test::More: '0'
 resources:
   repository: http://github.com/niner/inline-python-pm.git
-version: '0.46'
+version: '0.48'
diff --git a/Python.pm b/Python.pm
index 9ad7ff5..0a46a4c 100644
--- a/Python.pm
+++ b/Python.pm
@@ -6,7 +6,7 @@ require DynaLoader;
 require Exporter;
 use vars qw(@ISA $VERSION @EXPORT_OK);
 @ISA = qw(Inline DynaLoader Exporter);
-$VERSION = '0.46';
+$VERSION = '0.48';
 @EXPORT_OK = qw(py_eval
 		py_new_object
 		py_call_method 
diff --git a/Python.pod b/Python.pod
index c2359f0..c3c288a 100644
--- a/Python.pod
+++ b/Python.pod
@@ -481,18 +481,18 @@ to the result.
 
 =over 4
 
-=item 0
+=item Z<>0
 
 Accepts only expressions. Complete statements yield a syntax error. An
 expression is anything that can appear to the right of an '=' sign. Returns
 the value of the expression.
 
-=item 1
+=item Z<>1
 
 The default. Accepts arbitrarily long input, which may be any valid Python 
 code. Always returns C<undef>.
 
-=item 2
+=item Z<>2
 
 Accepts exactly one statement, and prints the result to STDOUT. This is
 how Python works in interactive mode. Always returns C<undef>.
@@ -757,7 +757,7 @@ https://docs.python.org/3/howto/pyporting.html
 For Perl integration:
 
  - Non-utf8-flagged Perl strings will be Python bytes, utf8-flagged Perl strings will be Python string
- - __cmp__ is no more supported in Python 3 and has been replaced by "rich comparison" (i.e. __eq__, __le__, etc.�. 
+ - __cmp__ is no more supported in Python 3 and has been replaced by "rich comparison" (i.e. __eq__, __le__, etc.).
 Since booleans in Perl are integers, renaming __cmp__ to __eq__ is often enough while wrapping a Perl object in Python.
  - perl.require, perl.use and perl.eval accept either bytes or strings.
 
diff --git a/Python.xs b/Python.xs
index b391e06..3f9bc4a 100644
--- a/Python.xs
+++ b/Python.xs
@@ -74,6 +74,10 @@ do_pyinit();
 
 PROTOTYPES: DISABLE
 
+void py_initialize()
+  CODE:
+    do_pyinit();
+
 void
 py_study_package(PYPKG="__main__")
     char*   PYPKG
diff --git a/perlmodule.c b/perlmodule.c
index 2059689..909d39b 100644
--- a/perlmodule.c
+++ b/perlmodule.c
@@ -716,12 +716,12 @@ PerlSub_call(PerlSub_object *self, PyObject *args, PyObject *kw) {
     Py_INCREF(self);
 
     if (self->ref)
-        count = perl_call_sv(self->ref, self->flgs);
+        count = perl_call_sv(self->ref, self->flgs | G_EVAL);
     else if (self->sub && self->obj)
 #if PY_MAJOR_VERSION >= 3
-        count = perl_call_method(PyBytes_AsString(self->sub), self->flgs);
+        count = perl_call_method(PyBytes_AsString(self->sub), self->flgs | G_EVAL);
 #else
-        count = perl_call_method(PyString_AsString(self->sub), self->flgs);
+        count = perl_call_method(PyString_AsString(self->sub), self->flgs | G_EVAL);
 #endif
     else {
         croak("Error: PerlSub called, but no C function, sub, or name found!\n");
@@ -732,7 +732,10 @@ PerlSub_call(PerlSub_object *self, PyObject *args, PyObject *kw) {
 
 
     if (SvTRUE(ERRSV)) {
-        warn("%s\n", SvPV_nolen(ERRSV));
+        PyObject *exc = Pl2Py(ERRSV);
+        PyErr_SetObject(PyExc_Perl, exc);
+        ERRSV = NULL;
+        return NULL;
     }
 
     /* what to return? */
@@ -1085,6 +1088,8 @@ create_perl()
 }
 #endif
 
+PyObject *PyExc_Perl;
+
 void
 initperl(void){
     PyObject *m, *d, *p;
@@ -1145,6 +1150,7 @@ initperl(void){
 #ifdef CREATE_PERL
     create_perl();
 #endif
+    PyExc_Perl = PyErr_NewException("perl.Exception", NULL, NULL);
 
     Py_DECREF(dummy1);
     Py_DECREF(dummy2);
diff --git a/py2pl.c b/py2pl.c
index 00cda8d..d1b5217 100644
--- a/py2pl.c
+++ b/py2pl.c
@@ -541,33 +541,48 @@ PyObject *Pl2Py(SV * const obj) {
 void
 croak_python_exception() {
     PyObject *ex_type, *ex_value, *ex_traceback;
-    PyErr_Fetch(&ex_type, &ex_value, &ex_traceback);
-    PyErr_NormalizeException(&ex_type, &ex_value, &ex_traceback);
+    if (PyErr_ExceptionMatches(PyExc_Perl)) {
+        PyErr_Fetch(&ex_type, &ex_value, &ex_traceback);
+        PyErr_NormalizeException(&ex_type, &ex_value, &ex_traceback);
+        PyObject *perl_exception_args = PyObject_GetAttrString(ex_value, "args");
+        PyObject *perl_exception = PySequence_GetItem(perl_exception_args, 0);
+        SV *perl_exception_object = Py2Pl(perl_exception);
+        sv_2mortal(perl_exception_object);
+        SV *errsv = get_sv("@", GV_ADD);
+        sv_setsv(errsv, perl_exception_object);
+        croak(NULL);
+        Py_DECREF(perl_exception);
+        Py_DECREF(perl_exception_args);
+    }
+    else {
+        PyErr_Fetch(&ex_type, &ex_value, &ex_traceback);
+        PyErr_NormalizeException(&ex_type, &ex_value, &ex_traceback);
 
-    PyObject * const ex_message = PyObject_Str(ex_value);    /* new reference */
+        PyObject * const ex_message = PyObject_Str(ex_value);    /* new reference */
 
 #if PY_MAJOR_VERSION >= 3
-    PyObject * const ex_message_bytes = PyUnicode_AsUTF8String(ex_message);    /* new reference */
-    char * const c_ex_message = PyBytes_AsString(ex_message_bytes);
+        PyObject * const ex_message_bytes = PyUnicode_AsUTF8String(ex_message);    /* new reference */
+        char * const c_ex_message = PyBytes_AsString(ex_message_bytes);
 #else
-    char * const c_ex_message = PyString_AsString(ex_message);
+        char * const c_ex_message = PyString_AsString(ex_message);
 #endif
 
-    if (ex_traceback) {
-        PyObject * const tb_lineno = PyObject_GetAttrString(ex_traceback, "tb_lineno");
+        if (ex_traceback) {
+            PyObject * const tb_lineno = PyObject_GetAttrString(ex_traceback, "tb_lineno");
 
-        croak("%s: %s at line %i\n", ((PyTypeObject *)ex_type)->tp_name, c_ex_message, PyInt_AsLong(tb_lineno));
+            croak("%s: %s at line %i\n", ((PyTypeObject *)ex_type)->tp_name, c_ex_message, PyInt_AsLong(tb_lineno));
 
-        Py_DECREF(tb_lineno);
-    }
-    else {
-        croak("%s: %s", ((PyTypeObject *)ex_type)->tp_name, c_ex_message);
-    }
+            Py_DECREF(tb_lineno);
+        }
+        else {
+            croak("%s: %s", ((PyTypeObject *)ex_type)->tp_name, c_ex_message);
+        }
 
 #if PY_MAJOR_VERSION >= 3
-    Py_DECREF(ex_message_bytes);
+        Py_DECREF(ex_message_bytes);
 #endif
-    Py_DECREF(ex_message);
+        Py_DECREF(ex_message);
+    }
     Py_DECREF(ex_type);
     Py_DECREF(ex_value);
     Py_XDECREF(ex_traceback);
diff --git a/py2pl.h b/py2pl.h
index 72ff7fe..80d93e0 100644
--- a/py2pl.h
+++ b/py2pl.h
@@ -6,6 +6,7 @@ extern PyObject *Pl2Py(SV * const obj);
 extern void croak_python_exception();
 extern SV* py_true;
 extern SV* py_false;
+extern PyObject *PyExc_Perl;
 
 #endif
 
diff --git a/t/02testpl.t b/t/02testpl.t
index 9aa7a24..7ed7d11 100644
--- a/t/02testpl.t
+++ b/t/02testpl.t
@@ -49,8 +49,8 @@ o.foof({'neil': 1}, ['laura', 1], 12)
 perl.ok(1)
 perl.eval('print qq{Hello. This is Neil\\n}')
 perl.ok(1)
-perl.use('CGI')
+perl.use('FindBin')
 perl.ok(1)
 END
 
-ok(defined $::{'CGI::'});
+ok($FindBin::Bin);
diff --git a/t/28exception.t b/t/28exception.t
index 97a4885..089f06a 100644
--- a/t/28exception.t
+++ b/t/28exception.t
@@ -1,4 +1,6 @@
-use Test::More tests => 6;
+use strict;
+use warnings;
+use Test::More tests => 9;
 
 use Inline Config => DIRECTORY => './blib_test';
 
@@ -20,6 +22,15 @@ class Foo:
 def thrower():
     return lambda: foo
 
+def catch_perl_exception(failer):
+    try:
+        failer()
+    except Exception, e:
+        return e.message
+
+def pass_through_perl_exception(failer):
+    failer()
+
 END
 
 eval {
@@ -48,3 +59,18 @@ eval {
     thrower()->();
 };
 like($@, qr/name 'foo' is not defined at line 16/, 'Exception found');
+
+my $exception = catch_perl_exception(sub { die "fail!"; });
+like($exception, qr/fail!/);
+
+eval {
+    pass_through_perl_exception(sub { die "fail!"; });
+};
+like($@, qr/fail!/);
+
+my $foo_exception = bless {}, 'FooException';
+
+eval {
+    pass_through_perl_exception(sub { die $foo_exception; });
+};
+is(ref $@, 'FooException');
diff --git a/t/32boolean.t b/t/32boolean.t
new file mode 100644
index 0000000..24999dc
--- /dev/null
+++ b/t/32boolean.t
@@ -0,0 +1,48 @@
+use strict;
+use warnings;
+
+use Inline Config => DIRECTORY => './blib_test';
+use Test::More tests => 14;
+
+use Inline Python => <<END;
+
+from types import BooleanType
+
+def is_boolean(value):
+    return isinstance(value, BooleanType) and 1 or 0
+
+def is_true(value):
+    return value == True
+
+def get_true():
+    return True
+
+def get_false():
+    return False
+
+def get_hash_with_bools():
+    return {'true': True, 'false': False}
+
+def values_are_boolean(hash):
+    return isinstance(hash['true'], BooleanType) and isinstance(hash['false'], BooleanType) and 1 or 0
+
+END
+
+ok($Inline::Python::Boolean::true);
+ok(! $Inline::Python::Boolean::false);
+is($Inline::Python::Boolean::true, 1);
+is(! $Inline::Python::Boolean::true, 0);
+is($Inline::Python::Boolean::false, 0);
+is(! $Inline::Python::Boolean::false, 1);
+
+is(is_boolean($Inline::Python::Boolean::true), 1);
+is(is_true($Inline::Python::Boolean::true), 1);
+
+is(is_boolean($Inline::Python::Boolean::false), 1);
+is(is_true($Inline::Python::Boolean::false), 0);
+
+ok(get_true()->isa('Inline::Python::Boolean'), 'Got a Boolean object for True');
+ok(is_boolean(get_true()),  'True got passed as Boolean through perl space');
+ok(is_boolean(get_false()), 'False got passed as Boolean through perl space');
+
+ok(values_are_boolean(get_hash_with_bools()), 'True and False work as dict values');
diff --git a/t/33reinit.t b/t/33reinit.t
new file mode 100644
index 0000000..07b317e
--- /dev/null
+++ b/t/33reinit.t
@@ -0,0 +1,10 @@
+use Test;
+BEGIN { plan tests => 10 }
+
+use Inline::Python qw();
+
+for (1 .. 10) {
+    Inline::Python::py_finalize;
+    Inline::Python::py_initialize;
+    ok(Inline::Python::py_eval("True", 0));
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libinline-python-perl.git



More information about the Pkg-perl-cvs-commits mailing list