mingw complaint with recent versions of gcc

This commit is contained in:
U-Khasa\Vitor 2010-02-10 03:03:03 -06:00
parent c59349d91d
commit 33190e290d
11 changed files with 81 additions and 25 deletions

4
C/agc.c Normal file → Executable file
View File

@ -429,7 +429,11 @@ atom_gc(void)
tot_agc_time += agc_time; tot_agc_time += agc_time;
tot_agc_recovered += agc_collected; tot_agc_recovered += agc_collected;
if (gc_verbose) { if (gc_verbose) {
#ifdef _WIN32
fprintf(Yap_stderr, "%% Collected %I64d bytes.\n", agc_collected);
#else
fprintf(Yap_stderr, "%% Collected %lld bytes.\n", agc_collected); 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); 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);
} }
} }

4
C/bignum.c Normal file → Executable file
View File

@ -76,7 +76,9 @@ Yap_MkULLIntTerm(YAP_ULONG_LONG n)
char tmp[256]; char tmp[256];
Term t; Term t;
#if HAVE_SNPRINTF #ifdef _WIN32
snprintf(tmp,256,"%I64u",n);
#elif HAVE_SNPRINTF
snprintf(tmp,256,"%llu",n); snprintf(tmp,256,"%llu",n);
#else #else
sprintf(tmp,"%llu",n); sprintf(tmp,"%llu",n);

6
C/gmp_support.c Normal file → Executable file
View File

@ -368,7 +368,13 @@ Yap_gmp_big_from_64bits(YAP_LONG_LONG i)
char s[64]; char s[64];
MP_INT new; 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); sprintf(s, "%lld", (long long int)i);
#endif
mpz_init_set_str (&new, s, 10); mpz_init_set_str (&new, s, 10);
return MkBigAndClose(&new); return MkBigAndClose(&new);
} }

6
C/init.c Normal file → Executable file
View File

@ -1141,8 +1141,8 @@ InitThreadHandles(void)
Yap_heap_regs->thread_handle[0].in_use = TRUE; Yap_heap_regs->thread_handle[0].in_use = TRUE;
Yap_heap_regs->thread_handle[0].default_yaam_regs = Yap_heap_regs->thread_handle[0].default_yaam_regs =
&Yap_standard_regs; &Yap_standard_regs;
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].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, NULL);
pthread_mutex_init(&ThreadHandle[0].tlock_status, NULL); pthread_mutex_init(&ThreadHandle[0].tlock_status, NULL);
Yap_heap_regs->thread_handle[0].tdetach = MkAtomTerm(AtomFalse); Yap_heap_regs->thread_handle[0].tdetach = MkAtomTerm(AtomFalse);
@ -1183,9 +1183,9 @@ InitCodes(void)
Yap_heap_regs->wl[i].consultbase = Yap_heap_regs->wl[i].consultsp = 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].consultlow + Yap_heap_regs->wl[i].consultcapacity;
Yap_heap_regs->wl[i].Gc_timestamp = 0; 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 #else
Yap_heap_regs->wl.dynamic_arrays = NULL; Yap_heap_regs->wl.dynamic_arrays = NULL;
Yap_heap_regs->wl.static_arrays = NULL; Yap_heap_regs->wl.static_arrays = NULL;

View File

