Browse Source

gcc warnings cleanup

Nicolas Cannasse 9 năm trước cách đây
mục cha
commit
8ce622e076
10 tập tin đã thay đổi với 57 bổ sung25 xóa
  1. 4 2
      Makefile
  2. 18 4
      src/hl.h
  3. 4 0
      src/hlc.h
  4. 1 1
      src/std/date.c
  5. 1 0
      src/std/error.c
  6. 12 11
      src/std/fun.c
  7. 7 2
      src/std/obj.c
  8. 0 3
      src/std/regexp.c
  9. 7 1
      src/std/sys.c
  10. 3 1
      src/std/types.c

+ 4 - 2
Makefile

@@ -1,7 +1,9 @@
-CFLAGS = -Wall -O3 -I src -msse2 -mfpmath=sse
+CFLAGS = -Wall -O3 -I src -msse2 -mfpmath=sse -std=c11 -I include/pcre
 LFLAGS =
 
-SRC = src/alloc.c src/callback.c src/code.c src/jit.c src/main.c src/module.c src/other.c src/std/misc.c
+SRC = src/alloc.c src/std/array.c src/std/buffer.c src/std/bytes.c src/std/cast.c src/std/date.c src/std/error.c \
+	src/std/fun.c src/std/maps.c src/std/math.c src/std/obj.c src/std/regexp.c src/std/string.c src/std/sys.c \
+	src/std/types.c
 
 # Cygwin
 ifeq ($(OS),Windows_NT)

+ 18 - 4
src/hl.h

@@ -96,7 +96,11 @@
 #else
 #	define HL_WSIZE 4
 #	define IS_64	0
-#	define _PTR_FMT	L"%X"
+#	ifdef HL_VCC
+#		define _PTR_FMT	L"%X"
+#	else
+#		define _PTR_FMT	u"%X"
+#	endif
 #endif
 
 #ifdef __cplusplus
@@ -138,9 +142,19 @@ typedef wchar_t	uchar;
 #	define ucmp(a,b)	wcscmp(a,b)
 #	define strtou(out,size,str) mbstowcs(out,str,size)	
 #else
+#	include <stdarg.h>
 typedef unsigned short uchar;
 #	undef USTR
 #	define USTR(str)	u##str
+extern int ustrlen( const uchar *str );
+extern uchar *ustrdup( const uchar *str );
+extern double utod( const uchar *str, uchar **end );
+extern int utoi( const uchar *str, uchar **end );
+extern int ucmp( const uchar *a, const uchar *b );
+extern int strtou( uchar *out, int out_size, const char *str ); 
+extern int usprintf( uchar *out, int out_size, const uchar *fmt, ... );
+extern int uprintf( const uchar *fmt, ... );
+extern int uvsprintf( uchar *out, const uchar *fmt, va_list arglist );
 #endif
 
 // ---- TYPES -------------------------------------------
@@ -316,7 +330,7 @@ typedef struct _vclosure {
 } vclosure;
 
 typedef struct {
-	struct _vclosure;
+	vclosure cl;
 	vclosure *wrappedFun;
 } vclosure_wrapper;
 
@@ -400,8 +414,8 @@ hl_field_lookup *hl_lookup_find( hl_field_lookup *l, int size, int hash );
 
 int hl_dyn_geti( vdynamic *d, int hfield, hl_type *t );
 void *hl_dyn_getp( vdynamic *d, int hfield, hl_type *t );
-float hl_dyn_getf( void *data, int hfield );
-double hl_dyn_getd( void *data, int hfield );
+float hl_dyn_getf( vdynamic *d, int hfield );
+double hl_dyn_getd( vdynamic *d, int hfield );
 
 int hl_dyn_casti( void *data, hl_type *t, hl_type *to );
 void *hl_dyn_castp( void *data, hl_type *t, hl_type *to );

+ 4 - 0
src/hlc.h

@@ -40,6 +40,8 @@
 
 #undef CONST
 
+#ifndef HLC_NO_STATIC
+
 static void hl_null_access() {
 	hl_error_msg(USTR("Null access"));
 }
@@ -105,6 +107,8 @@ static vdynamic *hlc_dyn_call_obj( vdynamic *o, int hfield, vdynamic **args, int
 	return NULL;
 }
 
