Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5: compilation on macos fails #6

Merged
merged 6 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
name: Go

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
- push
- pull_request

jobs:

build:
name: Build
build-linux:
name: Build on Linux
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.13
go-version: ^1.17
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi

- name: Build
run: go build -v .
run: go build -v -x ./...

- name: Test
run: go test -v ./...

build-macos:
name: Build on Darwin
runs-on: macos-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.17
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: go build -v -x ./...

- name: Test
run: go test -v ./...
23 changes: 0 additions & 23 deletions .github/workflows/go_macos.yml

This file was deleted.

10 changes: 5 additions & 5 deletions xpc/xpc_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func GetUUID(v interface{}) UUID {
return uuid
}

panic("invalid type for UUID: %#v", v)
panic(fmt.Sprintf("invalid type for UUID: %#v", v))
return UUID{}
}

Expand Down Expand Up @@ -250,7 +250,7 @@ func valueToXpc(val r.Value) C.xpc_object_t {
xv = valueToXpc(val.Elem())

default:
panic("unsupported %#v", val.String())
panic(fmt.Sprintf("unsupported value in conversion to Xpc: %s", val.String()))
}

return xv
Expand All @@ -277,15 +277,15 @@ func xpcToGo(v C.xpc_object_t) interface{} {
switch t {
case C.TYPE_ARRAY:
a := make(Array, C.int(C.xpc_array_get_count(v)))
C.XpcArrayApply(unsafe.Pointer(&a), v)
C.XpcArrayApply(C.uintptr_t(uintptr(unsafe.Pointer(&a))), v)
return a

case C.TYPE_DATA:
return C.GoBytes(C.xpc_data_get_bytes_ptr(v), C.int(C.xpc_data_get_length(v)))

case C.TYPE_DICT:
d := make(Dict)
C.XpcDictApply(unsafe.Pointer(&d), v)
C.XpcDictApply(C.uintptr_t(uintptr(unsafe.Pointer(&d))), v)
return d

case C.TYPE_INT64:
Expand All @@ -300,7 +300,7 @@ func xpcToGo(v C.xpc_object_t) interface{} {
return UUID(a[:])

default:
panic("unexpected type %#v, value %#v", t, v)
panic(fmt.Sprintf("unexpected type in conversion from xpc to Go: %#v, value %#v", t, v))
}

return nil
Expand Down
38 changes: 25 additions & 13 deletions xpc/xpc_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"testing"
)

func CheckUUID(t *testing.T, v interface{}) UUID {
func CheckUUID(t *testing.T, v interface{}) (uuid UUID) {
if uuid, ok := v.(UUID); ok {
return uuid
} else {
t.Errorf("not a UUID: %#v\n", v)
return uuid
}
t.Errorf("not a UUID: %#v\n", v)
return uuid
}

func TestConvertUUID(t *testing.T) {
Expand All @@ -23,7 +22,7 @@ func TestConvertUUID(t *testing.T) {

uuid2 := CheckUUID(t, v)

if uuid != uuid2 {
if uuid.String() != uuid2.String() {
t.Errorf("expected %#v got %#v\n", uuid, uuid2)
}
}
Expand All @@ -36,7 +35,7 @@ func TestConvertSlice(t *testing.T) {

xpc_release(xv)

if arr2, ok := v.(array); !ok {
if arr2, ok := v.(Array); !ok {
t.Errorf("not an array: %#v\n", v)
} else if len(arr) != len(arr2) {
t.Errorf("expected %#v got %#v\n", arr, arr2)
Expand All @@ -57,7 +56,7 @@ func TestConvertSliceUUID(t *testing.T) {

xpc_release(xv)

if arr2, ok := v.(array); !ok {
if arr2, ok := v.(Array); !ok {
t.Errorf("not an array: %#v\n", v)
} else if len(arr) != len(arr2) {
t.Errorf("expected %#v got %#v\n", arr, arr2)
Expand All @@ -66,15 +65,15 @@ func TestConvertSliceUUID(t *testing.T) {
uuid1 := CheckUUID(t, arr[i])
uuid2 := CheckUUID(t, arr2[i])

if uuid1 != uuid2 {
if uuid1.String() != uuid2.String() {
t.Errorf("expected array[%d]: %#v got %#v\n", i, arr[i], arr2[i])
}
}
}
}

func TestConvertMap(t *testing.T) {
d := dict{
d := Dict{
"number": int64(42),
"text": "hello gopher",
"uuid": MakeUUID("aabbccddeeff00112233445566778899"),
Expand All @@ -85,17 +84,30 @@ func TestConvertMap(t *testing.T) {

xpc_release(xv)

if d2, ok := v.(dict); !ok {
if d2, ok := v.(Dict); !ok {
t.Errorf("not a map: %#v", v)
} else if len(d) != len(d2) {
t.Errorf("expected %#v got %#v\n", d, d2)
} else {
fail := false

for k, v := range d {
if v != d2[k] {
t.Logf("expected map[%s]: %#v got %#v\n", k, v, d2[k])
fail = true
switch got := d2[k].(type) {
case int64:
if v.(int64) != got {
t.Logf("expected map[%s]: %#v got %#v\n", k, v, got)
fail = true
}
case string:
if v.(string) != got {
t.Logf("expected map[%s]: %#v got %#v\n", k, v, got)
fail = true
}
case UUID:
if v.(UUID).String() != got.String() {
t.Logf("expected map[%s]: %#v got %#v\n", k, v, got)
fail = true
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions xpc/xpc_wrapper_darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ void XpcSendMessage(xpc_connection_t conn, xpc_object_t message, bool release, b
}
}

void XpcArrayApply(void *v, xpc_object_t arr) {
void XpcArrayApply(uintptr_t v, xpc_object_t arr) {
xpc_array_apply(arr, ^bool(size_t index, xpc_object_t value) {
arraySet(v, index, value);
arraySet((void *)v, index, value);
return true;
});
}

void XpcDictApply(void *v, xpc_object_t dict) {
void XpcDictApply(uintptr_t v, xpc_object_t dict) {
xpc_dictionary_apply(dict, ^bool(const char *key, xpc_object_t value) {
dictSet(v, (char *)key, value);
dictSet((void *)v, (char *)key, value);
return true;
});
}
Expand Down
4 changes: 2 additions & 2 deletions xpc/xpc_wrapper_darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ extern xpc_object_t ERROR_CONNECTION_TERMINATED;

extern xpc_connection_t XpcConnect(char *, void *);
extern void XpcSendMessage(xpc_connection_t, xpc_object_t, bool, bool);
extern void XpcArrayApply(void *, xpc_object_t);
extern void XpcDictApply(void *, xpc_object_t);
extern void XpcArrayApply(uintptr_t, xpc_object_t);
extern void XpcDictApply(uintptr_t, xpc_object_t);
extern void XpcUUIDGetBytes(void *, xpc_object_t);

// the input type for xpc_uuid_create should be uuid_t but CGO instists on unsigned char *
Expand Down