From 33190e290d2b17e601c007dd604cb2855b471728 Mon Sep 17 00:00:00 2001 From: "U-Khasa\\Vitor" Date: Wed, 10 Feb 2010 03:03:03 -0600 Subject: [PATCH] mingw complaint with recent versions of gcc --- C/agc.c | 4 ++++ C/bignum.c | 4 +++- C/gmp_support.c | 6 ++++++ C/init.c | 6 +++--- C/iopreds.c | 4 +++- C/sysbits.c | 19 ++++++++++++------- C/threads.c | 15 ++++++--------- C/ypsocks.c | 16 +++++++++++++++- H/YapHeap.h | 4 ++-- include/yap_structs.h | 2 +- library/yap2swi/yap2swi.c | 26 ++++++++++++++++++++++++++ 11 files changed, 81 insertions(+), 25 deletions(-) mode change 100644 => 100755 C/agc.c mode change 100644 => 100755 C/bignum.c mode change 100644 => 100755 C/gmp_support.c mode change 100644 => 100755 C/init.c mode change 100644 => 100755 C/threads.c mode change 100644 => 100755 C/ypsocks.c mode change 100644 => 100755 H/YapHeap.h mode change 100644 => 100755 include/yap_structs.h mode change 100644 => 100755 library/yap2swi/yap2swi.c diff --git a/C/agc.c b/C/agc.c old mode 100644 new mode 100755 index ac531a283..2b7ce011b --- a/C/agc.c +++ b/C/agc.c @@ -429,7 +429,11 @@ atom_gc(void) tot_agc_time += agc_time; tot_agc_recovered += agc_collected; if (gc_verbose) { +#ifdef _WIN32 + fprintf(Yap_stderr, "%% Collected %I64d bytes.\n", agc_collected); +#else fprintf(Yap_stderr, "%% Collected %lld bytes.\n", agc_collected); +#endif fprintf(Yap_stderr, "%% GC %d took %g sec, total of %g sec doing GC so far.\n", agc_calls, (double)agc_time/1000, (double)tot_agc_time/1000); } } diff --git a/C/bignum.c b/C/bignum.c old mode 100644 new mode 100755 index 676626b12..a6ff9a6bd --- a/C/bignum.c +++ b/C/bignum.c @@ -76,7 +76,9 @@ Yap_MkULLIntTerm(YAP_ULONG_LONG n) char tmp[256]; Term t; -#if HAVE_SNPRINTF +#ifdef _WIN32 + snprintf(tmp,256,"%I64u",n); +#elif HAVE_SNPRINTF snprintf(tmp,256,"%llu",n); #else sprintf(tmp,"%llu",n); diff --git a/C/gmp_support.c b/C/gmp_support.c old mode 100644 new mode 100755 index 409e076ce..ff0ef079f --- a/C/gmp_support.c +++ b/C/gmp_support.c @@ -368,7 +368,13 @@ Yap_gmp_big_from_64bits(YAP_LONG_LONG i) char s[64]; MP_INT new; +#ifdef _WIN32 + snprintf(s,64,"%I64d", (long long int)i); +#elif HAVE_SNPRINTF + snprintf(s, 64, "%lld", (long long int)i); +#else sprintf(s, "%lld", (long long int)i); +#endif mpz_init_set_str (&new, s, 10); return MkBigAndClose(&new); } diff --git a/C/init.c b/C/init.c old mode 100644 new mode 100755 index f486b8297..c46df09a2 --- a/C/init.c +++ b/C/init.c @@ -1141,8 +1141,8 @@ InitThreadHandles(void) Yap_heap_regs->thread_handle[0].in_use = TRUE; Yap_heap_regs->thread_handle[0].default_yaam_regs = &Yap_standard_regs; - Yap_heap_regs->thread_handle[0].handle = pthread_self(); - Yap_heap_regs->thread_handle[0].handle = pthread_self(); + Yap_heap_regs->thread_handle[0].pthread_handle = pthread_self(); + Yap_heap_regs->thread_handle[0].pthread_handle = pthread_self(); pthread_mutex_init(&ThreadHandle[0].tlock, NULL); pthread_mutex_init(&ThreadHandle[0].tlock_status, NULL); Yap_heap_regs->thread_handle[0].tdetach = MkAtomTerm(AtomFalse); @@ -1183,8 +1183,8 @@ InitCodes(void) Yap_heap_regs->wl[i].consultbase = Yap_heap_regs->wl[i].consultsp = Yap_heap_regs->wl[i].consultlow + Yap_heap_regs->wl[i].consultcapacity; Yap_heap_regs->wl[i].Gc_timestamp = 0; + Yap_heap_regs->wl[i].ball_term = NULL; } - Yap_heap_regs->wl[i].ball_term = NULL; } #else Yap_heap_regs->wl.dynamic_arrays = NULL; diff --git a/C/iopreds.c b/C/iopreds.c index bfbacdd8f..8ef0d5e10 100755 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -522,8 +522,10 @@ InitPlIO (void) { Int i; - for (i = 0; i < MaxStreams; ++i) + for (i = 0; i < MaxStreams; ++i) { + INIT_LOCK(Stream[i].streamlock); Stream[i].status = Free_Stream_f; + } /* alloca alias array */ if (!FileAliases) FileAliases = (AliasDesc)Yap_AllocCodeSpace(sizeof(struct AliasDescS)*ALIASES_BLOCK_SIZE); diff --git a/C/sysbits.c b/C/sysbits.c index 0608112d7..29080b069 100755 --- a/C/sysbits.c +++ b/C/sysbits.c @@ -113,12 +113,6 @@ STATIC_PROTO (int chdir, (char *)); char yap_pwd[YAP_FILENAME_MAX]; #endif -#if HAVE_SIGNAL - -static int snoozing = FALSE; - -#endif - STD_PROTO (void exit, (int)); #ifdef _WIN32 @@ -1492,6 +1486,13 @@ Yap_ProcessSIGINT(void) return ProcessSIGINT(); } + +#if !_MSC_VER && !defined(__MINGW32__) + +#if HAVE_SIGNAL +static int snoozing = FALSE; +#endif + /* This function is called from the signal handler to process signals. We assume we are within the context of the signal handler, whatever that might be @@ -1543,6 +1544,7 @@ HandleSIGINT (int sig) ProcessSIGINT(); UNLOCK(SignalLock); } +#endif #if !defined(_WIN32) /* this routine is called if the system activated the alarm */ @@ -3113,7 +3115,10 @@ p_win_registry_get_value(void) case REG_DWORD: recover_space(k, KeyAt); recover_space(name, NameAt); - return Yap_unify(MkIntegerTerm(*((DWORD *)data)),ARG3); + { + DWORD *d = (DWORD *)data; + return Yap_unify(MkIntegerTerm((Int)d[0]),ARG3); + } default: recover_space(k, KeyAt); recover_space(name, NameAt); diff --git a/C/threads.c b/C/threads.c old mode 100644 new mode 100755 index 6ade18ba1..189a73509 --- a/C/threads.c +++ b/C/threads.c @@ -263,7 +263,7 @@ p_create_thread(void) return FALSE; ThreadHandle[new_worker_id].id = new_worker_id; ThreadHandle[new_worker_id].ref_count = 1; - if ((ThreadHandle[new_worker_id].ret = pthread_create(&ThreadHandle[new_worker_id].handle, NULL, thread_run, (void *)(&(ThreadHandle[new_worker_id].id)))) == 0) { + if ((ThreadHandle[new_worker_id].ret = pthread_create(&ThreadHandle[new_worker_id].pthread_handle, NULL, thread_run, (void *)(&(ThreadHandle[new_worker_id].id)))) == 0) { /* wait until the client is initialised */ return TRUE; } @@ -373,7 +373,7 @@ Yap_thread_create_engine(thread_attr *ops) if (!init_thread_engine(new_id, ops->ssize, ops->tsize, ops->sysize, &t, &t, &(ops->egoal))) return FALSE; ThreadHandle[new_id].id = new_id; - ThreadHandle[new_id].handle = pthread_self(); + ThreadHandle[new_id].pthread_handle = pthread_self(); ThreadHandle[new_id].ref_count = 0; setup_engine(new_id); return TRUE; @@ -384,13 +384,12 @@ Yap_thread_attach_engine(int wid) { DEBUG_TLOCK_ACCESS(7, wid); pthread_mutex_lock(&(ThreadHandle[wid].tlock)); - if (ThreadHandle[wid].ref_count && - ThreadHandle[wid].handle != pthread_self()) { + if (ThreadHandle[wid].ref_count ) { DEBUG_TLOCK_ACCESS(8, wid); pthread_mutex_unlock(&(ThreadHandle[wid].tlock)); return FALSE; } - ThreadHandle[wid].handle = pthread_self(); + ThreadHandle[wid].pthread_handle = pthread_self(); ThreadHandle[wid].ref_count++; worker_id = wid; DEBUG_TLOCK_ACCESS(9, wid); @@ -403,8 +402,6 @@ Yap_thread_detach_engine(int wid) { DEBUG_TLOCK_ACCESS(10, wid); pthread_mutex_lock(&(ThreadHandle[wid].tlock)); - if (ThreadHandle[wid].handle == pthread_self()) - ThreadHandle[wid].handle = 0; ThreadHandle[wid].ref_count--; DEBUG_TLOCK_ACCESS(11, wid); pthread_mutex_unlock(&(ThreadHandle[wid].tlock)); @@ -442,7 +439,7 @@ p_thread_join(void) } UNLOCK(ThreadHandlesLock); /* make sure this lock is accessible */ - if (pthread_join(ThreadHandle[tid].handle, NULL) < 0) { + if (pthread_join(ThreadHandle[tid].pthread_handle, NULL) < 0) { /* ERROR */ return FALSE; } @@ -470,7 +467,7 @@ p_thread_detach(void) Int tid = IntegerOfTerm(Deref(ARG1)); pthread_mutex_lock(&(ThreadHandle[tid].tlock)); DEBUG_TLOCK_ACCESS(14, tid); - if (pthread_detach(ThreadHandle[tid].handle) < 0) { + if (pthread_detach(ThreadHandle[tid].pthread_handle) < 0) { /* ERROR */ DEBUG_TLOCK_ACCESS(15, tid); pthread_mutex_unlock(&(ThreadHandle[tid].tlock)); diff --git a/C/ypsocks.c b/C/ypsocks.c old mode 100644 new mode 100755 index 7b91b019d..6fde03ff9 --- a/C/ypsocks.c +++ b/C/ypsocks.c @@ -659,7 +659,11 @@ p_socket_bind(void) if (IsVarTerm(tport)) { /* get the port number */ +#if _WIN32 || defined(__MINGW32__) + int namelen; +#else unsigned int namelen; +#endif Term t; if (getsockname(fd, (struct sockaddr *)&saddr, &namelen) < 0) { #if HAVE_STRERROR @@ -908,7 +912,11 @@ p_socket_accept(void) struct sockaddr_in caddr; Term tcli; char *s; +#if _WIN32 || defined(__MINGW32__) + int len; +#else unsigned int len; +#endif len = sizeof(caddr); memset((void *)&caddr,(int) 0, sizeof(caddr)); @@ -950,7 +958,13 @@ p_socket_buffering(void) Atom mode; int fd; int writing; - unsigned int bufsize, len; +#if _WIN32 || defined(__MINGW32__) + int bufsize; + int len; +#else + unsigned int bufsize; + unsigned int len; +#endif int sno; if ((sno = Yap_CheckSocketStream(t1, "socket_buffering/4")) < 0) { diff --git a/H/YapHeap.h b/H/YapHeap.h old mode 100644 new mode 100755 index 6f85d10cf..015aa5f24 --- a/H/YapHeap.h +++ b/H/YapHeap.h @@ -209,7 +209,7 @@ typedef struct thandle { REGSTORE *default_yaam_regs; REGSTORE *current_yaam_regs; struct pred_entry *local_preds; - pthread_t handle; + pthread_t pthread_handle; int ref_count; #ifdef LOW_LEVEL_TRACER long long int thread_inst_count; @@ -218,7 +218,7 @@ typedef struct thandle { #endif pthread_mutex_t tlock; pthread_mutex_t tlock_status; -#if HAVE_GETRUSAGE +#if HAVE_GETRUSAGE||defined(_WIN32) struct timeval *start_of_timesp; struct timeval *last_timep; #endif diff --git a/include/yap_structs.h b/include/yap_structs.h old mode 100644 new mode 100755 index e538bdd55..eb7ba6822 --- a/include/yap_structs.h +++ b/include/yap_structs.h @@ -161,7 +161,7 @@ typedef struct { struct yami *p; } YAP_dogoalinfo; -typedef int (*YAP_agc_hook)(YAP_Atom); +typedef int (*YAP_agc_hook)(void *_Atom); /********* execution mode ***********************/ diff --git a/library/yap2swi/yap2swi.c b/library/yap2swi/yap2swi.c old mode 100644 new mode 100755 index d211b4bad..d69e82864 --- a/library/yap2swi/yap2swi.c +++ b/library/yap2swi/yap2swi.c @@ -584,7 +584,11 @@ X_API int PL_get_int64(term_t ts, int64_t *i) return 0; } mpz_get_str (s, 10, &g); +#ifdef _WIN32 + sscanf(s, "%I64d", (long long int *)i); +#else sscanf(s, "%lld", (long long int *)i); +#endif return 1; #endif } @@ -907,7 +911,13 @@ X_API int PL_put_int64(term_t t, int64_t n) char s[64]; MP_INT rop; +#ifdef _WIN32 + snprintf(s, 64, "%I64d", (long long int)n); +#elif HAVE_SNPRINTF + snprintf(s, 64, "%lld", (long long int)n); +#else sprintf(s, "%lld", (long long int)n); +#endif mpz_init_set_str (&rop, s, 10); Yap_PutInSlot(t,YAP_MkBigNumTerm((void *)&rop)); return TRUE; @@ -1315,7 +1325,13 @@ X_API int PL_unify_int64(term_t t, int64_t n) char s[64]; MP_INT rop; +#ifdef _WIN32 + snprintf(s, 64, "%I64d", (long long int)n); +#elif HAVE_SNPRINTF + snprintf(s, 64, "%lld", (long long int)n); +#else sprintf(s, "%lld", (long long int)n); +#endif mpz_init_set_str (&rop, s, 10); iterm = YAP_MkBigNumTerm((void *)&rop); return YAP_Unify(Yap_GetFromSlot(t),iterm); @@ -1602,7 +1618,13 @@ X_API int PL_unify_term(term_t l,...) char s[64]; MP_INT rop; +#ifdef _WIN32 + snprintf(s, 64, "%I64d", va_arg(ap, long long int)); +#elif HAVE_SNPRINTF + snprintf(s, 64, "%lld", va_arg(ap, long long int)); +#else sprintf(s, "%lld", va_arg(ap, long long int)); +#endif mpz_init_set_str (&rop, s, 10); *pt++ = YAP_MkBigNumTerm((void *)&rop); } @@ -2336,7 +2358,11 @@ PL_eval_expression_to_int64_ex(term_t t, int64_t *val) return PL_error(NULL,0,NULL, ERR_EVALUATION, AtomToSWIAtom(Yap_LookupAtom("int_overflow"))); } mpz_get_str (s, 10, &g); +#ifdef _WIN32 + sscanf(s, "%I64d", (long long int *)val); +#else sscanf(s, "%lld", (long long int *)val); +#endif return 1; #endif }