+#endif
+
 #include <setjmp.h>
 
 typedef struct _hl_trap_ctx hl_trap_ctx;

+ 1 - 1
src/std/date.c

@@ -50,7 +50,7 @@ HL_PRIM int hl_date_from_time( double time ) {
 HL_PRIM int hl_date_from_string( vbyte *b ) {
 	uchar *str = (uchar*)b;
 	hl_fatal("TODO");
-	return 0;
+	return *str;
 }
 
 HL_PRIM int hl_date_new( int y, int mo, int d, int h, int m, int s ) {

+ 1 - 0
src/std/error.c

@@ -1,3 +1,4 @@
+#define HLC_NO_STATIC
 #include <hlc.h>
 #include <stdarg.h>
 #include <string.h>

+ 12 - 11
src/std/fun.c

@@ -138,6 +138,7 @@ static void fun_var_args() {
 
 void *hl_wrapper_call( void *_c, void **args, vdynamic *ret ) {
 	vclosure_wrapper *c = (vclosure_wrapper*)_c;
+	hl_type_fun *tfun = c->cl.t->fun;
 	union { double d; int i; float f; } tmp[HL_MAX_ARGS];
 	void *vargs[HL_MAX_ARGS+1];
 	vdynamic out;
@@ -150,9 +151,9 @@ void *hl_wrapper_call( void *_c, void **args, vdynamic *ret ) {
 	if( w->fun == fun_var_args ) {
 		varray *a;
 		w = (vclosure*)w->value; // the real callback
-		a = hl_aalloc(&hlt_dyn,c->t->fun->nargs);
-		for(i=0;i<c->t->fun->nargs;i++) {
-			hl_type *t = c->t->fun->args[i];
+		a = hl_aalloc(&hlt_dyn,tfun->nargs);
+		for(i=0;i<tfun->nargs;i++) {
+			hl_type *t = tfun->args[i];
 			void *v = hl_is_ptr(t) ? args + i : args[i];
 			*(void**)(a + 1) = hl_make_dyn(v,t);
 		}
@@ -163,7 +164,7 @@ void *hl_wrapper_call( void *_c, void **args, vdynamic *ret ) {
 		if( w->hasValue )
 			vargs[p++] = (vdynamic*)w->value;
 		for(i=0;i<w->t->fun->nargs;i++) {
-			hl_type *t = c->t->fun->args[i];
+			hl_type *t = tfun->args[i];
 			hl_type *to = w->t->fun->args[i];
 			void *v = hl_is_ptr(t) ? args + i : args[i];
 			switch( to->kind ) {
@@ -190,11 +191,11 @@ void *hl_wrapper_call( void *_c, void **args, vdynamic *ret ) {
 	}
 	pret = hlc_static_call(w->fun,w->hasValue ? w->t->fun->parent : w->t,vargs,ret);
 	aret = hl_is_ptr(w->t->fun->ret) ? &pret : pret;
-	switch( c->t->fun->ret->kind ) {
+	switch( tfun->ret->kind ) {
 	case HI8:
 	case HI16:
 	case HI32:
-		ret->v.i = hl_dyn_casti(aret,w->t->fun->ret,c->t->fun->ret);
+		ret->v.i = hl_dyn_casti(aret,w->t->fun->ret,tfun->ret);
 		break;
 	case HF32:
 		ret->v.f = hl_dyn_castf(aret,w->t->fun->ret);
@@ -203,7 +204,7 @@ void *hl_wrapper_call( void *_c, void **args, vdynamic *ret ) {
 		ret->v.d = hl_dyn_castd(aret,w->t->fun->ret);
 		break;
 	default:
-		pret = hl_dyn_castp(aret,w->t->fun->ret,c->t->fun->ret);
+		pret = hl_dyn_castp(aret,w->t->fun->ret,tfun->ret);
 		break;
 	}
 	return pret;
@@ -216,10 +217,10 @@ vclosure *hl_make_fun_wrapper( vclosure *v, hl_type *to ) {
 	if( v->fun != fun_var_args && v->t->fun->nargs != to->fun->nargs )
 		return NULL;
 	c = (vclosure_wrapper*)hl_gc_alloc(sizeof(vclosure_wrapper));
-	c->t = to;
-	c->fun = wrap;
-	c->hasValue = 2;
-	c->value = c;
+	c->cl.t = to;
+	c->cl.fun = wrap;
+	c->cl.hasValue = 2;
+	c->cl.value = c;
 	c->wrappedFun = v; 
 	return (vclosure*)c;
 }

+ 7 - 2
src/std/obj.c

@@ -208,7 +208,7 @@ void hl_init_virtual( hl_type *vt, hl_module_context *ctx ) {
 	Allocate a virtual fields mapping to a given value.
 **/
 vvirtual *hl_to_virtual( hl_type *vt, vdynamic *obj ) {
-	vvirtual *v;
+	vvirtual *v = NULL;
 	if( obj == NULL ) return NULL;
 #ifdef _DEBUG
 	if( vt->vobj_proto == NULL ) hl_fatal("virtual not initialized");
@@ -217,7 +217,6 @@ vvirtual *hl_to_virtual( hl_type *vt, vdynamic *obj ) {
 	case HOBJ:
 		{ 
 			int i;
-			hl_runtime_obj *rt = obj->t->obj->rt;
 			v = (vvirtual*)hl_gc_alloc(sizeof(vvirtual));
 			v->t = vt;
 			v->fields_data = (char*)obj;
@@ -415,6 +414,8 @@ static vdynamic *hl_obj_lookup_extra( vdynamic *d, int hfield ) {
 		break;
 	case HVIRTUAL:
 		return hl_obj_lookup_extra(((vvirtual*)d)->value, hfield);
+	default:
+		break;
 	}
 	return NULL;
 }
@@ -635,6 +636,8 @@ HL_PRIM bool hl_obj_has_field( vdynamic *obj, int hfield ) {
 		break;
 	case HVIRTUAL:
 		return hl_obj_has_field(((vvirtual*)obj)->value,hfield);
+	default:
+		break;
 	}
 	return false;
 }
@@ -697,6 +700,8 @@ HL_PRIM varray *hl_obj_fields( vdynamic *obj ) {
 			}
 		}
 		break;
+	default:
+		break;
 	}
 	return a;
 }

+ 0 - 3
src/std/regexp.c

@@ -70,9 +70,6 @@ HL_PRIM ereg *regexp_regexp_new_options( vbyte *str, vbyte *opts ) {
 	return r;
 }
 
-static bool do_exec( ereg *e, vbyte *str, int len, int pos ) {
-}
-
 HL_PRIM int regexp_regexp_matched_pos( ereg *e, int m, int *len ) {
 	int start;
 	if( !e->matched )

+ 7 - 1
src/std/sys.c

@@ -1,5 +1,10 @@
 #include <hl.h>
 
+#ifndef HL_WIN
+#	include <sys/time.h>
+#	include <sys/times.h>
+#endif
+
 HL_PRIM void hl_sys_print( vbyte *msg ) {
 	uprintf(USTR("%s"),(uchar*)msg);
 }
@@ -23,7 +28,7 @@ HL_PRIM double hl_sys_time() {
 #else
 	struct timeval tv;
 	if( gettimeofday(&tv,NULL) != 0 )
-		neko_error();
+		return 0.;
 	return tv.tv_sec + ((double)tv.tv_usec) / 1000000.0;
 #endif
 }
@@ -35,6 +40,7 @@ HL_PRIM int hl_random( int max ) {
 
 #ifndef HL_JIT
 
+#define HLC_NO_STATIC
 #include <hlc.h>
 #if defined(HL_VCC) && defined(_DEBUG)
 #	include <crtdbg.h>

+ 3 - 1
src/std/types.c

@@ -167,6 +167,8 @@ bool hl_safe_cast( hl_type *t, hl_type *to ) {
 			return true;
 		}
 		break;
+	default:
+		break;
 	}
 	return hl_same_type(t,to);
 }
@@ -292,7 +294,7 @@ HL_PRIM varray *hl_type_instance_fields( hl_type *t ) {
 	}
 	rt = hl_get_obj_rt(t);
 	a = hl_aalloc(&hlt_bytes,mcount + rt->nproto + rt->nfields);
-	names = (uchar**)(a + 1);
+	names = (const uchar**)(a + 1);
 	o = t->obj;
 	while( true ) {
 		int i;