Browse Source

enable + fixed warnings

Nicolas Cannasse 9 years ago
parent
commit
03cdb8ef89
12 changed files with 69 additions and 140 deletions
  1. 8 3
      hl.vcxproj
  2. 8 4
      hldll.vcxproj
  3. 3 4
      src/alloc.c
  4. 1 1
      src/code.c
  5. 2 2
      src/hl.h
  6. 20 104
      src/jit.c
  7. 2 0
      src/main.c
  8. 2 0
      src/module.c
  9. 6 5
      src/std/error.c
  10. 1 1
      src/std/file.c
  11. 11 11
      src/std/socket.c
  12. 5 5
      src/std/string.c

+ 8 - 3
hl.vcxproj

@@ -93,6 +93,8 @@
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
+      <WarningLevel>EnableAllWarnings</WarningLevel>
+      <AdditionalOptions>/wd4456 /wd4100 /wd4204 /wd4702 /wd4457 %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>
@@ -105,9 +107,10 @@
     <ClCompile>
       <PrecompiledHeader>
       </PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
+      <WarningLevel>EnableAllWarnings</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalOptions>/wd4456 /wd4100 /wd4204 /wd4702 /wd4457 %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>
@@ -118,7 +121,7 @@
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
+      <WarningLevel>EnableAllWarnings</WarningLevel>
       <PrecompiledHeader>
       </PrecompiledHeader>
       <Optimization>MaxSpeed</Optimization>
@@ -127,6 +130,7 @@
       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
       <WholeProgramOptimization>false</WholeProgramOptimization>
+      <AdditionalOptions>/wd4456 /wd4100 /wd4204 /wd4702 /wd4457 %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>
@@ -139,7 +143,7 @@
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
     <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
+      <WarningLevel>EnableAllWarnings</WarningLevel>
       <PrecompiledHeader>
       </PrecompiledHeader>
       <Optimization>MaxSpeed</Optimization>
@@ -147,6 +151,7 @@
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <WholeProgramOptimization>false</WholeProgramOptimization>
+      <AdditionalOptions>/wd4456 /wd4100 /wd4204 /wd4702 /wd4457 %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
       <SubSystem>Console</SubSystem>

+ 8 - 4
hldll.vcxproj

@@ -97,9 +97,10 @@
     <ClCompile>
       <PrecompiledHeader>
       </PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
+      <WarningLevel>EnableAllWarnings</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;HLDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalOptions>/wd4054 /wd4456 /wd4702 /wd4100 /wd4457 %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -111,9 +112,10 @@
     <ClCompile>
       <PrecompiledHeader>
       </PrecompiledHeader>
-      <WarningLevel>Level3</WarningLevel>
+      <WarningLevel>EnableAllWarnings</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;HLDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalOptions>/wd4054 /wd4456 /wd4702 /wd4100 /wd4457 %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -123,13 +125,14 @@
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
+      <WarningLevel>EnableAllWarnings</WarningLevel>
       <PrecompiledHeader>
       </PrecompiledHeader>
       <Optimization>MaxSpeed</Optimization>
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;HLDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalOptions>/wd4054 /wd4456 /wd4702 /wd4100 /wd4457 %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -141,13 +144,14 @@
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
     <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
+      <WarningLevel>EnableAllWarnings</WarningLevel>
       <PrecompiledHeader>
       </PrecompiledHeader>
       <Optimization>MaxSpeed</Optimization>
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;HLDLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalOptions>/wd4054 /wd4456 /wd4702 /wd4100 /wd4457 %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>

+ 3 - 4
src/alloc.c

