Skip to content

Commit c09d761

Browse files
authored
Fix model pointer passed to callbacks (#277)
1 parent 379220b commit c09d761

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

Diff for: src/C_wrapper.jl

+8-11
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ function _newpt_wrapper(
574574
@_checked KN_get_number_cons(model, nc)
575575
x = unsafe_wrap(Array, ptr_x, nx[])
576576
lambda = unsafe_wrap(Array, ptr_lambda, nx[] + nc[])
577-
# TODO: should `model` arugment be `ptr_model`?
578-
return model.newpt_callback(model, x, lambda, model.newpt_user_data)
577+
return model.newpt_callback(ptr_model, x, lambda, model.newpt_user_data)
579578
end
580579
end
581580

@@ -591,7 +590,7 @@ solution point (that is, after every iteration).
591590
`callback` is a function with signature:
592591
593592
```julia
594-
callback(kc::Model, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
593+
callback(kc::Ptr, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
595594
```
596595
597596
## Notes
@@ -629,8 +628,7 @@ function _ms_process_wrapper(
629628
@_checked KN_get_number_cons(model, nc)
630629
x = unsafe_wrap(Array, ptr_x, nx[])
631630
lambda = unsafe_wrap(Array, ptr_lambda, nx[] + nc[])
632-
# TODO: should `model` arugment be `ptr_model`?
633-
return model.ms_process_callback(model, x, lambda, model.ms_process_user_data)
631+
return model.ms_process_callback(ptr_model, x, lambda, model.ms_process_user_data)
634632
end
635633
end
636634

@@ -646,7 +644,7 @@ processing a multistart solve.
646644
`callback` is a function with signature:
647645
648646
```julia
649-
callback(kc::Model, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
647+
callback(kc::Ptr, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
650648
```
651649
652650
## Notes
@@ -681,8 +679,7 @@ function _mip_node_callback_wrapper(
681679
@_checked KN_get_number_cons(model, nc)
682680
x = unsafe_wrap(Array, ptr_x, nx[])
683681
lambda = unsafe_wrap(Array, ptr_lambda, nx[] + nc[])
684-
# TODO: should `model` arugment be `ptr_model`?
685-
return model.mip_node_callback(model, x, lambda, model.mip_node_user_data)
682+
return model.mip_node_callback(ptr_model, x, lambda, model.mip_node_user_data)
686683
end
687684
end
688685

@@ -699,7 +696,7 @@ procedure).
699696
`callback` is a function with signature:
700697
701698
```julia
702-
callback(kc::Model, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
699+
callback(kc::Ptr, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data::Any) -> Cint
703700
```
704701
705702
## Notes
@@ -735,7 +732,7 @@ function _ms_initpt_wrapper(
735732
x = unsafe_wrap(Array, ptr_x, nx[])
736733
lambda = unsafe_wrap(Array, ptr_lambda, nx[] + nc[])
737734
return model.ms_initpt_callback(
738-
model,
735+
ptr_model,
739736
nSolveNumber,
740737
x,
741738
lambda,
@@ -753,7 +750,7 @@ in the multistart procedure.
753750
754751
```julia
755752
callback(
756-
model::Model,
753+
kc::Ptr,
757754
nSolveNumber::Cint,
758755
x::Vector{Cdouble},
759756
lambda::Vector{Cdouble},

Diff for: test/knitroapi_licman.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using Test
1919
end
2020

2121
function newpt_callback(kc, x::Vector{Cdouble}, lambda::Vector{Cdouble}, user_data)
22-
@test kc isa KNITRO.Model
22+
@test kc isa Ptr{Cvoid}
2323
return 0
2424
end
2525

0 commit comments

Comments
 (0)