1+ __precompile__ ()
2+
13module LibGEOS
24
35 if isfile (joinpath (dirname (@__FILE__ )," .." ," deps" ," deps.jl" ))
@@ -24,22 +26,42 @@ module LibGEOS
2426
2527 include (" geos_c.jl" )
2628
27- # --- GEOSconnection ---
29+ type GEOSError <: Exception
30+ msg:: String
31+ end
32+ Base. showerror (io:: IO , err:: GEOSError ) = print (io, " GEOSError\n\t $(err. msg) " )
33+
34+ function geosjl_errorhandler (message:: Ptr{UInt8} , userdata)
35+ if unsafe_string (message) == " %s"
36+ throw (GEOSError (unsafe_string (Cstring (userdata))))
37+ else
38+ throw (GEOSError (unsafe_string (message)))
39+ end
40+ end
41+
2842 type GEOSconnection
2943 status:: Symbol
3044
3145 function GEOSconnection ()
32- geos_status = new (:Initialized )
33- initializeGEOS ()
34- finalizer (geos_status, finalizeGEOS)
35- geos_status
46+ connection = new (:Initialized )
47+ initializeGEOS (
48+ C_NULL ,
49+ cfunction (geosjl_errorhandler,Ptr{Void},(Ptr{UInt8},Ptr{Void}))
50+ )
51+ finalizer (connection, finalizeGEOS)
52+ connection
3653 end
3754 end
38- initializeGEOS () = initGEOS (C_NULL , C_NULL )
39- finalizeGEOS (status:: GEOSconnection ) = finishGEOS ()
4055
41- _connection = GEOSconnection ()
42- # --- END GEOSconnection ---
56+ initializeGEOS (notice_f, error_f) = initGEOS (notice_f, error_f)
57+ function finalizeGEOS (connection:: GEOSconnection )
58+ connection. status = :Finished
59+ finishGEOS ()
60+ end
61+
62+ function __init__ ()
63+ global const _connection = GEOSconnection ()
64+ end
4365
4466 include (" geos_functions.jl" )
4567 include (" geos_types.jl" )
0 commit comments