@@ -75,7 +75,7 @@ type VirtualMachine struct {
75
75
76
76
* pointer
77
77
dispatchQueue unsafe.Pointer
78
- stateHandle * machineState
78
+ machineState * machineState
79
79
80
80
finalizeOnce sync.Once
81
81
}
@@ -103,28 +103,28 @@ func NewVirtualMachine(config *VirtualMachineConfiguration) (*VirtualMachine, er
103
103
cs := (* char )(objc .GetUUID ())
104
104
dispatchQueue := C .makeDispatchQueue (cs .CString ())
105
105
106
- stateHandle := & machineState {
106
+ machineState := & machineState {
107
107
state : VirtualMachineState (0 ),
108
108
stateNotify : infinity .NewChannel [VirtualMachineState ](),
109
109
}
110
110
111
- stateHandlePtr := cgo .NewHandle (stateHandle )
111
+ stateHandle := cgo .NewHandle (machineState )
112
112
v := & VirtualMachine {
113
113
id : cs .String (),
114
114
pointer : objc .NewPointer (
115
115
C .newVZVirtualMachineWithDispatchQueue (
116
116
objc .Ptr (config ),
117
117
dispatchQueue ,
118
- unsafe . Pointer ( & stateHandlePtr ),
118
+ C . uintptr_t ( stateHandle ),
119
119
),
120
120
),
121
121
dispatchQueue : dispatchQueue ,
122
- stateHandle : stateHandle ,
122
+ machineState : machineState ,
123
123
}
124
124
125
125
objc .SetFinalizer (v , func (self * VirtualMachine ) {
126
126
self .finalize ()
127
- stateHandlePtr .Delete ()
127
+ stateHandle .Delete ()
128
128
})
129
129
return v , nil
130
130
}
@@ -155,11 +155,11 @@ func (v *VirtualMachine) SocketDevices() []*VirtioSocketDevice {
155
155
}
156
156
157
157
//export changeStateOnObserver
158
- func changeStateOnObserver (newStateRaw C.int , cgoHandlerPtr unsafe. Pointer ) {
159
- stateHandler := * ( * cgo .Handle )( cgoHandlerPtr )
158
+ func changeStateOnObserver (newStateRaw C.int , cgoHandleUintptr C. uintptr_t ) {
159
+ stateHandle := cgo .Handle ( cgoHandleUintptr )
160
160
// I expected it will not cause panic.
161
161
// if caused panic, that's unexpected behavior.
162
- v , _ := stateHandler .Value ().(* machineState )
162
+ v , _ := stateHandle .Value ().(* machineState )
163
163
v .mu .Lock ()
164
164
newState := VirtualMachineState (newStateRaw )
165
165
v .state = newState
@@ -169,16 +169,16 @@ func changeStateOnObserver(newStateRaw C.int, cgoHandlerPtr unsafe.Pointer) {
169
169
170
170
// State represents execution state of the virtual machine.
171
171
func (v * VirtualMachine ) State () VirtualMachineState {
172
- v .stateHandle .mu .RLock ()
173
- defer v .stateHandle .mu .RUnlock ()
174
- return v .stateHandle .state
172
+ v .machineState .mu .RLock ()
173
+ defer v .machineState .mu .RUnlock ()
174
+ return v .machineState .state
175
175
}
176
176
177
177
// StateChangedNotify gets notification is changed execution state of the virtual machine.
178
178
func (v * VirtualMachine ) StateChangedNotify () <- chan VirtualMachineState {
179
- v .stateHandle .mu .RLock ()
180
- defer v .stateHandle .mu .RUnlock ()
181
- return v .stateHandle .stateNotify .Out ()
179
+ v .machineState .mu .RLock ()
180
+ defer v .machineState .mu .RUnlock ()
181
+ return v .machineState .stateNotify .Out ()
182
182
}
183
183
184
184
// CanStart returns true if the machine is in a state that can be started.
@@ -213,10 +213,10 @@ func (v *VirtualMachine) CanStop() bool {
213
213
}
214
214
215
215
//export virtualMachineCompletionHandler
216
- func virtualMachineCompletionHandler (cgoHandlerPtr , errPtr unsafe.Pointer ) {
217
- cgoHandler := * ( * cgo .Handle )( cgoHandlerPtr )
216
+ func virtualMachineCompletionHandler (cgoHandleUintptr C. uintptr_t , errPtr unsafe.Pointer ) {
217
+ cgoHandle := cgo .Handle ( cgoHandleUintptr )
218
218
219
- handler := cgoHandler .Value ().(func (error ))
219
+ handler := cgoHandle .Value ().(func (error ))
220
220
221
221
if err := newNSError (errPtr ); err != nil {
222
222
handler (err )
@@ -255,18 +255,18 @@ func (v *VirtualMachine) Start(opts ...VirtualMachineStartOption) error {
255
255
}
256
256
257
257
h , errCh := makeHandler ()
258
- handler := cgo .NewHandle (h )
259
- defer handler .Delete ()
258
+ handle := cgo .NewHandle (h )
259
+ defer handle .Delete ()
260
260
261
261
if o .macOSVirtualMachineStartOptionsPtr != nil {
262
262
C .startWithOptionsCompletionHandler (
263
263
objc .Ptr (v ),
264
264
v .dispatchQueue ,
265
265
o .macOSVirtualMachineStartOptionsPtr ,
266
- unsafe . Pointer ( & handler ),
266
+ C . uintptr_t ( handle ),
267
267
)
268
268
} else {
269
- C .startWithCompletionHandler (objc .Ptr (v ), v .dispatchQueue , unsafe . Pointer ( & handler ))
269
+ C .startWithCompletionHandler (objc .Ptr (v ), v .dispatchQueue , C . uintptr_t ( handle ))
270
270
}
271
271
return <- errCh
272
272
}
@@ -276,9 +276,9 @@ func (v *VirtualMachine) Start(opts ...VirtualMachineStartOption) error {
276
276
// If you want to listen status change events, use the "StateChangedNotify" method.
277
277
func (v * VirtualMachine ) Pause () error {
278
278
h , errCh := makeHandler ()
279
- handler := cgo .NewHandle (h )
280
- defer handler .Delete ()
281
- C .pauseWithCompletionHandler (objc .Ptr (v ), v .dispatchQueue , unsafe . Pointer ( & handler ))
279
+ handle := cgo .NewHandle (h )
280
+ defer handle .Delete ()
281
+ C .pauseWithCompletionHandler (objc .Ptr (v ), v .dispatchQueue , C . uintptr_t ( handle ))
282
282
return <- errCh
283
283
}
284
284
@@ -287,9 +287,9 @@ func (v *VirtualMachine) Pause() error {
287
287
// If you want to listen status change events, use the "StateChangedNotify" method.
288
288
func (v * VirtualMachine ) Resume () error {
289
289
h , errCh := makeHandler ()
290
- handler := cgo .NewHandle (h )
291
- defer handler .Delete ()
292
- C .resumeWithCompletionHandler (objc .Ptr (v ), v .dispatchQueue , unsafe . Pointer ( & handler ))
290
+ handle := cgo .NewHandle (h )
291
+ defer handle .Delete ()
292
+ C .resumeWithCompletionHandler (objc .Ptr (v ), v .dispatchQueue , C . uintptr_t ( handle ))
293
293
return <- errCh
294
294
}
295
295
@@ -322,9 +322,9 @@ func (v *VirtualMachine) Stop() error {
322
322
return err
323
323
}
324
324
h , errCh := makeHandler ()
325
- handler := cgo .NewHandle (h )
326
- defer handler .Delete ()
327
- C .stopWithCompletionHandler (objc .Ptr (v ), v .dispatchQueue , unsafe . Pointer ( & handler ))
325
+ handle := cgo .NewHandle (h )
326
+ defer handle .Delete ()
327
+ C .stopWithCompletionHandler (objc .Ptr (v ), v .dispatchQueue , C . uintptr_t ( handle ))
328
328
return <- errCh
329
329
}
330
330
0 commit comments