rktio: repairs

More tests pass.
This commit is contained in:
Matthew Flatt 2017-06-16 10:01:33 -06:00
parent 99c3643033
commit 463862d793
11 changed files with 71 additions and 16 deletions

View File

@ -4514,6 +4514,8 @@ scheme_raise_exn(int id, ...)
Scheme_Object *eargs[MZEXN_MAXARGS], *errno_val = NULL; Scheme_Object *eargs[MZEXN_MAXARGS], *errno_val = NULL;
char *buffer; char *buffer;
rktio_remap_last_error(scheme_rktio);
/* Precise GC: Don't allocate before getting hidden args off stack */ /* Precise GC: Don't allocate before getting hidden args off stack */
HIDE_FROM_XFORM(va_start(args, id)); HIDE_FROM_XFORM(va_start(args, id));

View File

@ -4634,9 +4634,9 @@ static Scheme_Object *filesystem_root_list(int argc, Scheme_Object *argv[])
scheme_security_check_file("filesystem-root-list", NULL, SCHEME_GUARD_FILE_EXISTS); scheme_security_check_file("filesystem-root-list", NULL, SCHEME_GUARD_FILE_EXISTS);
roots = rktio_filesystem_root_list(scheme_rktio); roots = rktio_filesystem_roots(scheme_rktio);
for (i = 0; roots[i]; i++) { for (i = 0; roots[i]; i++) {
v = scheme_make_pair(scheme_make_sized_offset_path(roots[i], strlen(roots[i]), -1, 1), scheme_null); v = scheme_make_pair(scheme_make_sized_offset_path(roots[i], 0, -1, 1), scheme_null);
if (last) if (last)
SCHEME_CDR(last) = v; SCHEME_CDR(last) = v;
else else

View File

@ -97,7 +97,7 @@ static int mark_input_fd_MARK(void *p, struct NewGC *gc) {
Scheme_FD *fd = (Scheme_FD *)p; Scheme_FD *fd = (Scheme_FD *)p;
gcMARK2(fd->buffer, gc); gcMARK2(fd->buffer, gc);
gcMARK2(fd->refcount, gc); /* fd->refcount is malloc()ed */
gcMARK2(fd->flush_handle, gc); gcMARK2(fd->flush_handle, gc);
gcMARK2(fd->bufwidths, gc); gcMARK2(fd->bufwidths, gc);
@ -115,7 +115,7 @@ static int mark_input_fd_FIXUP(void *p, struct NewGC *gc) {
Scheme_FD *fd = (Scheme_FD *)p; Scheme_FD *fd = (Scheme_FD *)p;
gcFIXUP2(fd->buffer, gc); gcFIXUP2(fd->buffer, gc);
gcFIXUP2(fd->refcount, gc); /* fd->refcount is malloc()ed */
gcFIXUP2(fd->flush_handle, gc); gcFIXUP2(fd->flush_handle, gc);
gcFIXUP2(fd->bufwidths, gc); gcFIXUP2(fd->bufwidths, gc);

View File

@ -1736,7 +1736,7 @@ mark_input_fd {
Scheme_FD *fd = (Scheme_FD *)p; Scheme_FD *fd = (Scheme_FD *)p;
gcMARK2(fd->buffer, gc); gcMARK2(fd->buffer, gc);
gcMARK2(fd->refcount, gc); /* fd->refcount is malloc()ed */
gcMARK2(fd->flush_handle, gc); gcMARK2(fd->flush_handle, gc);
gcMARK2(fd->bufwidths, gc); gcMARK2(fd->bufwidths, gc);

View File

@ -40,6 +40,7 @@ typedef struct {
typedef struct Scheme_Tcp_Buf { typedef struct Scheme_Tcp_Buf {
MZTAG_IF_REQUIRED MZTAG_IF_REQUIRED
short refcount; short refcount;
short forget_on_close;
char *buffer, *out_buffer; char *buffer, *out_buffer;
short bufpos, bufmax; short bufpos, bufmax;
short hiteof, bufmode; short hiteof, bufmode;
@ -462,7 +463,10 @@ static void tcp_close_input(Scheme_Input_Port *port)
(void)scheme_rktio_fd_to_semaphore(data->tcp, MZFD_REMOVE); (void)scheme_rktio_fd_to_semaphore(data->tcp, MZFD_REMOVE);
rktio_close(scheme_rktio, data->tcp); if (data->b.forget_on_close)
rktio_forget(scheme_rktio, data->tcp);
else
rktio_close(scheme_rktio, data->tcp);
} }
static int static int
@ -635,7 +639,10 @@ static void tcp_close_output(Scheme_Output_Port *port)
(void)scheme_rktio_fd_to_semaphore(data->tcp, MZFD_REMOVE); (void)scheme_rktio_fd_to_semaphore(data->tcp, MZFD_REMOVE);
rktio_close(scheme_rktio, data->tcp); if (data->b.forget_on_close)
rktio_forget(scheme_rktio, data->tcp);
else
rktio_close(scheme_rktio, data->tcp);
} }
static int static int
@ -741,6 +748,7 @@ static Connect_Progress_Data *make_connect_progress_data()
pd->connect = NULL; pd->connect = NULL;
pd->dest_addr = NULL; pd->dest_addr = NULL;
pd->src_addr = NULL; pd->src_addr = NULL;
pd->trying_s = NULL;
pd->s = NULL; pd->s = NULL;
return pd; return pd;
@ -1583,7 +1591,9 @@ void scheme_socket_to_ports(intptr_t s, const char *name, int takeover,
rfd = rktio_system_fd(scheme_rktio, s, RKTIO_OPEN_READ | RKTIO_OPEN_WRITE | RKTIO_OPEN_SOCKET | RKTIO_OPEN_OWN); rfd = rktio_system_fd(scheme_rktio, s, RKTIO_OPEN_READ | RKTIO_OPEN_WRITE | RKTIO_OPEN_SOCKET | RKTIO_OPEN_OWN);
tcp = make_tcp_port_data(rfd, takeover ? 2 : 3); tcp = make_tcp_port_data(rfd, 2);
if (!takeover)
tcp->b.forget_on_close = 1;
v = make_tcp_input_port(tcp, name, NULL); v = make_tcp_input_port(tcp, name, NULL);
*_inp = v; *_inp = v;

View File

@ -4740,11 +4740,10 @@ fd_close_input(Scheme_Input_Port *port)
fip = (Scheme_FD *)port->port_data; fip = (Scheme_FD *)port->port_data;
rc = adj_refcount(fip->refcount, -1); rc = adj_refcount(fip->refcount, -1);
if (!rc) { if (!rc)
rktio_close(scheme_rktio, fip->fd); rktio_close(scheme_rktio, fip->fd);
} else { else
rktio_forget(scheme_rktio, fip->fd); rktio_forget(scheme_rktio, fip->fd);
}
} }
static void static void
@ -5327,6 +5326,7 @@ make_fd_output_port(rktio_fd_t *fd, Scheme_Object *name, int and_read, int flush
Scheme_Object *a[2]; Scheme_Object *a[2];
rc = malloc_refcount(1, 1); rc = malloc_refcount(1, 1);
fop->refcount = rc; fop->refcount = rc;
fd = rktio_system_fd(scheme_rktio, rktio_fd_system_fd(scheme_rktio, fd), rktio_fd_modes(scheme_rktio, fd));
a[1] = the_port; a[1] = the_port;
a[0] = make_fd_input_port(fd, name, rc, 0); a[0] = make_fd_input_port(fd, name, rc, 0);
return scheme_values(2, a); return scheme_values(2, a);

View File

@ -3916,6 +3916,8 @@ static int check_fd_semaphores()
if (!scheme_semaphore_fd_set) if (!scheme_semaphore_fd_set)
return 0; return 0;
rktio_ltps_poll(scheme_rktio, scheme_semaphore_fd_set);
while (1) { while (1) {
h = rktio_ltps_get_signaled_handle(scheme_rktio, scheme_semaphore_fd_set); h = rktio_ltps_get_signaled_handle(scheme_rktio, scheme_semaphore_fd_set);
if (h) { if (h) {

View File

@ -153,7 +153,7 @@ RKTIO_EXTERN int rktio_fd_modes(rktio_t *rktio, rktio_fd_t *rfd);
RKTIO_EXTERN rktio_fd_t *rktio_open(rktio_t *rktio, const char *src, int modes); RKTIO_EXTERN rktio_fd_t *rktio_open(rktio_t *rktio, const char *src, int modes);
/* Can report `RKTIO_ERROR_DOES_NOT_EXIST` in place of system error, /* Can report `RKTIO_ERROR_DOES_NOT_EXIST` in place of system error,
and can report `RKTIO_ERROR_UNSUPPORTED_TEXT_MODE` on Windows:=. */ and can report `RKTIO_ERROR_UNSUPPORTED_TEXT_MODE` on Windows. */
RKTIO_EXTERN rktio_ok_t rktio_close(rktio_t *rktio, rktio_fd_t *fd); RKTIO_EXTERN rktio_ok_t rktio_close(rktio_t *rktio, rktio_fd_t *fd);
/* Can report `RKTIO_ERROR_EXISTS` in place of system error, /* Can report `RKTIO_ERROR_EXISTS` in place of system error,
@ -702,7 +702,7 @@ RKTIO_EXTERN void rktio_directory_list_stop(rktio_t *rktio, rktio_directory_list
/* Interrupt a directory list in progress, not needed after /* Interrupt a directory list in progress, not needed after
rktio_directory_list_step() returns "": */ rktio_directory_list_step() returns "": */
RKTIO_EXTERN char **rktio_filesystem_root_list(rktio_t *rktio); RKTIO_EXTERN char **rktio_filesystem_roots(rktio_t *rktio);
/* Returns a NULL-terminated array. Free each string. Currently never /* Returns a NULL-terminated array. Free each string. Currently never
errors. */ errors. */
@ -822,6 +822,11 @@ enum {
RKTIO_EXTERN void rktio_set_last_error(rktio_t *rktio, int kind, int errid); RKTIO_EXTERN void rktio_set_last_error(rktio_t *rktio, int kind, int errid);
/* In case you need to save and restore error information. */ /* In case you need to save and restore error information. */
RKTIO_EXTERN void rktio_remap_last_error(rktio_t *rktio);
/* In a few cases, rktio substitutes a `RKTIO_ERROR_KIND_RACKET` error
for an OS-supplied error. This function can sometimes undo the
substitition, modifying the current error and kind. */
RKTIO_EXTERN const char *rktio_get_last_error_string(rktio_t *rktio); RKTIO_EXTERN const char *rktio_get_last_error_string(rktio_t *rktio);
RKTIO_EXTERN const char *rktio_get_error_string(rktio_t *rktio, int kind, int errid); RKTIO_EXTERN const char *rktio_get_error_string(rktio_t *rktio, int kind, int errid);
/* The returned strings for `rktio_...error_string()` should not be /* The returned strings for `rktio_...error_string()` should not be

View File

@ -9,6 +9,10 @@ struct rktio_envvars_t {
char **vals; char **vals;
}; };
#ifdef OS_X
# define SETENV_DROPS_LEADING_EQUAL_SIGN
#endif
#if defined(OS_X) && !TARGET_OS_IPHONE #if defined(OS_X) && !TARGET_OS_IPHONE
# include <crt_externs.h> # include <crt_externs.h>
# define GET_ENVIRON_ARRAY *_NSGetEnviron() # define GET_ENVIRON_ARRAY *_NSGetEnviron()
@ -85,8 +89,24 @@ int rktio_setenv(rktio_t *rktio, const char *name, const char *val)
#ifdef RKTIO_SYSTEM_UNIX #ifdef RKTIO_SYSTEM_UNIX
if (val) { if (val) {
int r; int r;
#ifdef SETENV_DROPS_LEADING_EQUAL_SIGN
char *tmp = NULL;
if (val[0] == '=') {
intptr_t len = strlen(val);
tmp = malloc(len + 2);
memcpy(tmp + 1, val, len + 1);
tmp[0] = '=';
val = tmp;
}
#endif
r = setenv(name, val, 1); r = setenv(name, val, 1);
#ifdef SETENV_DROPS_LEADING_EQUAL_SIGN
if (tmp)
free(tmp);
#endif
if (r) if (r)
get_posix_error(); get_posix_error();

View File

@ -81,6 +81,22 @@ void rktio_set_last_error(rktio_t *rktio, int kind, int errid)
rktio->errid = errid; rktio->errid = errid;
} }
void rktio_remap_last_error(rktio_t *rktio)
{
if (rktio->errkind == RKTIO_ERROR_KIND_RACKET) {
switch (rktio->errid) {
case RKTIO_ERROR_DOES_NOT_EXIST:
#ifdef RKTIO_SYSTEM_UNIX
rktio_set_last_error(rktio, RKTIO_ERROR_KIND_POSIX, ENOENT);
#endif
#ifdef RKTIO_SYSTEM_WINDOWS
rktio_set_last_error(rktio, RKTIO_ERROR_KIND_WINDOWS, ERROR_FILE_NOT_FOUND);
#endif
break;
}
}
}
const char *rktio_get_error_string(rktio_t *rktio, int kind, int errid) const char *rktio_get_error_string(rktio_t *rktio, int kind, int errid)
{ {
const char *s = NULL; const char *s = NULL;

View File

@ -1630,7 +1630,7 @@ void rktio_copy_file_stop(rktio_t *rktio, rktio_file_copy_t *fc)
/* filesystem root list */ /* filesystem root list */
/*========================================================================*/ /*========================================================================*/
char **rktio_filesystem_root_list(rktio_t *rktio) char **rktio_filesystem_roots(rktio_t *rktio)
/* returns a NULL-terminated array of strings */ /* returns a NULL-terminated array of strings */
{ {
#ifdef RKTIO_SYSTEM_WINDOWS #ifdef RKTIO_SYSTEM_WINDOWS
@ -1682,8 +1682,8 @@ char **rktio_filesystem_root_list(rktio_t *rktio)
char **ss; char **ss;
ss = malloc(sizeof(char*) * 2); ss = malloc(sizeof(char*) * 2);
ss[1] = strdup("/"); ss[0] = strdup("/");
ss[0] = NULL; ss[1] = NULL;
return ss; return ss;
#endif #endif