jump-dev / ECOS.jl

A Julia interface to the ECOS conic optimization solver
https://github.com/embotech/ecos
Other
41 stars 17 forks source link

Is it dangerous to use `unsafe_wrap` to pull solver solution? #95

Closed mpf closed 4 years ago

mpf commented 4 years ago

The MOI.optimize! function extracts the solution variables from the ECOS problem structure using unsafe_wrap, eg, on this line,

primal = unsafe_wrap(Array, ecos_prob.x, n)[:]

Perhaps I misunderstand the implications of unsafe_wrap, but couldn't the subsequent call to cleanup, which calls free on the corresponding memory location, cause a problem?

mlubin commented 4 years ago

Unless Julia changed recently, the [:] at the end should make a julia-managed copy of the array created by unsafe_wrap.

On Mon, Jan 13, 2020, 06:16 Michael Friedlander notifications@github.com wrote:

The MOI.optimize! function extracts the solution variables from the ECOS problem structure using unsafe_wrap, eg, on this line https://github.com/JuliaOpt/ECOS.jl/blob/c59788be8a89922f5a420858042b1329b84451a8/src/MOI_wrapper.jl#L269 ,

primal = unsafe_wrap(Array, ecos_prob.x, n)[:]

Perhaps I misunderstand the implications of unsafe_wrap, but couldn't the subsequent call to cleanup, which calls free on the corresponding memory location, cause a problem?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JuliaOpt/ECOS.jl/issues/95?email_source=notifications&email_token=AANHIM2VF3L3DDXKA53YKVLQ5P2JTA5CNFSM4KF4RPOKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IFUUTZA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANHIM42DC7RKZCJCRQCX7DQ5P2JTANCNFSM4KF4RPOA .

mpf commented 4 years ago

Thanks for explaining, @mlubin! Yes, that makes sense.