@@ -303,18 +303,22 @@ Each call must be matched with PyGILState_Release"}
303
303
:doc " Mark a python function as being an instance method." }
304
304
})
305
305
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 )))
306
321
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
- )))
318
322
(defonce pyobject-struct-type*
319
323
(delay (dt-struct/define-datatype!
320
324
:pyobject [{:name :ob_refcnt :datatype (ffi-size-t/size-t-type )}
@@ -345,19 +349,19 @@ Each call must be matched with PyGILState_Release"}
345
349
346
350
347
351
(defn reset-library!
348
- []
352
+ [& [library-definition] ]
349
353
(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*)
351
355
(:libpath @library-path*)))))
352
356
353
357
354
358
(defn set-library!
355
- [libpath]
359
+ [libpath & [library-definition] ]
356
360
(when @library*
357
361
(log/warnf " Python library is being reinitialized to (%s). Is this what you want?"
358
362
libpath))
359
363
(reset! library-path* {:libpath libpath})
360
- (reset-library! ))
364
+ (reset-library! library-definition ))
361
365
362
366
; ;Useful for repling around - this regenerates the library function bindings
363
367
(reset-library! )
@@ -572,11 +576,12 @@ Each call must be matched with PyGILState_Release"}
572
576
573
577
574
578
(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]
576
581
:or {signals? true
577
582
program-name " " }
578
583
:as opts}]]
579
- (set-library! libpath)
584
+ (set-library! libpath library-definition )
580
585
(when-not (= 1 (Py_IsInitialized ))
581
586
(log/debug " Initializing Python C Layer" )
582
587
; ;platform specific encoding
0 commit comments