From e6ad0ce65ce32b3ebe1572c1931410dee4fbc90c Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 21 Jan 2023 03:26:56 +0100 Subject: [PATCH] Some Crystal code to work on bindings. --- zig-impl/crystal/some-crystal-app/makefile | 9 + zig-impl/crystal/some-crystal-app/shard.yml | 13 + .../some-crystal-app/src/some-crystal-app.cr | 53 ++++ .../some-crystal-app/valgrind.suppressions | 229 ++++++++++++++++++ 4 files changed, 304 insertions(+) create mode 100644 zig-impl/crystal/some-crystal-app/makefile create mode 100644 zig-impl/crystal/some-crystal-app/shard.yml create mode 100644 zig-impl/crystal/some-crystal-app/src/some-crystal-app.cr create mode 100644 zig-impl/crystal/some-crystal-app/valgrind.suppressions diff --git a/zig-impl/crystal/some-crystal-app/makefile b/zig-impl/crystal/some-crystal-app/makefile new file mode 100644 index 0000000..68601f2 --- /dev/null +++ b/zig-impl/crystal/some-crystal-app/makefile @@ -0,0 +1,9 @@ +LDPATH ?= /tmp/libipc/zig-impl/build +SRC ?= ./bin/some-crystal-app + +VG_OPTS = --leak-check=full -v +VG_OPTS += --suppressions=valgrind.suppressions +VG_OPTS += --gen-suppressions=all + +valgrind: + LD_LIBRARY_PATH=$(LDPATH) valgrind $(VG_OPTS) $(SRC) diff --git a/zig-impl/crystal/some-crystal-app/shard.yml b/zig-impl/crystal/some-crystal-app/shard.yml new file mode 100644 index 0000000..3fafe97 --- /dev/null +++ b/zig-impl/crystal/some-crystal-app/shard.yml @@ -0,0 +1,13 @@ +name: some-crystal-app +version: 0.1.0 + +authors: + - Philippe Pittoli + +targets: + some-crystal-app: + main: src/some-crystal-app.cr + +crystal: 1.7.1 + +license: MIT diff --git a/zig-impl/crystal/some-crystal-app/src/some-crystal-app.cr b/zig-impl/crystal/some-crystal-app/src/some-crystal-app.cr new file mode 100644 index 0000000..68b8e72 --- /dev/null +++ b/zig-impl/crystal/some-crystal-app/src/some-crystal-app.cr @@ -0,0 +1,53 @@ +@[Link("ipc")] +lib LibIPC +# enum EventType +# Error # Self explanatory. +# Connection # New user. +# Disconnection # User disconnected. +# MessageRx # Message received. +# MessageTx # Message sent. +# Timer # Timeout in the poll(2) function. +# External # Message received from a non IPC socket. +# SwitchRx # Switch subsystem: message received. +# SwitchTx # Switch subsystem: message send. +# end + + fun init = ipc_context_init (Pointer(Pointer(Void))) : LibC::Int + fun deinit = ipc_context_deinit (Pointer(Void)) : Void + +# # Connection functions. +# # Context is allocated, ipcd is requested and the connection/initialisation is performed. +# fun service_init = ipc_service_init (Pointer(Void), LibC::Int*, LibC::Char*, LibC::UInt16) : LibC::Int +# fun connect_service = ipc_connect_service(Pointer(Void), LibC::Int*, LibC::Char*, LibC::UInt16) : LibC::Int +# +# # Closing connections. +# fun ipc_close(Pointer(Void), index : LibC::UInt64T) : LibC::Int +# fun ipc_close_all(Pointer(Void)) : LibC::Int +# +# # Loop function. +# fun ipc_wait_event(Ctx*, Event*, LibC::Int*) : LibC::Int +# +# # Adding and removing file discriptors to read. +# fun ipc_add(Ctx*, Connection*, Pollfd*) : LibC::Int +# fun ipc_del(Ctx*, LibC::UInt) : LibC::Int +# fun ipc_add_fd(Ctx*, LibC::Int) : LibC::Int +# fun ipc_del_fd(Ctx*, LibC::Int) : LibC::Int +# +# # Sending a message (will wait the fd to become available for IO operations). +# fun ipc_write(Ctx*, Message*) : LibC::Int +# fun ipc_schedule(Pointer(Void), ) : LibC::Int +# +# # Sending a message NOW. +# # WARNING: unbuffered send do not wait the fd to become available. +# fun ipc_write_fd(Int32, Message*) : LibC::Int +end + +# TODO: Write documentation for `Some::Crystal::App` +module Some::Crystal::App + VERSION = "0.1.0" + + # TODO: Put your code here + ctx : Pointer(Void) = Pointer(Void).null + LibIPC.init (pointerof(ctx)) + LibIPC.deinit (ctx) +end diff --git a/zig-impl/crystal/some-crystal-app/valgrind.suppressions b/zig-impl/crystal/some-crystal-app/valgrind.suppressions new file mode 100644 index 0000000..10795fb --- /dev/null +++ b/zig-impl/crystal/some-crystal-app/valgrind.suppressions @@ -0,0 +1,229 @@ +{ + + Memcheck:Addr1 + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_init_linux_data_start + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_push_all_eager + fun:GC_with_callee_saves_pushed + fun:GC_push_roots + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_push_all_eager + fun:GC_with_callee_saves_pushed + fun:GC_push_roots + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_mark_from + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_mark_from + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_mark_from + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_mark_from + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_mark_from + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:memalign + fun:posix_memalign + obj:/tmp/libipc/zig-impl/build/libipc.so.0.1.0 + fun:*Crystal::main_user_code:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + fun:*Signal::setup_segfault_handler:(Int32 | Nil) + fun:*Exception::CallStack::setup_crash_handler:(Int32 | Nil) + fun:__crystal_main + fun:*Crystal::main_user_code:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_mark_from + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_push_all_eager + fun:GC_with_callee_saves_pushed + fun:GC_push_roots + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Addr1 + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_init_linux_data_start + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_mark_from + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_mark_from + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_push_all_eager + fun:GC_with_callee_saves_pushed + fun:GC_push_roots + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_mark_from + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +} +{ + + Memcheck:Cond + fun:GC_mark_from + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_mark_some + obj:/usr/lib/libgc.so.1.5.0 + fun:GC_try_to_collect_inner + fun:GC_init + fun:*GC::init:Nil + fun:*Crystal::main:Int32 + fun:main +}