diff options
| author | lhchavez <[email protected]> | 2020-12-10 07:19:41 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-10 07:19:41 -0800 |
| commit | 10c67474a89c298172a6703b91980ea37c60d5e5 (patch) | |
| tree | 8b32fd2ce9540e01e90ddd09b59969d85832dc25 /wrapper.c | |
| parent | e28cce87c7551bffa1f4602ff492348f9a8cba60 (diff) | |
More callback refactoring (#713)
This change:
* Gets rid of the `.toC()` functions for Options objects, since they
were redundant with the `populateXxxOptions()`.
* Adds support for `errorTarget` to the `RemoteOptions`, since they are
used in the same stack for some functions (like `Fetch()`). Now for
those cases, the error returned by the callback will be preserved
as-is.
Diffstat (limited to 'wrapper.c')
| -rw-r--r-- | wrapper.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -14,7 +14,7 @@ // // // myfile.go // type FooCallback func(...) (..., error) -// type FooCallbackData struct { +// type fooCallbackData struct { // callback FooCallback // errorTarget *error // } @@ -60,20 +60,28 @@ // return git_my_function(..., (git_foo_cb)&fooCallback, payload); // } // -// * Otherwise, if the same callback can be invoked from multiple functions or -// from different stacks (e.g. when passing the callback to an object), a -// different pattern should be used instead, which has the downside of losing -// the original error object and converting it to a GitError: +// * Additionally, if the same callback can be invoked from multiple functions or +// from different stacks (e.g. when passing the callback to an object), the +// following pattern should be used in tandem, which has the downside of +// losing the original error object and converting it to a GitError if the +// callback happens from a different stack: // // // myfile.go // type FooCallback func(...) (..., error) +// type fooCallbackData struct { +// callback FooCallback +// errorTarget *error +// } // // //export fooCallback // func fooCallback(errorMessage **C.char, ..., handle unsafe.Pointer) C.int { -// callback := pointerHandles.Get(data).(*FooCallback) +// data := pointerHandles.Get(data).(*fooCallbackData) // ... -// err := callback(...) +// err := data.callback(...) // if err != nil { +// if data.errorTarget != nil { +// *data.errorTarget = err +// } // return setCallbackError(errorMessage, err) // } // return C.int(ErrorCodeOK) |
