started adding a socket module and the Socket class

This commit is contained in:
hyunghwan.chung 2017-10-18 16:15:51 +00:00
parent 016b7c2dac
commit 2c85319cb0
21 changed files with 546 additions and 104 deletions

31
moo/configure vendored
View File

@ -658,6 +658,8 @@ MOO_SIZEOF_LONG_LONG
MOO_SIZEOF_WCHAR_T
ENABLE_MOD_X11_FALSE
ENABLE_MOD_X11_TRUE
ENABLE_MOD_SCK_FALSE
ENABLE_MOD_SCK_TRUE
ENABLE_MOD_FFI_FALSE
ENABLE_MOD_FFI_TRUE
ENABLE_LIBLTDL_FALSE
@ -843,6 +845,7 @@ enable_dynamic_module
enable_static_module
enable_libltdl
enable_mod_ffi
enable_mod_sck
enable_mod_x11
'
ac_precious_vars='build_alias
@ -1497,6 +1500,7 @@ Optional Features:
library(default. no)
--enable-libltdl use libltdl(default. yes)
--enable-mod-ffi enable mod/ffi (default. yes)
--enable-mod-sck enable mod/sck (default. yes)
--enable-mod-x11 enable mod/x11 (default. yes)
Optional Packages:
@ -20845,6 +20849,29 @@ else
fi
# Check whether --enable-mod-sck was given.
if test "${enable_mod_sck+set}" = set; then :
enableval=$enable_mod_sck; enable_mod_sck_is=$enableval
else
enable_mod_sck_is=yes
fi
if test "${enable_mod_sck_is}" = "yes"
then
$as_echo "#define MOO_ENABLE_MOD_SCK /**/" >>confdefs.h
fi
if test "${enable_mod_sck_is}" = "yes"; then
ENABLE_MOD_SCK_TRUE=
ENABLE_MOD_SCK_FALSE='#'
else
ENABLE_MOD_SCK_TRUE='#'
ENABLE_MOD_SCK_FALSE=
fi
# Check whether --enable-mod-x11 was given.
if test "${enable_mod_x11+set}" = set; then :
enableval=$enable_mod_x11; enable_mod_x11_is=$enableval
@ -21091,6 +21118,10 @@ if test -z "${ENABLE_MOD_FFI_TRUE}" && test -z "${ENABLE_MOD_FFI_FALSE}"; then
as_fn_error $? "conditional \"ENABLE_MOD_FFI\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${ENABLE_MOD_SCK_TRUE}" && test -z "${ENABLE_MOD_SCK_FALSE}"; then
as_fn_error $? "conditional \"ENABLE_MOD_SCK\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${ENABLE_MOD_X11_TRUE}" && test -z "${ENABLE_MOD_X11_FALSE}"; then
as_fn_error $? "conditional \"ENABLE_MOD_X11\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5

View File

@ -509,6 +509,18 @@ then
fi
AM_CONDITIONAL(ENABLE_MOD_FFI, test "${enable_mod_ffi_is}" = "yes")
dnl ===== enable-mod-sck =====
AC_ARG_ENABLE([mod-sck],
[AS_HELP_STRING([--enable-mod-sck],[enable mod/sck (default. yes)])],
enable_mod_sck_is=$enableval,
enable_mod_sck_is=yes
)
if test "${enable_mod_sck_is}" = "yes"
then
AC_DEFINE([MOO_ENABLE_MOD_SCK],[],[build mod/sck])
fi
AM_CONDITIONAL(ENABLE_MOD_SCK, test "${enable_mod_sck_is}" = "yes")
dnl ===== enable-mod-x11 =====
AC_ARG_ENABLE([mod-x11],
[AS_HELP_STRING([--enable-mod-x11],[enable mod/x11 (default. yes)])],

48
moo/kernel/Socket.moo Normal file
View File

@ -0,0 +1,48 @@
class Socket(Object) from 'sck'
{
var handle := -1.
method(#primitive) _open(domain, type, proto).
method(#primitive) _connect(a,b,c).
method(#primitive) _close.
}
(* TODO: generate these domain and type from the C header *)
pooldic Socket.Domain
{
INET := 2.
INET6 := 10.
}
pooldic Socket.Type
{
STREAM := 1.
DGRAM := 2.
}
extend Socket
{
method(#class) domain: domain type: type
{
^super new _open(domain, type, 0).
}
method beginConnect
{
(*
| s1 s1 |
s1 = Semaphore new.
s2 = Semaphore new.
s1 signalHandler: [xxxxx].
s2 signalHandler: [xxxxxx].
fcntl (nonblock);
Processor signal: s1 onOutput: self.handle.
Processor signal: s2 after: timeout.
connect ();
*)
}
}

View File

@ -15,6 +15,7 @@ class MyObject(Object)
'internal error that should never have happened'
'insufficient system memory'
'insufficient object memory'
'invalid class/type'
'invalid parameter or argument'
'data not found'

View File

@ -76,6 +76,10 @@ if ENABLE_MOD_FFI
libmoo_la_LIBADD += -lmoo-ffi
libmoo_la_DEPENDENCIES += $(abs_builddir)/../mod/libmoo-ffi.la
endif
if ENABLE_MOD_SCK
libmoo_la_LIBADD += -lmoo-sck
libmoo_la_DEPENDENCIES += $(abs_builddir)/../mod/libmoo-sck.la
endif
if ENABLE_MOD_X11
libmoo_la_LIBADD += -lmoo-x11
libmoo_la_DEPENDENCIES += $(abs_builddir)/../mod/libmoo-x11.la

View File

@ -100,11 +100,14 @@ host_triplet = @host@
@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_3) \
@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) \
@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) \
@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) \
@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1)
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_6 = -lmoo-ffi
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_7 = $(abs_builddir)/../mod/libmoo-ffi.la
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_8 = -lmoo-x11
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_9 = $(abs_builddir)/../mod/libmoo-x11.la
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_8 = -lmoo-sck
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_9 = $(abs_builddir)/../mod/libmoo-sck.la
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_10 = -lmoo-x11
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_11 = $(abs_builddir)/../mod/libmoo-x11.la
bin_PROGRAMS = moo$(EXEEXT)
@ENABLE_STATIC_MODULE_FALSE@moo_DEPENDENCIES = $(am__DEPENDENCIES_3)
subdir = lib
@ -451,10 +454,11 @@ libmoo_la_SOURCES = \
libmoo_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
libmoo_la_LDFLAGS = $(LDFLAGS_LIB_COMMON)
libmoo_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_5) \
$(am__append_6) $(am__append_8)
$(am__append_6) $(am__append_8) $(am__append_10)
@ENABLE_STATIC_MODULE_TRUE@libmoo_la_DEPENDENCIES = $(abs_builddir)/../mod/libmoo-console.la \
@ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libmoo-stdio.la \
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_7) $(am__append_9)
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_7) $(am__append_9) \
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_11)
moo_SOURCES = main.c
moo_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
moo_LDFLAGS = $(LDFLAGS_LIB_COMMON)

