mescc: Mes C Library: Use casting functions.
Silence all casting errors by using casting functions. * lib/mes/cast.c: New file. * build-aux/configure-lib.sh (libmes_SOURCES): Add it. * lib/m2/cast.c: New file. * kaem.run: Add it. * simple.make: Add them both. * include/mes/lib.h: Add cast prototypes. * include/m2/lib.h: Likewise. * lib/linux/_getcwd.c (_getcwd): Use them. * lib/linux/access.c (access): Likewise. * lib/linux/brk.c (brk): Likewise. * lib/linux/chmod.c (chmod): Likewise. * lib/linux/clock_gettime.c (clock_gettime): Likewise. * lib/linux/gettimeofday.c (gettimeofday): Likewise. * lib/linux/unlink.c (unlink): Likewise. * lib/mes/fdputc.c (fdputc): Likewise. * lib/stdio/putchar.c (putchar): Likewise. * lib/linux/malloc.c (malloc): Likewise.
This commit is contained in:
parent
3b29abc850
commit
ca8e9f0342
|
@ -93,6 +93,7 @@ libmes_SOURCES="
|
||||||
$libc_mini_shared_SOURCES
|
$libc_mini_shared_SOURCES
|
||||||
lib/ctype/isnumber.c
|
lib/ctype/isnumber.c
|
||||||
lib/mes/abtol.c
|
lib/mes/abtol.c
|
||||||
|
lib/mes/cast.c
|
||||||
lib/mes/eputc.c
|
lib/mes/eputc.c
|
||||||
lib/mes/fdgetc.c
|
lib/mes/fdgetc.c
|
||||||
lib/mes/fdputc.c
|
lib/mes/fdputc.c
|
||||||
|
|
|
@ -30,6 +30,12 @@ int errno;
|
||||||
// CONSTANT EOF 0xffffffff
|
// CONSTANT EOF 0xffffffff
|
||||||
// CONSTANT __FILEDES_MAX 512
|
// CONSTANT __FILEDES_MAX 512
|
||||||
|
|
||||||
|
char* cast_intp_to_charp (int *i);
|
||||||
|
char* cast_long_to_charp (long i);
|
||||||
|
long cast_charp_to_long (char const *);
|
||||||
|
long cast_int_to_long (int i);
|
||||||
|
long cast_voidp_to_long (void const *);
|
||||||
|
|
||||||
char *itoa (int number);
|
char *itoa (int number);
|
||||||
char *ltoa (long number);
|
char *ltoa (long number);
|
||||||
int __ungetc_p (int filedes);
|
int __ungetc_p (int filedes);
|
||||||
|
|
|
@ -23,6 +23,18 @@
|
||||||
|
|
||||||
#include <mes/lib-mini.h>
|
#include <mes/lib-mini.h>
|
||||||
|
|
||||||
|
char* cast_intp_to_charp (int const *i);
|
||||||
|
char* cast_long_to_charp (long i);
|
||||||
|
long cast_charp_to_long (char const *);
|
||||||
|
long cast_int_to_long (int i);
|
||||||
|
long cast_voidp_to_long (void const *);
|
||||||
|
|
||||||
|
// #define cast_intp_to_charp(x) ((char*) x)
|
||||||
|
// #define cast_long_to_charp(x) ((char*) x)
|
||||||
|
// #define cast_charp_to_long(x) ((long) x)
|
||||||
|
// #define cast_int_to_long(x) ((long) x)
|
||||||
|
// #define cast_voidp_to_long(x) ((long) x)
|
||||||
|
|
||||||
int __mes_debug ();
|
int __mes_debug ();
|
||||||
void __ungetc_init ();
|
void __ungetc_init ();
|
||||||
void __ungetc_clear (int filedes);
|
void __ungetc_clear (int filedes);
|
||||||
|
|
1
kaem.run
1
kaem.run
|
@ -30,6 +30,7 @@ M2-Planet \
|
||||||
-f lib/linux/${mes_cpu}-mes-m2/_exit.c \
|
-f lib/linux/${mes_cpu}-mes-m2/_exit.c \
|
||||||
-f lib/linux/${mes_cpu}-mes-m2/_write.c \
|
-f lib/linux/${mes_cpu}-mes-m2/_write.c \
|
||||||
-f lib/mes/globals.c \
|
-f lib/mes/globals.c \
|
||||||
|
-f lib/m2/cast.c \
|
||||||
-f lib/m2/exit.c \
|
-f lib/m2/exit.c \
|
||||||
-f lib/mes/mini-write.c \
|
-f lib/mes/mini-write.c \
|
||||||
-f lib/linux/${mes_cpu}-mes-m2/syscall.c \
|
-f lib/linux/${mes_cpu}-mes-m2/syscall.c \
|
||||||
|
|
|
@ -18,14 +18,15 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <mes/lib-mini.h>
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
char *
|
char *
|
||||||
_getcwd (char *buffer, size_t size)
|
_getcwd (char *buffer, size_t size)
|
||||||
{
|
{
|
||||||
int r = _sys_call2 (SYS_getcwd, buffer, size);
|
long long_buffer = cast_charp_to_long (buffer);
|
||||||
|
int r = _sys_call2 (SYS_getcwd, long_buffer, size);
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
return buffer;
|
return buffer;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -18,13 +18,14 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
access (char const *file_name, int how)
|
access (char const *file_name, int how)
|
||||||
{
|
{
|
||||||
long long_file_name = file_name;
|
long long_file_name = cast_charp_to_long (file_name);
|
||||||
long long_how = how;
|
long long_how = cast_int_to_long (how);
|
||||||
return _sys_call2 (SYS_access, long_file_name, long_how);
|
return _sys_call2 (SYS_access, long_file_name, long_how);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,13 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
long
|
long
|
||||||
brk (void *addr)
|
brk (void *addr)
|
||||||
{
|
{
|
||||||
return _sys_call1 (SYS_brk, addr);
|
long long_addr = cast_voidp_to_long (addr);
|
||||||
|
return _sys_call1 (SYS_brk, long_addr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
int
|
int
|
||||||
chmod (char const *file_name, mode_t mask)
|
chmod (char const *file_name, mode_t mask)
|
||||||
{
|
{
|
||||||
long long_file_name = file_name;
|
long long_file_name = cast_charp_to_long (file_name);
|
||||||
long long_mask = mask;
|
long long_mask = cast_int_to_long (mask);
|
||||||
return _sys_call2 (SYS_chmod, long_file_name, long_mask);
|
return _sys_call2 (SYS_chmod, long_file_name, long_mask);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
int
|
int
|
||||||
clock_gettime (clockid_t clk_id, struct timespec *tp)
|
clock_gettime (clockid_t clk_id, struct timespec *tp)
|
||||||
{
|
{
|
||||||
long long_clk_id = clk_id;
|
long long_clk_id = cast_int_to_long (clk_id);
|
||||||
long long_tp = tp;
|
long long_tp = cast_voidp_to_long (tp);
|
||||||
return _sys_call2 (SYS_clock_gettime, clk_id, tp);
|
return _sys_call2 (SYS_clock_gettime, long_clk_id, long_tp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
int
|
int
|
||||||
gettimeofday (struct timeval *tv, struct timezone *tz)
|
gettimeofday (struct timeval *tv, struct timezone *tz)
|
||||||
{
|
{
|
||||||
long long_tv = tv;
|
long long_tv = cast_voidp_to_long (tv);
|
||||||
long long_tz = tz;
|
long long_tz = cast_voidp_to_long (tz);
|
||||||
return _sys_call2 (SYS_gettimeofday, long_tv, long_tz);
|
return _sys_call2 (SYS_gettimeofday, long_tv, long_tz);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ void *
|
||||||
malloc (size_t size)
|
malloc (size_t size)
|
||||||
{
|
{
|
||||||
if (!__brk)
|
if (!__brk)
|
||||||
__brk = (char *) brk (0);
|
__brk = cast_long_to_charp (brk (0));
|
||||||
/* align what we give back. */
|
/* align what we give back. */
|
||||||
__brk = (char*) (((uintptr_t) __brk
|
__brk = (char*) (((uintptr_t) __brk
|
||||||
+ sizeof (max_align_t) - 1) & -sizeof (max_align_t));
|
+ sizeof (max_align_t) - 1) & -sizeof (max_align_t));
|
||||||
|
|
|
@ -18,11 +18,13 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <linux/syscall.h>
|
#include <linux/syscall.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
unlink (char const *file_name)
|
unlink (char const *file_name)
|
||||||
{
|
{
|
||||||
return _sys_call1 (SYS_unlink, file_name);
|
long long_file_name = cast_charp_to_long (file_name);
|
||||||
|
return _sys_call1 (SYS_unlink, long_file_name);
|
||||||
}
|
}
|
||||||
|
|
57
lib/m2/cast.c
Normal file
57
lib/m2/cast.c
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
|
|
||||||
|
#undef cast_intp_to_charp
|
||||||
|
#undef cast_long_to_charp
|
||||||
|
#undef cast_charp_to_long
|
||||||
|
#undef cast_int_to_long
|
||||||
|
#undef cast_voidp_to_long
|
||||||
|
|
||||||
|
char*
|
||||||
|
cast_intp_to_charp (int const *i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
cast_long_to_charp (long i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_charp_to_long (char const *i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_int_to_long (int i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_voidp_to_long (void const *i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
57
lib/mes/cast.c
Normal file
57
lib/mes/cast.c
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of GNU Mes.
|
||||||
|
*
|
||||||
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* GNU Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
|
|
||||||
|
#undef cast_intp_to_charp
|
||||||
|
#undef cast_long_to_charp
|
||||||
|
#undef cast_charp_to_long
|
||||||
|
#undef cast_int_to_long
|
||||||
|
#undef cast_voidp_to_long
|
||||||
|
|
||||||
|
char*
|
||||||
|
cast_intp_to_charp (int const *i)
|
||||||
|
{
|
||||||
|
return (char*)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
cast_long_to_charp (long i)
|
||||||
|
{
|
||||||
|
return (char*)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_charp_to_long (char const *i)
|
||||||
|
{
|
||||||
|
return (long)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_int_to_long (int i)
|
||||||
|
{
|
||||||
|
return (long)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
cast_voidp_to_long (void const *i)
|
||||||
|
{
|
||||||
|
return (long)i;
|
||||||
|
}
|
|
@ -23,7 +23,7 @@
|
||||||
int
|
int
|
||||||
fdputc (int c, int fd)
|
fdputc (int c, int fd)
|
||||||
{
|
{
|
||||||
char *p = &c;
|
char *p = cast_intp_to_charp (&c);
|
||||||
write (fd, p, 1);
|
write (fd, p, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,13 @@
|
||||||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <mes/lib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
putchar (int c)
|
putchar (int c)
|
||||||
{
|
{
|
||||||
char *p = &c;
|
char *p = cast_intp_to_charp (&c);
|
||||||
write (__stdout, p, 1);
|
write (__stdout, p, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,12 +44,7 @@ CFLAGS:= \
|
||||||
-D 'MES_VERSION="git"' \
|
-D 'MES_VERSION="git"' \
|
||||||
-D 'MES_PKGDATADIR="/usr/local/share/mes"' \
|
-D 'MES_PKGDATADIR="/usr/local/share/mes"' \
|
||||||
-I include \
|
-I include \
|
||||||
-fno-builtin \
|
-fno-builtin
|
||||||
-Wno-discarded-qualifiers \
|
|
||||||
-Wno-discarded-array-qualifiers \
|
|
||||||
-Wno-ignored-qualifiers \
|
|
||||||
-Wno-incompatible-pointer-types \
|
|
||||||
-Wno-int-conversion
|
|
||||||
|
|
||||||
LIBMES_SOURCES = \
|
LIBMES_SOURCES = \
|
||||||
src/builtins.c \
|
src/builtins.c \
|
||||||
|
@ -81,6 +76,7 @@ M2_SOURCES = \
|
||||||
lib/linux/x86-mes-m2/crt1.c \
|
lib/linux/x86-mes-m2/crt1.c \
|
||||||
lib/linux/x86-mes-m2/_exit.c \
|
lib/linux/x86-mes-m2/_exit.c \
|
||||||
lib/linux/x86-mes-m2/_write.c \
|
lib/linux/x86-mes-m2/_write.c \
|
||||||
|
lib/m2/cast.c \
|
||||||
lib/m2/exit.c \
|
lib/m2/exit.c \
|
||||||
lib/mes/write.c \
|
lib/mes/write.c \
|
||||||
lib/linux/x86-mes-m2/syscall.c \
|
lib/linux/x86-mes-m2/syscall.c \
|
||||||
|
@ -162,6 +158,7 @@ MES_LIBC = \
|
||||||
|
|
||||||
GCC_SOURCES = \
|
GCC_SOURCES = \
|
||||||
lib/mes/__mes_debug.c \
|
lib/mes/__mes_debug.c \
|
||||||
|
lib/mes/cast.c \
|
||||||
lib/mes/eputc.c \
|
lib/mes/eputc.c \
|
||||||
lib/mes/eputs.c \
|
lib/mes/eputs.c \
|
||||||
lib/mes/fdgetc.c \
|
lib/mes/fdgetc.c \
|
||||||
|
|
Loading…
Reference in a new issue