This commit is contained in:
Vitor Santos Costa
2018-06-30 14:33:32 +01:00
parent 6c1d3d1a95
commit 5f96c07131
90 changed files with 632 additions and 623 deletions

View File

@@ -26,7 +26,7 @@
*/
:- module(charsio, [
:- module(system(charsio), [
format_to_chars/3,
format_to_chars/4,
write_to_chars/3,

View File

@@ -593,7 +593,7 @@ Bfree
}
}
#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \
#define Bcopy(x,y) memmove((char *)&x->sign, (char *)&y->sign, \
y->wds*sizeof(Long) + 2*sizeof(int))
static Bigint *

View File

@@ -42,7 +42,7 @@ growBuffer(Buffer b, size_t minfree)
{ if ( !(new = malloc(sz)) )
return FALSE;
memcpy(new, b->static_buffer, osz);
memmove(new, b->static_buffer, osz);
} else
{ if ( !(new = realloc(b->base, sz)) )
return FALSE;

View File

@@ -2381,7 +2381,7 @@ re_buffer(IOSTREAM *s, const char *from, size_t len)
{ s->bufp = s->limitp = s->buffer;
}
memcpy(s->bufp, from, len);
memmove(s->bufp, from, len);
s->bufp += len;
}
@@ -5846,7 +5846,7 @@ struct PL_local_data *Yap_InitThreadIO(int wid)
return p;
}
#if THREADS
memcpy(p, Yap_local[0]->PL_local_data_p_, sizeof(struct PL_local_data));
memmove(p, Yap_local[0]->PL_local_data_p_, sizeof(struct PL_local_data));
#endif
return p;
}

View File

@@ -1426,7 +1426,7 @@ localizeDecimalPoint(PL_locale *locale, Buffer b)
if ( strncmp(e, ddp, ddplen) == 0 )
{ if ( dplen == ddplen )
{ memcpy(e, dp, dplen);
{ memmove(e, dp, dplen);
} else
{ char *ob = baseBuffer(b, char);
if ( dplen > ddplen && !growBuffer(b, dplen-ddplen) )
@@ -1434,7 +1434,7 @@ localizeDecimalPoint(PL_locale *locale, Buffer b)
e += baseBuffer(b, char) - ob;
memmove(&e[dplen-ddplen], e, strlen(e)+1);
memcpy(e, dp, dplen);
memmove(e, dp, dplen);
}
}
}
@@ -1477,7 +1477,7 @@ groupDigits(PL_locale *locale, Buffer b)
{ *o-- = *e--;
if ( --gsize == 0 && e>=s )
{ o -= thslen-1;
memcpy(o, ths, thslen);
memmove(o, ths, thslen);
o--;
if ( grouping[1] == 0 )
gsize = grouping[0];

View File

@@ -429,7 +429,7 @@ win_exec(size_t len, const wchar_t *cmd, UINT show)
/* ensure 0-terminated */
wcmd = PL_malloc((len+1)*sizeof(wchar_t));
memcpy(wcmd, cmd, len*sizeof(wchar_t));
memmove(wcmd, cmd, len*sizeof(wchar_t));
wcmd[len] = 0;
rval = CreateProcessW(NULL, /* app */

View File

@@ -953,7 +953,7 @@ getenv3(const char *name, char *buf, size_t len)
if ( s )
{ if ( (l=strlen(s)) < len )
memcpy(buf, s, l+1);
memmove(buf, s, l+1);
else if ( len > 0 )
buf[0] = EOS; /* empty string if not fit */

View File

@@ -253,7 +253,7 @@ static void growToBuffer(int c, ReadData _PL_rd) {
if (rb.base == rb.fast) /* intptr_t clause: jump to use malloc() */
{
rb.base = PL_malloc(FASTBUFFERSIZE * 2);
memcpy(rb.base, rb.fast, FASTBUFFERSIZE);
memmove(rb.base, rb.fast, FASTBUFFERSIZE);
} else
rb.base = PL_realloc(rb.base, rb.size * 2);

View File

@@ -491,7 +491,7 @@ Sread_readline(void *handle, char *buf, size_t size)
{ PL_warning("Input line too long"); /* must be tested! */
l = size-1;
}
memcpy(buf, line, l);
memmove(buf, line, l);
buf[l++] = '\n';
rval = l;

View File

@@ -239,7 +239,7 @@ S__setbuf(IOSTREAM *s, char *buffer, size_t size)
}
}
memcpy(newbuf, s->bufp, copy);
memmove(newbuf, s->bufp, copy);
S__removebuf(s);
s->unbuffer = newunbuf;
s->bufp = s->buffer = newbuf;
@@ -1173,7 +1173,7 @@ Speekcode(IOSTREAM *s)
if ( s->bufp + UNDO_SIZE > s->limitp && !(s->flags&SIO_USERBUF) )
{ safe = s->limitp - s->bufp;
memcpy(s->buffer-safe, s->bufp, safe);
memmove(s->buffer-safe, s->bufp, safe);
}
start = s->bufp;
@@ -1262,11 +1262,11 @@ Sfread(void *data, size_t size, size_t elms, IOSTREAM *s)
{ size_t avail = s->limitp - s->bufp;
if ( chars <= avail )
{ memcpy(buf, s->bufp, chars);
{ memmove(buf, s->bufp, chars);
s->bufp += chars;
return elms;
} else
{ memcpy(buf, s->bufp, avail);
{ memmove(buf, s->bufp, avail);
chars -= avail;
buf += avail;
s->bufp += avail;
@@ -1325,7 +1325,7 @@ Sread_pending(IOSTREAM *s, char *buf, size_t limit, int flags)
n = s->limitp - s->bufp;
if ( n > limit )
n = limit;
memcpy(&buf[done], s->bufp, n);
memmove(&buf[done], s->bufp, n);
s->bufp += n;
return done+n;
@@ -3439,7 +3439,7 @@ Swrite_memfile(void *handle, char *buf, size_t size)
}
if ( !mf->malloced )
{ if ( mf->buffer )
memcpy(nb, mf->buffer, mf->allocated);
memmove(nb, mf->buffer, mf->allocated);
mf->malloced = TRUE;
}
} else
@@ -3453,7 +3453,7 @@ Swrite_memfile(void *handle, char *buf, size_t size)
*mf->bufferp = mf->buffer = nb;
}
memcpy(&mf->buffer[mf->here], buf, size);
memmove(&mf->buffer[mf->here], buf, size);
mf->here += size;
if ( mf->here > mf->size )
@@ -3478,7 +3478,7 @@ Sread_memfile(void *handle, char *buf, size_t size)
size = mf->size - mf->here;
}
memcpy(buf, &mf->buffer[mf->here], size);
memmove(buf, &mf->buffer[mf->here], size);
mf->here += size;
return size;

View File

@@ -69,7 +69,7 @@ PL_save_text(PL_chars_t *text, int flags)
{ size_t bl = bufsize_text(text, text->length+1);
void *new = PL_malloc(bl);
memcpy(new, text->text.t, bl);
memmove(new, text->text.t, bl);
text->text.t = new;
text->storage = PL_CHARS_MALLOC;
} else if ( text->storage == PL_CHARS_LOCAL )
@@ -104,7 +104,7 @@ PL_from_stack_text(PL_chars_t *text)
{ size_t bl = bufsize_text(text, text->length+1);
if ( bl < sizeof(text->buf) )
{ memcpy(text->buf, text->text.t, bl);
{ memmove(text->buf, text->text.t, bl);
text->text.t = text->buf;
text->storage = PL_CHARS_LOCAL;
} else
@@ -135,7 +135,7 @@ ui64toa(uint64_t val, char *out)
} while ( val );
nbDigs = ptrOrg - ptr;
memcpy(out, ptr, nbDigs);
memmove(out, ptr, nbDigs);
out += nbDigs;
*out = '\0';
@@ -610,7 +610,7 @@ PL_promote_text(PL_chars_t *text)
unsigned char *e = &buf[text->length];
pl_wchar_t *t = (pl_wchar_t*)text->buf;
memcpy(buf, text->buf, text->length*sizeof(char));
memmove(buf, text->buf, text->length*sizeof(char));
while(f<e)
{ *t++ = *f++;
}
@@ -663,7 +663,7 @@ PL_demote_text(PL_chars_t *text)
pl_wchar_t *e = &buf[text->length];
char *t = text->buf;
memcpy(buf, text->buf, text->length*sizeof(pl_wchar_t));
memmove(buf, text->buf, text->length*sizeof(pl_wchar_t));
while(f<e)
{ if ( *f > 0xff )
return FALSE;
@@ -1021,7 +1021,7 @@ PL_canonise_text(PL_chars_t *text)
text->encoding = ENC_WCHAR;
if ( len+1 < sizeof(text->buf)/sizeof(wchar_t) )
{ if ( text->text.t == text->buf )
{ memcpy(b2, text->buf, sizeof(text->buf));
{ memmove(b2, text->buf, sizeof(text->buf));
from = b2;
}
text->text.w = (wchar_t*)text->buf;
@@ -1239,7 +1239,7 @@ PL_concat_text(int n, PL_chars_t **text, PL_chars_t *result)
}
for(to=result->text.t, i=0; i<n; i++)
{ memcpy(to, text[i]->text.t, text[i]->length);
{ memmove(to, text[i]->text.t, text[i]->length);
to += text[i]->length;
}
*to = EOS;
@@ -1257,7 +1257,7 @@ PL_concat_text(int n, PL_chars_t **text, PL_chars_t *result)
for(to=result->text.w, i=0; i<n; i++)
{ if ( text[i]->encoding == ENC_WCHAR )
{ memcpy(to, text[i]->text.w, text[i]->length*sizeof(pl_wchar_t));
{ memmove(to, text[i]->text.w, text[i]->length*sizeof(pl_wchar_t));
to += text[i]->length;
} else
{ const unsigned char *f = (const unsigned char *)text[i]->text.t;

View File

@@ -137,7 +137,7 @@ format_float(double f, char *buf)
{ *o++ = s[0];
*o++ = '.';
if ( end-s > 1 )
{ memcpy(o, s+1, end-s-1);
{ memmove(o, s+1, end-s-1);
o += end-s-1;
} else
*o++ = '0';
@@ -149,14 +149,14 @@ format_float(double f, char *buf)
*o++ = '.';
for(i=0; i < -decpt; i++)
*o++ = '0';
memcpy(o, s, end-s);
memmove(o, s, end-s);
o[end-s] = 0;
}
} else if ( end-s > decpt ) /* decimal dot inside */
{ memcpy(o, s, decpt);
{ memmove(o, s, decpt);
o += decpt;
*o++ = '.';
memcpy(o, s+decpt, end-s-decpt);
memmove(o, s+decpt, end-s-decpt);
o[end-s-decpt] = 0;
} else /* decimal dot after */
{ int i;
@@ -167,13 +167,13 @@ format_float(double f, char *buf)
*o++ = '.';
if ( end-s > 1 )
{ trailing += (int)(end-s)-1;
memcpy(o, s+1, end-s-1);
memmove(o, s+1, end-s-1);
o += end-s-1;
} else
*o++ = '0';
sprintf(o, "e+%d", trailing);
} else /* within precision trail with .0 */
{ memcpy(o, s, end-s);
{ memmove(o, s, end-s);
o += end-s;
for(i=(int)(end-s); i<decpt; i++)

View File

@@ -159,7 +159,7 @@ new_int_matrix(int ndims, int dims[], long int data[])
}
bdata = matrix_long_data(mat,ndims);
if (data)
memcpy((void *)bdata,(void *)data,sizeof(double)*nelems);
memmove((void *)bdata,(void *)data,sizeof(double)*nelems);
return blob;
}
@@ -193,7 +193,7 @@ new_float_matrix(int ndims, int dims[], double data[])
}
bdata = matrix_double_data(mat,ndims);
if (data)
memcpy((void *)bdata,(void *)data,sizeof(double)*nelems);
memmove((void *)bdata,(void *)data,sizeof(double)*nelems);
return blob;
}

View File

@@ -88,7 +88,7 @@ expand_buffer( int space )
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "out of memory" );
Yap_exit( EXIT_FAILURE );
}
memcpy( tmp, buf, bufsize );
memmove( tmp, buf, bufsize );
free( buf );
buf = tmp;
#else /* use realloc */

View File

@@ -1539,7 +1539,7 @@ sopno finish; /* to this less one */
return (ret);
enlarge(p, p->ssize + len); /* this many unexpected additions */
assert(p->ssize >= p->slen + len);
(void)memcpy((char *)(p->strip + p->slen), (char *)(p->strip + start),
(void)memmove((char *)(p->strip + p->slen), (char *)(p->strip + start),
(size_t)len * sizeof(sop));
p->slen += len;
return (ret);

View File

@@ -130,7 +130,7 @@ static int nope = 0; /* for use in asserts; shuts lint up */
#define SET0(v, n) ((v)[n] = 0)
#define SET1(v, n) ((v)[n] = 1)
#define ISSET(v, n) ((v)[n])
#define ASSIGN(d, s) memcpy(d, s, m->g->nstates)
#define ASSIGN(d, s) memmove(d, s, m->g->nstates)
#define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0)
#define STATEVARS \
long vn; \

View File

@@ -153,8 +153,8 @@ RL_Tree *copy_rl(RL_Tree *tree) {
free(new);
return NULL;
}
memcpy(new, tree, sizeof(RL_Tree));
memcpy(buf_ptr, &tree->root[0], tree->size * NODE_SIZE);
memmove(new, tree, sizeof(RL_Tree));
memmove(buf_ptr, &tree->root[0], tree->size * NODE_SIZE);
new->root = buf_ptr;
new->mem_alloc = tree->size *NODE_SIZE;
return new;

View File

@@ -167,7 +167,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
X = (const md5_word_t *)data;
} else {
/* not aligned */
memcpy(xbuf, data, 64);
memmove(xbuf, data, 64);
X = xbuf;
}
}
@@ -353,7 +353,7 @@ md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned int nbytes)
if (offset) {
unsigned int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
memcpy(pms->buf + offset, p, copy);
memmove(pms->buf + offset, p, copy);
if (offset + copy < 64)
return;
p += copy;
@@ -367,7 +367,7 @@ md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned int nbytes)
/* Process a final partial block. */
if (left)
memcpy(pms->buf, p, left);
memmove(pms->buf, p, left);
}
void

View File

@@ -114,7 +114,7 @@ typedef struct itrie_data {
YAP_Int i, new_num_buckets = DEPTH + BASE_TR_DATA_BUCKETS; \
bucket = TrEntry_buckets(TR_ENTRY); \
new_itrie_buckets(TR_ENTRY, new_num_buckets); \
memcpy(TrEntry_buckets(TR_ENTRY), bucket, \
memmove(TrEntry_buckets(TR_ENTRY), bucket, \
TrEntry_num_buckets(TR_ENTRY) * SIZEOF_TR_DATA_BUCKET); \
free_itrie_buckets(bucket, TrEntry_num_buckets(TR_ENTRY)); \
bucket = TrEntry_buckets(TR_ENTRY); \

View File

@@ -1468,12 +1468,12 @@ void traverse_and_print(TrNode node, int *arity, char *str, int str_index, int m
hash = (TrHash) node;
first_bucket = TrHash_buckets(hash);
bucket = first_bucket + TrHash_num_buckets(hash);
memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1));
memmove(current_arity, arity, sizeof(int) * (arity[0] + 1));
do {
if (*--bucket) {
node = *bucket;
traverse_and_print(node, arity, str, str_index, mode);
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
memmove(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
if (mode != TRIE_PRINT_FLOAT2 && arity[arity[0]] < 0) {
/* restore possible PairEndEmptyTag/PairEndTermTag/CommaEndTag side-effect */
if (str_index > 0 && str[str_index - 1] != '[')
@@ -1490,9 +1490,9 @@ void traverse_and_print(TrNode node, int *arity, char *str, int str_index, int m
if (TrNode_next(node)) {
int *current_arity = (int *) malloc(sizeof(int) * (arity[0] + 1));
memcpy(current_arity, arity, sizeof(int) * (arity[0] + 1));
memmove(current_arity, arity, sizeof(int) * (arity[0] + 1));
traverse_and_print(TrNode_next(node), arity, str, str_index, mode);
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
memmove(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
if (mode != TRIE_PRINT_FLOAT2 && arity[arity[0]] < 0) {
/* restore possible PairEndEmptyTag/PairEndTermTag/CommaEndTag side-effect */
if (str_index > 0 && str[str_index - 1] != '[')

View File

@@ -221,7 +221,7 @@ typedef struct trie_hash {
{ YAP_Term *aux_stack; \
YAP_Int aux_size = CURRENT_AUXILIARY_TERM_STACK_SIZE * sizeof(YAP_Term); \
new_struct(aux_stack, YAP_Term, aux_size * 2); \
memcpy(aux_stack, AUXILIARY_TERM_STACK, aux_size); \
memmove(aux_stack, AUXILIARY_TERM_STACK, aux_size); \
free_struct(AUXILIARY_TERM_STACK); \
AUXILIARY_TERM_STACK = aux_stack; \
CURRENT_AUXILIARY_TERM_STACK_SIZE *= 2; \