Skip to content

Instantly share code, notes, and snippets.

@isuruf
Created March 22, 2017 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isuruf/4fcb76eaf27daa820bc7b9d1c7a0df50 to your computer and use it in GitHub Desktop.
Save isuruf/4fcb76eaf27daa820bc7b9d1c7a0df50 to your computer and use it in GitHub Desktop.
diff --git a/src/mathops.jl b/src/mathops.jl
index 09f85ca..42bb7c5 100644
--- a/src/mathops.jl
+++ b/src/mathops.jl
@@ -49,19 +49,23 @@ for op in [:IM, :PI, :E, :EulerGamma]
eval(Expr(:export, op))
end
-function init_constants()
- for (op, libnm) in [(:IM, :I),
- (:PI, :pi),
- (:E, :E),
- (:EulerGamma, :EulerGamma)
- ]
- tup = (Base.Symbol("basic_const_$libnm"), libsymengine)
- @eval begin
- ccall((:basic_new_stack, libsymengine), Void, (Ptr{Basic}, ), &($op))
+macro init_constant(op, libnm)
+ tup = (Base.Symbol("basic_const_$libnm"), libsymengine)
+ alloc_tup = (:basic_new_stack, libsymengine)
+ :(
+ begin
+ ccall($alloc_tup, Void, (Ptr{Basic}, ), &($op))
ccall($tup, Void, (Ptr{Basic}, ), &($op))
finalizer($op, basic_free)
end
- end
+ )
+end
+
+function init_constants()
+ @init_constant IM I
+ @init_constant PI pi
+ @init_constant E E
+ @init_constant EulerGamma EulerGamma
end
## ## Conversions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment