Skip to content

Commit 7f35fbf

Browse files
committed
fix: Fix warnings under OSX.
1 parent ab45365 commit 7f35fbf

File tree

5 files changed

+98
-111
lines changed

5 files changed

+98
-111
lines changed

callbacks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ VOID SC_CALLBACK LPCWSTR_RECEIVER_cgo(LPCWSTR str, UINT str_length, LPVOID param
2323
// typedef VOID SC_CALLBACK LPCSTR_RECEIVER(LPCSTR str, UINT str_length, LPVOID param);
2424
VOID SC_CALLBACK LPCSTR_RECEIVER_cgo(LPCSTR str, UINT str_length, LPVOID param)
2525
{
26-
goLPCSTR_RECEIVER((CHAR*)str, str_length, param);
26+
goLPCSTR_RECEIVER(str, str_length, param);
2727
}
2828

2929
// typedef BOOL SC_CALLBACK ElementEventProc(LPVOID tag, HELEMENT he, UINT evtg, LPVOID prms);
@@ -54,7 +54,7 @@ VOID NATIVE_FUNCTOR_RELEASE_cgo(VOID* tag)
5454

5555
INT SC_CALLBACK ELEMENT_COMPARATOR_cgo(HELEMENT he1, HELEMENT he2, LPVOID param)
5656
{
57-
goELEMENT_COMPARATOR(he1, he2, param);
57+
return goELEMENT_COMPARATOR(he1, he2, param);
5858
}
5959

6060
// typedef BOOL SC_CALLBACK KeyValueCallback(LPVOID param, const VALUE* pkey, const VALUE* pval);

sciter-x-api.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const char * SCITER_DLL_PATH = SCITER_DLL_NAME;
5757

5858
#elif defined(OSX)
5959

60+
#include <string.h>
61+
6062
//typedef ISciterAPI* SCAPI (*SciterAPI_ptr)();
6163

6264
ISciterAPI* SAPI( ISciterAPI* ext )

sciter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,9 @@ func goLPCWSTR_RECEIVER(bs *uint16, n uint, param unsafe.Pointer) int {
670670
// typedef VOID SC_CALLBACK LPCSTR_RECEIVER( LPCSTR str, UINT str_length, LPVOID param );
671671

672672
//export goLPCSTR_RECEIVER
673-
func goLPCSTR_RECEIVER(bs *byte, n uint, param unsafe.Pointer) int {
673+
func goLPCSTR_RECEIVER(bs C.LPCSTR, n uint, param unsafe.Pointer) int {
674674
s := (*string)(param)
675-
*s = BytePtrToString(bs)
675+
*s = C.GoString(bs)
676676
return 0
677677
}
678678

types.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ const (
7171
HANDLE_DRAW = 0x0040 /** drawing request (event) */
7272
HANDLE_DATA_ARRIVED = 0x080 /** requested data () has been delivered */
7373
HANDLE_BEHAVIOR_EVENT = 0x0100 /** logical synthetic events:
74-
BUTTON_CLICK HYPERLINK_CLICK etc.
75-
a.k.a. notifications from intrinsic behaviors */
74+
BUTTON_CLICK HYPERLINK_CLICK etc.
75+
a.k.a. notifications from intrinsic behaviors */
7676
HANDLE_METHOD_CALL = 0x0200 /** behavior specific methods */
7777
HANDLE_SCRIPTING_METHOD_CALL = 0x0400 /** behavior specific methods */
7878
HANDLE_TISCRIPT_METHOD_CALL = 0x0800 /** behavior specific methods using direct tiscript::value's */
@@ -384,7 +384,7 @@ const (
384384
BY_MOUSE_CLICK EventReason = iota
385385
BY_KEY_CLICK
386386
SYNTHESIZED // synthesized programmatically generated.
387-
BY_MOUSE_ON_ICON
387+
BY_MOUSE_ON_ICON
388388
)
389389

390390
type EditChangedReason uint
@@ -395,7 +395,7 @@ const (
395395
BY_INS_CHARS // character range insertion clipboard
396396
BY_DEL_CHAR // single char deletion
397397
BY_DEL_CHARS // character range deletion (selection)
398-
BY_UNDO_REDO // undo/redo
398+
BY_UNDO_REDO // undo/redo
399399
)
400400

401401
type BehaviorMethodIdentifier uint32
@@ -593,7 +593,7 @@ type MethodParams struct {
593593
type ScriptingMethodParams C.SCRIPTING_METHOD_PARAMS
594594

595595
func (s *ScriptingMethodParams) Name() string {
596-
return BytePtrToString((*byte)(unsafe.Pointer(s.name)))
596+
return C.GoString(s.name)
597597
}
598598

599599
func (s *ScriptingMethodParams) Argc() int {
@@ -780,7 +780,7 @@ const (
780780
* asynchronously.
781781
**/
782782
/* obsolete #define SC_DOCUMENT_COMPLETE 0x03
783-
use DOCUMENT_COMPLETE DOM event.
783+
use DOCUMENT_COMPLETE DOM event.
784784
*/
785785

786786
/**This notification is sent on parsing the document and while processing
@@ -976,7 +976,7 @@ type ScnAttachBehavior C.SCN_ATTACH_BEHAVIOR
976976
// }
977977

978978
func (s *ScnAttachBehavior) BehaviorName() string {
979-
return BytePtrToString((*byte)(unsafe.Pointer(s.behaviorName)))
979+
return C.GoString(s.behaviorName)
980980
}
981981

982982
func (s *ScnAttachBehavior) Element() C.HELEMENT {
@@ -1175,12 +1175,12 @@ const (
11751175
// {
11761176
const (
11771177
GFX_LAYER_GDI = 1
1178-
GFX_LAYER_CG = 1
1179-
GFX_LAYER_CAIRO= 1
1178+
GFX_LAYER_CG = 1
1179+
GFX_LAYER_CAIRO= 1
11801180
GFX_LAYER_WARP = 2
11811181
GFX_LAYER_D2D = 3
1182-
GFX_LAYER_SKIA = 4
1183-
GFX_LAYER_SKIA_OPENGL = 5
1182+
GFX_LAYER_SKIA = 4
1183+
GFX_LAYER_SKIA_OPENGL = 5
11841184
GFX_LAYER_AUTO = 0xFFFF
11851185
)
11861186

utils.go

Lines changed: 81 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,81 @@
1-
package sciter
2-
3-
/*
4-
#cgo CFLAGS: -Iinclude
5-
#include "sciter-x.h"
6-
*/
7-
import "C"
8-
import (
9-
"syscall"
10-
"unicode/utf16"
11-
"unsafe"
12-
)
13-
14-
// Returns the utf-8 encoding of the utf-16 sequence s,
15-
// with a terminating NUL removed.
16-
func Utf16ToString(s *uint16) string {
17-
if s == nil {
18-
panic("null cstring")
19-
}
20-
us := make([]uint16, 0, 256)
21-
for p := uintptr(unsafe.Pointer(s)); ; p += 2 {
22-
u := *(*uint16)(unsafe.Pointer(p))
23-
if u == 0 {
24-
return string(utf16.Decode(us))
25-
}
26-
us = append(us, u)
27-
}
28-
return ""
29-
}
30-
31-
func Utf16ToStringLength(s *uint16, length int) string {
32-
if s == nil {
33-
panic("null cstring")
34-
}
35-
us := make([]uint16, 0, 256)
36-
for p, i := uintptr(unsafe.Pointer(s)), 0; i < length; p, i = p+2, i+1 {
37-
u := *(*uint16)(unsafe.Pointer(p))
38-
us = append(us, u)
39-
}
40-
return string(utf16.Decode(us))
41-
}
42-
43-
func BytePtrToString(s *byte) string {
44-
if s == nil {
45-
panic("null cstring")
46-
}
47-
bs := make([]byte, 0, 256)
48-
for p := uintptr(unsafe.Pointer(s)); ; p += 1 {
49-
b := *(*byte)(unsafe.Pointer(p))
50-
if b == 0 {
51-
return string(bs)
52-
}
53-
bs = append(bs, b)
54-
}
55-
return ""
56-
}
57-
58-
func StringToBytePtr(s string) *byte {
59-
bs := ([]byte)(s)
60-
return &bs[0]
61-
}
62-
63-
func Utf16FromString(s string) ([]uint16, error) {
64-
for i := 0; i < len(s); i++ {
65-
if s[i] == 0 {
66-
return nil, syscall.EINVAL
67-
}
68-
}
69-
return utf16.Encode([]rune(s + "\x00")), nil
70-
}
71-
72-
func StringToWcharPtr(s string) *C.WCHAR {
73-
return (*C.WCHAR)(unsafe.Pointer(StringToUTF16Ptr(s)))
74-
}
75-
76-
func StringToUTF16Ptr(s string) *uint16 {
77-
us, _ := Utf16FromString(s)
78-
return &us[0]
79-
}
80-
81-
func StringToUTF16PtrWithLen(s string) (*uint16, int) {
82-
us, _ := Utf16FromString(s)
83-
length := len(us) - 1
84-
return &us[0], length
85-
}
86-
87-
func BytePtrToBytes(bp *byte, size uint) []byte {
88-
bs := []byte{}
89-
p := uintptr(unsafe.Pointer(bp))
90-
step := unsafe.Sizeof(*bp)
91-
for i := uint(0); i < size; i++ {
92-
b := *(*byte)(unsafe.Pointer(p + uintptr(i)*step))
93-
bs = append(bs, b)
94-
}
95-
return bs
96-
}
1+
package sciter
2+
3+
/*
4+
#cgo CFLAGS: -Iinclude
5+
#include "sciter-x.h"
6+
*/
7+
import "C"
8+
import (
9+
"syscall"
10+
"unicode/utf16"
11+
"unsafe"
12+
)
13+
14+
// Returns the utf-8 encoding of the utf-16 sequence s,
15+
// with a terminating NUL removed.
16+
func Utf16ToString(s *uint16) string {
17+
if s == nil {
18+
panic("null cstring")
19+
}
20+
us := make([]uint16, 0, 256)
21+
for p := uintptr(unsafe.Pointer(s)); ; p += 2 {
22+
u := *(*uint16)(unsafe.Pointer(p))
23+
if u == 0 {
24+
return string(utf16.Decode(us))
25+
}
26+
us = append(us, u)
27+
}
28+
return ""
29+
}
30+
31+
func Utf16ToStringLength(s *uint16, length int) string {
32+
if s == nil {
33+
panic("null cstring")
34+
}
35+
us := make([]uint16, 0, 256)
36+
for p, i := uintptr(unsafe.Pointer(s)), 0; i < length; p, i = p+2, i+1 {
37+
u := *(*uint16)(unsafe.Pointer(p))
38+
us = append(us, u)
39+
}
40+
return string(utf16.Decode(us))
41+
}
42+
43+
func StringToBytePtr(s string) *byte {
44+
bs := ([]byte)(s)
45+
return &bs[0]
46+
}
47+
48+
func Utf16FromString(s string) ([]uint16, error) {
49+
for i := 0; i < len(s); i++ {
50+
if s[i] == 0 {
51+
return nil, syscall.EINVAL
52+
}
53+
}
54+
return utf16.Encode([]rune(s + "\x00")), nil
55+
}
56+
57+
func StringToWcharPtr(s string) *C.WCHAR {
58+
return (*C.WCHAR)(unsafe.Pointer(StringToUTF16Ptr(s)))
59+
}
60+
61+
func StringToUTF16Ptr(s string) *uint16 {
62+
us, _ := Utf16FromString(s)
63+
return &us[0]
64+
}
65+
66+
func StringToUTF16PtrWithLen(s string) (*uint16, int) {
67+
us, _ := Utf16FromString(s)
68+
length := len(us) - 1
69+
return &us[0], length
70+
}
71+
72+
func BytePtrToBytes(bp *byte, size uint) []byte {
73+
bs := []byte{}
74+
p := uintptr(unsafe.Pointer(bp))
75+
step := unsafe.Sizeof(*bp)
76+
for i := uint(0); i < size; i++ {
77+
b := *(*byte)(unsafe.Pointer(p + uintptr(i)*step))
78+
bs = append(bs, b)
79+
}
80+
return bs
81+
}

0 commit comments

Comments
 (0)