View File

@ -5063,6 +5063,10 @@ static int compile_unary_message (moo_t* moo, int to_super)
}
if (emit_double_param_instruction(moo, send_message_cmd[to_super], nargs, index) <= -1) return -1;
/* In 'super new xxx', xxx is sent to the object returned by new.
* that means it is not sent to 'super' */
to_super = 0;
}
while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT);
@ -5102,6 +5106,7 @@ static int compile_binary_message (moo_t* moo, int to_super)
if (add_symbol_literal(moo, &binsel, 0, &index) <= -1 ||
emit_double_param_instruction(moo, send_message_cmd[to_super], 1, index) <= -1) goto oops;
to_super = 0; /* In super + 2 - 3, '-' is sent to the return value of '+', not to super */
moo->c->mth.binsels.len = saved_binsels_len;
}
while (TOKEN_TYPE(moo) == MOO_IOTOK_BINSEL);

View File

@ -37,36 +37,37 @@ static moo_ooch_t errstr_3[] = {'s','u','b','s','y','s','t','e','m',' ','e','r',
static moo_ooch_t errstr_4[] = {'i','n','t','e','r','n','a','l',' ','e','r','r','o','r',' ','t','h','a','t',' ','s','h','o','u','l','d',' ','n','e','v','e','r',' ','h','a','v','e',' ','h','a','p','p','e','n','e','d','\0'};
static moo_ooch_t errstr_5[] = {'i','n','s','u','f','f','i','c','i','e','n','t',' ','s','y','s','t','e','m',' ','m','e','m','o','r','y','\0'};
static moo_ooch_t errstr_6[] = {'i','n','s','u','f','f','i','c','i','e','n','t',' ','o','b','j','e','c','t',' ','m','e','m','o','r','y','\0'};
static moo_ooch_t errstr_7[] = {'i','n','v','a','l','i','d',' ','p','a','r','a','m','e','t','e','r',' ','o','r',' ','a','r','g','u','m','e','n','t','\0'};
static moo_ooch_t errstr_8[] = {'d','a','t','a',' ','n','o','t',' ','f','o','u','n','d','\0'};
static moo_ooch_t errstr_9[] = {'e','x','i','s','t','i','n','g','/','d','u','p','l','i','c','a','t','e',' ','d','a','t','a','\0'};
static moo_ooch_t errstr_10[] = {'b','u','s','y','\0'};
static moo_ooch_t errstr_11[] = {'a','c','c','e','s','s',' ','d','e','n','i','e','d','\0'};
static moo_ooch_t errstr_12[] = {'o','p','e','r','a','t','i','o','n',' ','n','o','t',' ','p','e','r','m','i','t','t','e','d','\0'};
static moo_ooch_t errstr_13[] = {'n','o','t',' ','a',' ','d','i','r','e','c','t','o','r','y','\0'};
static moo_ooch_t errstr_14[] = {'i','n','t','e','r','r','u','p','t','e','d','\0'};
static moo_ooch_t errstr_15[] = {'p','i','p','e',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_16[] = {'r','e','s','o','u','r','c','e',' ','t','e','m','p','o','r','a','r','i','l','y',' ','u','n','a','v','a','i','l','a','b','l','e','\0'};
static moo_ooch_t errstr_17[] = {'d','a','t','a',' ','n','o','t',' ','a','v','a','i','l','a','b','l','e','\0'};
static moo_ooch_t errstr_18[] = {'m','e','s','s','a','g','e',' ','r','e','c','e','i','v','e','r',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_19[] = {'m','e','s','s','a','g','e',' ','s','e','n','d','i','n','g',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_20[] = {'w','r','o','n','g',' ','n','u','m','b','e','r',' ','o','f',' ','a','r','g','u','m','e','n','t','s','\0'};
static moo_ooch_t errstr_21[] = {'r','a','n','g','e',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_22[] = {'b','y','t','e','-','c','o','d','e',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_23[] = {'d','i','c','t','i','o','n','a','r','y',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_24[] = {'p','r','o','c','e','s','s','o','r',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_25[] = {'s','e','m','a','p','h','o','r','e',' ','h','e','a','p',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_26[] = {'s','e','m','a','p','h','o','r','e',' ','l','i','s','t',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_27[] = {'d','i','v','i','d','e',' ','b','y',' ','z','e','r','o','\0'};
static moo_ooch_t errstr_28[] = {'I','/','O',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_29[] = {'e','n','c','o','d','i','n','g',' ','c','o','n','v','e','r','s','i','o','n',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_30[] = {'b','u','f','f','e','r',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_7[] = {'i','n','v','a','l','i','d',' ','c','l','a','s','s','/','t','y','p','e','\0'};
static moo_ooch_t errstr_8[] = {'i','n','v','a','l','i','d',' ','p','a','r','a','m','e','t','e','r',' ','o','r',' ','a','r','g','u','m','e','n','t','\0'};
static moo_ooch_t errstr_9[] = {'d','a','t','a',' ','n','o','t',' ','f','o','u','n','d','\0'};
static moo_ooch_t errstr_10[] = {'e','x','i','s','t','i','n','g','/','d','u','p','l','i','c','a','t','e',' ','d','a','t','a','\0'};
static moo_ooch_t errstr_11[] = {'b','u','s','y','\0'};
static moo_ooch_t errstr_12[] = {'a','c','c','e','s','s',' ','d','e','n','i','e','d','\0'};
static moo_ooch_t errstr_13[] = {'o','p','e','r','a','t','i','o','n',' ','n','o','t',' ','p','e','r','m','i','t','t','e','d','\0'};
static moo_ooch_t errstr_14[] = {'n','o','t',' ','a',' ','d','i','r','e','c','t','o','r','y','\0'};
static moo_ooch_t errstr_15[] = {'i','n','t','e','r','r','u','p','t','e','d','\0'};
static moo_ooch_t errstr_16[] = {'p','i','p','e',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_17[] = {'r','e','s','o','u','r','c','e',' ','t','e','m','p','o','r','a','r','i','l','y',' ','u','n','a','v','a','i','l','a','b','l','e','\0'};
static moo_ooch_t errstr_18[] = {'d','a','t','a',' ','t','o','o',' ','l','a','r','g','e','\0'};
static moo_ooch_t errstr_19[] = {'m','e','s','s','a','g','e',' ','r','e','c','e','i','v','e','r',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_20[] = {'m','e','s','s','a','g','e',' ','s','e','n','d','i','n','g',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_21[] = {'w','r','o','n','g',' ','n','u','m','b','e','r',' ','o','f',' ','a','r','g','u','m','e','n','t','s','\0'};
static moo_ooch_t errstr_22[] = {'r','a','n','g','e',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_23[] = {'b','y','t','e','-','c','o','d','e',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_24[] = {'d','i','c','t','i','o','n','a','r','y',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_25[] = {'p','r','o','c','e','s','s','o','r',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_26[] = {'s','e','m','a','p','h','o','r','e',' ','h','e','a','p',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_27[] = {'s','e','m','a','p','h','o','r','e',' ','l','i','s','t',' ','f','u','l','l','\0'};
static moo_ooch_t errstr_28[] = {'d','i','v','i','d','e',' ','b','y',' ','z','e','r','o','\0'};
static moo_ooch_t errstr_29[] = {'I','/','O',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_30[] = {'e','n','c','o','d','i','n','g',' ','c','o','n','v','e','r','s','i','o','n',' ','e','r','r','o','r','\0'};
static moo_ooch_t errstr_31[] = {'b','u','f','f','e','r',' ','f','u','l','l','\0'};
static moo_ooch_t* errstr[] =
{
errstr_0, errstr_1, errstr_2, errstr_3, errstr_4, errstr_5, errstr_6, errstr_7,
errstr_8, errstr_9, errstr_10, errstr_11, errstr_12, errstr_13, errstr_14, errstr_15,
errstr_16, errstr_17, errstr_18, errstr_19, errstr_20, errstr_21, errstr_22, errstr_23,
errstr_24, errstr_25, errstr_26, errstr_27, errstr_28, errstr_29, errstr_30
errstr_24, errstr_25, errstr_26, errstr_27, errstr_28, errstr_29, errstr_30, errstr_31
};
#if defined(MOO_INCLUDE_COMPILER)
@ -159,14 +160,14 @@ static moo_ooch_t* synerrstr[] =
/* --------------------------------------------------------------------------
* ERROR NUMBER TO STRING CONVERSION
* -------------------------------------------------------------------------- */
const moo_ooch_t* moo_errnumtoerrstr (moo_errnum_t errnum)
const moo_ooch_t* moo_errnum_to_errstr (moo_errnum_t errnum)
{
static moo_ooch_t e_unknown[] = {'u','n','k','n','o','w','n',' ','e','r','r','o','r','\0'};
return (errnum >= 0 && errnum < MOO_COUNTOF(errstr))? errstr[errnum]: e_unknown;
}
#if defined(MOO_INCLUDE_COMPILER)
const moo_ooch_t* moo_synerrnumtoerrstr (moo_synerrnum_t errnum)
const moo_ooch_t* moo_synerrnum_to_errstr (moo_synerrnum_t errnum)
{
static moo_ooch_t e_unknown[] = {'u','n','k','n','o','w','n',' ','e','r','r','o','r','\0'};
return (errnum >= 0 && errnum < MOO_COUNTOF(synerrstr))? synerrstr[errnum]: e_unknown;
@ -213,7 +214,7 @@ const moo_ooch_t* moo_synerrnumtoerrstr (moo_synerrnum_t errnum)
# include <errno.h>
#endif
moo_errnum_t moo_syserrtoerrnum (int e)
moo_errnum_t moo_syserr_to_errnum (int e)
{
#if defined(__OS2__)
/* APIRET e */

View File

@ -32,24 +32,6 @@
#define PROC_STATE_SUSPENDED 0
#define PROC_STATE_TERMINATED -1
/* receiver check failure leads to hard failure.
* RATIONAL: the primitive handler should be used by relevant classes and
* objects only. if the receiver check fails, you must review
* your class library */
#define MOO_PF_CHECK_RCV(moo,cond) do { \
if (!(cond)) { moo_seterrnum((moo), MOO_EMSGRCV); return MOO_PF_HARD_FAILURE; } \
} while(0)
/* argument check failure causes the wrapping method to return an error.
* RATIONAL: Being a typeless language, it's hard to control the kinds of
* arguments.
*/
#define MOO_PF_CHECK_ARGS(moo,nargs,cond) do { \
if (!(cond)) { MOO_STACK_SETRETTOERROR ((moo), (nargs), MOO_EINVAL); return MOO_PF_SUCCESS; } \
} while(0)
static MOO_INLINE const char* proc_state_to_string (int state)
{
static const char* str[] =
@ -3357,7 +3339,7 @@ static moo_pfrc_t pf_error_as_string (moo_t* moo, moo_ooi_t nargs)
MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(ec));
/* TODO: error string will be mostly the same.. do i really have to call makestring every time? */
s = moo_errnumtoerrstr (ec);
s = moo_errnum_to_errstr (ec);
ss = moo_makestring (moo, s, moo_countoocstr(s));
if (!ss)
{
@ -4667,7 +4649,7 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
tmp = moo_makestring (moo, moo->errmsg.buf, moo->errmsg.len);
moo_poptmp (moo);
/* [NOTE] carry on even if instantiation fails */
moo->processor->active->perrmsg = tmp? tmp: moo->_nil;
moo->processor->active->perrmsg = tmp? tmp: moo->_nil; /* TODO: set to nil or set to an empty string if instantiation fails? */
}
else
{

View File

@ -849,7 +849,7 @@ static int _add_poll_fd (moo_t* moo, int fd, int event_mask, moo_oow_t event_dat
ev.revents = 0;
if (write (xtn->ep, &ev, MOO_SIZEOF(ev)) != MOO_SIZEOF(ev))
{
moo_syserrtoerrnum (errno);
moo_syserr_to_errnum (errno);
MOO_DEBUG2 (moo, "Cannot add file descriptor %d to devpoll - %hs\n", fd, strerror(errno));
return -1;
}
@ -872,7 +872,7 @@ static int _add_poll_fd (moo_t* moo, int fd, int event_mask, moo_oow_t event_dat
ev.data.ptr = (void*)event_data;
if (epoll_ctl (xtn->ep, EPOLL_CTL_ADD, fd, &ev) == -1)
{
moo_syserrtoerrnum (errno);
moo_syserr_to_errnum (errno);
MOO_DEBUG2 (moo, "Cannot add file descriptor %d to epoll - %hs\n", fd, strerror(errno));
return -1;
}
@ -956,7 +956,7 @@ static int _del_poll_fd (moo_t* moo, int fd)
ev.revents = 0;
if (write (xtn->ep, &ev, MOO_SIZEOF(ev)) != MOO_SIZEOF(ev))
{
moo_syserrtoerrnum (errno);
moo_syserr_to_errnum (errno);
MOO_DEBUG2 (moo, "Cannot remove file descriptor %d from devpoll - %hs\n", fd, strerror(errno));
return -1;
}
@ -971,7 +971,7 @@ static int _del_poll_fd (moo_t* moo, int fd)
memset (&ev, 0, MOO_SIZEOF(ev));
if (epoll_ctl (xtn->ep, EPOLL_CTL_DEL, fd, &ev) == -1)
{
moo_syserrtoerrnum (errno);
moo_syserr_to_errnum (errno);
MOO_DEBUG2 (moo, "Cannot remove file descriptor %d from epoll - %hs\n", fd, strerror(errno));
return -1;
}
@ -1053,7 +1053,7 @@ static int _mod_poll_fd (moo_t* moo, int fd, int event_mask, moo_oow_t event_dat
ev.data.ptr = (void*)event_data;
if (epoll_ctl (xtn->ep, EPOLL_CTL_MOD, fd, &ev) == -1)
{
moo_syserrtoerrnum (errno);
moo_syserr_to_errnum (errno);
MOO_DEBUG2 (moo, "Cannot modify file descriptor %d in epoll - %hs\n", fd, strerror(errno));
return -1;
}
@ -1131,7 +1131,7 @@ static int vm_startup (moo_t* moo)
xtn->ep = open ("/dev/poll", O_RDWR);
if (xtn->ep == -1)
{
moo_syserrtoerrnum (errno);
moo_syserr_to_errnum (errno);
MOO_DEBUG1 (moo, "Cannot create devpoll - %hs\n", strerror(errno));
goto oops;
}
@ -1147,7 +1147,7 @@ static int vm_startup (moo_t* moo)
#endif
if (xtn->ep == -1)
{
moo_syserrtoerrnum (errno);
moo_syserr_to_errnum (errno);
MOO_DEBUG1 (moo, "Cannot create epoll - %hs\n", strerror(errno));
goto oops;
}
@ -1173,7 +1173,7 @@ static int vm_startup (moo_t* moo)
#if defined(USE_THREAD)
if (pipe(xtn->p) == -1)
{
moo_syserrtoerrnum (errno);
moo_syserr_to_errnum (errno);
MOO_DEBUG1 (moo, "Cannot create pipes - %hs\n", strerror(errno));
goto oops;
}
@ -2156,12 +2156,12 @@ int main (int argc, char* argv[])
bcslen = MOO_COUNTOF(bcs);
#if defined(MOO_OOCH_IS_UCH)
if (moo_convootobcstr (moo, moo_synerrnumtoerrstr(synerr.num), &ucslen, bcs, &bcslen) >= 0)
if (moo_convootobcstr (moo, moo_synerrnum_to_errstr(synerr.num), &ucslen, bcs, &bcslen) >= 0)
{
printf (" [%.*s]", (int)bcslen, bcs);
}
#else
printf (" [%s]", moo_synerrnumtoerrstr(synerr.num));
printf (" [%s]", moo_synerrnum_to_errstr(synerr.num));
#endif
if (synerr.tgt.len > 0)

View File

@ -350,6 +350,9 @@
/* build mod/ffi */
#undef MOO_ENABLE_MOD_FFI
/* build mod/sck */
#undef MOO_ENABLE_MOD_SCK
/* build mod/x11 */
#undef MOO_ENABLE_MOD_X11

View File

@ -230,12 +230,12 @@ void moo_fini (moo_t* moo)
const moo_ooch_t* moo_geterrstr (moo_t* moo)
{
return moo_errnumtoerrstr (moo->errnum);
return moo_errnum_to_errstr (moo->errnum);
}
const moo_ooch_t* moo_geterrmsg (moo_t* moo)
{
if (moo->errmsg.len <= 0) return moo_errnumtoerrstr (moo->errnum);
if (moo->errmsg.len <= 0) return moo_errnum_to_errstr (moo->errnum);
return moo->errmsg.buf;
}
@ -400,6 +400,9 @@ void moo_freemem (moo_t* moo, void* ptr)
#if defined(MOO_ENABLE_MOD_FFI)
# include "../mod/_ffi.h"
#endif
#if defined(MOO_ENABLE_MOD_SCK)
# include "../mod/_sck.h"
#endif
#include "../mod/_stdio.h"
#if defined(MOO_ENABLE_MOD_X11)
# include "../mod/_x11.h"
@ -415,6 +418,9 @@ static_modtab[] =
{ "console", moo_mod_console },
#if defined(MOO_ENABLE_MOD_FFI)
{ "ffi", moo_mod_ffi },
#endif
#if defined(MOO_ENABLE_MOD_SCK)
{ "sck", moo_mod_sck },
#endif
{ "stdio", moo_mod_stdio },
#if defined(MOO_ENABLE_MOD_X11)

View File

@ -48,10 +48,11 @@ enum moo_errnum_t
MOO_EGENERIC, /**< generic error */
MOO_ENOIMPL, /**< not implemented */
MOO_ESYSERR, /**< subsystem error */
MOO_ESYSERR, /**< system error */
MOO_EINTERN, /**< internal error */
MOO_ESYSMEM, /**< insufficient system memory */
MOO_EOOMEM, /**< insufficient object memory */
MOO_ETYPE, /**< invalid class/type */
MOO_EINVAL, /**< invalid parameter or data */
MOO_ENOENT, /**< data not found */
@ -966,10 +967,8 @@ struct moo_cb_t
/* =========================================================================
* MODULE MANIPULATION
* PRIMITIVE FUNCTIONS
* ========================================================================= */
#define MOO_MOD_NAME_LEN_MAX 120
enum moo_pfrc_t
{
MOO_PF_HARD_FAILURE = -1,
@ -1001,6 +1000,28 @@ struct moo_pfinfo_t
moo_pfbase_t base;
};
/* receiver check failure leads to hard failure.
* RATIONAL: the primitive handler should be used by relevant classes and
* objects only. if the receiver check fails, you must review
* your class library */
#define MOO_PF_CHECK_RCV(moo,cond) do { \
if (!(cond)) { moo_seterrnum((moo), MOO_EMSGRCV); return MOO_PF_HARD_FAILURE; } \
} while(0)
/* argument check failure causes the wrapping method to return an error.
* RATIONAL: Being a typeless language, it's hard to control the kinds of
* arguments.
*/
#define MOO_PF_CHECK_ARGS(moo,nargs,cond) do { \
if (!(cond)) { MOO_STACK_SETRETTOERROR ((moo), (nargs), MOO_EINVAL); return MOO_PF_SUCCESS; } \
} while(0)
/* =========================================================================
* MODULE MANIPULATION
* ========================================================================= */
#define MOO_MOD_NAME_LEN_MAX 120
typedef struct moo_mod_t moo_mod_t;
enum moo_mod_hint_t
@ -2034,11 +2055,11 @@ MOO_EXPORT void moo_assertfailed (
moo_oow_t line
);
MOO_EXPORT moo_errnum_t moo_syserrtoerrnum (
MOO_EXPORT moo_errnum_t moo_syserr_to_errnum (
int syserr
);
MOO_EXPORT const moo_ooch_t* moo_errnumtoerrstr (
MOO_EXPORT const moo_ooch_t* moo_errnum_to_errstr (
moo_errnum_t errnum
);
@ -2059,7 +2080,7 @@ MOO_EXPORT void moo_getsynerr (
moo_synerr_t* synerr
);
MOO_EXPORT const moo_ooch_t* moo_synerrnumtoerrstr (
MOO_EXPORT const moo_ooch_t* moo_synerrnum_to_errstr (
moo_synerrnum_t errnum
);
#endif

View File

@ -279,12 +279,17 @@ CTAGS = ctags
CSCOPE = cscope
AM_RECURSIVE_TARGETS = cscope
am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config-h.in \
$(top_srcdir)/../ac/compile $(top_srcdir)/../ac/config.guess \
$(top_srcdir)/../ac/config.sub $(top_srcdir)/../ac/depcomp \
$(top_srcdir)/../ac/install-sh $(top_srcdir)/../ac/ltmain.sh \
$(top_srcdir)/../ac/missing ../ac/ar-lib ../ac/compile \
../ac/config.guess ../ac/config.sub ../ac/depcomp \
../ac/install-sh ../ac/ltmain.sh ../ac/missing COPYING.LIB \
$(top_srcdir)/../ac/compile \
$(top_srcdir)/../ac/config.guess \
$(top_srcdir)/../ac/config.sub \
$(top_srcdir)/../ac/depcomp \
$(top_srcdir)/../ac/install-sh \
$(top_srcdir)/../ac/ltmain.sh \
$(top_srcdir)/../ac/missing ../ac/compile \
../ac/config.guess ../ac/config.sub \
../ac/depcomp ../ac/install-sh \
../ac/ltmain.sh \
../ac/missing COPYING.LIB \
README lt__argz.c lt__dirent.c lt__strl.c
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)

View File

@ -23,11 +23,18 @@ if ENABLE_STATIC_MODULE
LDFLAGS_COMMON =-L$(libdir) -version-info 1:0:0 -no-undefined
LIBADD_COMMON =
noinst_LTLIBRARIES = libmoo-console.la libmoo-stdio.la
noinst_LTLIBRARIES =
if ENABLE_MOD_FFI
noinst_LTLIBRARIES += libmoo-ffi.la
endif
if ENABLE_MOD_SCK
noinst_LTLIBRARIES += libmoo-sck.la
endif
noinst_LTLIBRARIES += libmoo-stdio.la
if ENABLE_MOD_X11
noinst_LTLIBRARIES += libmoo-x11.la
endif
@ -41,11 +48,20 @@ LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir) -version-info 1:0:0 -no-un
LIBADD_COMMON = -lmoo
pkgmodexecdir = $(libdir)
pkgmodexec_LTLIBRARIES = libmoo-console.la libmoo-stdio.la
pkgmodexec_LTLIBRARIES =
pkgmodexec_LTLIBRARIES += libmoo-console.la
if ENABLE_MOD_FFI
pkgmodexec_LTLIBRARIES += libmoo-ffi.la
endif
if ENABLE_MOD_SCK
pkgmodexec_LTLIBRARIES += libmoo-sck.la
endif
pkgmodexec_LTLIBRARIES += libmoo-stdio.la
if ENABLE_MOD_X11
pkgmodexec_LTLIBRARIES += libmoo-x11.la
endif
@ -64,6 +80,13 @@ libmoo_ffi_la_LDFLAGS = $(LDFLAGS_COMMON)
libmoo_ffi_la_LIBADD = $(LIBADD_COMMON) $(DYNCALL_LIBS)
endif
if ENABLE_MOD_SCK
libmoo_sck_la_SOURCES = sck.c _sck.h
libmoo_sck_la_CPPFLAGS = $(CPPFLAGS_COMMON)
libmoo_sck_la_LDFLAGS = $(LDFLAGS_COMMON)
libmoo_sck_la_LIBADD = $(LIBADD_COMMON)
endif
libmoo_stdio_la_SOURCES = stdio.c _stdio.h
libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON)
libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON)

View File

@ -94,9 +94,11 @@ host_triplet = @host@
@WIN32_TRUE@am__append_1 = -DMOO_DEFAULT_PFMODPREFIX=\"libmoo-\" -DMOO_DEFAULT_PFMODPOSTFIX=\"-1\"
@WIN32_FALSE@am__append_2 = -DMOO_DEFAULT_PFMODPREFIX=\"$(libdir)/libmoo-\" -DMOO_DEFAULT_PFMODPOSTFIX=\"\"
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_3 = libmoo-ffi.la
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_4 = libmoo-x11.la
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_5 = libmoo-ffi.la
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_6 = libmoo-x11.la
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_4 = libmoo-sck.la
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_5 = libmoo-x11.la
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_6 = libmoo-ffi.la
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_7 = libmoo-sck.la
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_8 = libmoo-x11.la
subdir = mod
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_cxx_namespace.m4 \
@ -156,7 +158,6 @@ libmoo_console_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
-o $@
@ENABLE_STATIC_MODULE_FALSE@am_libmoo_console_la_rpath = -rpath \
@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
@ENABLE_STATIC_MODULE_TRUE@am_libmoo_console_la_rpath =
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_DEPENDENCIES = \
@ENABLE_MOD_FFI_TRUE@ $(am__DEPENDENCIES_1) \
@ENABLE_MOD_FFI_TRUE@ $(am__DEPENDENCIES_1)
@ -170,6 +171,18 @@ libmoo_ffi_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@ -rpath \
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am_libmoo_ffi_la_rpath =
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_DEPENDENCIES = \
@ENABLE_MOD_SCK_TRUE@ $(am__DEPENDENCIES_1)
am__libmoo_sck_la_SOURCES_DIST = sck.c _sck.h
@ENABLE_MOD_SCK_TRUE@am_libmoo_sck_la_OBJECTS = libmoo_sck_la-sck.lo
libmoo_sck_la_OBJECTS = $(am_libmoo_sck_la_OBJECTS)
libmoo_sck_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libmoo_sck_la_LDFLAGS) $(LDFLAGS) -o $@
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@am_libmoo_sck_la_rpath = \
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@ -rpath \
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am_libmoo_sck_la_rpath =
libmoo_stdio_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am_libmoo_stdio_la_OBJECTS = libmoo_stdio_la-stdio.lo
libmoo_stdio_la_OBJECTS = $(am_libmoo_stdio_la_OBJECTS)
@ -227,9 +240,11 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(libmoo_console_la_SOURCES) $(libmoo_ffi_la_SOURCES) \
$(libmoo_stdio_la_SOURCES) $(libmoo_x11_la_SOURCES)
$(libmoo_sck_la_SOURCES) $(libmoo_stdio_la_SOURCES) \
$(libmoo_x11_la_SOURCES)
DIST_SOURCES = $(libmoo_console_la_SOURCES) \
$(am__libmoo_ffi_la_SOURCES_DIST) $(libmoo_stdio_la_SOURCES) \
$(am__libmoo_ffi_la_SOURCES_DIST) \
$(am__libmoo_sck_la_SOURCES_DIST) $(libmoo_stdio_la_SOURCES) \
$(am__libmoo_x11_la_SOURCES_DIST)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
@ -435,13 +450,14 @@ CPPFLAGS_COMMON = -I$(abs_builddir) -I$(abs_builddir)/../lib \
@ENABLE_STATIC_MODULE_TRUE@LDFLAGS_COMMON = -L$(libdir) -version-info 1:0:0 -no-undefined
@ENABLE_STATIC_MODULE_FALSE@LIBADD_COMMON = -lmoo
@ENABLE_STATIC_MODULE_TRUE@LIBADD_COMMON =
@ENABLE_STATIC_MODULE_TRUE@noinst_LTLIBRARIES = libmoo-console.la \
@ENABLE_STATIC_MODULE_TRUE@ libmoo-stdio.la $(am__append_3) \
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_4)
@ENABLE_STATIC_MODULE_TRUE@noinst_LTLIBRARIES = $(am__append_3) \
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_4) libmoo-stdio.la \
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_5)
@ENABLE_STATIC_MODULE_FALSE@pkgmodexecdir = $(libdir)
@ENABLE_STATIC_MODULE_FALSE@pkgmodexec_LTLIBRARIES = \
@ENABLE_STATIC_MODULE_FALSE@ libmoo-console.la libmoo-stdio.la \
@ENABLE_STATIC_MODULE_FALSE@ $(am__append_5) $(am__append_6)
@ENABLE_STATIC_MODULE_FALSE@ libmoo-console.la $(am__append_6) \
@ENABLE_STATIC_MODULE_FALSE@ $(am__append_7) libmoo-stdio.la \
@ENABLE_STATIC_MODULE_FALSE@ $(am__append_8)
libmoo_console_la_SOURCES = console.c console.h
libmoo_console_la_CPPFLAGS = $(CPPFLAGS_COMMON)
libmoo_console_la_LDFLAGS = $(LDFLAGS_COMMON)
@ -450,6 +466,10 @@ libmoo_console_la_LIBADD = $(LIBADD_COMMON) $(TERMINAL_LIBS)
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_CPPFLAGS = $(CPPFLAGS_COMMON)
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_LDFLAGS = $(LDFLAGS_COMMON)
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_LIBADD = $(LIBADD_COMMON) $(DYNCALL_LIBS)
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_SOURCES = sck.c _sck.h
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_CPPFLAGS = $(CPPFLAGS_COMMON)
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_LDFLAGS = $(LDFLAGS_COMMON)
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_LIBADD = $(LIBADD_COMMON)
libmoo_stdio_la_SOURCES = stdio.c _stdio.h
libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON)
libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON)
@ -544,6 +564,9 @@ libmoo-console.la: $(libmoo_console_la_OBJECTS) $(libmoo_console_la_DEPENDENCIES
libmoo-ffi.la: $(libmoo_ffi_la_OBJECTS) $(libmoo_ffi_la_DEPENDENCIES) $(EXTRA_libmoo_ffi_la_DEPENDENCIES)
$(AM_V_CCLD)$(libmoo_ffi_la_LINK) $(am_libmoo_ffi_la_rpath) $(libmoo_ffi_la_OBJECTS) $(libmoo_ffi_la_LIBADD) $(LIBS)
libmoo-sck.la: $(libmoo_sck_la_OBJECTS) $(libmoo_sck_la_DEPENDENCIES) $(EXTRA_libmoo_sck_la_DEPENDENCIES)
$(AM_V_CCLD)$(libmoo_sck_la_LINK) $(am_libmoo_sck_la_rpath) $(libmoo_sck_la_OBJECTS) $(libmoo_sck_la_LIBADD) $(LIBS)
libmoo-stdio.la: $(libmoo_stdio_la_OBJECTS) $(libmoo_stdio_la_DEPENDENCIES) $(EXTRA_libmoo_stdio_la_DEPENDENCIES)
$(AM_V_CCLD)$(libmoo_stdio_la_LINK) $(am_libmoo_stdio_la_rpath) $(libmoo_stdio_la_OBJECTS) $(libmoo_stdio_la_LIBADD) $(LIBS)
@ -558,6 +581,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_console_la-console.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_ffi_la-ffi.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_sck_la-sck.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_stdio_la-stdio.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_x11_la-x11.Plo@am__quote@
@ -599,6 +623,13 @@ libmoo_ffi_la-ffi.lo: ffi.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_ffi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_ffi_la-ffi.lo `test -f 'ffi.c' || echo '$(srcdir)/'`ffi.c
libmoo_sck_la-sck.lo: sck.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_sck_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_sck_la-sck.lo -MD -MP -MF $(DEPDIR)/libmoo_sck_la-sck.Tpo -c -o libmoo_sck_la-sck.lo `test -f 'sck.c' || echo '$(srcdir)/'`sck.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_sck_la-sck.Tpo $(DEPDIR)/libmoo_sck_la-sck.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='sck.c' object='libmoo_sck_la-sck.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_sck_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_sck_la-sck.lo `test -f 'sck.c' || echo '$(srcdir)/'`sck.c
libmoo_stdio_la-stdio.lo: stdio.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_stdio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_stdio_la-stdio.lo -MD -MP -MF $(DEPDIR)/libmoo_stdio_la-stdio.Tpo -c -o libmoo_stdio_la-stdio.lo `test -f 'stdio.c' || echo '$(srcdir)/'`stdio.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_stdio_la-stdio.Tpo $(DEPDIR)/libmoo_stdio_la-stdio.Plo

52
moo/mod/_sck.h Normal file
View File

@ -0,0 +1,52 @@
/*
* $Id$
*
Copyright (c) 2014-2017 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _MOO_MOD_SCK_H_
#define _MOO_MOD_SCK_H_
#include <moo.h>
typedef struct sck_t* oop_sck_t;
struct sck_t
{
MOO_OBJ_HEADER;
moo_oop_t handle; /* SmallInteger */
/* there are more fields in the actual object */
};
#if defined(__cplusplus)
extern "C" {
#endif
MOO_EXPORT int moo_mod_sck (moo_t* moo, moo_mod_t* mod);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -113,7 +113,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
dc = dcNewCallVM (4096); /* TODO: right size? */
if (!dc)
{
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
moo->vmprim.dl_close (moo, handle);
goto softfail;
}

208
moo/mod/sck.c Normal file
View File

@ -0,0 +1,208 @@
/*
* $Id$
*
Copyright (c) 2014-2017 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "_sck.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
static moo_pfrc_t pf_open_socket (moo_t* moo, moo_ooi_t nargs)
{
oop_sck_t sck;
moo_oop_t dom, type, proto;
int fd = -1;
moo_errnum_t errnum;
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
MOO_PF_CHECK_RCV (moo,
MOO_OOP_IS_POINTER(sck) &&
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t))
);
dom = MOO_STACK_GETARG(moo, nargs, 0);
type = MOO_STACK_GETARG(moo, nargs, 1);
proto = MOO_STACK_GETARG(moo, nargs, 2);
MOO_PF_CHECK_ARGS (moo, nargs, MOO_OOP_IS_SMOOI(dom) && MOO_OOP_IS_SMOOI(type) && MOO_OOP_IS_SMOOI(proto));
fd = socket (MOO_OOP_TO_SMOOI(dom), MOO_OOP_TO_SMOOI(type), MOO_OOP_TO_SMOOI(proto));
if (fd == -1)
{
errnum = moo_syserr_to_errnum(errno);
goto oops;
}
if (!MOO_IN_SMOOI_RANGE(fd))
{
/* the file descriptor is too big to be represented as a small integer */
errnum = MOO_ERANGE;
goto oops;
}
sck->handle = MOO_SMOOI_TO_OOP(fd);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
oops:
if (fd >= 0) close (fd);
MOO_STACK_SETRETTOERROR (moo, nargs, errnum);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_close_socket (moo_t* moo, moo_ooi_t nargs)
{
oop_sck_t sck;
int fd;
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
MOO_PF_CHECK_RCV (moo,
MOO_OOP_IS_POINTER(sck) &&
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
MOO_OOP_IS_SMOOI(sck->handle)
);
fd = MOO_OOP_TO_SMOOI(sck->handle);
if (fd >= 0)
{
if (close(MOO_OOP_TO_SMOOI(sck->handle)) == -1)
{
MOO_STACK_SETRETTOERROR (moo, nargs, moo_syserr_to_errnum(errno));
return MOO_PF_SUCCESS;
}
else
{
sck->handle = MOO_SMOOI_TO_OOP(-1);
}
}
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_connect (moo_t* moo, moo_ooi_t nargs)
{
oop_sck_t sck;
int fd, oldfl, n;
moo_errnum_t errnum;
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
MOO_PF_CHECK_RCV (moo,
MOO_OOP_IS_POINTER(sck) &&
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
MOO_OOP_IS_SMOOI(sck->handle));
fd = MOO_OOP_TO_SMOOI(sck->handle);
oldfl = fcntl(fd, F_GETFL, 0);
if (oldfl == -1 || fcntl(fd, F_SETFL, oldfl | O_NONBLOCK) == -1) goto oops_syserr;
{
struct sockaddr_in sin;
memset (&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr ("1.234.53.142");
sin.sin_port = htons(80);
do
{
n = connect(fd, (struct sockaddr*)&sin, sizeof(sin));
}
while (n == -1 && errno == EINTR);
}
if (n == -1 && errno != EINPROGRESS)
{
fcntl (fd, F_SETFL, oldfl);
goto oops_syserr;
}
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
oops_syserr:
errnum = moo_syserr_to_errnum(errno);
oops:
MOO_STACK_SETRETTOERROR (moo, nargs, errnum);
return MOO_PF_SUCCESS;
}
/* ------------------------------------------------------------------------ */
typedef struct fnctab_t fnctab_t;
struct fnctab_t
{
moo_method_type_t type;
moo_ooch_t mthname[15];
int variadic;
moo_pfimpl_t handler;
};
#define C MOO_METHOD_CLASS
#define I MOO_METHOD_INSTANCE
#define MA MOO_TYPE_MAX(moo_oow_t)
static moo_pfinfo_t pfinfos[] =
{
{ I, { '_','c','l','o','s','e','\0' }, 0, { pf_close_socket, 0, 0 } },
{ I, { '_','c','o','n','n','e','c','t','\0' }, 0, { pf_connect, 3, 3 } },
{ I, { '_','o','p','e','n','\0' }, 0, { pf_open_socket, 3, 3 } },
};
/* ------------------------------------------------------------------------ */
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
{
/*if (moo_setclasstrsize (moo, _class, MOO_SIZEOF(sck_t), MOO_NULL) <= -1) return -1;*/
return 0;
}
static moo_pfbase_t* query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
{
return moo_findpfbase (moo, pfinfos, MOO_COUNTOF(pfinfos), name, namelen);
}
static void unload (moo_t* moo, moo_mod_t* mod)
{
/* TODO: anything? close open open dll handles? For that, pf_open must store the value it returns to mod->ctx or somewhere..*/
}
int moo_mod_sck (moo_t* moo, moo_mod_t* mod)
{
mod->import = import;
mod->query = query;
mod->unload = unload;
mod->ctx = MOO_NULL;
return 0;
}

View File

@ -75,7 +75,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs)
#endif
if (!stdio->fp)
{
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
goto softfail;
}
@ -157,7 +157,7 @@ static moo_pfrc_t __pf_puts (moo_t* moo, moo_ooi_t nargs, moo_oow_t limit)
if (fwrite (bcs, 1, bcslen, stdio->fp) < bcslen)
{
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
goto softfail;
}
@ -169,8 +169,8 @@ static moo_pfrc_t __pf_puts (moo_t* moo, moo_ooi_t nargs, moo_oow_t limit)
puts_string:
if (fwrite (x->slot, 1, MOO_OBJ_GET_SIZE(x), stdio->fp) < MOO_OBJ_GET_SIZE(x))
{
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
moo_seterrnum (moo, moo_syserrtoerrnum(errno));
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
goto softfail;
}
#endif

View File

@ -705,34 +705,39 @@ static moo_pfrc_t pf_draw_string (moo_t* moo, moo_ooi_t nargs)
if (MOO_OOP_IS_SMPTR(gc->font_set))
{
moo_oow_t ucslen, bcslen;
moo_oow_t bcslen;
moo_bch_t* bb;
int ascent = 10;
XRectangle r;
ucslen = MOO_OBJ_GET_SIZE(a3);
if (moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &ucslen, MOO_NULL, &bcslen) <= -1 ||
#if defined(MOO_OOCH_IS_UCH)
moo_oow_t oocslen;
oocslen = MOO_OBJ_GET_SIZE(a3);
if (moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &oocslen, MOO_NULL, &bcslen) <= -1 ||
!(bb = moo_allocmem (moo, MOO_SIZEOF(moo_bch_t) * bcslen)))
{
MOO_DEBUG0 (moo, "<x11.draw_string> Error in converting a string\n");
MOO_STACK_SETRETTOERRNUM (moo, nargs);
return MOO_PF_SUCCESS;
}
//#if defined(MOO_OOCH_IS_UCH)
moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &ucslen, bb, &bcslen);
//#else
// moo_copybcstr (&bb->fn[parlen], bcslen + 1, arg->name);
//#endif
moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &oocslen, bb, &bcslen);
#else
bb = MOO_OBJ_GET_CHAR_SLOT(a3);
bcslen = oocslen;
#endif
XmbTextExtents(MOO_OOP_TO_SMPTR(gc->font_set), bb, bcslen, MOO_NULL, &r);
ascent = r.height;
/* what about Xutf8DrawString? */
XmbDrawString (disp, (Window)MOO_OOP_TO_SMOOI(((oop_x11_widget_t)gc->widget)->window_handle),
MOO_OOP_TO_SMPTR(gc->font_set), MOO_OOP_TO_SMPTR(gc->gc_handle),
MOO_OOP_TO_SMOOI(a1), MOO_OOP_TO_SMOOI(a2) + ascent, bb, bcslen);
#if defined(MOO_OOCH_IS_UCH)
moo_freemem (moo, bb);
#endif
}
else
{