Charlene, Theo,

Thanks for the input. I have an expanded diff taking all of this into
account.

The additions are:

- Instead of stub resolve function in uv.c, use the commit from Motion
  Twin. This allows leaderboards and daily challenges to work in Dead
  Cells.
- Add conditionals for typedef's for char{16,32}_t in hl.h. Otherwise,
  including this in C++ projects with clang fails. Noticed with [1].
  brynet@ helped figure out the logic here.

Still builds and runs on amd64.

I would appreciate testing on a gcc arch, Charlene maybe?

Further comments inline.


> > This does build on sparc64. Not sure how to test it though, as haxe is
> > marked broken.

I built the simple Haxe Hello World example [2] according to [3] as
output.hl and uploaded it to https://thfr.info/pub/output.hl for
testing.

$ hl output.hl
Main.hx:3: Hello World
$

> > Shouldn't this set COMPILER_LANGS = c also?

Included based on Charlene's updated diff.

> > The use of pthread_self() in patches/patch-src_std_thread_c looks
> > fishy. It generates this warning:
> > 
> > src/std/thread.c: In function 'hl_thread_id':
> > src/std/thread.c:374:9: warning: returning 'pthread_t' {aka 'struct
> > pthread *'} from a function with return type 'int' makes integer from
> > pointer without a cast [-Wint-conversion] return pthread_self();
> >           ^~~~~~~~~~~~~~
> > 
> > Is this intended and really correct?

You're right; while it works and I haven't run into any significant
issues, this is a recipe for trouble in the future. I did some more
research and getthrid(2) seems to be a better choice. It returns pid_t,
which should be a signed int. The warning doesn't show up anymore with
this change.

> > The second one is ugly but probably harmless:
> > 
> > ===>  Building for hashlink-1.10p0 
> > getconf: LONG_BIT: unknown variable
> > 
> > The Makefile tries to set some arch-specific things using this:
> > 
> > LBITS := $(shell getconf LONG_BIT)
> > ARCH ?= $(LBITS)
> > [...]
> > ifeq ($(ARCH),32)                       
> > CFLAGS += -I /usr/include/i386-linux-gnu
> > LIBFLAGS += -L/opt/libjpeg-turbo/lib    
> > else                                    
> > LIBFLAGS += -L/opt/libjpeg-turbo/lib64  
> > endif

I removed those Makefile segments because we don't do any of the
lib{,64} or i386-linux gnu compatibility stuff.

Thanks for raising these valid points!

[1] https://github.com/rfht/hlsteam-stub
[2] https://haxe.org/manual/introduction-hello-world.html
[3] https://hashlink.haxe.org/

Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/hashlink/Makefile,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 Makefile
--- Makefile    25 Feb 2020 02:36:47 -0000      1.1.1.1
+++ Makefile    6 Mar 2020 00:52:31 -0000
@@ -9,6 +9,7 @@ V =             1.10
 GH_ACCOUNT =   HaxeFoundation
 GH_PROJECT =   hashlink
 GH_TAGNAME =   ${V}
+REVISION =     0
 
 SHARED_LIBS =  hl      0.0     # 1.10
 
@@ -22,6 +23,10 @@ PERMIT_PACKAGE =     Yes
 WANTLIB += SDL2 c m mbedcrypto mbedtls mbedx509 openal png pthread
 WANTLIB += turbojpeg uv vorbisfile z
 
+# C11
+COMPILER =             base-clang ports-gcc
+COMPILER_LANGS =       c
+
 LIB_DEPENDS =  audio/openal \
                devel/libuv \
                devel/sdl2 \
@@ -34,6 +39,12 @@ SUBST_VARS +=        CFLAGS
 
 post-extract:
        rm -rf ${WRKSRC}/include/{fmt,turbojpeg}
+       # remove dos line endings
+       cd ${WRKSRC} && perl -i -pe 's/\r$$//' \
+               libs/uv/uv.c \
+               src/hl.h \
+               src/std/socket.c \
+               src/std/thread.c
 
 do-gen:
        ${SUBST_CMD} ${WRKSRC}/Makefile
Index: patches/patch-Makefile
===================================================================
RCS file: /cvs/ports/lang/hashlink/patches/patch-Makefile,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 patch-Makefile
--- patches/patch-Makefile      25 Feb 2020 02:36:47 -0000      1.1.1.1
+++ patches/patch-Makefile      6 Mar 2020 00:52:31 -0000
@@ -3,11 +3,17 @@ $OpenBSD: patch-Makefile,v 1.1.1.1 2020/
 remove -m$(ARCH)
 add versioning to libhl
 {CFLAGS} -> (CFLAGS) to not get picked up by SUBST_CMD
+remove Linux's 32-/64-bit detection
 
 Index: Makefile
 --- Makefile.orig
 +++ Makefile
-@@ -6,11 +6,11 @@ INSTALL_DIR ?= $(PREFIX)
+@@ -1,16 +1,14 @@
+ 
+-LBITS := $(shell getconf LONG_BIT)
+-ARCH ?= $(LBITS)
+ PREFIX ?= /usr/local
+ INSTALL_DIR ?= $(PREFIX)
  
  LIBS=fmt sdl ssl openal ui uv mysql
  
@@ -24,7 +30,7 @@ Index: Makefile
  LIBTURBOJPEG = -lturbojpeg
  
  PCRE = include/pcre/pcre_chartables.o include/pcre/pcre_compile.o 
include/pcre/pcre_dfa_exec.o \
-@@ -80,7 +80,7 @@ RELEASE_NAME = osx
+@@ -80,16 +78,9 @@ RELEASE_NAME = osx
  else
  
  # Linux
@@ -32,8 +38,17 @@ Index: Makefile
 +CFLAGS += -fPIC -pthread
  LFLAGS += -lm -Wl,-rpath,. -Wl,--export-dynamic -Wl,--no-undefined
  
- ifeq ($(ARCH),32)
-@@ -123,34 +123,34 @@ uninstall:
+-ifeq ($(ARCH),32)
+-CFLAGS += -I /usr/include/i386-linux-gnu
+-LIBFLAGS += -L/opt/libjpeg-turbo/lib
+-else
+-LIBFLAGS += -L/opt/libjpeg-turbo/lib64
+-endif
+-
+ LIBOPENAL = -lopenal
+ RELEASE_NAME = linux
+ 
+@@ -123,34 +114,34 @@ uninstall:
  libs: $(LIBS)
  
  libhl: ${LIB}
@@ -78,7 +93,7 @@ Index: Makefile
        
  mesa:
        (cd libs/mesa && make)
-@@ -204,7 +204,7 @@ release_osx:
+@@ -204,7 +195,7 @@ release_osx:
  .SUFFIXES : .c .o
  
  .c.o :
Index: patches/patch-libs_uv_uv_c
===================================================================
RCS file: /cvs/ports/lang/hashlink/patches/patch-libs_uv_uv_c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 patch-libs_uv_uv_c
--- patches/patch-libs_uv_uv_c  25 Feb 2020 02:36:47 -0000      1.1.1.1
+++ patches/patch-libs_uv_uv_c  6 Mar 2020 00:52:31 -0000
@@ -1,17 +1,55 @@
 $OpenBSD: patch-libs_uv_uv_c,v 1.1.1.1 2020/02/25 02:36:47 thfr Exp $
 
-add stub resolve function
+add resolve function from https://github.com/motion-twin
+commit 61be4ae30e52a5ffcfa9212b9b81d4e06225c2ea
 
 Index: libs/uv/uv.c
 --- libs/uv/uv.c.orig
 +++ libs/uv/uv.c
-@@ -93,6 +93,9 @@ static void on_write( uv_write_t *wr, int status ) {
-       trigger_callb((uv_handle_t*)wr,EVT_WRITE,&args,1,false);
-       on_close((uv_handle_t*)wr);
- }
-+HL_PRIM void HL_NAME(resolve)() {
+@@ -94,6 +94,46 @@ static void on_write( uv_write_t *wr, int status ) {
+       on_close((uv_handle_t*)wr);
+ }
+ 
++void on_resolve(uv_getaddrinfo_t *h, int status, struct addrinfo *resp) {
++      vclosure *cb = (vclosure*)h->data;
++      hl_remove_root(&h->data);
++      int ipv4 = 0;
++      vbyte *ipv6 = NULL;
++      if (status == 0 && resp) {
++              if (resp->ai_family == AF_INET) {
++                      ipv4 = ((struct 
sockaddr_in*)resp->ai_addr)->sin_addr.s_addr;
++              } else if (resp->ai_family == AF_INET6) {
++                      struct in6_addr *ip = &((struct sockaddr_in6 
*)resp->ai_addr)->sin6_addr;
++                      ipv6 = hl_copy_bytes((vbyte*)ip, sizeof(ip));
++              } else {
++                      hl_error("Unsupported address family");
++              }
++      }
++
++      if (cb->hasValue)
++              ((void(*)(void*, int, int, vbyte*))cb->fun)(cb->value, status, 
ipv4, ipv6);
++      else
++              ((void(*)(int, int, vbyte*))cb->fun)(status, ipv4, ipv6);
++
++      free(h);
 +}
-+DEFINE_PRIM(_VOID, resolve, _NO_ARG);
- 
- HL_PRIM bool HL_NAME(stream_write)( uv_stream_t *s, vbyte *b, int size, 
vclosure *c ) {
-       uv_write_t *wr = UV_ALLOC(uv_write_t);
++
++HL_PRIM bool HL_NAME(resolve)(uv_loop_t *loop, char *node, int ihints, 
vclosure *cb) {
++      // TODO hints
++      uv_getaddrinfo_t *h = UV_ALLOC(uv_getaddrinfo_t);
++      memset(h, 0, sizeof(h));
++      h->data = (void*)cb;
++      int r = uv_getaddrinfo(loop, h, on_resolve, node, NULL, NULL);
++      if (r) {
++              free(h);
++              return false;
++      }
++      hl_add_root(&h->data);
++      return true;
++}
++
++DEFINE_PRIM(_VOID, resolve, _LOOP _BYTES _I32 _FUN(_VOID, _I32 _I32 _BYTES));
++
+ HL_PRIM bool HL_NAME(stream_write)( uv_stream_t *s, vbyte *b, int size, 
vclosure *c ) {
+       uv_write_t *wr = UV_ALLOC(uv_write_t);
+       events_data *d = init_hl_data((uv_handle_t*)wr);
Index: patches/patch-src_hl_h
===================================================================
RCS file: /cvs/ports/lang/hashlink/patches/patch-src_hl_h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 patch-src_hl_h
--- patches/patch-src_hl_h      25 Feb 2020 02:36:47 -0000      1.1.1.1
+++ patches/patch-src_hl_h      6 Mar 2020 00:52:31 -0000
@@ -1,16 +1,23 @@
 $OpenBSD: patch-src_hl_h,v 1.1.1.1 2020/02/25 02:36:47 thfr Exp $
 
 add OpenBSD to ifdef
+don't typedef char{16,32}_t in clang with C++
 
 Index: src/hl.h
 --- src/hl.h.orig
 +++ src/hl.h
-@@ -234,7 +234,7 @@ typedef uint16_t uchar;
- #     define USTR(str)        u##str
- #else
- #     include <stdarg.h>
--#if defined(HL_IOS) || defined(HL_TVOS) || defined(HL_MAC)
-+#if defined(HL_IOS) || defined(HL_TVOS) || defined(HL_MAC) || 
defined(__OpenBSD__)
- #include <stddef.h>
- #include <stdint.h>
- typedef uint16_t char16_t;
+@@ -234,11 +234,13 @@ typedef uint16_t uchar;
+ #     define USTR(str)        u##str
+ #else
+ #     include <stdarg.h>
+-#if defined(HL_IOS) || defined(HL_TVOS) || defined(HL_MAC)
++#if defined(HL_IOS) || defined(HL_TVOS) || defined(HL_MAC) || 
defined(__OpenBSD__)
+ #include <stddef.h>
+ #include <stdint.h>
++#if defined(__clang__) && !defined(__cplusplus)
+ typedef uint16_t char16_t;
+ typedef uint32_t char32_t;
++#endif
+ #else
+ #     include <uchar.h>
+ #endif
Index: patches/patch-src_std_socket_c
===================================================================
RCS file: /cvs/ports/lang/hashlink/patches/patch-src_std_socket_c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 patch-src_std_socket_c
--- patches/patch-src_std_socket_c      25 Feb 2020 02:36:47 -0000      1.1.1.1
+++ patches/patch-src_std_socket_c      6 Mar 2020 00:52:31 -0000
@@ -5,12 +5,21 @@ add OpenBSD to ifdef
 Index: src/std/socket.c
 --- src/std/socket.c.orig
 +++ src/std/socket.c
-@@ -192,7 +192,7 @@ HL_PRIM int hl_host_resolve( vbyte *host ) {
-       ip = inet_addr((char*)host);
-       if( ip == INADDR_NONE ) {
-               struct hostent *h;
--#     if defined(HL_WIN) || defined(HL_MAC) || defined(HL_IOS) || 
defined(HL_TVOS) || defined (HL_CYGWIN) || defined(HL_CONSOLE)
-+#     if defined(HL_WIN) || defined(__OpenBSD__) || defined(HL_MAC) || 
defined(HL_IOS) || defined(HL_TVOS) || defined (HL_CYGWIN) || 
defined(HL_CONSOLE)
-               h = gethostbyname((char*)host);
- #     else
-               struct hostent hbase;
+@@ -192,7 +192,7 @@ HL_PRIM int hl_host_resolve( vbyte *host ) {
+       ip = inet_addr((char*)host);
+       if( ip == INADDR_NONE ) {
+               struct hostent *h;
+-#     if defined(HL_WIN) || defined(HL_MAC) || defined(HL_IOS) || 
defined(HL_TVOS) || defined (HL_CYGWIN) || defined(HL_CONSOLE)
++#     if defined(HL_WIN) || defined(HL_MAC) || defined(HL_IOS) || 
defined(HL_TVOS) || defined (HL_CYGWIN) || defined(HL_CONSOLE) || 
defined(__OpenBSD__)
+               h = gethostbyname((char*)host);
+ #     else
+               struct hostent hbase;
+@@ -219,7 +219,7 @@ HL_PRIM vbyte *hl_host_to_string( int ip ) {
+ HL_PRIM vbyte *hl_host_reverse( int ip ) {
+       struct hostent *h;
+       hl_blocking(true);
+-#     if defined(HL_WIN) || defined(HL_MAC) || defined(HL_IOS) || 
defined(HL_TVOS) || defined(HL_CYGWIN) || defined(HL_CONSOLE)
++#     if defined(HL_WIN) || defined(HL_MAC) || defined(HL_IOS) || 
defined(HL_TVOS) || defined(HL_CYGWIN) || defined(HL_CONSOLE) || 
defined(__OpenBSD__)
+       h = gethostbyaddr((char *)&ip,4,AF_INET);
+ #     elif defined(__ANDROID__)
+       hl_error("hl_host_reverse() not available for this platform");
Index: patches/patch-src_std_thread_c
===================================================================
RCS file: /cvs/ports/lang/hashlink/patches/patch-src_std_thread_c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 patch-src_std_thread_c
--- patches/patch-src_std_thread_c      25 Feb 2020 02:36:47 -0000      1.1.1.1
+++ patches/patch-src_std_thread_c      6 Mar 2020 00:52:31 -0000
@@ -1,16 +1,16 @@
 $OpenBSD: patch-src_std_thread_c,v 1.1.1.1 2020/02/25 02:36:47 thfr Exp $
 
-enable thread_id for OpenBSD using pthread_self()
+enable hl_thread_id for OpenBSD using getthrid(2)
 
 Index: src/std/thread.c
 --- src/std/thread.c.orig
 +++ src/std/thread.c
-@@ -370,6 +370,8 @@ HL_PRIM int hl_thread_id() {
-       uint64_t tid64;
-       pthread_threadid_np(NULL, &tid64);
-       return (pid_t)tid64;
+@@ -370,6 +370,8 @@ HL_PRIM int hl_thread_id() {
+       uint64_t tid64;
+       pthread_threadid_np(NULL, &tid64);
+       return (pid_t)tid64;
 +#elif defined(__OpenBSD__)
-+      return pthread_self();
- #elif defined(SYS_gettid) && !defined(HL_TVOS)
-       return syscall(SYS_gettid);
- #else
++      return getthrid();
+ #elif defined(SYS_gettid) && !defined(HL_TVOS)
+       return syscall(SYS_gettid);
+ #else

Reply via email to