Skip to content

ffi: NULL char* does not reliably round-trip to empty string in TS #591

@cs01

Description

@cs01

Bug

A null char* returned from FFI doesn't reliably compare === "" on the TS side. Worked around in lib/net.ts (PR #585) by exposing an explicit isOpen() probe instead of relying on empty-string-as-sentinel.

Impact

Bridges that return "error or no result" via a null C string can't use empty-string as a failure sentinel from the TS side. Forces each bridge to add explicit _is_* / _last_error probe functions.

Workaround pattern (current)

// net-bridge.c
char *cs_net_last_error(void *sock) { ... returns GC'd string or NULL ... }
int cs_socket_is_open(void *sock) { ... returns 0/1 explicitly ... }
// lib/net.ts — instead of
if (err === "") { /* ok */ }
// use
if (socket.isOpen()) { /* ok */ }

Likely fix location

FFI string-return marshaling — null char* should round-trip to TS as empty string or a distinguished null sentinel consistently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions