on master help sign in
Update the windows RTS files and consolidate the headers
d16d418niklas
rts/Makefile+1−3
@@ -3,16 +3,14 @@ include ../config.mk
3OBJS = idris_rts.o idris_heap.o idris_gc.o idris_gmp.o idris_bitstring.o \
3OBJS = idris_rts.o idris_heap.o idris_gc.o idris_gmp.o idris_bitstring.o \
4 idris_opts.o idris_stats.o mini-gmp.o
4 idris_opts.o idris_stats.o mini-gmp.o
5HDRS = idris_rts.h idris_heap.h idris_gc.h idris_gmp.h idris_bitstring.h \
5HDRS = idris_rts.h idris_heap.h idris_gc.h idris_gmp.h idris_bitstring.h \
6− idris_opts.h idris_stats.h mini-gmp.h
6+ idris_opts.h idris_stats.h mini-gmp.h idris_stdfgn.h idris_net.h
7CFLAGS:=-fPIC $(CFLAGS)
7CFLAGS:=-fPIC $(CFLAGS)
8CFLAGS += $(GMP_INCLUDE_DIR) $(GMP)
8CFLAGS += $(GMP_INCLUDE_DIR) $(GMP)
9
9
10ifeq ($(OS), windows)
10ifeq ($(OS), windows)
11 OBJS += windows/idris_stdfgn.o windows/idris_net.o
11 OBJS += windows/idris_stdfgn.o windows/idris_net.o
12− HDRS += windows/idris_stdfgn.h windows/idris_net.h
13else
12else
14 OBJS += idris_stdfgn.o idris_net.o
13 OBJS += idris_stdfgn.o idris_net.o
15− HDRS += idris_stdfgn.h idris_net.h
16endif
14endif
17
15
18LIBTARGET = libidris_rts.a
16LIBTARGET = libidris_rts.a
rts/idris_net.c+11−1
@@ -1,9 +1,19 @@
1// C-Side of the Idris network library
1// C-Side of the Idris network library
2// (C) Simon Fowler, 2014
2// (C) Simon Fowler, 2014
3// MIT Licensed. Have fun!
3// MIT Licensed. Have fun!
4−#include "idris_net.h"
4+#include <errno.h>
5+#include <netdb.h>
6+#include <stdbool.h>
7+#include <stdlib.h>
8+#include <stdio.h>
9+#include <string.h>
10+#include <sys/types.h>
11+#include <sys/socket.h>
12+#include <netinet/in.h>
5#include <arpa/inet.h>
13#include <arpa/inet.h>
6
14
15+#include "idris_net.h"
16+
7void* idrnet_malloc(int size) {
17void* idrnet_malloc(int size) {
8 return malloc(size);
18 return malloc(size);
9}
19}
rts/idris_net.h−10
@@ -1,16 +1,6 @@
1#ifndef IDRISNET_H
1#ifndef IDRISNET_H
2#define IDRISNET_H
2#define IDRISNET_H
3
3
4−#include <errno.h>
5−#include <netdb.h>
6−#include <stdbool.h>
7−#include <stdlib.h>
8−#include <stdio.h>
9−#include <string.h>
10−#include <sys/types.h>
11−#include <sys/socket.h>
12−#include <netinet/in.h>
13−
14typedef struct idrnet_recv_result {
4typedef struct idrnet_recv_result {
15 int result;
5 int result;
16 void* payload;
6 void* payload;
rts/windows/idris_net.c+15−4
@@ -1,7 +1,7 @@
1// C-Side of the Idris network library
1// C-Side of the Idris network library
2// (C) Simon Fowler, 2014
2// (C) Simon Fowler, 2014
3// MIT Licensed. Have fun!
3// MIT Licensed. Have fun!
4−#include "idris_net.h"
4+#include "../idris_net.h"
5
5
6#include <errno.h>
6#include <errno.h>
7#include <stdbool.h>
7#include <stdbool.h>
@@ -11,6 +11,12 @@
11#include <Winsock2.h>
11#include <Winsock2.h>
12#include <Ws2tcpip.h>
12#include <Ws2tcpip.h>
13
13
14+
15+// inet_ntop isn't defined in the old mingw delivered with GHC,
16+// so put the prototype here, cribbed from a newer version of it
17+WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, PVOID pAddr,
18+ LPSTR pStringBuf, size_t StringBufSize);
19+
14static int socket_inited = 0;
20static int socket_inited = 0;
15static WSADATA wsa_data;
21static WSADATA wsa_data;
16
22
@@ -22,12 +28,17 @@ void idrnet_free(void* ptr) {
22 free(ptr);
28 free(ptr);
23}
29}
24
30
31+static void clean_sockets(void) {
32+ WSACleanup();
33+}
34+
25−static int check_init()
35+static int check_init(void)
26{
36{
27 if (!socket_inited) {
37 if (!socket_inited) {
28 int result = WSAStartup(MAKEWORD(2, 2), &wsa_data);
38 int result = WSAStartup(MAKEWORD(2, 2), &wsa_data);
29 if (result == NO_ERROR) {
39 if (result == NO_ERROR) {
30 socket_inited = 1;
40 socket_inited = 1;
41+ atexit(clean_sockets);
31 }
42 }
32 }
43 }
33 return socket_inited;
44 return socket_inited;
@@ -104,7 +115,7 @@ int idrnet_sockaddr_family(void* sockaddr) {
104char* idrnet_sockaddr_ipv4(void* sockaddr) {
115char* idrnet_sockaddr_ipv4(void* sockaddr) {
105 struct sockaddr_in* addr = (struct sockaddr_in*) sockaddr;
116 struct sockaddr_in* addr = (struct sockaddr_in*) sockaddr;
106 char* ip_addr = (char*) malloc(sizeof(char) * INET_ADDRSTRLEN);
117 char* ip_addr = (char*) malloc(sizeof(char) * INET_ADDRSTRLEN);
107− inet_ntop(AF_INET, &(addr->sin_addr), ip_addr, INET_ADDRSTRLEN);
118+ InetNtopA(AF_INET, &(addr->sin_addr), ip_addr, INET_ADDRSTRLEN);
108 return ip_addr;
119 return ip_addr;
109}
120}
110
121
@@ -139,7 +150,7 @@ int idrnet_send_buf(int sockfd, void* data, int len) {
139
150
140void* idrnet_recv(int sockfd, int len) {
151void* idrnet_recv(int sockfd, int len) {
141 if (!check_init()) {
152 if (!check_init()) {
142− return -1;
153+ return NULL;
143 }
154 }
144 idrnet_recv_result* res_struct =
155 idrnet_recv_result* res_struct =
145 (idrnet_recv_result*) malloc(sizeof(idrnet_recv_result));
156 (idrnet_recv_result*) malloc(sizeof(idrnet_recv_result));
rts/windows/idris_net.hdeleted−45
@@ -1,45 +0,0 @@
1−#ifndef IDRISNET_H
2−#define IDRISNET_H
3−
4−
5−typedef struct idrnet_recv_result {
6− int result;
7− void* payload;
8−} idrnet_recv_result;
9−
10−// Memory management functions
11−void* idrnet_malloc(int size);
12−void idrnet_free(void* ptr);
13−
14−// Gets value of errno
15−int idrnet_errno();
16−
17−// Bind
18−int idrnet_bind(int sockfd, int family, int socket_type, char* host, int port);
19−
20−// Connect
21−int idrnet_connect(int sockfd, int family, int socket_type, char* host, int port);
22−
23−// Accessor functions for struct_sockaddr
24−int idrnet_sockaddr_family(void* sockaddr);
25−char* idrnet_sockaddr_ipv4(void* sockaddr);
26−void* idrnet_create_sockaddr();
27−
28−// Accept
29−int idrnet_accept(int sockfd, void* sockaddr);
30−
31−// Send
32−int idrnet_send(int sockfd, char* data);
33−int idrnet_send_buf(int sockfd, void* data, int len);
34−
35−// Receive
36−// Creates a result structure containing result and payload
37−void* idrnet_recv(int sockfd, int len);
38−// Receives directly into a buffer
39−int idrnet_recv_buf(int sockfd, void* buf, int len);
40−
41−// Receive structure accessors
42−int idrnet_get_recv_res(void* res_struct);
43−void* idrnet_get_recv_payload(void* res_struct);
44−void idrnet_free_recv_struct(void* res_struct);
45−#endif
rts/windows/idris_stdfgn.c+13−1
@@ -1,7 +1,10 @@
1−#include "idris_stdfgn.h"
1+#include "../idris_stdfgn.h"
2#include "../idris_rts.h"
2#include "../idris_rts.h"
3+#include "../idris_gc.h"
4+
3#include <fcntl.h>
5#include <fcntl.h>
4#include <stdio.h>
6#include <stdio.h>
7+#include <time.h>
5
8
6extern char** environ;
9extern char** environ;
7
10
@@ -61,3 +64,12 @@ void* idris_stdin() {
61char* getEnvPair(int i) {
64char* getEnvPair(int i) {
62 return *(environ + i);
65 return *(environ + i);
63}
66}
67+
68+int idris_time() {
69+ time_t t = time(NULL);
70+ return (int)t;
71+}
72+
73+void idris_forceGC(void* vm) {
74+ idris_gc((VM*)vm);
75+}
rts/windows/idris_stdfgn.hdeleted−24
@@ -1,24 +0,0 @@
1−#ifndef _IDRISSTDFGN_H
2−#define _IDRISSTDFGN_H
3−
4−// A collection of useful standard functions to be used by the prelude.
5−
6−void putStr(char* str);
7−//char* readStr();
8−
9−void* fileOpen(char* f, char* mode);
10−void fileClose(void* h);
11−int fileEOF(void* h);
12−int fileError(void* h);
13−void fputStr(void*h, char* str);
14−
15−void* do_popen(const char* cmd, const char* mode);
16−int fpoll(void* h);
17−
18−int idris_eqPtr(void* x, void* y);
19−int isNull(void* ptr);
20−void* idris_stdin();
21−
22−char* getEnvPair(int i);
23−
24−#endif