Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Dec 8, 2024
1 parent aaabb68 commit 6ad2873
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Time for a ChangeLog!

## 2.026 - UNRELEASED
* Faster string conversion from c->jvm for large strings.

Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.11.1" :scope "provided"}
cnuernber/dtype-next {:mvn/version "10.111"}
cnuernber/dtype-next {:mvn/version "10.124"}
net.java.dev.jna/jna {:mvn/version "5.12.1"}
org.clojure/data.json {:mvn/version "1.0.0"}
;;Replace me with caffeine...
Expand Down
2 changes: 1 addition & 1 deletion src/libpython_clj2/python.clj
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ user> (py/py. np linspace 2 3 :num 10)
(cond
(instance? IFn pyobj)
true
(dtype-ffi/convertible-to-pointer? pyobj)
(py-ffi/convertible-to-pointer? pyobj)
(py-ffi/with-gil
(let [retval (long (py-ffi/PyCallable_Check pyobj))]
(case retval
Expand Down
4 changes: 2 additions & 2 deletions src/libpython_clj2/python/base.clj
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@
(extend-type Object
py-proto/PCopyToJVM
(->jvm [item options]
(if (dt-ffi/convertible-to-pointer? item)
(if (py-ffi/convertible-to-pointer? item)
(py-proto/pyobject->jvm item options)
;;item is already a jvm object
item))
py-proto/PBridgeToJVM
(as-jvm [item options]
(if (dt-ffi/convertible-to-pointer? item)
(if (py-ffi/convertible-to-pointer? item)
(py-proto/pyobject-as-jvm item options)
item))
py-proto/PPyCallable
Expand Down
4 changes: 2 additions & 2 deletions src/libpython_clj2/python/bridge_as_jvm.clj
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
(get-attr [item# item-name#]
(with-gil
(-> (py-proto/get-attr @pyobj*# item-name#)
py-base/as-jvm)))
(py-base/as-jvm))))
(set-attr! [item# item-name# item-value#]
(with-gil
(py-ffi/with-decref [item-value# (py-ffi/untracked->python
Expand Down Expand Up @@ -225,7 +225,7 @@
(py-base/->jvm (py-fn/call-attr @pyobj*# "__str__" nil))))))
(equals [this# other#]
(boolean
(when (dt-ffi/convertible-to-pointer? other#)
(when (py-ffi/convertible-to-pointer? other#)
(py-base/equals? @pyobj*# other#))))
(hashCode [this#]
(.hashCode ^Object (py-base/hash-code this#)))
Expand Down
10 changes: 10 additions & 0 deletions src/libpython_clj2/python/ffi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,16 @@ Each call must be matched with PyGILState_Release"}
:pyobject [{:name :ob_refcnt :datatype (ffi-size-t/size-t-type)}
{:name :ob_type :datatype (ffi-size-t/size-t-type)}])))


(defn convertible-to-pointer?
"Older definition - excludes Long objects which were made convertible-to-pointer
in later versions of dtype-next."
[d]
(boolean
(when-not (instance? Long d)
(dt-ffi/convertible-to-pointer? d))))


(defn pytype-offset
^long []
(first (dt-struct/offset-of @pyobject-struct-type* :ob_type)))
Expand Down

0 comments on commit 6ad2873

Please sign in to comment.