Skip to content

Commit

Permalink
Merge pull request #96 from saltosystems/feature/use-uintptr-in-deleg…
Browse files Browse the repository at this point in the history
…ate-functions

delegate: return uintptr as callback result
  • Loading branch information
jagobagascon authored May 10, 2024
2 parents 4f7860a + 11a17da commit db61b37
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions internal/codegen/templates/delegate.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Signature{{.Name}} string = "{{.Signature}}"
type {{.Name}} struct {
ole.IUnknown
sync.Mutex
refs uint64
refs uintptr
IID ole.GUID
}

Expand Down Expand Up @@ -70,15 +70,15 @@ func (r *{{.Name}}) GetIID() *ole.GUID {
}

// addRef increments the reference counter by one
func (r *{{.Name}}) addRef() uint64 {
func (r *{{.Name}}) addRef() uintptr {
r.Lock()
defer r.Unlock()
r.refs++
return r.refs
}

// removeRef decrements the reference counter by one. If it was already zero, it will just return zero.
func (r *{{.Name}}) removeRef() uint64 {
func (r *{{.Name}}) removeRef() uintptr {
r.Lock()
defer r.Unlock()

Expand Down Expand Up @@ -112,11 +112,11 @@ func (instance *{{.Name}}) Invoke(instancePtr, rawArgs0, rawArgs1, rawArgs2, raw
return ole.S_OK
}

func (instance *{{.Name}}) AddRef() uint64 {
func (instance *{{.Name}}) AddRef() uintptr {
return instance.addRef()
}

func (instance *{{.Name}}) Release() uint64 {
func (instance *{{.Name}}) Release() uintptr {
rem := instance.removeRef()
if rem == 0 {
// We're done.
Expand Down
8 changes: 4 additions & 4 deletions internal/delegate/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var (
type Delegate interface {
GetIID() *ole.GUID
Invoke(instancePtr, rawArgs0, rawArgs1, rawArgs2, rawArgs3, rawArgs4, rawArgs5, rawArgs6, rawArgs7, rawArgs8 unsafe.Pointer) uintptr
AddRef() uint64
Release() uint64
AddRef() uintptr
Release() uintptr
}

// Callbacks contains the syscalls registered on Windows.
Expand Down Expand Up @@ -113,7 +113,7 @@ func invoke(instancePtr, rawArgs0, rawArgs1, rawArgs2, rawArgs3, rawArgs4, rawAr
return instance.Invoke(instancePtr, rawArgs0, rawArgs1, rawArgs2, rawArgs3, rawArgs4, rawArgs5, rawArgs6, rawArgs7, rawArgs8)
}

func addRef(instancePtr unsafe.Pointer) uint64 {
func addRef(instancePtr unsafe.Pointer) uintptr {
instance, ok := getInstance(instancePtr)
if !ok {
// instance not found
Expand All @@ -123,7 +123,7 @@ func addRef(instancePtr unsafe.Pointer) uint64 {
return instance.AddRef()
}

func release(instancePtr unsafe.Pointer) uint64 {
func release(instancePtr unsafe.Pointer) uintptr {
instance, ok := getInstance(instancePtr)
if !ok {
// instance not found
Expand Down
10 changes: 5 additions & 5 deletions windows/foundation/asyncoperationcompletedhandler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions windows/foundation/deferralcompletedhandler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions windows/foundation/typedeventhandler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db61b37

Please sign in to comment.