@@ -303,18 +303,22 @@ Each call must be matched with PyGILState_Release"}
303303 :doc " Mark a python function as being an instance method." }
304304 })
305305
306+ (defn define-library!
307+ [python-lib-classname]
308+ (dt-ffi/define-library
309+ python-library-fns
310+ [" _Py_NoneStruct"
311+ " _Py_FalseStruct"
312+ " _Py_TrueStruct"
313+ " PyType_Type"
314+ " PyExc_StopIteration"
315+ " PyRange_Type"
316+ " PyExc_Exception" ]
317+ {:classname python-lib-classname}))
318+
319+
320+ (def python-lib-def* (delay (define-library! nil )))
306321
307- (def python-lib-def* (delay (dt-ffi/define-library
308- python-library-fns
309- [" _Py_NoneStruct"
310- " _Py_FalseStruct"
311- " _Py_TrueStruct"
312- " PyType_Type"
313- " PyExc_StopIteration"
314- " PyRange_Type"
315- " PyExc_Exception" ]
316- nil
317- )))
318322(defonce pyobject-struct-type*
319323 (delay (dt-struct/define-datatype!
320324 :pyobject [{:name :ob_refcnt :datatype (ffi-size-t/size-t-type )}
@@ -345,19 +349,19 @@ Each call must be matched with PyGILState_Release"}
345349
346350
347351(defn reset-library!
348- []
352+ [& [library-definition] ]
349353 (when @library-path*
350- (reset! library* (dt-ffi/instantiate-library @python-lib-def*
354+ (reset! library* (dt-ffi/instantiate-library ( or library-definition @python-lib-def*)
351355 (:libpath @library-path*)))))
352356
353357
354358(defn set-library!
355- [libpath]
359+ [libpath & [library-definition] ]
356360 (when @library*
357361 (log/warnf " Python library is being reinitialized to (%s). Is this what you want?"
358362 libpath))
359363 (reset! library-path* {:libpath libpath})
360- (reset-library! ))
364+ (reset-library! library-definition ))
361365
362366; ;Useful for repling around - this regenerates the library function bindings
363367(reset-library! )
@@ -572,11 +576,12 @@ Each call must be matched with PyGILState_Release"}
572576
573577
574578(defn initialize!
575- [libpath python-home & [{:keys [signals? program-name python-home]
579+ [libpath python-home & [{:keys [signals? program-name python-home
580+ library-definition]
576581 :or {signals? true
577582 program-name " " }
578583 :as opts}]]
579- (set-library! libpath)
584+ (set-library! libpath library-definition )
580585 (when-not (= 1 (Py_IsInitialized ))
581586 (log/debug " Initializing Python C Layer" )
582587 ; ;platform specific encoding
0 commit comments