1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-13 07:09:58 +00:00

Removes StrNCpyFromLispToC(), renames StrNCpyFromCToLisp to MemCpyToLispFromNative

Removes StrNCpyFromLispToC and the single use of it in
LispStringToCString in the BYTESWAP implementation case.

Rename StrNCpyFromCToLisp, which does NOT follow "strncpy" semantics,
to be MemCpyToLispFromNative, where the types in the name match the
types of the arguments, and the semantics (and argument order) are
those of the C library "memcpy".
This commit is contained in:
Nick Briggs 2025-07-25 14:12:30 -07:00
parent 428e7cf1a2
commit 364bc1f31c
5 changed files with 25 additions and 24 deletions

View File

@ -44,18 +44,17 @@
/* For getfileinfo. For WDATE&RDATE */
/* 29969152 == (timer.c)LISP_UNIX_TIME_DIFF */
#define StrNCpyFromCToLisp(lispbuf, cbuf ,len) do { \
char *lf_sptr = (cbuf); \
char *lf_dptr = (lispbuf); \
for(size_t lf_i=0;lf_i<(len);lf_i++)\
GETBYTE(lf_dptr++) = *lf_sptr++; \
} while (0)
#define StrNCpyFromLispToC(cbuf , lispbuf, len) do { \
char *lf_sptr = (lispbuf); \
char *lf_dptr = (cbuf); \
for(size_t lf_i=0;lf_i<(len);lf_i++)\
*lf_dptr++ = GETBYTE(lf_sptr++); \
/*
* Copy memory between native memory locations accounting for potential
* byte-swapping necessary when then destination is within Lisp memory space
* though the provided destination pointer is a native address within the
* Lisp space.
*/
#define MemCpyToLispFromNative(lispbuf, cbuf, len) \
do { \
char *lf_sptr = (cbuf); \
char *lf_dptr = (lispbuf); \
for (size_t lf_i = 0; lf_i < (len); lf_i++) *BYTEPTR(lf_dptr++) = *lf_sptr++; \
} while (0)
#define FGetNum(ptr, place) do { \
@ -122,8 +121,10 @@
case THIN_CHAR_TYPENUMBER: \
lf_base = ((char *)(NativeAligned2FromLAddr(lf_arrayp->base))) \
+ ((int)(lf_arrayp->offset)); \
StrNCpyFromLispToC(C , lf_base , lf_length ); \
(C)[lf_length] = '\0'; \
lf_dp = C; \
for (size_t lf_i = 0; lf_i < lf_length; lf_i++) \
*lf_dp++ = GETBYTE(lf_base++); \
*lf_dp = '\0'; \
break; \
\
case FAT_CHAR_TYPENUMBER: \

View File

@ -2159,7 +2159,7 @@ LispPTR COM_next_file(LispPTR *args)
#ifndef BYTESWAP
strncpy(base, fp->lname, fp->lname_len);
#else
StrNCpyFromCToLisp(base, fp->lname, fp->lname_len);
MemCpyToLispFromNative(base, fp->lname, fp->lname_len);
#endif /* BYTESWAP */
if (!propp) return (GetPosSmallp(fp->lname_len));
@ -2175,7 +2175,7 @@ LispPTR COM_next_file(LispPTR *args)
#ifndef BYTESWAP
strncpy(base, pp->author, pp->au_len);
#else
StrNCpyFromCToLisp(base, pp->author, pp->au_len);
MemCpyToLispFromNative(base, pp->author, pp->au_len);
#endif /* BYTESWAP */
gfsp->aulen = pp->au_len;

View File

@ -1034,7 +1034,7 @@ LispPTR DSK_getfilename(LispPTR *args)
#ifndef BYTESWAP
strncpy(base, lfname, len + 1);
#else
StrNCpyFromCToLisp(base, lfname, len + 1);
MemCpyToLispFromNative(base, lfname, len + 1);
#endif /* BYTESWAP */
return (GetPosSmallp(len));
@ -1070,7 +1070,7 @@ LispPTR DSK_getfilename(LispPTR *args)
#ifndef BYTESWAP
strncpy(base, lfname, len + 1);
#else
StrNCpyFromCToLisp(base, lfname, len + 1);
MemCpyToLispFromNative(base, lfname, len + 1);
#endif /* BYTESWAP */
return (GetPosSmallp(len));
@ -1509,7 +1509,7 @@ LispPTR DSK_directorynamep(LispPTR *args)
#ifndef BYTESWAP
strncpy(base, dirname, len + 1);
#else
StrNCpyFromCToLisp(base, dirname, len + 1);
MemCpyToLispFromNative(base, dirname, len + 1);
#endif /* BYTESWAP */
return (GetPosSmallp(len));
@ -1671,7 +1671,7 @@ LispPTR COM_getfileinfo(LispPTR *args)
#ifndef BYTESWAP
strncpy(base, pwd->pw_name, len);
#else
StrNCpyFromCToLisp(base, pwd->pw_name, len);
MemCpyToLispFromNative(base, pwd->pw_name, len);
#endif /* BYTESWAP */
#endif /* DOS */
return (GetPosSmallp(len));
@ -1710,7 +1710,7 @@ LispPTR COM_getfileinfo(LispPTR *args)
#ifndef BYTESWAP
strncpy(base, pwd->pw_name, len);
#else
StrNCpyFromCToLisp(base, pwd->pw_name, len);
MemCpyToLispFromNative(base, pwd->pw_name, len);
#endif /* BYTESWAP */
#endif /* DOS */
return (GetPosSmallp(len));

View File

@ -283,7 +283,7 @@ LispPTR mess_read(LispPTR *args)
if (temp_buf[i] == '\n') temp_buf[i] = '\000';
}
/* COPY actual Lisp Buffer(for BYTESWAP magic) */
StrNCpyFromCToLisp(base, temp_buf, size);
MemCpyToLispFromNative(base, temp_buf, size);
return (GetSmallp(size));
#else

View File

@ -218,7 +218,7 @@ LispPTR UFS_getfilename(LispPTR *args)
#ifndef BYTESWAP
strncpy(base, lfname, len + 1);
#else
StrNCpyFromCToLisp(base, lfname, len + 1);
MemCpyToLispFromNative(base, lfname, len + 1);
#endif /* BYTESWAP */
return (GetSmallp(len));
@ -422,7 +422,7 @@ LispPTR UFS_directorynamep(LispPTR *args)
#ifndef BYTESWAP
strncpy(base, dirname, len + 1);
#else
StrNCpyFromCToLisp(base, dirname, len + 1);
MemCpyToLispFromNative(base, dirname, len + 1);
#endif /* BYTESWAP */
return (GetSmallp(len));