Skip to content

Commit

Permalink
Fixes #148
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Mar 3, 2021
1 parent 18a7b01 commit 021c97c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/libpython_clj2/python/base.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
(defn ->jvm
"Copying conversion to the jvm."
([obj]
(when obj
(when-not (nil? obj)
(py-proto/->jvm obj nil)))
([obj opts]
(when obj
(when-not (nil? obj)
(py-proto/->jvm obj opts))))


Expand All @@ -22,7 +22,7 @@
([obj]
(as-jvm obj nil))
([obj opts]
(when obj
(when-not (nil? obj)
(py-proto/as-jvm obj opts))))


Expand Down
3 changes: 1 addition & 2 deletions src/libpython_clj2/python/ffi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,7 @@ Object's refcount is bad. Crash is imminent"
:str (with-decref [pyobj pyobj]
(pystr->str pyobj))
:bool (with-decref [pyobj pyobj]
(= (dt-ffi/->pointer pyobj)
(py-true)))
(== 1 (long (PyObject_IsTrue pyobj))))
;;maybe copy, maybe bridge - in any case we have to decref the item
(track-pyobject pyobj)))
(check-error-throw)))
6 changes: 5 additions & 1 deletion src/libpython_clj2/python/fn.clj
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
py-proto/PyCall
(call [callable arglist kw-arg-map]
(call-py-fn callable arglist kw-arg-map py-base/->python))
(marshal-return [callable retval] retval))
(marshal-return [callable retval]
retval))


(defn call
Expand All @@ -137,11 +138,14 @@
(py-ffi/with-gil
(if (string? att-name)
(py-ffi/with-decref [attval (py-ffi/PyObject_GetAttrString item att-name)]
(when-not attval (py-ffi/check-error-throw))
(->> (call-py-fn attval arglist kw-map arg-converter)
(py-proto/marshal-return item)))
(py-ffi/with-decref
[att-name (py-ffi/untracked->python att-name py-base/->python)
att-val (py-ffi/untracked->python att-name py-base/->python)]
(when (or (nil? att-name) (nil? att-val))
(py-ffi/check-error-throw))
(->> (call-py-fn att-val arglist kw-map arg-converter)
(py-proto/marshal-return item))))))

Expand Down
6 changes: 6 additions & 0 deletions test/libpython_clj2/python_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ class Foo:
(py/->jvm (py/->python \c)))))


(deftest numpy-all
(let [np (py/import-module "numpy")]
(is (= true (py/call-attr np "all" (py/call-attr np "array" [true true true]))))
(is (= false (py/call-attr np "all" (py/call-attr np "array" [true false true]))))))


(comment
(require '[libpython-clj.require :refer [require-python]])

Expand Down

2 comments on commit 021c97c

@jjtolton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're getting really good at tracking these down!

@KUR-creative
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix!

Please sign in to comment.