about summary refs log tree commit diff stats
path: root/src/bindings
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-02 10:56:42 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-02 10:56:42 +0100
commitc9588388d04bb3180c3cfec4359462421c0407f0 (patch)
treeea0de3de960bfb88ae2463c92cf7a3f745f2b63b /src/bindings
parent2fb87f5c609be4d42f71fbd6a9439de47c6d0189 (diff)
downloadchawan-c9588388d04bb3180c3cfec4359462421c0407f0.tar.gz
Get rid of clang 16 workaround
* bindings/quickjs: importc and use correct pointer types
* add constcharp module for when it is unavoidable
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/constcharp.nim6
-rw-r--r--src/bindings/quickjs.nim19
2 files changed, 20 insertions, 5 deletions
diff --git a/src/bindings/constcharp.nim b/src/bindings/constcharp.nim
new file mode 100644
index 00000000..057b8acb
--- /dev/null
+++ b/src/bindings/constcharp.nim
@@ -0,0 +1,6 @@
+type
+  cstringConstImpl {.importc: "const char*".} = cstring
+  cstringConst* = distinct cstringConstImpl
+
+proc `[]`*(s: cstringConst, i: int): char = cstring(s)[i]
+proc `$`*(s: cstringConst): string {.borrow.}
diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim
index 65d6c679..d573a1dd 100644
--- a/src/bindings/quickjs.nim
+++ b/src/bindings/quickjs.nim
@@ -1,3 +1,5 @@
+import bindings/constcharp
+
 const qjsheader = "quickjs/quickjs.h"
 
 {.passC: "-Ilib/".}
@@ -65,9 +67,16 @@ else:
     JSValue(u: JSValueUnion(`ptr`: p), tag: t)
 
 type
-  JSRuntime* = ptr object
-  JSContext* = ptr object
-  JSModuleDef* = ptr object
+  JSRuntimeT {.importc: "JSRuntime", header: qjsheader,
+    incompleteStruct.} = object
+  JSContextT {.importc: "JSContext", header: qjsheader,
+    incompleteStruct.} = object
+  JSModuleDefT {.importc: "JSModuleDef", header: qjsheader,
+    incompleteStruct.} = object
+
+  JSRuntime* = ptr JSRuntimeT
+  JSContext* = ptr JSContextT
+  JSModuleDef* = ptr JSModuleDefT
   JSCFunction* = proc (ctx: JSContext, this_val: JSValue, argc: cint,
       argv: ptr UncheckedArray[JSValue]): JSValue {.cdecl.}
   JSCFunctionData* = proc (ctx: JSContext, this_val: JSValue, argc: cint, argv: ptr JSValue, magic: cint, func_data: ptr JSValue): JSValue {.cdecl.}
@@ -83,8 +92,8 @@ type
   JSClassGCMark* = proc (rt: JSRuntime, val: JSValue, mark_func: JS_MarkFunc) {.cdecl.}
   JS_MarkFunc* = proc (rt: JSRuntime, gp: ptr JSGCObjectHeader) {.cdecl.}
   JSModuleNormalizeFunc* = proc(ctx: JSContext, module_base_name,
-    module_name: cstring, opaque: pointer): cstring {.cdecl.}
-  JSModuleLoaderFunc* = proc(ctx: JSContext, module_name: cstring,
+    module_name: cstringConst, opaque: pointer): cstring {.cdecl.}
+  JSModuleLoaderFunc* = proc(ctx: JSContext, module_name: cstringConst,
     opaque: pointer): JSModuleDef {.cdecl.}
   JSJobFunc* = proc (ctx: JSContext, argc: cint, argv: ptr JSValue): JSValue {.cdecl.}
   JSGCObjectHeader* {.importc, header: qjsheader.} = object