diff --git a/lib/Makefile.am b/lib/Makefile.am index 3262f07..7266431 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -102,7 +102,7 @@ libhcl_la_DEPENDENCIES += $(abs_builddir)/../mod/libhcl-str.la endif bin_PROGRAMS = hcl -hcl_SOURCES = main.c +hcl_SOURCES = main.c cb-impl.c cb-impl.h hcl_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) hcl_LDFLAGS = $(LDFLAGS_ALL_COMMON) hcl_LDADD = $(LIBADD_LIB_COMMON) -lhcl @@ -123,21 +123,21 @@ libhclex_la_LIBADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl libhclex_la_DEPENDENCIES = libhcl.la bin_PROGRAMS += hcls -hcls_SOURCES = main-s.c +hcls_SOURCES = main-s.c cb-impl.c cb-impl.h hcls_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) hcls_LDFLAGS = $(LDFLAGS_ALL_COMMON) hcls_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex hcls_DEPENDENCIES = libhclex.la bin_PROGRAMS += hclc -hclc_SOURCES = main-c.c +hclc_SOURCES = main-c.c cb-impl.c cb-impl.h hclc_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) hclc_LDFLAGS = $(LDFLAGS_ALL_COMMON) hclc_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex hclc_DEPENDENCIES = libhclex.la bin_PROGRAMS += hclj -hclj_SOURCES = main-j.c +hclj_SOURCES = main-j.c cb-impl.c cb-impl.h hclj_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) hclj_LDFLAGS = $(LDFLAGS_ALL_COMMON) hclj_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex diff --git a/lib/Makefile.in b/lib/Makefile.in index 7524f67..4e29e3a 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -183,25 +183,28 @@ libhclex_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ @ENABLE_HCLEX_TRUE@am__EXEEXT_1 = hcls$(EXEEXT) hclc$(EXEEXT) \ @ENABLE_HCLEX_TRUE@ hclj$(EXEEXT) PROGRAMS = $(bin_PROGRAMS) -am_hcl_OBJECTS = hcl-main.$(OBJEXT) +am_hcl_OBJECTS = hcl-main.$(OBJEXT) hcl-cb-impl.$(OBJEXT) hcl_OBJECTS = $(am_hcl_OBJECTS) hcl_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(hcl_LDFLAGS) $(LDFLAGS) -o $@ -am__hclc_SOURCES_DIST = main-c.c -@ENABLE_HCLEX_TRUE@am_hclc_OBJECTS = hclc-main-c.$(OBJEXT) +am__hclc_SOURCES_DIST = main-c.c cb-impl.c cb-impl.h +@ENABLE_HCLEX_TRUE@am_hclc_OBJECTS = hclc-main-c.$(OBJEXT) \ +@ENABLE_HCLEX_TRUE@ hclc-cb-impl.$(OBJEXT) hclc_OBJECTS = $(am_hclc_OBJECTS) hclc_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(hclc_LDFLAGS) $(LDFLAGS) -o $@ -am__hclj_SOURCES_DIST = main-j.c -@ENABLE_HCLEX_TRUE@am_hclj_OBJECTS = hclj-main-j.$(OBJEXT) +am__hclj_SOURCES_DIST = main-j.c cb-impl.c cb-impl.h +@ENABLE_HCLEX_TRUE@am_hclj_OBJECTS = hclj-main-j.$(OBJEXT) \ +@ENABLE_HCLEX_TRUE@ hclj-cb-impl.$(OBJEXT) hclj_OBJECTS = $(am_hclj_OBJECTS) hclj_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(hclj_LDFLAGS) $(LDFLAGS) -o $@ -am__hcls_SOURCES_DIST = main-s.c -@ENABLE_HCLEX_TRUE@am_hcls_OBJECTS = hcls-main-s.$(OBJEXT) +am__hcls_SOURCES_DIST = main-s.c cb-impl.c cb-impl.h +@ENABLE_HCLEX_TRUE@am_hcls_OBJECTS = hcls-main-s.$(OBJEXT) \ +@ENABLE_HCLEX_TRUE@ hcls-cb-impl.$(OBJEXT) hcls_OBJECTS = $(am_hcls_OBJECTS) hcls_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ @@ -495,7 +498,7 @@ libhcl_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) libhcl_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) libhcl_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_6) libhcl_la_DEPENDENCIES = $(am__append_7) -hcl_SOURCES = main.c +hcl_SOURCES = main.c cb-impl.c cb-impl.h hcl_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) hcl_LDFLAGS = $(LDFLAGS_ALL_COMMON) hcl_LDADD = $(LIBADD_LIB_COMMON) -lhcl @@ -511,17 +514,17 @@ hcl_DEPENDENCIES = libhcl.la @ENABLE_HCLEX_TRUE@libhclex_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) @ENABLE_HCLEX_TRUE@libhclex_la_LIBADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl @ENABLE_HCLEX_TRUE@libhclex_la_DEPENDENCIES = libhcl.la -@ENABLE_HCLEX_TRUE@hcls_SOURCES = main-s.c +@ENABLE_HCLEX_TRUE@hcls_SOURCES = main-s.c cb-impl.c cb-impl.h @ENABLE_HCLEX_TRUE@hcls_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hcls_LDFLAGS = $(LDFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hcls_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex @ENABLE_HCLEX_TRUE@hcls_DEPENDENCIES = libhclex.la -@ENABLE_HCLEX_TRUE@hclc_SOURCES = main-c.c +@ENABLE_HCLEX_TRUE@hclc_SOURCES = main-c.c cb-impl.c cb-impl.h @ENABLE_HCLEX_TRUE@hclc_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hclc_LDFLAGS = $(LDFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hclc_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex @ENABLE_HCLEX_TRUE@hclc_DEPENDENCIES = libhclex.la -@ENABLE_HCLEX_TRUE@hclj_SOURCES = main-j.c +@ENABLE_HCLEX_TRUE@hclj_SOURCES = main-j.c cb-impl.c cb-impl.h @ENABLE_HCLEX_TRUE@hclj_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hclj_LDFLAGS = $(LDFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hclj_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex @@ -688,9 +691,13 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hcl-cb-impl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hcl-main.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hclc-cb-impl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hclc-main-c.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hclj-cb-impl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hclj-main-j.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hcls-cb-impl.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hcls-main-s.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-bigint.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-comp.Plo@am__quote@ @@ -939,6 +946,20 @@ hcl-main.obj: main.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcl-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi` +hcl-cb-impl.o: cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcl-cb-impl.o -MD -MP -MF $(DEPDIR)/hcl-cb-impl.Tpo -c -o hcl-cb-impl.o `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcl-cb-impl.Tpo $(DEPDIR)/hcl-cb-impl.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cb-impl.c' object='hcl-cb-impl.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcl-cb-impl.o `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c + +hcl-cb-impl.obj: cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcl-cb-impl.obj -MD -MP -MF $(DEPDIR)/hcl-cb-impl.Tpo -c -o hcl-cb-impl.obj `if test -f 'cb-impl.c'; then $(CYGPATH_W) 'cb-impl.c'; else $(CYGPATH_W) '$(srcdir)/cb-impl.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcl-cb-impl.Tpo $(DEPDIR)/hcl-cb-impl.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cb-impl.c' object='hcl-cb-impl.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcl-cb-impl.obj `if test -f 'cb-impl.c'; then $(CYGPATH_W) 'cb-impl.c'; else $(CYGPATH_W) '$(srcdir)/cb-impl.c'; fi` + hclc-main-c.o: main-c.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclc_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclc-main-c.o -MD -MP -MF $(DEPDIR)/hclc-main-c.Tpo -c -o hclc-main-c.o `test -f 'main-c.c' || echo '$(srcdir)/'`main-c.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclc-main-c.Tpo $(DEPDIR)/hclc-main-c.Po @@ -953,6 +974,20 @@ hclc-main-c.obj: main-c.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclc_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclc-main-c.obj `if test -f 'main-c.c'; then $(CYGPATH_W) 'main-c.c'; else $(CYGPATH_W) '$(srcdir)/main-c.c'; fi` +hclc-cb-impl.o: cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclc_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclc-cb-impl.o -MD -MP -MF $(DEPDIR)/hclc-cb-impl.Tpo -c -o hclc-cb-impl.o `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclc-cb-impl.Tpo $(DEPDIR)/hclc-cb-impl.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cb-impl.c' object='hclc-cb-impl.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclc_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclc-cb-impl.o `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c + +hclc-cb-impl.obj: cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclc_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclc-cb-impl.obj -MD -MP -MF $(DEPDIR)/hclc-cb-impl.Tpo -c -o hclc-cb-impl.obj `if test -f 'cb-impl.c'; then $(CYGPATH_W) 'cb-impl.c'; else $(CYGPATH_W) '$(srcdir)/cb-impl.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclc-cb-impl.Tpo $(DEPDIR)/hclc-cb-impl.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cb-impl.c' object='hclc-cb-impl.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclc_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclc-cb-impl.obj `if test -f 'cb-impl.c'; then $(CYGPATH_W) 'cb-impl.c'; else $(CYGPATH_W) '$(srcdir)/cb-impl.c'; fi` + hclj-main-j.o: main-j.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclj_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclj-main-j.o -MD -MP -MF $(DEPDIR)/hclj-main-j.Tpo -c -o hclj-main-j.o `test -f 'main-j.c' || echo '$(srcdir)/'`main-j.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclj-main-j.Tpo $(DEPDIR)/hclj-main-j.Po @@ -967,6 +1002,20 @@ hclj-main-j.obj: main-j.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclj_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclj-main-j.obj `if test -f 'main-j.c'; then $(CYGPATH_W) 'main-j.c'; else $(CYGPATH_W) '$(srcdir)/main-j.c'; fi` +hclj-cb-impl.o: cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclj_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclj-cb-impl.o -MD -MP -MF $(DEPDIR)/hclj-cb-impl.Tpo -c -o hclj-cb-impl.o `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclj-cb-impl.Tpo $(DEPDIR)/hclj-cb-impl.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cb-impl.c' object='hclj-cb-impl.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclj_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclj-cb-impl.o `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c + +hclj-cb-impl.obj: cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclj_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclj-cb-impl.obj -MD -MP -MF $(DEPDIR)/hclj-cb-impl.Tpo -c -o hclj-cb-impl.obj `if test -f 'cb-impl.c'; then $(CYGPATH_W) 'cb-impl.c'; else $(CYGPATH_W) '$(srcdir)/cb-impl.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclj-cb-impl.Tpo $(DEPDIR)/hclj-cb-impl.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cb-impl.c' object='hclj-cb-impl.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclj_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclj-cb-impl.obj `if test -f 'cb-impl.c'; then $(CYGPATH_W) 'cb-impl.c'; else $(CYGPATH_W) '$(srcdir)/cb-impl.c'; fi` + hcls-main-s.o: main-s.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcls_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcls-main-s.o -MD -MP -MF $(DEPDIR)/hcls-main-s.Tpo -c -o hcls-main-s.o `test -f 'main-s.c' || echo '$(srcdir)/'`main-s.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcls-main-s.Tpo $(DEPDIR)/hcls-main-s.Po @@ -981,6 +1030,20 @@ hcls-main-s.obj: main-s.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcls_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcls-main-s.obj `if test -f 'main-s.c'; then $(CYGPATH_W) 'main-s.c'; else $(CYGPATH_W) '$(srcdir)/main-s.c'; fi` +hcls-cb-impl.o: cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcls_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcls-cb-impl.o -MD -MP -MF $(DEPDIR)/hcls-cb-impl.Tpo -c -o hcls-cb-impl.o `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcls-cb-impl.Tpo $(DEPDIR)/hcls-cb-impl.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cb-impl.c' object='hcls-cb-impl.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcls_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcls-cb-impl.o `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c + +hcls-cb-impl.obj: cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcls_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcls-cb-impl.obj -MD -MP -MF $(DEPDIR)/hcls-cb-impl.Tpo -c -o hcls-cb-impl.obj `if test -f 'cb-impl.c'; then $(CYGPATH_W) 'cb-impl.c'; else $(CYGPATH_W) '$(srcdir)/cb-impl.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcls-cb-impl.Tpo $(DEPDIR)/hcls-cb-impl.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cb-impl.c' object='hcls-cb-impl.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcls_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcls-cb-impl.obj `if test -f 'cb-impl.c'; then $(CYGPATH_W) 'cb-impl.c'; else $(CYGPATH_W) '$(srcdir)/cb-impl.c'; fi` + mostlyclean-libtool: -rm -f *.lo diff --git a/lib/cb-impl.c b/lib/cb-impl.c new file mode 100644 index 0000000..3d1ad18 --- /dev/null +++ b/lib/cb-impl.c @@ -0,0 +1,1071 @@ +#include "cb-impl.h" +#include + +#include +#include +#include + +#if defined(_WIN32) +# include +# include +# include +# include +# include + +# if defined(MOO_HAVE_CFG_H) && defined(MOO_ENABLE_LIBLTDL) +# include +# define USE_LTDL +# else +# define USE_WIN_DLL +# endif + +#elif defined(__OS2__) +# define INCL_DOSMODULEMGR +# define INCL_DOSPROCESS +# define INCL_DOSEXCEPTIONS +# define INCL_DOSMISC +# define INCL_DOSDATETIME +# define INCL_DOSFILEMGR +# define INCL_DOSERRORS +# include +# include +# include + +#elif defined(__DOS__) +# include +# include +# include +# include +# include + +# if defined(_INTELC32_) +# define DOS_EXIT 0x4C +# else +# include +# endif + +#elif defined(macintosh) +# include +# include +# include + +# include +# include +# include +# include + +#else + +# include +# include +# include + +# if defined(HAVE_TIME_H) +# include +# endif +# if defined(HAVE_SYS_TIME_H) +# include +# endif +# if defined(HAVE_SIGNAL_H) +# include +# endif +# if defined(HAVE_SYS_MMAN_H) +# include +# endif + +# if defined(HCL_ENABLE_LIBLTDL) +# include +# define USE_LTDL +# elif defined(HAVE_DLFCN_H) +# include +# define USE_DLFCN +# elif defined(__APPLE__) || defined(__MACOSX__) +# define USE_MACH_O_DYLD +# include +# else +# error UNSUPPORTED DYNAMIC LINKER +# endif +#endif + +#if !defined(HCL_DEFAULT_PFMODDIR) +# define HCL_DEFAULT_PFMODDIR "" +#endif + +#if !defined(HCL_DEFAULT_PFMODPREFIX) +# if defined(_WIN32) +# define HCL_DEFAULT_PFMODPREFIX "hcl-" +# elif defined(__OS2__) +# define HCL_DEFAULT_PFMODPREFIX "hcl" +# elif defined(__DOS__) +# define HCL_DEFAULT_PFMODPREFIX "hcl" +# else +# define HCL_DEFAULT_PFMODPREFIX "libhcl-" +# endif +#endif + +#if !defined(HCL_DEFAULT_PFMODPOSTFIX) +# if defined(_WIN32) +# define HCL_DEFAULT_PFMODPOSTFIX "" +# elif defined(__OS2__) +# define HCL_DEFAULT_PFMODPOSTFIX "" +# elif defined(__DOS__) +# define HCL_DEFAULT_PFMODPOSTFIX "" +# else +# if defined(USE_DLFCN) +# define HCL_DEFAULT_PFMODPOSTFIX ".so" +# elif defined(USE_MACH_O_DYLD) +# define HCL_DEFAULT_PFMODPOSTFIX ".dylib" +# else +# define HCL_DEFAULT_PFMODPOSTFIX "" +# endif +# endif +#endif + + +/* ----------------------------------------------------------------- + * SYSTEM ERROR CONVERSION + * ----------------------------------------------------------------- */ +static hcl_errnum_t errno_to_errnum (int errcode) +{ + switch (errcode) + { + case ENOMEM: return HCL_ESYSMEM; + case EINVAL: return HCL_EINVAL; + + #if defined(EBUSY) + case EBUSY: return HCL_EBUSY; + #endif + case EACCES: return HCL_EACCES; + #if defined(EPERM) + case EPERM: return HCL_EPERM; + #endif + #if defined(ENOTDIR) + case ENOTDIR: return HCL_ENOTDIR; + #endif + case ENOENT: return HCL_ENOENT; + #if defined(EEXIST) + case EEXIST: return HCL_EEXIST; + #endif + #if defined(EINTR) + case EINTR: return HCL_EINTR; + #endif + + #if defined(EPIPE) + case EPIPE: return HCL_EPIPE; + #endif + + #if defined(EAGAIN) && defined(EWOULDBLOCK) && (EAGAIN != EWOULDBLOCK) + case EAGAIN: + case EWOULDBLOCK: return HCL_EAGAIN; + #elif defined(EAGAIN) + case EAGAIN: return HCL_EAGAIN; + #elif defined(EWOULDBLOCK) + case EWOULDBLOCK: return HCL_EAGAIN; + #endif + + #if defined(EBADF) + case EBADF: return HCL_EBADHND; + #endif + + #if defined(EIO) + case EIO: return HCL_EIOERR; + #endif + + default: return HCL_ESYSERR; + } +} + +#if defined(_WIN32) +static hcl_errnum_t winerr_to_errnum (DWORD errcode) +{ + switch (errcode) + { + case ERROR_NOT_ENOUGH_MEMORY: + case ERROR_OUTOFMEMORY: + return HCL_ESYSMEM; + + case ERROR_INVALID_PARAMETER: + case ERROR_INVALID_NAME: + return HCL_EINVAL; + + case ERROR_INVALID_HANDLE: + return HCL_EBADHND; + + case ERROR_ACCESS_DENIED: + case ERROR_SHARING_VIOLATION: + return HCL_EACCES; + + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + return HCL_ENOENT; + + case ERROR_ALREADY_EXISTS: + case ERROR_FILE_EXISTS: + return HCL_EEXIST; + + case ERROR_BROKEN_PIPE: + return HCL_EPIPE; + + default: + return HCL_ESYSERR; + } +} +#endif + +#if defined(__OS2__) +static hcl_errnum_t os2err_to_errnum (APIRET errcode) +{ + /* APIRET e */ + switch (errcode) + { + case ERROR_NOT_ENOUGH_MEMORY: + return HCL_ESYSMEM; + + case ERROR_INVALID_PARAMETER: + case ERROR_INVALID_NAME: + return HCL_EINVAL; + + case ERROR_INVALID_HANDLE: + return HCL_EBADHND; + + case ERROR_ACCESS_DENIED: + case ERROR_SHARING_VIOLATION: + return HCL_EACCES; + + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + return HCL_ENOENT; + + case ERROR_ALREADY_EXISTS: + return HCL_EEXIST; + + /*TODO: add more mappings */ + default: + return HCL_ESYSERR; + } +} +#endif + +#if defined(macintosh) +static hcl_errnum_t macerr_to_errnum (int errcode) +{ + switch (e) + { + case notEnoughMemoryErr: + return HCL_ESYSMEM; + case paramErr: + return HCL_EINVAL; + + case qErr: /* queue element not found during deletion */ + case fnfErr: /* file not found */ + case dirNFErr: /* direcotry not found */ + case resNotFound: /* resource not found */ + case resFNotFound: /* resource file not found */ + case nbpNotFound: /* name not found on remove */ + return HCL_ENOENT; + + /*TODO: add more mappings */ + default: + return HCL_ESYSERR; + } +} +#endif + +hcl_errnum_t hcl_vmprim_syserrstrb (hcl_t* hcl, int syserr_type, int syserr_code, hcl_bch_t* buf, hcl_oow_t len) +{ + switch (syserr_type) + { + case 1: + #if defined(_WIN32) + if (buf) + { + DWORD rc; + rc = FormatMessageA ( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, syserr_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buf, len, HCL_NULL + ); + while (rc > 0 && buf[rc - 1] == '\r' || buf[rc - 1] == '\n') buf[--rc] = '\0'; + } + return winerr_to_errnum(syserr_code); + #elif defined(__OS2__) + /* TODO: convert code to string */ + if (buf) hcl_copy_bcstr (buf, len, "system error"); + return os2err_to_errnum(syserr_code); + #elif defined(macintosh) + /* TODO: convert code to string */ + if (buf) hcl_copy_bcstr (buf, len, "system error"); + return os2err_to_errnum(syserr_code); + #else + /* in other systems, errno is still the native system error code. + * fall thru */ + #endif + + case 0: + #if defined(HAVE_STRERROR_R) + if (buf) strerror_r (syserr_code, buf, len); + #else + /* this is not thread safe */ + if (buf) hcl_copy_bcstr (buf, len, strerror(syserr_code)); + #endif + return errno_to_errnum(syserr_code); + } + + if (buf) hcl_copy_bcstr (buf, len, "system error"); + return HCL_ESYSERR; +} + + +/* -------------------------------------------------------------------------- + * ASSERTION SUPPORT + * -------------------------------------------------------------------------- */ + +#if defined(HCL_BUILD_RELEASE) + +void hcl_cb_assertfail (hcl_t* hcl, const hcl_bch_t* expr, const hcl_bch_t* file, hcl_oow_t line) +{ + /* do nothing */ +} + +#else /* defined(HCL_BUILD_RELEASE) */ + +/* -------------------------------------------------------------------------- + * SYSTEM DEPENDENT HEADERS + * -------------------------------------------------------------------------- */ + +#if defined(_WIN32) +# include +# include +#elif defined(__OS2__) + +# define INCL_DOSERRORS +# include +#elif defined(__DOS__) +# include +# if defined(_INTELC32_) +# define DOS_EXIT 0x4C +# else +# include +# endif +# include +#elif defined(vms) || defined(__vms) +# define __NEW_STARLET 1 +# include /* (SYS$...) */ +# include /* (SS$...) */ +# include /* (lib$...) */ +#elif defined(macintosh) +# include +# include +# include +# include +#else +# include +# include +# include +# include +#endif + +#if defined(HCL_ENABLE_LIBUNWIND) +#include +static void backtrace_stack_frames (hcl_t* hcl) +{ + unw_cursor_t cursor; + unw_context_t context; + int n; + + unw_getcontext(&context); + unw_init_local(&cursor, &context); + + hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_DEBUG, "[BACKTRACE]\n"); + for (n = 0; unw_step(&cursor) > 0; n++) + { + unw_word_t ip, sp, off; + char symbol[256]; + + unw_get_reg (&cursor, UNW_REG_IP, &ip); + unw_get_reg (&cursor, UNW_REG_SP, &sp); + + if (unw_get_proc_name(&cursor, symbol, HCL_COUNTOF(symbol), &off)) + { + hcl_copy_bcstr (symbol, HCL_COUNTOF(symbol), ""); + } + + hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_DEBUG, + "#%02d ip=0x%*p sp=0x%*p %s+0x%zu\n", + n, HCL_SIZEOF(void*) * 2, (void*)ip, HCL_SIZEOF(void*) * 2, (void*)sp, symbol, (hcl_oow_t)off); + } +} +#elif defined(HAVE_BACKTRACE) +#include +static void backtrace_stack_frames (hcl_t* hcl) +{ + void* btarray[128]; + hcl_oow_t btsize; + char** btsyms; + + btsize = backtrace (btarray, HCL_COUNTOF(btarray)); + btsyms = backtrace_symbols (btarray, btsize); + if (btsyms) + { + hcl_oow_t i; + hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_DEBUG, "[BACKTRACE]\n"); + + for (i = 0; i < btsize; i++) + { + hcl_logbfmt(hcl, HCL_LOG_UNTYPED | HCL_LOG_DEBUG, " %s\n", btsyms[i]); + } + free (btsyms); + } +} +#else +static void backtrace_stack_frames (hcl_t* hcl) +{ + /* do nothing. not supported */ +} +#endif + +void hcl_vmprim_assertfail (hcl_t* hcl, const hcl_bch_t* expr, const hcl_bch_t* file, hcl_oow_t line) +{ + hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_FATAL, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line); + backtrace_stack_frames (hcl); + +#if defined(_WIN32) + ExitProcess (249); +#elif defined(__OS2__) + DosExit (EXIT_PROCESS, 249); +#elif defined(__DOS__) + { + union REGS regs; + regs.h.ah = DOS_EXIT; + regs.h.al = 249; + intdos (®s, ®s); + } +#elif defined(vms) || defined(__vms) + lib$stop (SS$_ABORT); /* use SS$_OPCCUS instead? */ + /* this won't be reached since lib$stop() terminates the process */ + sys$exit (SS$_ABORT); /* this condition code can be shown with + * 'show symbol $status' from the command-line. */ +#elif defined(macintosh) + + ExitToShell (); + +#else + + kill (getpid(), SIGABRT); + _exit (1); +#endif +} + +#endif /* defined(HCL_BUILD_RELEASE) */ + + +/* ----------------------------------------------------------------- + * HEAP ALLOCATION + * ----------------------------------------------------------------- */ + +void* hcl_vmprim_alloc_heap (hcl_t* hcl, hcl_oow_t size) +{ +#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP) && defined(MAP_ANONYMOUS) + /* It's called via hcl_makeheap() when HCL creates a GC heap. + * The heap is large in size. I can use a different memory allocation + * function instead of an ordinary malloc. + * upon failure, it doesn't require to set error information as hcl_makeheap() + * set the error number to HCL_EOOMEM. */ + +#if !defined(MAP_HUGETLB) && (defined(__amd64__) || defined(__x86_64__)) +# define MAP_HUGETLB 0x40000 +#endif + + hcl_oow_t* ptr; + int flags; + hcl_oow_t actual_size; + + flags = MAP_PRIVATE | MAP_ANONYMOUS; + + #if defined(MAP_HUGETLB) + flags |= MAP_HUGETLB; + #endif + + #if defined(MAP_UNINITIALIZED) + flags |= MAP_UNINITIALIZED; + #endif + + actual_size = HCL_SIZEOF(hcl_oow_t) + size; + actual_size = HCL_ALIGN_POW2(actual_size, 2 * 1024 * 1024); + ptr = (hcl_oow_t*)mmap(NULL, actual_size, PROT_READ | PROT_WRITE, flags, -1, 0); + if (ptr == MAP_FAILED) + { + #if defined(MAP_HUGETLB) + flags &= ~MAP_HUGETLB; + ptr = (hcl_oow_t*)mmap(NULL, actual_size, PROT_READ | PROT_WRITE, flags, -1, 0); + if (ptr == MAP_FAILED) return HCL_NULL; + #else + return HCL_NULL; + #endif + } + *ptr = actual_size; + + return (void*)(ptr + 1); + +#else + return HCL_MMGR_ALLOC(hcl->mmgr, size); +#endif +} + +void hcl_vmprim_free_heap (hcl_t* hcl, void* ptr) +{ +#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP) + hcl_oow_t* actual_ptr; + actual_ptr = (hcl_oow_t*)ptr - 1; + munmap (actual_ptr, *actual_ptr); +#else + return HCL_MMGR_FREE(hcl->mmgr, ptr); +#endif +} + +/* ----------------------------------------------------------------- + * POSSIBLY MONOTONIC TIME + * ----------------------------------------------------------------- */ + +void hcl_vmprim_gettime (hcl_t* hcl, hcl_ntime_t* now) +{ +#if defined(_WIN32) + + #if defined(_WIN64) || (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)) + hcl_uint64_t bigsec, bigmsec; + bigmsec = GetTickCount64(); + #else + xtn_t* xtn = (xtn_t*)hcl_getxtn(hcl); + hcl_uint64_t bigsec, bigmsec; + DWORD msec; + + msec = GetTickCount(); /* this can sustain for 49.7 days */ + if (msec < xtn->tc_last) + { + /* i assume the difference is never bigger than 49.7 days */ + /*diff = (HCL_TYPE_MAX(DWORD) - xtn->tc_last) + 1 + msec;*/ + xtn->tc_overflow++; + bigmsec = ((hcl_uint64_t)HCL_TYPE_MAX(DWORD) * xtn->tc_overflow) + msec; + } + else bigmsec = msec; + xtn->tc_last = msec; + #endif + + bigsec = HCL_MSEC_TO_SEC(bigmsec); + bigmsec -= HCL_SEC_TO_MSEC(bigsec); + HCL_INIT_NTIME(now, bigsec, HCL_MSEC_TO_NSEC(bigmsec)); + +#elif defined(__OS2__) + xtn_t* xtn = (xtn_t*)hcl_getxtn(hcl); + hcl_uint64_t bigsec, bigmsec; + ULONG msec; + +/* TODO: use DosTmrQueryTime() and DosTmrQueryFreq()? */ + DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, &msec, HCL_SIZEOF(msec)); /* milliseconds */ + /* it must return NO_ERROR */ + if (msec < xtn->tc_last) + { + xtn->tc_overflow++; + bigmsec = ((hcl_uint64_t)HCL_TYPE_MAX(ULONG) * xtn->tc_overflow) + msec; + } + else bigmsec = msec; + xtn->tc_last = msec; + + bigsec = HCL_MSEC_TO_SEC(bigmsec); + bigmsec -= HCL_SEC_TO_MSEC(bigsec); + HCL_INIT_NTIME (now, bigsec, HCL_MSEC_TO_NSEC(bigmsec)); + +#elif defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__)) + clock_t c; + +/* TODO: handle overflow?? */ + c = clock (); + now->sec = c / CLOCKS_PER_SEC; + #if (CLOCKS_PER_SEC == 100) + now->nsec = HCL_MSEC_TO_NSEC((c % CLOCKS_PER_SEC) * 10); + #elif (CLOCKS_PER_SEC == 1000) + now->nsec = HCL_MSEC_TO_NSEC(c % CLOCKS_PER_SEC); + #elif (CLOCKS_PER_SEC == 1000000L) + now->nsec = HCL_USEC_TO_NSEC(c % CLOCKS_PER_SEC); + #elif (CLOCKS_PER_SEC == 1000000000L) + now->nsec = (c % CLOCKS_PER_SEC); + #else + # error UNSUPPORTED CLOCKS_PER_SEC + #endif + +#elif defined(macintosh) + UnsignedWide tick; + hcl_uint64_t tick64; + Microseconds (&tick); + tick64 = *(hcl_uint64_t*)&tick; + HCL_INIT_NTIME (now, HCL_USEC_TO_SEC(tick64), HCL_USEC_TO_NSEC(tick64)); +#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) + struct timespec ts; + clock_gettime (CLOCK_MONOTONIC, &ts); + HCL_INIT_NTIME(now, ts.tv_sec, ts.tv_nsec); +#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME) + struct timespec ts; + clock_gettime (CLOCK_REALTIME, &ts); + HCL_INIT_NTIME(now, ts.tv_sec, ts.tv_nsec); +#else + struct timeval tv; + gettimeofday (&tv, HCL_NULL); + HCL_INIT_NTIME(now, tv.tv_sec, HCL_USEC_TO_NSEC(tv.tv_usec)); +#endif +} + +/* ----------------------------------------------------------------- + * SLEEPING + * ----------------------------------------------------------------- */ + +#if defined(__DOS__) +# if defined(_INTELC32_) + void _halt_cpu (void); +# elif defined(__WATCOMC__) + void _halt_cpu (void); +# pragma aux _halt_cpu = "hlt" +# endif +#endif + +void hcl_vmprim_sleep (hcl_t* hcl, const hcl_ntime_t* dur) +{ +#if defined(_WIN32) + xtn_t* xtn = (xtn_t*)hcl_getxtn(hcl); + if (xtn->waitable_timer) + { + LARGE_INTEGER li; + li.QuadPart = -(HCL_SECNSEC_TO_NSEC(dur->sec, dur->nsec) / 100); /* in 100 nanoseconds */ + if(SetWaitableTimer(xtn->waitable_timer, &li, 0, HCL_NULL, HCL_NULL, FALSE) == FALSE) goto normal_sleep; + WaitForSingleObject(xtn->waitable_timer, INFINITE); + } + else + { + normal_sleep: + /* fallback to normal Sleep() */ + Sleep (HCL_SECNSEC_TO_MSEC(dur->sec,dur->nsec)); + } +#elif defined(__OS2__) + + /* TODO: in gui mode, this is not a desirable method??? + * this must be made event-driven coupled with the main event loop */ + DosSleep (HCL_SECNSEC_TO_MSEC(dur->sec,dur->nsec)); + +#elif defined(macintosh) + + /* TODO: ... */ + +#elif defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__)) + + clock_t c; + + c = clock (); + c += dur->sec * CLOCKS_PER_SEC; + + #if (CLOCKS_PER_SEC == 100) + c += HCL_NSEC_TO_MSEC(dur->nsec) / 10; + #elif (CLOCKS_PER_SEC == 1000) + c += HCL_NSEC_TO_MSEC(dur->nsec); + #elif (CLOCKS_PER_SEC == 1000000L) + c += HCL_NSEC_TO_USEC(dur->nsec); + #elif (CLOCKS_PER_SEC == 1000000000L) + c += dur->nsec; + #else + # error UNSUPPORTED CLOCKS_PER_SEC + #endif + +/* TODO: handle clock overvlow */ +/* TODO: check if there is abortion request or interrupt */ + while (c > clock()) + { + _halt_cpu(); + } + +#else + #if defined(HAVE_NANOSLEEP) + struct timespec ts; + ts.tv_sec = dur->sec; + ts.tv_nsec = dur->nsec; + nanosleep (&ts, HCL_NULL); + #elif defined(HAVE_USLEEP) + usleep (HCL_SECNSEC_TO_USEC(dur->sec, dur->nsec)); + #else + # error UNSUPPORT SLEEP + #endif +#endif +} + +/* ----------------------------------------------------------------- + * SHARED LIBRARY HANDLING + * ----------------------------------------------------------------- */ + +#if defined(USE_LTDL) +# define sys_dl_error() lt_dlerror() +# define sys_dl_open(x) lt_dlopen(x) +# define sys_dl_openext(x) lt_dlopenext(x) +# define sys_dl_close(x) lt_dlclose(x) +# define sys_dl_getsym(x,n) lt_dlsym(x,n) + +#elif defined(USE_DLFCN) +# define sys_dl_error() dlerror() +# define sys_dl_open(x) dlopen(x,RTLD_NOW) +# define sys_dl_openext(x) dlopen(x,RTLD_NOW) +# define sys_dl_close(x) dlclose(x) +# define sys_dl_getsym(x,n) dlsym(x,n) + +#elif defined(USE_WIN_DLL) +# define sys_dl_error() win_dlerror() +# define sys_dl_open(x) LoadLibraryExA(x, MOO_NULL, 0) +# define sys_dl_openext(x) LoadLibraryExA(x, MOO_NULL, 0) +# define sys_dl_close(x) FreeLibrary(x) +# define sys_dl_getsym(x,n) GetProcAddress(x,n) + +#elif defined(USE_MACH_O_DYLD) +# define sys_dl_error() mach_dlerror() +# define sys_dl_open(x) mach_dlopen(x) +# define sys_dl_openext(x) mach_dlopen(x) +# define sys_dl_close(x) mach_dlclose(x) +# define sys_dl_getsym(x,n) mach_dlsym(x,n) +#endif + +#if defined(USE_WIN_DLL) + +static const char* win_dlerror (void) +{ + /* TODO: handle wchar_t, moo_ooch_t etc? */ + static char buf[256]; + DWORD rc; + + rc = FormatMessageA ( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + buf, MOO_COUNTOF(buf), MOO_NULL + ); + while (rc > 0 && buf[rc - 1] == '\r' || buf[rc - 1] == '\n') + { + buf[--rc] = '\0'; + } + return buf; +} + +#elif defined(USE_MACH_O_DYLD) +static const char* mach_dlerror_str = ""; + +static void* mach_dlopen (const char* path) +{ + NSObjectFileImage image; + NSObjectFileImageReturnCode rc; + void* handle; + + mach_dlerror_str = ""; + if ((rc = NSCreateObjectFileImageFromFile(path, &image)) != NSObjectFileImageSuccess) + { + switch (rc) + { + case NSObjectFileImageFailure: + case NSObjectFileImageFormat: + mach_dlerror_str = "unable to crate object file image"; + break; + + case NSObjectFileImageInappropriateFile: + mach_dlerror_str = "inappropriate file"; + break; + + case NSObjectFileImageArch: + mach_dlerror_str = "incompatible architecture"; + break; + + case NSObjectFileImageAccess: + mach_dlerror_str = "inaccessible file"; + break; + + default: + mach_dlerror_str = "unknown error"; + break; + } + return HCL_NULL; + } + handle = (void*)NSLinkModule(image, path, NSLINKMODULE_OPTION_PRIVATE | NSLINKMODULE_OPTION_RETURN_ON_ERROR); + NSDestroyObjectFileImage (image); + return handle; +} + +static HCL_INLINE void mach_dlclose (void* handle) +{ + mach_dlerror_str = ""; + NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_NONE); +} + +static HCL_INLINE void* mach_dlsym (void* handle, const char* name) +{ + mach_dlerror_str = ""; + return (void*)NSAddressOfSymbol(NSLookupSymbolInModule(handle, name)); +} + +static const char* mach_dlerror (void) +{ + int err_no; + const char* err_file; + NSLinkEditErrors err; + + if (mach_dlerror_str[0] == '\0') + NSLinkEditError (&err, &err_no, &err_file, &mach_dlerror_str); + + return mach_dlerror_str; +} +#endif + +void hcl_vmprim_dl_startup (hcl_t* hcl) +{ +#if defined(USE_LTDL) + lt_dlinit (); +#endif +} + +void hcl_vmprim_dl_cleanup (hcl_t* hcl) +{ +#if defined(USE_LTDL) + lt_dlexit (); +#endif +} + +void* hcl_vmprim_dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) +{ +#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) + hcl_bch_t stabuf[128], * bufptr; + hcl_oow_t ucslen, bcslen, bufcapa; + void* handle; + + #if defined(HCL_OOCH_IS_UCH) + if (hcl_convootobcstr(hcl, name, &ucslen, HCL_NULL, &bufcapa) <= -1) return HCL_NULL; + /* +1 for terminating null. but it's not needed because HCL_COUNTOF(HCL_DEFAULT_PFMODPREFIX) + * and HCL_COUNTOF(HCL_DEFAULT_PFMODPOSTIFX) include the terminating nulls. Never mind about + * the extra 2 characters. */ + #else + bufcapa = hcl_count_bcstr(name); + #endif + bufcapa += HCL_COUNTOF(HCL_DEFAULT_PFMODDIR) + HCL_COUNTOF(HCL_DEFAULT_PFMODPREFIX) + HCL_COUNTOF(HCL_DEFAULT_PFMODPOSTFIX) + 1; + + if (bufcapa <= HCL_COUNTOF(stabuf)) bufptr = stabuf; + else + { + bufptr = (hcl_bch_t*)hcl_allocmem(hcl, bufcapa * HCL_SIZEOF(*bufptr)); + if (!bufptr) return HCL_NULL; + } + + if (flags & HCL_VMPRIM_DLOPEN_PFMOD) + { + hcl_oow_t len, i, xlen, dlen; + + /* opening a primitive function module - mostly libhcl-xxxx. + * if PFMODPREFIX is absolute, never use PFMODDIR */ + dlen = HCL_IS_PATH_ABSOLUTE(HCL_DEFAULT_PFMODPREFIX)? + 0: hcl_copy_bcstr(bufptr, bufcapa, HCL_DEFAULT_PFMODDIR); + len = hcl_copy_bcstr(bufptr, bufcapa, HCL_DEFAULT_PFMODPREFIX); + len += dlen; + + bcslen = bufcapa - len; + #if defined(HCL_OOCH_IS_UCH) + hcl_convootobcstr(hcl, name, &ucslen, &bufptr[len], &bcslen); + #else + bcslen = hcl_copy_bcstr(&bufptr[len], bcslen, name); + #endif + + /* length including the directory, the prefix and the name. but excluding the postfix */ + xlen = len + bcslen; + + for (i = len; i < xlen; i++) + { + /* convert a period(.) to a dash(-) */ + if (bufptr[i] == '.') bufptr[i] = '-'; + } + + retry: + hcl_copy_bcstr (&bufptr[xlen], bufcapa - xlen, HCL_DEFAULT_PFMODPOSTFIX); + + /* both prefix and postfix attached. for instance, libhcl-xxx */ + handle = sys_dl_openext(bufptr); + if (!handle) + { + HCL_DEBUG3 (hcl, "Unable to open(ext) PFMOD %hs[%js] - %hs\n", &bufptr[dlen], name, sys_dl_error()); + + if (dlen > 0) + { + handle = sys_dl_openext(&bufptr[0]); + if (handle) goto pfmod_open_ok; + HCL_DEBUG3 (hcl, "Unable to open(ext) PFMOD %hs[%js] - %hs\n", &bufptr[0], name, sys_dl_error()); + } + + /* try without prefix and postfix */ + bufptr[xlen] = '\0'; + handle = sys_dl_openext(&bufptr[len]); + if (!handle) + { + hcl_bch_t* dash; + const hcl_bch_t* dl_errstr; + dl_errstr = sys_dl_error(); + HCL_DEBUG3 (hcl, "Unable to open(ext) PFMOD %hs[%js] - %hs\n", &bufptr[len], name, dl_errstr); + hcl_seterrbfmt (hcl, HCL_ESYSERR, "unable to open(ext) PFMOD %js - %hs", name, dl_errstr); + + dash = hcl_rfind_bchar(bufptr, hcl_count_bcstr(bufptr), '-'); + if (dash) + { + /* remove a segment at the back. + * [NOTE] a dash contained in the original name before + * period-to-dash transformation may cause extraneous/wrong + * loading reattempts. */ + xlen = dash - bufptr; + goto retry; + } + } + else + { + HCL_DEBUG3 (hcl, "Opened(ext) PFMOD %hs[%js] handle %p\n", &bufptr[len], name, handle); + } + } + else + { + pfmod_open_ok: + HCL_DEBUG3 (hcl, "Opened(ext) PFMOD %hs[%js] handle %p\n", &bufptr[dlen], name, handle); + } + } + else + { + /* opening a raw shared object without a prefix and/or a postfix */ + #if defined(HCL_OOCH_IS_UCH) + bcslen = bufcapa; + hcl_convootobcstr(hcl, name, &ucslen, bufptr, &bcslen); + #else + bcslen = hcl_copy_bcstr(bufptr, bufcapa, name); + #endif + + if (hcl_find_bchar(bufptr, bcslen, '.')) + { + handle = sys_dl_open(bufptr); + if (!handle) + { + const hcl_bch_t* dl_errstr; + dl_errstr = sys_dl_error(); + HCL_DEBUG2 (hcl, "Unable to open DL %hs - %hs\n", bufptr, dl_errstr); + hcl_seterrbfmt (hcl, HCL_ESYSERR, "unable to open DL %js - %hs", name, dl_errstr); + } + else HCL_DEBUG2 (hcl, "Opened DL %hs handle %p\n", bufptr, handle); + } + else + { + handle = sys_dl_openext(bufptr); + if (!handle) + { + const hcl_bch_t* dl_errstr; + dl_errstr = sys_dl_error(); + HCL_DEBUG2 (hcl, "Unable to open(ext) DL %hs - %s\n", bufptr, dl_errstr); + hcl_seterrbfmt (hcl, HCL_ESYSERR, "unable to open(ext) DL %js - %hs", name, dl_errstr); + } + else HCL_DEBUG2 (hcl, "Opened(ext) DL %hs handle %p\n", bufptr, handle); + } + } + + if (bufptr != stabuf) hcl_freemem (hcl, bufptr); + return handle; + +#else + +/* TODO: support various platforms */ + /* TODO: implemenent this */ + HCL_DEBUG1 (hcl, "Dynamic loading not implemented - cannot open %js\n", name); + hcl_seterrbfmt (hcl, HCL_ENOIMPL, "dynamic loading not implemented - cannot open %js", name); + return HCL_NULL; +#endif +} + +void hcl_vmprim_dl_close (hcl_t* hcl, void* handle) +{ +#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) + HCL_DEBUG1 (hcl, "Closed DL handle %p\n", handle); + sys_dl_close (handle); + +#else + /* TODO: implemenent this */ + HCL_DEBUG1 (hcl, "Dynamic loading not implemented - cannot close handle %p\n", handle); +#endif +} + +void* hcl_vmprim_dl_getsym (hcl_t* hcl, void* handle, const hcl_ooch_t* name) +{ +#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) + hcl_bch_t stabuf[64], * bufptr; + hcl_oow_t bufcapa, ucslen, bcslen, i; + const hcl_bch_t* symname; + void* sym; + + #if defined(HCL_OOCH_IS_UCH) + if (hcl_convootobcstr(hcl, name, &ucslen, HCL_NULL, &bcslen) <= -1) return HCL_NULL; + #else + bcslen = hcl_count_bcstr (name); + #endif + + if (bcslen >= HCL_COUNTOF(stabuf) - 2) + { + bufcapa = bcslen + 3; + bufptr = (hcl_bch_t*)hcl_allocmem(hcl, bufcapa * HCL_SIZEOF(*bufptr)); + if (!bufptr) return HCL_NULL; + } + else + { + bufcapa = HCL_COUNTOF(stabuf); + bufptr = stabuf; + } + + bcslen = bufcapa - 1; + #if defined(HCL_OOCH_IS_UCH) + hcl_convootobcstr (hcl, name, &ucslen, &bufptr[1], &bcslen); + #else + bcslen = hcl_copy_bcstr(&bufptr[1], bcslen, name); + #endif + + /* convert a period(.) to an underscore(_) */ + for (i = 1; i <= bcslen; i++) if (bufptr[i] == '.') bufptr[i] = '_'; + + symname = &bufptr[1]; /* try the name as it is */ + + sym = sys_dl_getsym(handle, symname); + if (!sym) + { + bufptr[0] = '_'; + symname = &bufptr[0]; /* try _name */ + sym = sys_dl_getsym(handle, symname); + if (!sym) + { + bufptr[bcslen + 1] = '_'; + bufptr[bcslen + 2] = '\0'; + + symname = &bufptr[1]; /* try name_ */ + sym = sys_dl_getsym(handle, symname); + + if (!sym) + { + symname = &bufptr[0]; /* try _name_ */ + sym = sys_dl_getsym(handle, symname); + if (!sym) + { + const hcl_bch_t* dl_errstr; + dl_errstr = sys_dl_error(); + HCL_DEBUG3 (hcl, "Failed to get module symbol %js from handle %p - %hs\n", name, handle, dl_errstr); + hcl_seterrbfmt (hcl, HCL_ENOENT, "unable to get module symbol %hs - %hs", symname, dl_errstr); + + } + } + } + } + + if (sym) HCL_DEBUG3 (hcl, "Loaded module symbol %js from handle %p - %hs\n", name, handle, symname); + if (bufptr != stabuf) hcl_freemem (hcl, bufptr); + return sym; + +#else + /* TODO: IMPLEMENT THIS */ + HCL_DEBUG2 (hcl, "Dynamic loading not implemented - Cannot load module symbol %js from handle %p\n", name, handle); + hcl_seterrbfmt (hcl, HCL_ENOIMPL, "dynamic loading not implemented - Cannot load module symbol %js from handle %p", name, handle); + return HCL_NULL; +#endif +} + diff --git a/lib/cb-impl.h b/lib/cb-impl.h index e07bcd1..cf53906 100644 --- a/lib/cb-impl.h +++ b/lib/cb-impl.h @@ -1,940 +1,89 @@ -/* this function contains commonly used callback functions for hcl */ -/* ----------------------------------------------------------------- - * SYSTEM ERROR CONVERSION - * ----------------------------------------------------------------- */ -static hcl_errnum_t errno_to_errnum (int errcode) -{ - switch (errcode) - { - case ENOMEM: return HCL_ESYSMEM; - case EINVAL: return HCL_EINVAL; +#ifndef _CB_IMPL_H_ +#define _CB_IMPL_H_ - #if defined(EBUSY) - case EBUSY: return HCL_EBUSY; - #endif - case EACCES: return HCL_EACCES; - #if defined(EPERM) - case EPERM: return HCL_EPERM; - #endif - #if defined(ENOTDIR) - case ENOTDIR: return HCL_ENOTDIR; - #endif - case ENOENT: return HCL_ENOENT; - #if defined(EEXIST) - case EEXIST: return HCL_EEXIST; - #endif - #if defined(EINTR) - case EINTR: return HCL_EINTR; - #endif - - #if defined(EPIPE) - case EPIPE: return HCL_EPIPE; - #endif - - #if defined(EAGAIN) && defined(EWOULDBLOCK) && (EAGAIN != EWOULDBLOCK) - case EAGAIN: - case EWOULDBLOCK: return HCL_EAGAIN; - #elif defined(EAGAIN) - case EAGAIN: return HCL_EAGAIN; - #elif defined(EWOULDBLOCK) - case EWOULDBLOCK: return HCL_EAGAIN; - #endif - - #if defined(EBADF) - case EBADF: return HCL_EBADHND; - #endif - - #if defined(EIO) - case EIO: return HCL_EIOERR; - #endif - - default: return HCL_ESYSERR; - } -} - -#if defined(_WIN32) -static hcl_errnum_t winerr_to_errnum (DWORD errcode) -{ - switch (errcode) - { - case ERROR_NOT_ENOUGH_MEMORY: - case ERROR_OUTOFMEMORY: - return HCL_ESYSMEM; - - case ERROR_INVALID_PARAMETER: - case ERROR_INVALID_NAME: - return HCL_EINVAL; - - case ERROR_INVALID_HANDLE: - return HCL_EBADHND; - - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - return HCL_EACCES; - - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - return HCL_ENOENT; - - case ERROR_ALREADY_EXISTS: - case ERROR_FILE_EXISTS: - return HCL_EEXIST; - - case ERROR_BROKEN_PIPE: - return HCL_EPIPE; - - default: - return HCL_ESYSERR; - } -} -#endif - -#if defined(__OS2__) -static hcl_errnum_t os2err_to_errnum (APIRET errcode) -{ - /* APIRET e */ - switch (errcode) - { - case ERROR_NOT_ENOUGH_MEMORY: - return HCL_ESYSMEM; - - case ERROR_INVALID_PARAMETER: - case ERROR_INVALID_NAME: - return HCL_EINVAL; - - case ERROR_INVALID_HANDLE: - return HCL_EBADHND; - - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - return HCL_EACCES; - - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - return HCL_ENOENT; - - case ERROR_ALREADY_EXISTS: - return HCL_EEXIST; - - /*TODO: add more mappings */ - default: - return HCL_ESYSERR; - } -} -#endif - -#if defined(macintosh) -static hcl_errnum_t macerr_to_errnum (int errcode) -{ - switch (e) - { - case notEnoughMemoryErr: - return HCL_ESYSMEM; - case paramErr: - return HCL_EINVAL; - - case qErr: /* queue element not found during deletion */ - case fnfErr: /* file not found */ - case dirNFErr: /* direcotry not found */ - case resNotFound: /* resource not found */ - case resFNotFound: /* resource file not found */ - case nbpNotFound: /* name not found on remove */ - return HCL_ENOENT; - - /*TODO: add more mappings */ - default: - return HCL_ESYSERR; - } -} -#endif - -static hcl_errnum_t syserrstrb (hcl_t* hcl, int syserr_type, int syserr_code, hcl_bch_t* buf, hcl_oow_t len) -{ - switch (syserr_type) - { - case 1: - #if defined(_WIN32) - if (buf) - { - DWORD rc; - rc = FormatMessageA ( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, syserr_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - buf, len, HCL_NULL - ); - while (rc > 0 && buf[rc - 1] == '\r' || buf[rc - 1] == '\n') buf[--rc] = '\0'; - } - return winerr_to_errnum(syserr_code); - #elif defined(__OS2__) - /* TODO: convert code to string */ - if (buf) hcl_copy_bcstr (buf, len, "system error"); - return os2err_to_errnum(syserr_code); - #elif defined(macintosh) - /* TODO: convert code to string */ - if (buf) hcl_copy_bcstr (buf, len, "system error"); - return os2err_to_errnum(syserr_code); - #else - /* in other systems, errno is still the native system error code. - * fall thru */ - #endif - - case 0: - #if defined(HAVE_STRERROR_R) - if (buf) strerror_r (syserr_code, buf, len); - #else - /* this is not thread safe */ - if (buf) hcl_copy_bcstr (buf, len, strerror(syserr_code)); - #endif - return errno_to_errnum(syserr_code); - } - - if (buf) hcl_copy_bcstr (buf, len, "system error"); - return HCL_ESYSERR; -} +#include -/* -------------------------------------------------------------------------- - * ASSERTION SUPPORT - * -------------------------------------------------------------------------- */ - -#if defined(HCL_BUILD_RELEASE) - -void assert_failed (hcl_t* hcl, const hcl_bch_t* expr, const hcl_bch_t* file, hcl_oow_t line) -{ - /* do nothing */ -} - -#else /* defined(HCL_BUILD_RELEASE) */ - -/* -------------------------------------------------------------------------- - * SYSTEM DEPENDENT HEADERS - * -------------------------------------------------------------------------- */ - -#if defined(_WIN32) -# include -# include -#elif defined(__OS2__) -# define INCL_DOSPROCESS -# define INCL_DOSFILEMGR -# define INCL_DOSERRORS -# include -#elif defined(__DOS__) -# include -# if defined(_INTELC32_) -# define DOS_EXIT 0x4C -# else -# include -# endif -# include -#elif defined(vms) || defined(__vms) -# define __NEW_STARLET 1 -# include /* (SYS$...) */ -# include /* (SS$...) */ -# include /* (lib$...) */ -#elif defined(macintosh) -# include -# include -# include -# include +#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) +# define HCL_IS_PATH_SEP(c) ((c) == '/' || (c) == '\\') #else -# include -# include -# include -# include +# define HCL_IS_PATH_SEP(c) ((c) == '/') #endif -#if defined(HCL_ENABLE_LIBUNWIND) -#include -static void backtrace_stack_frames (hcl_t* hcl) -{ - unw_cursor_t cursor; - unw_context_t context; - int n; +/* TODO: handle path with a drive letter or in the UNC notation */ +#define HCL_IS_PATH_ABSOLUTE(x) HCL_IS_PATH_SEP(x[0]) - unw_getcontext(&context); - unw_init_local(&cursor, &context); - hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_DEBUG, "[BACKTRACE]\n"); - for (n = 0; unw_step(&cursor) > 0; n++) - { - unw_word_t ip, sp, off; - char symbol[256]; +#if defined(__cplusplus) +extern "C" { +#endif - unw_get_reg (&cursor, UNW_REG_IP, &ip); - unw_get_reg (&cursor, UNW_REG_SP, &sp); +hcl_errnum_t hcl_vmprim_syserrstrb ( + hcl_t* hcl, + int syserr_type, + int syserr_code, + hcl_bch_t* buf, + hcl_oow_t len +); - if (unw_get_proc_name(&cursor, symbol, HCL_COUNTOF(symbol), &off)) - { - hcl_copy_bcstr (symbol, HCL_COUNTOF(symbol), ""); - } +void hcl_vmprim_assertfail ( + hcl_t* hcl, + const hcl_bch_t* expr, + const hcl_bch_t* file, + hcl_oow_t line +); - hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_DEBUG, - "#%02d ip=0x%*p sp=0x%*p %s+0x%zu\n", - n, HCL_SIZEOF(void*) * 2, (void*)ip, HCL_SIZEOF(void*) * 2, (void*)sp, symbol, (hcl_oow_t)off); - } -} -#elif defined(HAVE_BACKTRACE) -#include -static void backtrace_stack_frames (hcl_t* hcl) -{ - void* btarray[128]; - hcl_oow_t btsize; - char** btsyms; - btsize = backtrace (btarray, HCL_COUNTOF(btarray)); - btsyms = backtrace_symbols (btarray, btsize); - if (btsyms) - { - hcl_oow_t i; - hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_DEBUG, "[BACKTRACE]\n"); +void* hcl_vmprim_alloc_heap ( + hcl_t* hcl, + hcl_oow_t size +); - for (i = 0; i < btsize; i++) - { - hcl_logbfmt(hcl, HCL_LOG_UNTYPED | HCL_LOG_DEBUG, " %s\n", btsyms[i]); - } - free (btsyms); - } -} -#else -static void backtrace_stack_frames (hcl_t* hcl) -{ - /* do nothing. not supported */ +void hcl_vmprim_free_heap ( + hcl_t* hcl, + void* ptr +); + +void hcl_vmprim_gettime ( + hcl_t* hcl, + hcl_ntime_t* now +); + +void hcl_vmprim_sleep ( + hcl_t* hcl, + const hcl_ntime_t* dur +); + + +void hcl_vmprim_dl_startup ( + hcl_t* hcl +); + +void hcl_vmprim_dl_cleanup ( + hcl_t* hcl +); + +void* hcl_vmprim_dl_open ( + hcl_t* hcl, + const hcl_ooch_t* name, + int flags +); + +void hcl_vmprim_dl_close ( + hcl_t* hcl, + void* handle +); + +void* hcl_vmprim_dl_getsym ( + hcl_t* hcl, + void* handle, + const hcl_ooch_t* name +); + + +#if defined(__cplusplus) } #endif -static void assert_failed (hcl_t* hcl, const hcl_bch_t* expr, const hcl_bch_t* file, hcl_oow_t line) -{ - hcl_logbfmt (hcl, HCL_LOG_UNTYPED | HCL_LOG_FATAL, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line); - backtrace_stack_frames (hcl); - -#if defined(_WIN32) - ExitProcess (249); -#elif defined(__OS2__) - DosExit (EXIT_PROCESS, 249); -#elif defined(__DOS__) - { - union REGS regs; - regs.h.ah = DOS_EXIT; - regs.h.al = 249; - intdos (®s, ®s); - } -#elif defined(vms) || defined(__vms) - lib$stop (SS$_ABORT); /* use SS$_OPCCUS instead? */ - /* this won't be reached since lib$stop() terminates the process */ - sys$exit (SS$_ABORT); /* this condition code can be shown with - * 'show symbol $status' from the command-line. */ -#elif defined(macintosh) - - ExitToShell (); - -#else - - kill (getpid(), SIGABRT); - _exit (1); #endif -} - -#endif /* defined(HCL_BUILD_RELEASE) */ - - -/* ----------------------------------------------------------------- - * HEAP ALLOCATION - * ----------------------------------------------------------------- */ - -static void* alloc_heap (hcl_t* hcl, hcl_oow_t size) -{ -#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP) && defined(MAP_ANONYMOUS) - /* It's called via hcl_makeheap() when HCL creates a GC heap. - * The heap is large in size. I can use a different memory allocation - * function instead of an ordinary malloc. - * upon failure, it doesn't require to set error information as hcl_makeheap() - * set the error number to HCL_EOOMEM. */ - -#if !defined(MAP_HUGETLB) && (defined(__amd64__) || defined(__x86_64__)) -# define MAP_HUGETLB 0x40000 -#endif - - hcl_oow_t* ptr; - int flags; - hcl_oow_t actual_size; - - flags = MAP_PRIVATE | MAP_ANONYMOUS; - - #if defined(MAP_HUGETLB) - flags |= MAP_HUGETLB; - #endif - - #if defined(MAP_UNINITIALIZED) - flags |= MAP_UNINITIALIZED; - #endif - - actual_size = HCL_SIZEOF(hcl_oow_t) + size; - actual_size = HCL_ALIGN_POW2(actual_size, 2 * 1024 * 1024); - ptr = (hcl_oow_t*)mmap(NULL, actual_size, PROT_READ | PROT_WRITE, flags, -1, 0); - if (ptr == MAP_FAILED) - { - #if defined(MAP_HUGETLB) - flags &= ~MAP_HUGETLB; - ptr = (hcl_oow_t*)mmap(NULL, actual_size, PROT_READ | PROT_WRITE, flags, -1, 0); - if (ptr == MAP_FAILED) return HCL_NULL; - #else - return HCL_NULL; - #endif - } - *ptr = actual_size; - - return (void*)(ptr + 1); - -#else - return HCL_MMGR_ALLOC(hcl->mmgr, size); -#endif -} - -static void free_heap (hcl_t* hcl, void* ptr) -{ -#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP) - hcl_oow_t* actual_ptr; - actual_ptr = (hcl_oow_t*)ptr - 1; - munmap (actual_ptr, *actual_ptr); -#else - return HCL_MMGR_FREE(hcl->mmgr, ptr); -#endif -} - - -/* ----------------------------------------------------------------- - * POSSIBLY MONOTONIC TIME - * ----------------------------------------------------------------- */ - -static void vm_gettime (hcl_t* hcl, hcl_ntime_t* now) -{ -#if defined(_WIN32) - - #if defined(_WIN64) || (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)) - hcl_uint64_t bigsec, bigmsec; - bigmsec = GetTickCount64(); - #else - xtn_t* xtn = (xtn_t*)hcl_getxtn(hcl); - hcl_uint64_t bigsec, bigmsec; - DWORD msec; - - msec = GetTickCount(); /* this can sustain for 49.7 days */ - if (msec < xtn->tc_last) - { - /* i assume the difference is never bigger than 49.7 days */ - /*diff = (HCL_TYPE_MAX(DWORD) - xtn->tc_last) + 1 + msec;*/ - xtn->tc_overflow++; - bigmsec = ((hcl_uint64_t)HCL_TYPE_MAX(DWORD) * xtn->tc_overflow) + msec; - } - else bigmsec = msec; - xtn->tc_last = msec; - #endif - - bigsec = HCL_MSEC_TO_SEC(bigmsec); - bigmsec -= HCL_SEC_TO_MSEC(bigsec); - HCL_INIT_NTIME(now, bigsec, HCL_MSEC_TO_NSEC(bigmsec)); - -#elif defined(__OS2__) - xtn_t* xtn = (xtn_t*)hcl_getxtn(hcl); - hcl_uint64_t bigsec, bigmsec; - ULONG msec; - -/* TODO: use DosTmrQueryTime() and DosTmrQueryFreq()? */ - DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, &msec, HCL_SIZEOF(msec)); /* milliseconds */ - /* it must return NO_ERROR */ - if (msec < xtn->tc_last) - { - xtn->tc_overflow++; - bigmsec = ((hcl_uint64_t)HCL_TYPE_MAX(ULONG) * xtn->tc_overflow) + msec; - } - else bigmsec = msec; - xtn->tc_last = msec; - - bigsec = HCL_MSEC_TO_SEC(bigmsec); - bigmsec -= HCL_SEC_TO_MSEC(bigsec); - HCL_INIT_NTIME (now, bigsec, HCL_MSEC_TO_NSEC(bigmsec)); - -#elif defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__)) - clock_t c; - -/* TODO: handle overflow?? */ - c = clock (); - now->sec = c / CLOCKS_PER_SEC; - #if (CLOCKS_PER_SEC == 100) - now->nsec = HCL_MSEC_TO_NSEC((c % CLOCKS_PER_SEC) * 10); - #elif (CLOCKS_PER_SEC == 1000) - now->nsec = HCL_MSEC_TO_NSEC(c % CLOCKS_PER_SEC); - #elif (CLOCKS_PER_SEC == 1000000L) - now->nsec = HCL_USEC_TO_NSEC(c % CLOCKS_PER_SEC); - #elif (CLOCKS_PER_SEC == 1000000000L) - now->nsec = (c % CLOCKS_PER_SEC); - #else - # error UNSUPPORTED CLOCKS_PER_SEC - #endif - -#elif defined(macintosh) - UnsignedWide tick; - hcl_uint64_t tick64; - Microseconds (&tick); - tick64 = *(hcl_uint64_t*)&tick; - HCL_INIT_NTIME (now, HCL_USEC_TO_SEC(tick64), HCL_USEC_TO_NSEC(tick64)); -#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) - struct timespec ts; - clock_gettime (CLOCK_MONOTONIC, &ts); - HCL_INIT_NTIME(now, ts.tv_sec, ts.tv_nsec); -#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME) - struct timespec ts; - clock_gettime (CLOCK_REALTIME, &ts); - HCL_INIT_NTIME(now, ts.tv_sec, ts.tv_nsec); -#else - struct timeval tv; - gettimeofday (&tv, HCL_NULL); - HCL_INIT_NTIME(now, tv.tv_sec, HCL_USEC_TO_NSEC(tv.tv_usec)); -#endif -} - -/* ----------------------------------------------------------------- - * SLEEPING - * ----------------------------------------------------------------- */ - -#if defined(__DOS__) -# if defined(_INTELC32_) - void _halt_cpu (void); -# elif defined(__WATCOMC__) - void _halt_cpu (void); -# pragma aux _halt_cpu = "hlt" -# endif -#endif - -static void vm_sleep (hcl_t* hcl, const hcl_ntime_t* dur) -{ -#if defined(_WIN32) - xtn_t* xtn = (xtn_t*)hcl_getxtn(hcl); - if (xtn->waitable_timer) - { - LARGE_INTEGER li; - li.QuadPart = -(HCL_SECNSEC_TO_NSEC(dur->sec, dur->nsec) / 100); /* in 100 nanoseconds */ - if(SetWaitableTimer(xtn->waitable_timer, &li, 0, HCL_NULL, HCL_NULL, FALSE) == FALSE) goto normal_sleep; - WaitForSingleObject(xtn->waitable_timer, INFINITE); - } - else - { - normal_sleep: - /* fallback to normal Sleep() */ - Sleep (HCL_SECNSEC_TO_MSEC(dur->sec,dur->nsec)); - } -#elif defined(__OS2__) - - /* TODO: in gui mode, this is not a desirable method??? - * this must be made event-driven coupled with the main event loop */ - DosSleep (HCL_SECNSEC_TO_MSEC(dur->sec,dur->nsec)); - -#elif defined(macintosh) - - /* TODO: ... */ - -#elif defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__)) - - clock_t c; - - c = clock (); - c += dur->sec * CLOCKS_PER_SEC; - - #if (CLOCKS_PER_SEC == 100) - c += HCL_NSEC_TO_MSEC(dur->nsec) / 10; - #elif (CLOCKS_PER_SEC == 1000) - c += HCL_NSEC_TO_MSEC(dur->nsec); - #elif (CLOCKS_PER_SEC == 1000000L) - c += HCL_NSEC_TO_USEC(dur->nsec); - #elif (CLOCKS_PER_SEC == 1000000000L) - c += dur->nsec; - #else - # error UNSUPPORTED CLOCKS_PER_SEC - #endif - -/* TODO: handle clock overvlow */ -/* TODO: check if there is abortion request or interrupt */ - while (c > clock()) - { - _halt_cpu(); - } - -#else - #if defined(HAVE_NANOSLEEP) - struct timespec ts; - ts.tv_sec = dur->sec; - ts.tv_nsec = dur->nsec; - nanosleep (&ts, HCL_NULL); - #elif defined(HAVE_USLEEP) - usleep (HCL_SECNSEC_TO_USEC(dur->sec, dur->nsec)); - #else - # error UNSUPPORT SLEEP - #endif -#endif -} - - - -/* ----------------------------------------------------------------- - * SHARED LIBRARY HANDLING - * ----------------------------------------------------------------- */ - -#if defined(USE_LTDL) -# define sys_dl_error() lt_dlerror() -# define sys_dl_open(x) lt_dlopen(x) -# define sys_dl_openext(x) lt_dlopenext(x) -# define sys_dl_close(x) lt_dlclose(x) -# define sys_dl_getsym(x,n) lt_dlsym(x,n) - -#elif defined(USE_DLFCN) -# define sys_dl_error() dlerror() -# define sys_dl_open(x) dlopen(x,RTLD_NOW) -# define sys_dl_openext(x) dlopen(x,RTLD_NOW) -# define sys_dl_close(x) dlclose(x) -# define sys_dl_getsym(x,n) dlsym(x,n) - -#elif defined(USE_WIN_DLL) -# define sys_dl_error() win_dlerror() -# define sys_dl_open(x) LoadLibraryExA(x, MOO_NULL, 0) -# define sys_dl_openext(x) LoadLibraryExA(x, MOO_NULL, 0) -# define sys_dl_close(x) FreeLibrary(x) -# define sys_dl_getsym(x,n) GetProcAddress(x,n) - -#elif defined(USE_MACH_O_DYLD) -# define sys_dl_error() mach_dlerror() -# define sys_dl_open(x) mach_dlopen(x) -# define sys_dl_openext(x) mach_dlopen(x) -# define sys_dl_close(x) mach_dlclose(x) -# define sys_dl_getsym(x,n) mach_dlsym(x,n) -#endif - -#if defined(USE_WIN_DLL) - -static const char* win_dlerror (void) -{ - /* TODO: handle wchar_t, moo_ooch_t etc? */ - static char buf[256]; - DWORD rc; - - rc = FormatMessageA ( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - buf, MOO_COUNTOF(buf), MOO_NULL - ); - while (rc > 0 && buf[rc - 1] == '\r' || buf[rc - 1] == '\n') - { - buf[--rc] = '\0'; - } - return buf; -} - -#elif defined(USE_MACH_O_DYLD) -static const char* mach_dlerror_str = ""; - -static void* mach_dlopen (const char* path) -{ - NSObjectFileImage image; - NSObjectFileImageReturnCode rc; - void* handle; - - mach_dlerror_str = ""; - if ((rc = NSCreateObjectFileImageFromFile(path, &image)) != NSObjectFileImageSuccess) - { - switch (rc) - { - case NSObjectFileImageFailure: - case NSObjectFileImageFormat: - mach_dlerror_str = "unable to crate object file image"; - break; - - case NSObjectFileImageInappropriateFile: - mach_dlerror_str = "inappropriate file"; - break; - - case NSObjectFileImageArch: - mach_dlerror_str = "incompatible architecture"; - break; - - case NSObjectFileImageAccess: - mach_dlerror_str = "inaccessible file"; - break; - - default: - mach_dlerror_str = "unknown error"; - break; - } - return HCL_NULL; - } - handle = (void*)NSLinkModule(image, path, NSLINKMODULE_OPTION_PRIVATE | NSLINKMODULE_OPTION_RETURN_ON_ERROR); - NSDestroyObjectFileImage (image); - return handle; -} - -static HCL_INLINE void mach_dlclose (void* handle) -{ - mach_dlerror_str = ""; - NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_NONE); -} - -static HCL_INLINE void* mach_dlsym (void* handle, const char* name) -{ - mach_dlerror_str = ""; - return (void*)NSAddressOfSymbol(NSLookupSymbolInModule(handle, name)); -} - -static const char* mach_dlerror (void) -{ - int err_no; - const char* err_file; - NSLinkEditErrors err; - - if (mach_dlerror_str[0] == '\0') - NSLinkEditError (&err, &err_no, &err_file, &mach_dlerror_str); - - return mach_dlerror_str; -} -#endif - -static void* dl_open (hcl_t* hcl, const hcl_ooch_t* name, int flags) -{ -#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) - hcl_bch_t stabuf[128], * bufptr; - hcl_oow_t ucslen, bcslen, bufcapa; - void* handle; - - #if defined(HCL_OOCH_IS_UCH) - if (hcl_convootobcstr(hcl, name, &ucslen, HCL_NULL, &bufcapa) <= -1) return HCL_NULL; - /* +1 for terminating null. but it's not needed because HCL_COUNTOF(HCL_DEFAULT_PFMODPREFIX) - * and HCL_COUNTOF(HCL_DEFAULT_PFMODPOSTIFX) include the terminating nulls. Never mind about - * the extra 2 characters. */ - #else - bufcapa = hcl_count_bcstr(name); - #endif - bufcapa += HCL_COUNTOF(HCL_DEFAULT_PFMODDIR) + HCL_COUNTOF(HCL_DEFAULT_PFMODPREFIX) + HCL_COUNTOF(HCL_DEFAULT_PFMODPOSTFIX) + 1; - - if (bufcapa <= HCL_COUNTOF(stabuf)) bufptr = stabuf; - else - { - bufptr = (hcl_bch_t*)hcl_allocmem(hcl, bufcapa * HCL_SIZEOF(*bufptr)); - if (!bufptr) return HCL_NULL; - } - - if (flags & HCL_VMPRIM_DLOPEN_PFMOD) - { - hcl_oow_t len, i, xlen, dlen; - - /* opening a primitive function module - mostly libhcl-xxxx. - * if PFMODPREFIX is absolute, never use PFMODDIR */ - dlen = IS_PATH_ABSOLUTE(HCL_DEFAULT_PFMODPREFIX)? - 0: hcl_copy_bcstr(bufptr, bufcapa, HCL_DEFAULT_PFMODDIR); - len = hcl_copy_bcstr(bufptr, bufcapa, HCL_DEFAULT_PFMODPREFIX); - len += dlen; - - bcslen = bufcapa - len; - #if defined(HCL_OOCH_IS_UCH) - hcl_convootobcstr(hcl, name, &ucslen, &bufptr[len], &bcslen); - #else - bcslen = hcl_copy_bcstr(&bufptr[len], bcslen, name); - #endif - - /* length including the directory, the prefix and the name. but excluding the postfix */ - xlen = len + bcslen; - - for (i = len; i < xlen; i++) - { - /* convert a period(.) to a dash(-) */ - if (bufptr[i] == '.') bufptr[i] = '-'; - } - - retry: - hcl_copy_bcstr (&bufptr[xlen], bufcapa - xlen, HCL_DEFAULT_PFMODPOSTFIX); - - /* both prefix and postfix attached. for instance, libhcl-xxx */ - handle = sys_dl_openext(bufptr); - if (!handle) - { - HCL_DEBUG3 (hcl, "Unable to open(ext) PFMOD %hs[%js] - %hs\n", &bufptr[dlen], name, sys_dl_error()); - - if (dlen > 0) - { - handle = sys_dl_openext(&bufptr[0]); - if (handle) goto pfmod_open_ok; - HCL_DEBUG3 (hcl, "Unable to open(ext) PFMOD %hs[%js] - %hs\n", &bufptr[0], name, sys_dl_error()); - } - - /* try without prefix and postfix */ - bufptr[xlen] = '\0'; - handle = sys_dl_openext(&bufptr[len]); - if (!handle) - { - hcl_bch_t* dash; - const hcl_bch_t* dl_errstr; - dl_errstr = sys_dl_error(); - HCL_DEBUG3 (hcl, "Unable to open(ext) PFMOD %hs[%js] - %hs\n", &bufptr[len], name, dl_errstr); - hcl_seterrbfmt (hcl, HCL_ESYSERR, "unable to open(ext) PFMOD %js - %hs", name, dl_errstr); - - dash = hcl_rfind_bchar(bufptr, hcl_count_bcstr(bufptr), '-'); - if (dash) - { - /* remove a segment at the back. - * [NOTE] a dash contained in the original name before - * period-to-dash transformation may cause extraneous/wrong - * loading reattempts. */ - xlen = dash - bufptr; - goto retry; - } - } - else - { - HCL_DEBUG3 (hcl, "Opened(ext) PFMOD %hs[%js] handle %p\n", &bufptr[len], name, handle); - } - } - else - { - pfmod_open_ok: - HCL_DEBUG3 (hcl, "Opened(ext) PFMOD %hs[%js] handle %p\n", &bufptr[dlen], name, handle); - } - } - else - { - /* opening a raw shared object without a prefix and/or a postfix */ - #if defined(HCL_OOCH_IS_UCH) - bcslen = bufcapa; - hcl_convootobcstr(hcl, name, &ucslen, bufptr, &bcslen); - #else - bcslen = hcl_copy_bcstr(bufptr, bufcapa, name); - #endif - - if (hcl_find_bchar(bufptr, bcslen, '.')) - { - handle = sys_dl_open(bufptr); - if (!handle) - { - const hcl_bch_t* dl_errstr; - dl_errstr = sys_dl_error(); - HCL_DEBUG2 (hcl, "Unable to open DL %hs - %hs\n", bufptr, dl_errstr); - hcl_seterrbfmt (hcl, HCL_ESYSERR, "unable to open DL %js - %hs", name, dl_errstr); - } - else HCL_DEBUG2 (hcl, "Opened DL %hs handle %p\n", bufptr, handle); - } - else - { - handle = sys_dl_openext(bufptr); - if (!handle) - { - const hcl_bch_t* dl_errstr; - dl_errstr = sys_dl_error(); - HCL_DEBUG2 (hcl, "Unable to open(ext) DL %hs - %s\n", bufptr, dl_errstr); - hcl_seterrbfmt (hcl, HCL_ESYSERR, "unable to open(ext) DL %js - %hs", name, dl_errstr); - } - else HCL_DEBUG2 (hcl, "Opened(ext) DL %hs handle %p\n", bufptr, handle); - } - } - - if (bufptr != stabuf) hcl_freemem (hcl, bufptr); - return handle; - -#else - -/* TODO: support various platforms */ - /* TODO: implemenent this */ - HCL_DEBUG1 (hcl, "Dynamic loading not implemented - cannot open %js\n", name); - hcl_seterrbfmt (hcl, HCL_ENOIMPL, "dynamic loading not implemented - cannot open %js", name); - return HCL_NULL; -#endif -} - -static void dl_close (hcl_t* hcl, void* handle) -{ -#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) - HCL_DEBUG1 (hcl, "Closed DL handle %p\n", handle); - sys_dl_close (handle); - -#else - /* TODO: implemenent this */ - HCL_DEBUG1 (hcl, "Dynamic loading not implemented - cannot close handle %p\n", handle); -#endif -} - -static void* dl_getsym (hcl_t* hcl, void* handle, const hcl_ooch_t* name) -{ -#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) - hcl_bch_t stabuf[64], * bufptr; - hcl_oow_t bufcapa, ucslen, bcslen, i; - const hcl_bch_t* symname; - void* sym; - - #if defined(HCL_OOCH_IS_UCH) - if (hcl_convootobcstr(hcl, name, &ucslen, HCL_NULL, &bcslen) <= -1) return HCL_NULL; - #else - bcslen = hcl_count_bcstr (name); - #endif - - if (bcslen >= HCL_COUNTOF(stabuf) - 2) - { - bufcapa = bcslen + 3; - bufptr = (hcl_bch_t*)hcl_allocmem(hcl, bufcapa * HCL_SIZEOF(*bufptr)); - if (!bufptr) return HCL_NULL; - } - else - { - bufcapa = HCL_COUNTOF(stabuf); - bufptr = stabuf; - } - - bcslen = bufcapa - 1; - #if defined(HCL_OOCH_IS_UCH) - hcl_convootobcstr (hcl, name, &ucslen, &bufptr[1], &bcslen); - #else - bcslen = hcl_copy_bcstr(&bufptr[1], bcslen, name); - #endif - - /* convert a period(.) to an underscore(_) */ - for (i = 1; i <= bcslen; i++) if (bufptr[i] == '.') bufptr[i] = '_'; - - symname = &bufptr[1]; /* try the name as it is */ - - sym = sys_dl_getsym(handle, symname); - if (!sym) - { - bufptr[0] = '_'; - symname = &bufptr[0]; /* try _name */ - sym = sys_dl_getsym(handle, symname); - if (!sym) - { - bufptr[bcslen + 1] = '_'; - bufptr[bcslen + 2] = '\0'; - - symname = &bufptr[1]; /* try name_ */ - sym = sys_dl_getsym(handle, symname); - - if (!sym) - { - symname = &bufptr[0]; /* try _name_ */ - sym = sys_dl_getsym(handle, symname); - if (!sym) - { - const hcl_bch_t* dl_errstr; - dl_errstr = sys_dl_error(); - HCL_DEBUG3 (hcl, "Failed to get module symbol %js from handle %p - %hs\n", name, handle, dl_errstr); - hcl_seterrbfmt (hcl, HCL_ENOENT, "unable to get module symbol %hs - %hs", symname, dl_errstr); - - } - } - } - } - - if (sym) HCL_DEBUG3 (hcl, "Loaded module symbol %js from handle %p - %hs\n", name, handle, symname); - if (bufptr != stabuf) hcl_freemem (hcl, bufptr); - return sym; - -#else - /* TODO: IMPLEMENT THIS */ - HCL_DEBUG2 (hcl, "Dynamic loading not implemented - Cannot load module symbol %js from handle %p\n", name, handle); - hcl_seterrbfmt (hcl, HCL_ENOIMPL, "dynamic loading not implemented - Cannot load module symbol %js from handle %p", name, handle); - return HCL_NULL; -#endif -} - - diff --git a/lib/exec.c b/lib/exec.c index aa78d70..434b999 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -132,7 +132,7 @@ static int vm_startup (hcl_t* hcl) return -1; } } - hcl->vmprim.vm_gettime (hcl, &hcl->exec_start_time); /* raw time. no adjustment */ + hcl->vmprim.gettime (hcl, &hcl->exec_start_time); /* raw time. no adjustment */ return 0; } @@ -140,7 +140,7 @@ static int vm_startup (hcl_t* hcl) static void vm_cleanup (hcl_t* hcl) { hcl_cb_t* cb; - hcl->vmprim.vm_gettime (hcl, &hcl->exec_end_time); /* raw time. no adjustment */ + hcl->vmprim.gettime (hcl, &hcl->exec_end_time); /* raw time. no adjustment */ for (cb = hcl->cblist; cb; cb = cb->next) { if (cb->vm_cleanup) cb->vm_cleanup(hcl); @@ -1281,7 +1281,7 @@ static int execute (hcl_t* hcl) if (hcl->sem_heap_count > 0) { hcl_ntime_t ft, now; - hcl->vmprim.vm_gettime (hcl, &now); + hcl->vmprim.gettime (hcl, &now); do { @@ -1325,8 +1325,8 @@ static int execute (hcl_t* hcl) else if (hcl->processor->active == hcl->nil_process) { HCL_SUB_NTIME (&ft, &ft, (hcl_ntime_t*)&now); - hcl->vmprim.vm_sleep (hcl, &ft); /* TODO: change this to i/o multiplexer??? */ - hcl->vmprim.vm_gettime (hcl, &now); + hcl->vmprim.sleep (hcl, &ft); /* TODO: change this to i/o multiplexer??? */ + hcl->vmprim.gettime (hcl, &now); } else { diff --git a/lib/hcl-c.c b/lib/hcl-c.c index d4178a2..af81592 100644 --- a/lib/hcl-c.c +++ b/lib/hcl-c.c @@ -26,6 +26,7 @@ #include "hcl-c.h" #include "hcl-prv.h" +#include "cb-impl.h" #include #include @@ -137,16 +138,6 @@ static void log_write_for_dummy (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_ client->prim.log_write (client, mask, msg, len); } -static void syserrstrb (hcl_t* hcl, int syserr, hcl_bch_t* buf, hcl_oow_t len) -{ -#if defined(HAVE_STRERROR_R) - strerror_r (syserr, buf, len); -#else - /* this may not be thread safe */ - hcl_copy_bcstr (buf, len, strerror(syserr)); -#endif -} - /* ========================================================================= */ static HCL_INLINE int is_spacechar (hcl_bch_t c) @@ -820,8 +811,8 @@ hcl_client_t* hcl_client_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize, hcl_client_p HCL_MEMSET (&vmprim, 0, HCL_SIZEOF(vmprim)); vmprim.log_write = log_write_for_dummy; - vmprim.syserrstrb = syserrstrb; - vmprim.assertfail = assert_fail; + vmprim.syserrstrb = hcl_vmprim_syserrstrb; + vmprim.assertfail = hcl_vmprim_assertfail; hcl = hcl_open(mmgr, HCL_SIZEOF(*xtn), 2048, &vmprim, errnum); if (!hcl) diff --git a/lib/hcl-s.c b/lib/hcl-s.c index 13aae72..784b18b 100644 --- a/lib/hcl-s.c +++ b/lib/hcl-s.c @@ -28,6 +28,7 @@ #include "hcl-prv.h" #include "hcl-tmr.h" #include "hcl-xutl.h" +#include "cb-impl.h" #include #include @@ -354,15 +355,15 @@ struct hcl_server_t /* ========================================================================= */ #if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) -# define IS_PATH_SEP(c) ((c) == '/' || (c) == '\\') +# define HCL_IS_PATH_SEP(c) ((c) == '/' || (c) == '\\') # define PATH_SEP_CHAR ('\\') #else -# define IS_PATH_SEP(c) ((c) == '/') +# define HCL_IS_PATH_SEP(c) ((c) == '/') # define PATH_SEP_CHAR ('/') #endif /* TODO: handle path with a drive letter or in the UNC notation */ -#define IS_PATH_ABSOLUTE(x) IS_PATH_SEP(x[0]) +#define HCL_IS_PATH_ABSOLUTE(x) HCL_IS_PATH_SEP(x[0]) static const hcl_bch_t* get_base_name (const hcl_bch_t* path) @@ -371,7 +372,7 @@ static const hcl_bch_t* get_base_name (const hcl_bch_t* path) for (p = path; *p != '\0'; p++) { - if (IS_PATH_SEP(*p)) last = p; + if (HCL_IS_PATH_SEP(*p)) last = p; } return (last == HCL_NULL)? path: (last + 1); @@ -426,7 +427,7 @@ static HCL_INLINE int open_input (hcl_t* hcl, hcl_ioinarg_t* arg) #else hcl_copy_bchars (bb->fn, server->cfg.script_include_path, parlen); #endif - if (!IS_PATH_SEP(bb->fn[parlen])) bb->fn[parlen++] = PATH_SEP_CHAR; /* +2 was used in hcl_callocmem() for this (+1 for this, +1 for '\0' */ + if (!HCL_IS_PATH_SEP(bb->fn[parlen])) bb->fn[parlen++] = PATH_SEP_CHAR; /* +2 was used in hcl_callocmem() for this (+1 for this, +1 for '\0' */ } else { @@ -665,8 +666,6 @@ static void log_write_for_dummy (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_ pthread_mutex_unlock (&server->log_mutex); } -#include "cb-impl.h" - /* ========================================================================= */ static int vm_startup (hcl_t* hcl) @@ -715,17 +714,19 @@ hcl_server_proto_t* hcl_server_proto_open (hcl_oow_t xtnsize, hcl_server_worker_ HCL_MEMSET (&vmprim, 0, HCL_SIZEOF(vmprim)); if (worker->server->cfg.trait & HCL_SERVER_TRAIT_USE_LARGE_PAGES) { - vmprim.alloc_heap = alloc_heap; - vmprim.free_heap = free_heap; + vmprim.alloc_heap = hcl_vmprim_alloc_heap; + vmprim.free_heap = hcl_vmprim_free_heap; } vmprim.log_write = log_write; - vmprim.syserrstrb = syserrstrb; - vmprim.assertfail = assert_fail; - vmprim.dl_open = dl_open; - vmprim.dl_close = dl_close; - vmprim.dl_getsym = dl_getsym; - vmprim.vm_gettime = vm_gettime; - vmprim.vm_sleep = vm_sleep; + vmprim.syserrstrb = hcl_vmprim_syserrstrb; + vmprim.assertfail = hcl_vmprim_assertfail; + vmprim.dl_startup = hcl_vmprim_dl_startup; + vmprim.dl_cleanup = hcl_vmprim_dl_cleanup; + vmprim.dl_open = hcl_vmprim_dl_open; + vmprim.dl_close = hcl_vmprim_dl_close; + vmprim.dl_getsym = hcl_vmprim_dl_getsym; + vmprim.gettime = hcl_vmprim_gettime; + vmprim.sleep = hcl_vmprim_sleep; proto = (hcl_server_proto_t*)hcl_server_allocmem(worker->server, HCL_SIZEOF(*proto)); if (!proto) return HCL_NULL; @@ -1190,7 +1191,7 @@ static int insert_exec_timer (hcl_server_proto_t* proto, const hcl_ntime_t* tmou HCL_MEMSET (&event, 0, HCL_SIZEOF(event)); event.ctx = proto; - proto->hcl->vmprim.vm_gettime (proto->hcl, &event.when); + proto->hcl->vmprim.gettime (proto->hcl, &event.when); HCL_ADD_NTIME (&event.when, &event.when, tmout); event.handler = exec_runtime_handler; event.updater = exec_runtime_updater; @@ -1582,12 +1583,15 @@ hcl_server_t* hcl_server_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize, hcl_server_p HCL_MEMSET (&vmprim, 0, HCL_SIZEOF(vmprim)); vmprim.log_write = log_write_for_dummy; - vmprim.syserrstrb = syserrstrb; - vmprim.dl_open = dl_open; - vmprim.dl_close = dl_close; - vmprim.dl_getsym = dl_getsym; - vmprim.vm_gettime = vm_gettime; - vmprim.vm_sleep = vm_sleep; + vmprim.syserrstrb = hcl_vmprim_syserrstrb; + vmprim.assertfail = hcl_vmprim_assertfail; + vmprim.dl_startup = hcl_vmprim_dl_startup; + vmprim.dl_cleanup = hcl_vmprim_dl_cleanup; + vmprim.dl_open = hcl_vmprim_dl_open; + vmprim.dl_close = hcl_vmprim_dl_close; + vmprim.dl_getsym = hcl_vmprim_dl_getsym; + vmprim.gettime = hcl_vmprim_gettime; + vmprim.sleep = hcl_vmprim_sleep; #if defined(USE_LTDL) lt_dlinit (); @@ -1605,7 +1609,7 @@ hcl_server_t* hcl_server_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize, hcl_server_p if (pipe(pfd) <= -1) { - if (errnum) *errnum = syserrstrb(hcl, 0, errno, HCL_NULL, 0); + if (errnum) *errnum = hcl_vmprim_syserrstrb(hcl, 0, errno, HCL_NULL, 0); goto oops; } @@ -1682,9 +1686,6 @@ oops: /* NOTE: pipe should be closed if jump to here is made after pipe() above */ if (tmr) hcl_tmr_close (tmr); if (hcl) hcl_close (hcl); -#if defined(USE_LTDL) - lt_dlexit (); -#endif if (server) HCL_MMGR_FREE (mmgr, server); return HCL_NULL; @@ -1714,10 +1715,6 @@ void hcl_server_close (hcl_server_t* server) hcl_tmr_close (server->tmr); hcl_close (server->dummy_hcl); -#if defined(USE_LTDL) - lt_dlexit (); -#endif - HCL_MMGR_FREE (server->mmgr, server); } @@ -1811,7 +1808,7 @@ static hcl_server_worker_t* alloc_worker (hcl_server_t* server, int cli_sck, con worker->peeraddr = *peeraddr; worker->server = server; - server->dummy_hcl->vmprim.vm_gettime (server->dummy_hcl, &worker->alloc_time); /* TODO: the callback may return monotonic time. find a way to guarantee it is realtime??? */ + server->dummy_hcl->vmprim.gettime (server->dummy_hcl, &worker->alloc_time); /* TODO: the callback may return monotonic time. find a way to guarantee it is realtime??? */ if (server->wid_map.free_first == HCL_SERVER_WID_INVALID && prepare_to_acquire_wid(server) <= -1) { diff --git a/lib/hcl.c b/lib/hcl.c index eae830c..0e66d38 100644 --- a/lib/hcl.c +++ b/lib/hcl.c @@ -103,6 +103,14 @@ int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t return -1; } +#if !defined(HCL_BUILD_RELEASE) + if (!vmprim->assertfail) + { + hcl_seterrnum (hcl, HCL_EINVAL); + return -1; + } +#endif + HCL_MEMSET (hcl, 0, HCL_SIZEOF(*hcl)); hcl->mmgr = mmgr; hcl->cmgr = hcl_get_utf8_cmgr(); @@ -149,6 +157,7 @@ int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t hcl->newheap = hcl_makeheap(hcl, heapsz); if (!hcl->newheap) goto oops; + if (hcl->vmprim.dl_startup) hcl->vmprim.dl_startup (hcl); return 0; oops: @@ -284,6 +293,8 @@ void hcl_fini (hcl_t* hcl) hcl->sprintf.xbuf.capa = 0; hcl->sprintf.xbuf.len = 0; } + + if (hcl->vmprim.dl_cleanup) hcl->vmprim.dl_cleanup (hcl); } void hcl_reset (hcl_t* hcl) diff --git a/lib/hcl.h b/lib/hcl.h index 5f2154d..f955421 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -843,6 +843,14 @@ enum hcl_vmprim_dlopen_flag_t }; typedef enum hcl_vmprim_dlopen_flag_t hcl_vmprim_dlopen_flag_t; +typedef void (*hcl_vmprim_dlstartup_t) ( + hcl_t* hcl +); + +typedef void (*hcl_vmprim_dlcleanup_t) ( + hcl_t* hcl +); + typedef void* (*hcl_vmprim_dlopen_t) ( hcl_t* hcl, const hcl_ooch_t* name, @@ -867,7 +875,8 @@ typedef void (*hcl_vmprim_gettime_t) ( typedef void (*hcl_vmprim_sleep_t) ( hcl_t* hcl, - const hcl_ntime_t* duration); + const hcl_ntime_t* duration +); struct hcl_vmprim_t { @@ -875,25 +884,27 @@ struct hcl_vmprim_t * before hcl is fully initialized. so few features are availble * in this callback function. If it's not provided, the default * implementation is used. */ - hcl_alloc_heap_t alloc_heap; /* optional */ + hcl_alloc_heap_t alloc_heap; /* optional */ /* If you customize the heap allocator by providing the alloc_heap * callback, you should implement the heap freer. otherwise the default * implementation doesn't know how to free the heap allocated by * the allocator callback. */ - hcl_free_heap_t free_heap; /* optional */ + hcl_free_heap_t free_heap; /* optional */ - hcl_log_write_t log_write; /* required */ - hcl_syserrstrb_t syserrstrb; /* one of syserrstrb or syserrstru required */ - hcl_syserrstru_t syserrstru; - hcl_assertfail_t assertfail; + hcl_log_write_t log_write; /* required */ + hcl_syserrstrb_t syserrstrb; /* one of syserrstrb or syserrstru required */ + hcl_syserrstru_t syserrstru; + hcl_assertfail_t assertfail; - hcl_vmprim_dlopen_t dl_open; /* required */ - hcl_vmprim_dlclose_t dl_close; /* required */ - hcl_vmprim_dlgetsym_t dl_getsym; /* requried */ + hcl_vmprim_dlstartup_t dl_startup; /* optional */ + hcl_vmprim_dlcleanup_t dl_cleanup; /* optional */ + hcl_vmprim_dlopen_t dl_open; /* required */ + hcl_vmprim_dlclose_t dl_close; /* required */ + hcl_vmprim_dlgetsym_t dl_getsym; /* requried */ - hcl_vmprim_gettime_t vm_gettime; /* required */ - hcl_vmprim_sleep_t vm_sleep; /* required */ + hcl_vmprim_gettime_t gettime; /* required */ + hcl_vmprim_sleep_t sleep; /* required */ }; typedef struct hcl_vmprim_t hcl_vmprim_t; diff --git a/lib/json.c b/lib/json.c index bd49e3a..00cabe2 100644 --- a/lib/json.c +++ b/lib/json.c @@ -26,6 +26,7 @@ #include "hcl-json.h" #include "hcl-prv.h" +#include "cb-impl.h" #include #include @@ -119,16 +120,6 @@ static void log_write_for_dummy (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_ json->prim.log_write (json, mask, msg, len); } -static void syserrstrb (hcl_t* hcl, int syserr, hcl_bch_t* buf, hcl_oow_t len) -{ -#if defined(HAVE_STRERROR_R) - strerror_r (syserr, buf, len); -#else - /* this may not be thread safe */ - hcl_copy_bcstr (buf, len, strerror(syserr)); -#endif -} - /* ========================================================================= */ static HCL_INLINE int is_spacechar (hcl_bch_t c) @@ -909,8 +900,8 @@ hcl_json_t* hcl_json_open (hcl_mmgr_t* mmgr, hcl_oow_t xtnsize, hcl_json_prim_t* HCL_MEMSET (&vmprim, 0, HCL_SIZEOF(vmprim)); vmprim.log_write = log_write_for_dummy; - vmprim.syserrstrb = syserrstrb; - vmprim.assertfail = assert_fail; + vmprim.syserrstrb = hcl_vmprim_syserrstrb; + vmprim.assertfail = hcl_vmprim_assertfail; hcl = hcl_open(mmgr, HCL_SIZEOF(*xtn), 2048, &vmprim, errnum); if (!hcl) diff --git a/lib/main.c b/lib/main.c index 461bb37..f10cc70 100644 --- a/lib/main.c +++ b/lib/main.c @@ -26,6 +26,7 @@ #include "hcl-prv.h" #include "hcl-opt.h" +#include "cb-impl.h" #include #include @@ -41,36 +42,24 @@ # include # include # include -# if defined(HCL_HAVE_CFG_H) && defined(HCL_ENABLE_LIBLTDL) -# include -# define USE_LTDL -# else -# define USE_WIN_DLL -# endif + #elif defined(__OS2__) # define INCL_DOSMODULEMGR # define INCL_DOSPROCESS # define INCL_DOSERRORS # include -#elif defined(__MSDOS__) + +#elif defined(__DOS__) # include # include #elif defined(macintosh) # include #else -# if defined(HCL_ENABLE_LIBLTDL) -# include -# define USE_LTDL -# elif defined(HAVE_DLFCN_H) -# include -# define USE_DLFCN -# elif defined(__APPLE__) || defined(__MACOSX__) -# define USE_MACH_O_DYLD -# include -# else -# error UNSUPPORTED DYNAMIC LINKER -# endif +# include +# include +# include +# include # if defined(HAVE_TIME_H) # include @@ -81,49 +70,7 @@ # if defined(HAVE_SIGNAL_H) # include # endif -# if defined(HAVE_SYS_MMAN_H) -# include -# endif - -# include -# include -# include - -#endif - -#if !defined(HCL_DEFAULT_PFMODDIR) -# define HCL_DEFAULT_PFMODDIR "" -#endif - -#if !defined(HCL_DEFAULT_PFMODPREFIX) -# if defined(_WIN32) -# define HCL_DEFAULT_PFMODPREFIX "hcl-" -# elif defined(__OS2__) -# define HCL_DEFAULT_PFMODPREFIX "hcl" -# elif defined(__DOS__) -# define HCL_DEFAULT_PFMODPREFIX "hcl" -# else -# define HCL_DEFAULT_PFMODPREFIX "libhcl-" -# endif -#endif - -#if !defined(HCL_DEFAULT_PFMODPOSTFIX) -# if defined(_WIN32) -# define HCL_DEFAULT_PFMODPOSTFIX "" -# elif defined(__OS2__) -# define HCL_DEFAULT_PFMODPOSTFIX "" -# elif defined(__DOS__) -# define HCL_DEFAULT_PFMODPOSTFIX "" -# else -# if defined(USE_DLFCN) -# define HCL_DEFAULT_PFMODPOSTFIX ".so" -# elif defined(USE_MACH_O_DYLD) -# define HCL_DEFAULT_PFMODPOSTFIX ".dylib" -# else -# define HCL_DEFAULT_PFMODPOSTFIX "" -# endif -# endif #endif typedef struct bb_t bb_t; @@ -190,23 +137,13 @@ static hcl_mmgr_t sys_mmgr = /* ========================================================================= */ - -#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) -# define IS_PATH_SEP(c) ((c) == '/' || (c) == '\\') -#else -# define IS_PATH_SEP(c) ((c) == '/') -#endif - -/* TODO: handle path with a drive letter or in the UNC notation */ -#define IS_PATH_ABSOLUTE(x) IS_PATH_SEP(x[0]) - static const hcl_bch_t* get_base_name (const hcl_bch_t* path) { const hcl_bch_t* p, * last = HCL_NULL; for (p = path; *p != '\0'; p++) { - if (IS_PATH_SEP(*p)) last = p; + if (HCL_IS_PATH_SEP(*p)) last = p; } return (last == HCL_NULL)? path: (last + 1); @@ -699,8 +636,6 @@ static void log_write (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* msg, hc flush_log (hcl, logfd); } -#include "cb-impl.h" - /* ========================================================================= */ static int vm_startup (hcl_t* hcl) @@ -882,113 +817,6 @@ static hcl_t* g_hcl = HCL_NULL; /* ========================================================================= */ -#if defined(__MSDOS__) && defined(_INTELC32_) -static void (*prev_timer_intr_handler) (void); - -#pragma interrupt(timer_intr_handler) -static void timer_intr_handler (void) -{ - /* - _XSTACK *stk; - int r; - stk = (_XSTACK *)_get_stk_frame(); - r = (unsigned short)stk_ptr->eax; - */ - - /* The timer interrupt (normally) occurs 18.2 times per second. */ - if (g_hcl) hcl_switchprocess (g_hcl); - _chain_intr(prev_timer_intr_handler); -} - -#elif defined(macintosh) - -static TMTask g_tmtask; -static ProcessSerialNumber g_psn; - -#define TMTASK_DELAY 50 /* milliseconds if positive, microseconds(after negation) if negative */ - -static pascal void timer_intr_handler (TMTask* task) -{ - if (g_hcl) hcl_switchprocess (g_hcl); - WakeUpProcess (&g_psn); - PrimeTime ((QElem*)&g_tmtask, TMTASK_DELAY); -} - -#else -static void arrange_process_switching (int sig) -{ - if (g_hcl) hcl_switchprocess (g_hcl); -} -#endif - -#if 0 -static void setup_tick (void) -{ -#if defined(__MSDOS__) && defined(_INTELC32_) - - prev_timer_intr_handler = _dos_getvect (0x1C); - _dos_setvect (0x1C, timer_intr_handler); - -#elif defined(macintosh) - - GetCurrentProcess (&g_psn); - memset (&g_tmtask, 0, HCL_SIZEOF(g_tmtask)); - g_tmtask.tmAddr = NewTimerProc (timer_intr_handler); - InsXTime ((QElem*)&g_tmtask); - - PrimeTime ((QElem*)&g_tmtask, TMTASK_DELAY); - -#elif defined(HAVE_SETITIMER) && defined(SIGVTALRM) && defined(ITIMER_VIRTUAL) - struct itimerval itv; - struct sigaction act; - - sigemptyset (&act.sa_mask); - act.sa_handler = arrange_process_switching; - act.sa_flags = 0; - sigaction (SIGVTALRM, &act, HCL_NULL); - - itv.it_interval.tv_sec = 0; - itv.it_interval.tv_usec = 100; /* 100 microseconds */ - itv.it_value.tv_sec = 0; - itv.it_value.tv_usec = 100; - setitimer (ITIMER_VIRTUAL, &itv, HCL_NULL); -#else - -# error UNSUPPORTED -#endif -} - -static void cancel_tick (void) -{ -#if defined(__MSDOS__) && defined(_INTELC32_) - - _dos_setvect (0x1C, prev_timer_intr_handler); - -#elif defined(macintosh) - RmvTime ((QElem*)&g_tmtask); - /*DisposeTimerProc (g_tmtask.tmAddr);*/ - -#elif defined(HAVE_SETITIMER) && defined(SIGVTALRM) && defined(ITIMER_VIRTUAL) - struct itimerval itv; - struct sigaction act; - - itv.it_interval.tv_sec = 0; - itv.it_interval.tv_usec = 0; - itv.it_value.tv_sec = 0; /* make setitimer() one-shot only */ - itv.it_value.tv_usec = 0; - setitimer (ITIMER_VIRTUAL, &itv, HCL_NULL); - - sigemptyset (&act.sa_mask); - act.sa_handler = SIG_IGN; /* ignore the signal potentially fired by the one-shot arrange above */ - act.sa_flags = 0; - sigaction (SIGVTALRM, &act, HCL_NULL); - -#else -# error UNSUPPORTED -#endif -} -#endif - /* ========================================================================= */ #if defined(_WIN32) || defined(__MSDOS__) || defined(__OS2__) || defined(macintosh) @@ -1062,7 +890,6 @@ static void set_signal_to_default (int sig) #endif } - /* ========================================================================= */ static void print_synerr (hcl_t* hcl) @@ -1188,23 +1015,21 @@ int main (int argc, char* argv[]) memset (&vmprim, 0, HCL_SIZEOF(vmprim)); if (large_pages) { - vmprim.alloc_heap = alloc_heap; - vmprim.free_heap = free_heap; + vmprim.alloc_heap = hcl_vmprim_alloc_heap; + vmprim.free_heap = hcl_vmprim_free_heap; } vmprim.log_write = log_write; - vmprim.syserrstrb = syserrstrb; - vmprim.assertfail = assert_fail; - vmprim.dl_open = dl_open; - vmprim.dl_close = dl_close; - vmprim.dl_getsym = dl_getsym; - vmprim.vm_gettime = vm_gettime; - vmprim.vm_sleep = vm_sleep; + vmprim.syserrstrb = hcl_vmprim_syserrstrb; + vmprim.assertfail = hcl_vmprim_assertfail; + vmprim.dl_startup = hcl_vmprim_dl_startup; + vmprim.dl_cleanup = hcl_vmprim_dl_cleanup; + vmprim.dl_open = hcl_vmprim_dl_open; + vmprim.dl_close = hcl_vmprim_dl_close; + vmprim.dl_getsym = hcl_vmprim_dl_getsym; + vmprim.gettime = hcl_vmprim_gettime; + vmprim.sleep = hcl_vmprim_sleep; -#if defined(USE_LTDL) - lt_dlinit (); -#endif - - hcl = hcl_open (&sys_mmgr, HCL_SIZEOF(xtn_t), memsize, &vmprim, HCL_NULL); + hcl = hcl_open(&sys_mmgr, HCL_SIZEOF(xtn_t), memsize, &vmprim, HCL_NULL); if (!hcl) { printf ("ERROR: cannot open hcl\n"); @@ -1417,16 +1242,10 @@ count++; set_signal_to_default (SIGINT); hcl_close (hcl); -#if defined(USE_LTDL) - lt_dlexit (); -#endif return 0; oops: set_signal_to_default (SIGINT); /* harmless to call multiple times without set_signal() */ if (hcl) hcl_close (hcl); -#if defined(USE_LTDL) - lt_dlexit (); -#endif return -1; } diff --git a/lib/tmr.c b/lib/tmr.c index 23ebc3a..8e04aa6 100644 --- a/lib/tmr.c +++ b/lib/tmr.c @@ -244,7 +244,7 @@ int hcl_tmr_fire (hcl_tmr_t* tmr, const hcl_ntime_t* tm, hcl_oow_t* firecnt) /* if the current time is not specified, get it from the system */ if (tm) now = *tm; /*else if (hcl_gettime(&now) <= -1) return -1;*/ - tmr->hcl->vmprim.vm_gettime (tmr->hcl, &now); + tmr->hcl->vmprim.gettime (tmr->hcl, &now); while (tmr->size > 0) { @@ -271,7 +271,7 @@ int hcl_tmr_gettmout (hcl_tmr_t* tmr, const hcl_ntime_t* tm, hcl_ntime_t* tmout) /* if the current time is not specified, get it from the system */ if (tm) now = *tm; /*else if (hcl_gettime(&now) <= -1) return -1;*/ - tmr->hcl->vmprim.vm_gettime (tmr->hcl, &now); + tmr->hcl->vmprim.gettime (tmr->hcl, &now); HCL_SUB_NTIME (tmout, &tmr->event[0].when, &now); if (tmout->sec < 0) HCL_CLEAR_NTIME (tmout);