-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugs/fixes #12 #13
Bugs/fixes #12 #13
Conversation
I forgot to update the makefiles in my first version of the PR. It compiled just fine with fpm, and I did not see that the explicit list of files was required. I committed the fix. |
This reverts commit c5ef813.
The C interop with the type |
Is this because of the kind needed for the literal numbers? Would it be possible to use a named kind for the literals in that case? Like |
It seems that there is an issue with you macOS environment. function evalf(b, r) result(res)
class(basic), intent(in) :: b
integer(c_int) :: r
type(basic), allocatable :: res
integer(c_long) :: exception
allocate(res)
res = Basic()
exception = c_basic_evalf(res%ptr, b%ptr, 53_c_long, r)
call handle_exception(exception)
end function Amd for the dense_matrix function zeros(r, c) result(res)
integer(kind=int32) :: r, c
type(DenseMatrix), allocatable :: res
integer(c_long) :: exception
allocate(res)
res%ptr = c_dense_matrix_new()
exception = c_dense_matrix_zeros(res%ptr, int(r, c_long), int(c, c_long))
call handle_exception(exception)
end function |
It looks like you CI on MacOS is broken.
I am no expert in GitHub actions and I do not have a mac to test it locally. Unfortunately, I will not be able to fix it. |
Thanks. Using gfortran on github actions on MacOS has always been a bit harder than on the other platforms. I think it is safe to ignore that fail in the context of this PR. |
OK, and what about using this action? |
Sure, if it works! |
I was actually just looking into updating this CI: #14 |
Cool. With the new CI it went through! |
I think this is good. Big question is: Before we used For example, instead of: function pi()
type(basic), allocatable :: pi
allocate(pi)
pi = Basic()
call c_basic_const_pi(pi%ptr)
end function why cannot we have: function pi()
type(basic) :: pi
pi = Basic()
call c_basic_const_pi(pi%ptr)
end function ? |
🤔 , good point. I was under the wrong impression that the finalizer would only get called for allocatable variables. I just did the test, and the code works perfectly fine without declaring the variables allocatable. I also checked for memory leaks with intel inspector and did not find any problem. subroutine basic_assign(a, b)
class(basic), intent(inout) :: a
class(basic), intent(in) :: b
integer(c_long) :: exception
if (.not. c_associated(a%ptr)) then
a%ptr = c_basic_new_heap()
end if
exception = c_basic_assign(a%ptr, b%ptr)
call handle_exception(exception)
if (b%tmp) then
call basic_free(b)
end if
end subroutine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this looks great now! I agree, tmp
feels hackish, and the finalizer approach looks clean. Now without the allocatable
attribute this looks perfect.
@davidpfister thank you. Great job. |
This PR fixes #12 . The %tmp component has been removed and allocatable property is used instead. By doing so, the unmanaged memory is realized when the
final
is called.In addition a bug in the unit test has been fixed (see dense matrix testing)
A test of the eval function has been added
And I took the liberty to create the dbl function (in symengine_basic) together with the
conversion
module that takes theBasic
object and returns a double precision (taken from stdlib)The code was compiled with fpm using gfortran and ifort on Windows + I checked for memory leaks using Intel Inspector which returned 'No Problems Detected' when running the unit tests.