@@ -392,7 +392,6 @@ alloc_var:
 	if( p->bmp ) {
 		int i;
 		int bid = p->next_block;
-		int mark = 1;
 		for(i=0;i<nblocks;i++) {
 #			ifdef HL_DEBUG
 			if( (p->bmp[bid>>3]&(1<<(bid&7))) != 0 ) hl_fatal("Alloc on marked block");
@@ -407,7 +406,7 @@ alloc_var:
 	p->alloc_hashes[p->next_block] = hl_get_stack_hash();
 #	endif
 	if( nblocks > 1 ) MZERO(p->sizes + p->next_block, nblocks);
-	p->sizes[p->next_block] = nblocks;
+	p->sizes[p->next_block] = (unsigned char)nblocks;
 	p->next_block += nblocks;
 	gc_stats.total_allocated += size + 1;
 	return ptr;
@@ -415,7 +414,7 @@ alloc_var:
 
 static void *gc_alloc_gen( int size, int flags ) {
 	int m = size & (GC_ALIGN - 1);
-	int p, bestP = 0;
+	int p;
 	gc_stats.allocation_count++;
 	gc_stats.total_requested += size;
 	if( m ) size += GC_ALIGN - m;
@@ -758,7 +757,7 @@ static void hl_gc_init( void *stack_top ) {
 		hl_gc_page_map[i] = gc_level1_null;
 	if( TRAILING_ONES(0x080003FF) != 10 || TRAILING_ONES(0) != 0 || TRAILING_ONES(0xFFFFFFFF) != 32 )
 		hl_fatal("Invalid builtin tl1");
-	if( TRAILING_ZEROES(~0x080003FF) != 10 || TRAILING_ZEROES(0) != 32 || TRAILING_ZEROES(0xFFFFFFFF) != 0 )
+	if( TRAILING_ZEROES((unsigned)~0x080003FF) != 10 || TRAILING_ZEROES(0) != 32 || TRAILING_ZEROES(0xFFFFFFFF) != 0 )
 		hl_fatal("Invalid builtin tl0");
 }
 

+ 1 - 1
src/code.c

@@ -139,7 +139,7 @@ static const uchar *hl_get_ustring( hl_reader *r ) {
 	}
 	str = r->code->ustrings[i];
 	if( str == NULL ) {
-		int size = hl_utf8_length(r->code->strings[i],0);
+		int size = hl_utf8_length((vbyte*)r->code->strings[i],0);
 		str = hl_malloc(&r->code->alloc,(size+1)<<1);
 		strtou(str,size+1,r->code->strings[i]);
 		r->code->ustrings[i] = str;

+ 2 - 2
src/hl.h

@@ -99,7 +99,7 @@
 #	define HL_WSIZE 8
 #	define IS_64	1
 #	ifdef HL_VCC
-#		define _PTR_FMT	L"%llX"
+#		define _PTR_FMT	L"%IX"
 #	else
 #		define _PTR_FMT	u"%lX"
 #	endif
@@ -107,7 +107,7 @@
 #	define HL_WSIZE 4
 #	define IS_64	0
 #	ifdef HL_VCC
-#		define _PTR_FMT	L"%X"
+#		define _PTR_FMT	L"%IX"
 #	else
 #		define _PTR_FMT	u"%X"
 #	endif

+ 20 - 104
src/jit.c

@@ -106,7 +106,7 @@ typedef enum {
 #define JZero		JEq
 #define JNotZero	JNeq
 
-#define B(bv)	*ctx->buf.b++ = bv
+#define B(bv)	*ctx->buf.b++ = (unsigned char)(bv)
 #define W(wv)	*ctx->buf.w++ = wv
 
 #ifdef HL_64
@@ -207,7 +207,7 @@ static int RCPU_SCRATCH_REGS[] = { Eax, Ecx, Edx };
 
 #define ID2(a,b)	((a) | ((b)<<8))
 #define R(id)		(ctx->vregs + (id))
-#define ASSERT(i)	{ printf("JIT ERROR %d (jic.c line %d)\n",i,__LINE__); jit_exit(); }
+#define ASSERT(i)	{ printf("JIT ERROR %d (jic.c line %d)\n",i,(int)__LINE__); jit_exit(); }
 #define IS_FLOAT(r)	((r)->t->kind == HF64 || (r)->t->kind == HF32)
 #define RLOCK(r)		if( (r)->lock < ctx->currentPos ) (r)->lock = ctx->currentPos
 #define RUNLOCK(r)		if( (r)->lock == ctx->currentPos ) (r)->lock = 0
@@ -1165,7 +1165,7 @@ static void call_native( jit_ctx *ctx, void *nativeFun, int size ) {
 
 static void op_call_fun( jit_ctx *ctx, vreg *dst, int findex, int count, int *args ) {
 	int fid = findex < 0 ? -1 : ctx->m->functions_indexes[findex];
-	int isNative = fid >= ctx->m->code->nfunctions;
+	bool isNative = fid >= ctx->m->code->nfunctions;
 	int size = prepare_call_args(ctx,count,args,ctx->vregs,isNative);
 	preg p;
 	if( fid < 0 ) {
@@ -1196,102 +1196,6 @@ static void op_call_fun( jit_ctx *ctx, vreg *dst, int findex, int count, int *ar
 	store(ctx, dst, IS_FLOAT(dst) ? PXMM(0) : PEAX, true);
 }
 
-static void op_call_closure( jit_ctx *ctx, vreg *dst, vreg *f, int nargs, int *rargs ) {
-	/*
-		We don't know in avance what is the size of the first argument of the closure, so we need 
-		a dynamic check here.
-		
-		Note : sizes != 4/8 and closures of natives functions are directly handled into the compiler
-		by creating a trampoline function.
-	*/
-	preg p;
-	preg *r = alloc_cpu(ctx, f, true);
-	preg *tmp;
-	int i, has_param, double_param, end1, end2;
-	tmp = alloc_reg(ctx, RCPU);
-	// read bits
-	op32(ctx,MOV,tmp,pmem(&p,(CpuReg)r->id,HL_WSIZE*2));
-	op32(ctx,CMP,tmp,pconst(&p,0));
-	XJump(JNeq,has_param);
-	{
-		// no argument call
-		int size = prepare_call_args(ctx,nargs,rargs,ctx->vregs,false);
-		op64(ctx,CALL,pmem(&p,(CpuReg)r->id,HL_WSIZE),UNUSED);
-		if( size ) op64(ctx,ADD,PESP,pconst(&p,size));
-		XJump(JAlways,end1);
-	}
-	patch_jump(ctx,has_param);
-	op32(ctx,CMP,tmp,pconst(&p,1));
-	XJump(JNeq,double_param);
-	{
-		// int32 argument call
-		int *args;
-		vreg *vargs;
-		int size;
-
-		// load our first arg into a fake vreg
-		vreg fake;
-		hl_type ti32;
-		ti32.kind = HI32;
-		fake.size = 4;
-		fake.t = &ti32;
-		fake.current = alloc_reg(ctx,RCPU);
-		op32(ctx,MOV,fake.current,pmem(&p,(CpuReg)r->id,HL_WSIZE*2 + 8));
-
-		// prepare the args
-		vargs = (vreg*)hl_malloc(&ctx->falloc,sizeof(vreg)*(nargs+1));
-		args = (int*)hl_malloc(&ctx->falloc,sizeof(int)*(nargs+1));
-		vargs[0] = fake;
-		args[0] = 0;
-		for(i=0;i<nargs;i++) {
-			vargs[i+1] = ctx->vregs[rargs[i]];
-			args[i+1] = i + 1;
-		}
-
-		// call
-		size = prepare_call_args(ctx,nargs+1,args,vargs,false);
-		op64(ctx,CALL,pmem(&p,(CpuReg)r->id,HL_WSIZE),UNUSED);
-		op64(ctx,ADD,PESP,pconst(&p,size));
-		XJump(JAlways,end2);
-	}
-	patch_jump(ctx,double_param);
-	{
-		// int64 argument call
-		int *args;
-		vreg *vargs;
-		int size;
-
-		// load our first arg into a fake vreg
-		vreg fake;
-		hl_type ti64;
-		ti64.kind = HF64;
-		fake.size = 8;
-		fake.t = &ti64;
-		fake.current = alloc_reg(ctx,RFPU);
-
-		op64(ctx,MOVSD,fake.current,pmem(&p,(CpuReg)r->id,HL_WSIZE*2 + 8));
-
-		// prepare the args
-		vargs = (vreg*)hl_malloc(&ctx->falloc,sizeof(vreg)*(nargs+1));
-		args = (int*)hl_malloc(&ctx->falloc,sizeof(int)*(nargs+1));
-		vargs[0] = fake;
-		args[0] = 0;
-		for(i=0;i<nargs;i++) {
-			vargs[i+1] = ctx->vregs[rargs[i]];
-			args[i+1] = i + 1;
-		}
-
-		// call
-		size = prepare_call_args(ctx,nargs+1,args,vargs,false);
-		op64(ctx,CALL,pmem(&p,(CpuReg)r->id,HL_WSIZE),UNUSED);
-		op64(ctx,ADD,PESP,pconst(&p,size));
-	}
-	patch_jump(ctx,end1);
-	patch_jump(ctx,end2);
-	discard_regs(ctx, false);
-	store(ctx, dst, IS_FLOAT(dst) ? PXMM(0) : PEAX, true);
-}
-
 static void op_enter( jit_ctx *ctx ) {
 	preg p;
 	op64(ctx, PUSH, PEBP, UNUSED);
@@ -1557,7 +1461,8 @@ static void call_native_consts( jit_ctx *ctx, void *nativeFun, int_val *args, in
 
 static void on_jit_error( const char *msg, int_val line ) {
 	char buf[256];
-	sprintf(buf,"%s (line %d)",msg,(int)line);
+	int iline = (int)line;
+	sprintf(buf,"%s (line %d)",msg,iline);
 #ifdef HL_WIN
 	MessageBoxA(NULL,buf,"JIT ERROR",MB_OK);
 #else
@@ -2062,9 +1967,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				store(ctx, dst, PEAX, true);
 			}
 			break;
-*/		case OCallClosure:
-			op_call_closure(ctx,dst,ra,o->p3,o->extra);
-			break;
+*/
 		case OStaticClosure:
 			{
 				// todo : share duplicates ?
@@ -2087,7 +1990,20 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 					}
 					break;
 				case HVIRTUAL:
-					jit_error("TODO");
+					// ASM for --> if( hl_vfields(o)[f] ) r = *hl_vfields(o)[f]; else r = hl_dyn_get(o,hash(field),vt)
+					{
+						int jhasfield, jend;
+						preg *v = alloc_cpu(ctx,ra,true);
+						preg *r = alloc_reg(ctx,RCPU);
+						op64(ctx,MOV,r,pmem(&p,v->id,sizeof(vvirtual)+HL_WSIZE*o->p3));
+						op64(ctx,TEST,r,r);
+						XJump_small(JNotZero,jhasfield);
+						jit_error("TODO");
+						XJump_small(JAlways,jend);
+						patch_jump(ctx,jhasfield);
+						copy_to(ctx, dst, pmem(&p,(CpuReg)r->id,0));
+						patch_jump(ctx,jend);
+					}
 					break;
 				default:
 					ASSERT(ra->t->kind);

+ 2 - 0
src/main.c

@@ -39,6 +39,8 @@ typedef char pchar;
 #define pfopen fopen
 #endif
 
+extern void *hl_callback( void *f, int nargs, vdynamic **args );
+
 static hl_code *load_code( const pchar *file ) {
 	hl_code *code;
 	FILE *f = pfopen(file,"rb");

+ 2 - 0
src/module.c

@@ -29,6 +29,8 @@
 #	include <dlfcn.h>
 #endif
 
+extern void hl_callback_init( void *e );
+
 static void hl_init_enum( hl_type_enum *e ) {
 	int i, j;
 	for(i=0;i<e->nconstructs;i++) {

+ 6 - 5
src/std/error.c

@@ -65,7 +65,7 @@ HL_PRIM int hl_get_stack_hash() {
 	int hash = 0;
 	int count = 0;
 #ifdef _WIN32
-	count = CaptureStackBackTrace(1, 16, stack, &hash);
+	count = CaptureStackBackTrace(1, 16, stack, (PDWORD)&hash);
 #endif
 	// lookup if we already know this hash
 	if( hl_lookup_find(stack_hashes,stack_hashes_count,hash) != NULL )
@@ -109,13 +109,13 @@ HL_PRIM uchar *hl_resolve_symbol( void *addr, uchar *out, int *outSize ) {
 	} data;
 	data.sym.SizeOfStruct = sizeof(data.sym);
 	data.sym.MaxNameLen = 255;
-	if( SymFromAddrW(stack_process_handle,(DWORD64)addr,&index,&data.sym) ) {
+	if( SymFromAddrW(stack_process_handle,(DWORD64)(int_val)addr,&index,&data.sym) ) {
 		DWORD offset = 0;
 		line.SizeOfStruct = sizeof(line);
 		line.FileName = USTR("\\?");
 		line.LineNumber = 0;
-		SymGetLineFromAddrW64(stack_process_handle, (DWORD64)addr, &offset, &line);
-		*outSize = usprintf(out,*outSize,USTR("%s(%s) line %d"),data.sym.Name,wcsrchr(line.FileName,'\\')+1,line.LineNumber);
+		SymGetLineFromAddrW64(stack_process_handle, (DWORD64)(int_val)addr, &offset, &line);
+		*outSize = usprintf(out,*outSize,USTR("%s(%s) line %d"),data.sym.Name,wcsrchr(line.FileName,'\\')+1,(int)line.LineNumber);
 		return out;
 	}
 #endif
@@ -138,8 +138,9 @@ HL_PRIM varray *hl_exception_stack() {
 		int size = 512;
 		uchar *str = hl_resolve_symbol(addr, sym, &size);
 		if( str == NULL ) {
+			int iaddr = (int)(int_val)addr;
 			str = sym;
-			size = usprintf(str,512,USTR("@0x%X"),(int)(int_val)addr);
+			size = usprintf(str,512,USTR("@0x%X"),iaddr);
 		}
 		hl_aptr(a,vbyte*)[i] = hl_copy_bytes((vbyte*)str,sizeof(uchar)*(size+1));
 	}

+ 1 - 1
src/std/file.c

@@ -87,7 +87,7 @@ HL_PRIM int hl_file_tell( hl_fdesc *f ) {
 }
 
 HL_PRIM bool hl_file_eof( hl_fdesc *f ) {
-	return feof(f->f);
+	return (bool)feof(f->f);
 }
 
 HL_PRIM bool hl_file_flush( hl_fdesc *f ) {

+ 11 - 11
src/std/socket.c

@@ -119,8 +119,8 @@ HL_PRIM void hl_socket_close( hl_socket *s ) {
 }
 
 HL_PRIM int hl_socket_send_char( hl_socket *s, int c ) {
-	unsigned char cc;
-	cc = (unsigned char)c;
+	char cc;
+	cc = (char)(unsigned char)c;
 	if( send(s->sock,&cc,1,MSG_NOSIGNAL) == SOCKET_ERROR )
 		return block_error();
 	return 1;
@@ -128,7 +128,7 @@ HL_PRIM int hl_socket_send_char( hl_socket *s, int c ) {
 
 HL_PRIM int hl_socket_send( hl_socket *s, vbyte *buf, int pos, int len ) {
 	int r = send(s->sock, (char*)buf + pos, len, MSG_NOSIGNAL);
-	if( len == SOCKET_ERROR )
+	if( r == SOCKET_ERROR )
 		return block_error();
 	return len;
 }
@@ -142,11 +142,11 @@ HL_PRIM int hl_socket_recv( hl_socket *s, vbyte *buf, int pos, int len ) {
 }
 
 HL_PRIM int hl_socket_recv_char( hl_socket *s ) {
-	unsigned char cc;
+	char cc;
 	int ret = recv(s->sock,&cc,1,MSG_NOSIGNAL);
 	if( ret == SOCKET_ERROR || ret == 0 )
 		return block_error();
-	return cc;
+	return (unsigned char)cc;
 }
 
 HL_PRIM int hl_host_resolve( vbyte *host ) {
@@ -201,7 +201,7 @@ HL_PRIM bool hl_socket_connect( hl_socket *s, int host, int port ) {
 	struct sockaddr_in addr;
 	memset(&addr,0,sizeof(addr));
 	addr.sin_family = AF_INET;
-	addr.sin_port = htons(port);
+	addr.sin_port = htons((unsigned short)port);
 	*(int*)&addr.sin_addr.s_addr = host;
 	if( connect(s->sock,(struct sockaddr*)&addr,sizeof(addr)) != 0 ) {
 		int err = block_error();
@@ -216,13 +216,13 @@ HL_PRIM bool hl_socket_listen( hl_socket *s, int n ) {
 }
 
 HL_PRIM bool hl_socket_bind( hl_socket *s, int host, int port ) {
-	int opt = 1;
 	struct sockaddr_in addr;
 	memset(&addr,0,sizeof(addr));
 	addr.sin_family = AF_INET;
-	addr.sin_port = htons(port);
+	addr.sin_port = htons((unsigned short)port);
 	*(int*)&addr.sin_addr.s_addr = host;
 	#ifndef HL_WIN
+	int opt = 1;
 	setsockopt(s->sock,SOL_SOCKET,SO_REUSEADDR,(char*)&opt,sizeof(opt));
 	#endif
 	return bind(s->sock,(struct sockaddr*)&addr,sizeof(addr)) != SOCKET_ERROR;
@@ -230,7 +230,7 @@ HL_PRIM bool hl_socket_bind( hl_socket *s, int host, int port ) {
 
 HL_PRIM hl_socket *hl_socket_accept( hl_socket *s ) {
 	struct sockaddr_in addr;
-	unsigned int addrlen = sizeof(addr);
+	int addrlen = sizeof(addr);
 	SOCKET nsock;
 	hl_socket *hs;
 	nsock = accept(s->sock,(struct sockaddr*)&addr,&addrlen);
@@ -243,7 +243,7 @@ HL_PRIM hl_socket *hl_socket_accept( hl_socket *s ) {
 
 HL_PRIM bool hl_socket_peer( hl_socket *s, int *host, int *port ) {
 	struct sockaddr_in addr;
-	unsigned int addrlen = sizeof(addr);
+	int addrlen = sizeof(addr);
 	if( getpeername(s->sock,(struct sockaddr*)&addr,&addrlen) == SOCKET_ERROR )
 		return false;
 	*host = *(int*)&addr.sin_addr;
@@ -253,7 +253,7 @@ HL_PRIM bool hl_socket_peer( hl_socket *s, int *host, int *port ) {
 
 HL_PRIM bool hl_socket_host( hl_socket *s, int *host, int *port ) {
 	struct sockaddr_in addr;
-	unsigned int addrlen = sizeof(addr);
+	int addrlen = sizeof(addr);
 	if( getsockname(s->sock,(struct sockaddr*)&addr,&addrlen) == SOCKET_ERROR )
 		return false;
 	*host = *(int*)&addr.sin_addr;

+ 5 - 5
src/std/string.c

@@ -198,7 +198,7 @@ HL_PRIM vbyte *hl_utf16_to_utf8( vbyte *str, int pos, int *size ) {
 
 HL_PRIM char *hl_to_utf8( uchar *bytes ) {
 	int size;
-	return hl_utf16_to_utf8((vbyte*)bytes, 0, &size);
+	return (char*)hl_utf16_to_utf8((vbyte*)bytes, 0, &size);
 }
 
 HL_PRIM vbyte *hl_url_encode( vbyte *str, int *len ) {
@@ -249,7 +249,7 @@ static uchar decode_hex_char( uchar c ) {
 	else if( c >= 'A' && c <= 'F' )
 		c -= 'A' - 10;
 	else
-		return -1;
+		return (uchar)-1;
 	return c;
 }
 
@@ -257,9 +257,9 @@ static uchar decode_hex( uchar **cstr ) {
 	uchar *c = *cstr;
 	uchar p1 = decode_hex_char(c[0]);
 	uchar p2;
-	if( p1 < 0 ) return -1;
+	if( p1 == (uchar)-1 ) return p1;
 	p2 = decode_hex_char(c[1]);
-	if( p2 < 0 ) return -1;
+	if( p2 == (uchar)-1 ) return p2;
 	*cstr = c + 2;
 	return (p1 << 4) | p2;
 }
@@ -275,7 +275,7 @@ HL_PRIM vbyte *hl_url_decode( vbyte *str, int *len ) {
 			c = ' ';
 		else if( c == '%' ) {
 			uchar p1 = decode_hex(&cstr);
-			if( p1 < 0 ) {
+			if( p1 == (uchar)-1 ) {
 				hl_buffer_char(b,'%');
 				continue;
 			}