@ -522,8 +522,10 @@ InitPlIO (void)
{ {
Int i; 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; Stream[i].status = Free_Stream_f;
}
/* alloca alias array */ /* alloca alias array */
if (!FileAliases) if (!FileAliases)
FileAliases = (AliasDesc)Yap_AllocCodeSpace(sizeof(struct AliasDescS)*ALIASES_BLOCK_SIZE); FileAliases = (AliasDesc)Yap_AllocCodeSpace(sizeof(struct AliasDescS)*ALIASES_BLOCK_SIZE);

View File

@ -113,12 +113,6 @@ STATIC_PROTO (int chdir, (char *));
char yap_pwd[YAP_FILENAME_MAX]; char yap_pwd[YAP_FILENAME_MAX];
#endif #endif
#if HAVE_SIGNAL
static int snoozing = FALSE;
#endif
STD_PROTO (void exit, (int)); STD_PROTO (void exit, (int));
#ifdef _WIN32 #ifdef _WIN32
@ -1492,6 +1486,13 @@ Yap_ProcessSIGINT(void)
return ProcessSIGINT(); 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. /* This function is called from the signal handler to process signals.
We assume we are within the context of the signal handler, whatever We assume we are within the context of the signal handler, whatever
that might be that might be
@ -1543,6 +1544,7 @@ HandleSIGINT (int sig)
ProcessSIGINT(); ProcessSIGINT();
UNLOCK(SignalLock); UNLOCK(SignalLock);
} }
#endif
#if !defined(_WIN32) #if !defined(_WIN32)
/* this routine is called if the system activated the alarm */ /* this routine is called if the system activated the alarm */
@ -3113,7 +3115,10 @@ p_win_registry_get_value(void)
case REG_DWORD: case REG_DWORD:
recover_space(k, KeyAt); recover_space(k, KeyAt);
recover_space(name, NameAt); recover_space(name, NameAt);
return Yap_unify(MkIntegerTerm(*((DWORD *)data)),ARG3); {
DWORD *d = (DWORD *)data;
return Yap_unify(MkIntegerTerm((Int)d[0]),ARG3);
}
default: default:
recover_space(k, KeyAt); recover_space(k, KeyAt);
recover_space(name, NameAt); recover_space(name, NameAt);

15
C/threads.c Normal file → Executable file
View File

@ -263,7 +263,7 @@ p_create_thread(void)
return FALSE; return FALSE;
ThreadHandle[new_worker_id].id = new_worker_id; ThreadHandle[new_worker_id].id = new_worker_id;
ThreadHandle[new_worker_id].ref_count = 1; 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 */ /* wait until the client is initialised */
return TRUE; 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))) if (!init_thread_engine(new_id, ops->ssize, ops->tsize, ops->sysize, &t, &t, &(ops->egoal)))
return FALSE; return FALSE;
ThreadHandle[new_id].id = new_id; 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; ThreadHandle[new_id].ref_count = 0;
setup_engine(new_id); setup_engine(new_id);
return TRUE; return TRUE;
@ -384,13 +384,12 @@ Yap_thread_attach_engine(int wid)
{ {
DEBUG_TLOCK_ACCESS(7, wid); DEBUG_TLOCK_ACCESS(7, wid);
pthread_mutex_lock(&(ThreadHandle[wid].tlock)); pthread_mutex_lock(&(ThreadHandle[wid].tlock));
if (ThreadHandle[wid].ref_count && if (ThreadHandle[wid].ref_count ) {
ThreadHandle[wid].handle != pthread_self()) {
DEBUG_TLOCK_ACCESS(8, wid); DEBUG_TLOCK_ACCESS(8, wid);
pthread_mutex_unlock(&(ThreadHandle[wid].tlock)); pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
return FALSE; return FALSE;
} }
ThreadHandle[wid].handle = pthread_self(); ThreadHandle[wid].pthread_handle = pthread_self();
ThreadHandle[wid].ref_count++; ThreadHandle[wid].ref_count++;
worker_id = wid; worker_id = wid;
DEBUG_TLOCK_ACCESS(9, wid); DEBUG_TLOCK_ACCESS(9, wid);
@ -403,8 +402,6 @@ Yap_thread_detach_engine(int wid)
{ {
DEBUG_TLOCK_ACCESS(10, wid); DEBUG_TLOCK_ACCESS(10, wid);
pthread_mutex_lock(&(ThreadHandle[wid].tlock)); pthread_mutex_lock(&(ThreadHandle[wid].tlock));
if (ThreadHandle[wid].handle == pthread_self())
ThreadHandle[wid].handle = 0;
ThreadHandle[wid].ref_count--; ThreadHandle[wid].ref_count--;
DEBUG_TLOCK_ACCESS(11, wid); DEBUG_TLOCK_ACCESS(11, wid);
pthread_mutex_unlock(&(ThreadHandle[wid].tlock)); pthread_mutex_unlock(&(ThreadHandle[wid].tlock));
@ -442,7 +439,7 @@ p_thread_join(void)
} }
UNLOCK(ThreadHandlesLock); UNLOCK(ThreadHandlesLock);
/* make sure this lock is accessible */ /* make sure this lock is accessible */
if (pthread_join(ThreadHandle[tid].handle, NULL) < 0) { if (pthread_join(ThreadHandle[tid].pthread_handle, NULL) < 0) {
/* ERROR */ /* ERROR */
return FALSE; return FALSE;
} }
@ -470,7 +467,7 @@ p_thread_detach(void)
Int tid = IntegerOfTerm(Deref(ARG1)); Int tid = IntegerOfTerm(Deref(ARG1));
pthread_mutex_lock(&(ThreadHandle[tid].tlock)); pthread_mutex_lock(&(ThreadHandle[tid].tlock));
DEBUG_TLOCK_ACCESS(14, tid); DEBUG_TLOCK_ACCESS(14, tid);
if (pthread_detach(ThreadHandle[tid].handle) < 0) { if (pthread_detach(ThreadHandle[tid].pthread_handle) < 0) {
/* ERROR */ /* ERROR */
DEBUG_TLOCK_ACCESS(15, tid); DEBUG_TLOCK_ACCESS(15, tid);
pthread_mutex_unlock(&(ThreadHandle[tid].tlock)); pthread_mutex_unlock(&(ThreadHandle[tid].tlock));

16
C/ypsocks.c Normal file → Executable file
View File

@ -659,7 +659,11 @@ p_socket_bind(void)
if (IsVarTerm(tport)) { if (IsVarTerm(tport)) {
/* get the port number */ /* get the port number */
#if _WIN32 || defined(__MINGW32__)
int namelen;
#else
unsigned int namelen; unsigned int namelen;
#endif
Term t; Term t;
if (getsockname(fd, (struct sockaddr *)&saddr, &namelen) < 0) { if (getsockname(fd, (struct sockaddr *)&saddr, &namelen) < 0) {
#if HAVE_STRERROR #if HAVE_STRERROR
@ -908,7 +912,11 @@ p_socket_accept(void)
struct sockaddr_in caddr; struct sockaddr_in caddr;
Term tcli; Term tcli;
char *s; char *s;
#if _WIN32 || defined(__MINGW32__)
int len;
#else
unsigned int len; unsigned int len;
#endif
len = sizeof(caddr); len = sizeof(caddr);
memset((void *)&caddr,(int) 0, sizeof(caddr)); memset((void *)&caddr,(int) 0, sizeof(caddr));
@ -950,7 +958,13 @@ p_socket_buffering(void)
Atom mode; Atom mode;
int fd; int fd;
int writing; int writing;
unsigned int bufsize, len; #if _WIN32 || defined(__MINGW32__)
int bufsize;
int len;
#else
unsigned int bufsize;
unsigned int len;
#endif
int sno; int sno;
if ((sno = Yap_CheckSocketStream(t1, "socket_buffering/4")) < 0) { if ((sno = Yap_CheckSocketStream(t1, "socket_buffering/4")) < 0) {

4
H/YapHeap.h Normal file → Executable file
View File

@ -209,7 +209,7 @@ typedef struct thandle {
REGSTORE *default_yaam_regs; REGSTORE *default_yaam_regs;
REGSTORE *current_yaam_regs; REGSTORE *current_yaam_regs;
struct pred_entry *local_preds; struct pred_entry *local_preds;
pthread_t handle; pthread_t pthread_handle;
int ref_count; int ref_count;
#ifdef LOW_LEVEL_TRACER #ifdef LOW_LEVEL_TRACER
long long int thread_inst_count; long long int thread_inst_count;
@ -218,7 +218,7 @@ typedef struct thandle {
#endif #endif
pthread_mutex_t tlock; pthread_mutex_t tlock;
pthread_mutex_t tlock_status; pthread_mutex_t tlock_status;
#if HAVE_GETRUSAGE #if HAVE_GETRUSAGE||defined(_WIN32)
struct timeval *start_of_timesp; struct timeval *start_of_timesp;
struct timeval *last_timep; struct timeval *last_timep;
#endif #endif

2
include/yap_structs.h Normal file → Executable file
View File

@ -161,7 +161,7 @@ typedef struct {
struct yami *p; struct yami *p;
} YAP_dogoalinfo; } YAP_dogoalinfo;
typedef int (*YAP_agc_hook)(YAP_Atom); typedef int (*YAP_agc_hook)(void *_Atom);
/********* execution mode ***********************/ /********* execution mode ***********************/

26
library/yap2swi/yap2swi.c Normal file → Executable file
View File

@ -584,7 +584,11 @@ X_API int PL_get_int64(term_t ts, int64_t *i)
return 0; return 0;
} }
mpz_get_str (s, 10, &g); mpz_get_str (s, 10, &g);
#ifdef _WIN32
sscanf(s, "%I64d", (long long int *)i);
#else
sscanf(s, "%lld", (long long int *)i); sscanf(s, "%lld", (long long int *)i);
#endif
return 1; return 1;
#endif #endif
} }
@ -907,7 +911,13 @@ X_API int PL_put_int64(term_t t, int64_t n)
char s[64]; char s[64];
MP_INT rop; 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); sprintf(s, "%lld", (long long int)n);
#endif
mpz_init_set_str (&rop, s, 10); mpz_init_set_str (&rop, s, 10);
Yap_PutInSlot(t,YAP_MkBigNumTerm((void *)&rop)); Yap_PutInSlot(t,YAP_MkBigNumTerm((void *)&rop));
return TRUE; return TRUE;
@ -1315,7 +1325,13 @@ X_API int PL_unify_int64(term_t t, int64_t n)
char s[64]; char s[64];
MP_INT rop; 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); sprintf(s, "%lld", (long long int)n);
#endif
mpz_init_set_str (&rop, s, 10); mpz_init_set_str (&rop, s, 10);
iterm = YAP_MkBigNumTerm((void *)&rop); iterm = YAP_MkBigNumTerm((void *)&rop);
return YAP_Unify(Yap_GetFromSlot(t),iterm); return YAP_Unify(Yap_GetFromSlot(t),iterm);
@ -1602,7 +1618,13 @@ X_API int PL_unify_term(term_t l,...)
char s[64]; char s[64];
MP_INT rop; 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)); sprintf(s, "%lld", va_arg(ap, long long int));
#endif
mpz_init_set_str (&rop, s, 10); mpz_init_set_str (&rop, s, 10);
*pt++ = YAP_MkBigNumTerm((void *)&rop); *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"))); return PL_error(NULL,0,NULL, ERR_EVALUATION, AtomToSWIAtom(Yap_LookupAtom("int_overflow")));
} }
mpz_get_str (s, 10, &g); mpz_get_str (s, 10, &g);
#ifdef _WIN32
sscanf(s, "%I64d", (long long int *)val);
#else
sscanf(s, "%lld", (long long int *)val); sscanf(s, "%lld", (long long int *)val);
#endif
return 1; return 1;
#endif #endif
} }