Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support passing Any to Python (ends up as None)
  • Loading branch information
niner committed Oct 14, 2014
1 parent efc8caa commit caf7b40
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/Inline/Python.pm6
Expand Up @@ -97,6 +97,9 @@ sub py_sequence_get_item(OpaquePointer, int)
sub py_mapping_items(OpaquePointer)
returns OpaquePointer { ... }
native(&py_mapping_items);
sub py_none()
returns OpaquePointer { ... }
native(&py_none);
sub py_dec_ref(OpaquePointer)
{ ... }
native(&py_dec_ref);
Expand Down Expand Up @@ -191,6 +194,10 @@ multi method p6_to_py(Hash:D $value) returns OpaquePointer {
return $dict;
}

multi method p6_to_py(Any:U $value) returns OpaquePointer {
py_none();
}

method !setup_arguments(@args) {
my $len = @args.elems;
my $tuple = py_tuple_new($len);
Expand Down
5 changes: 5 additions & 0 deletions pyhelper.c
Expand Up @@ -145,6 +145,11 @@ void py_dict_set_item(PyObject *dict, PyObject *key, PyObject *item) {
PyDict_SetItem(dict, key, item);
}

PyObject *py_none() {
Py_INCREF(Py_None);
return Py_None;
}

void py_dec_ref(PyObject *obj) {
Py_DECREF(obj);
}
Expand Down
6 changes: 3 additions & 3 deletions t/p6_to_py.t
Expand Up @@ -4,7 +4,7 @@ use v6;
use Test;
use Inline::Python;

plan 10;
plan 11;

my $py = Inline::Python.new();
$py.run(q[
Expand All @@ -14,8 +14,8 @@ def identity(a):

class Foo {
}
# , Any, Foo.new
for ('abcö', Buf.new('äbc'.encode('latin-1')), 24, 2.4.Num, [1, 2], { a => 1, b => 2}) -> $obj {
# , Foo.new
for ('abcö', Buf.new('äbc'.encode('latin-1')), 24, 2.4.Num, [1, 2], { a => 1, b => 2}, Any) -> $obj {
is_deeply $py.call('__main__', 'identity', $obj), $obj, "Can round-trip " ~ $obj.^name;
}

Expand Down

0 comments on commit caf7b40

Please sign in to comment.