1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

* Avoid redundant casting of argument numbers to char* and vice versa.

This commit is contained in:
Dirk Herrmann 2001-04-10 07:57:05 +00:00
parent 40f83c3e1b
commit e4b265d817
15 changed files with 87 additions and 61 deletions

View file

@ -1,3 +1,26 @@
2001-04-10 Dirk Herrmann <D.Herrmann@tu-bs.de>
* numbers.[ch] (scm_num2long, scm_num2long_long,
scm_num2ulong_long, scm_num2ulong): Argument position is an
unsigned integer.
* environments.c (eval_environment_folder,
import_environment_folder), gh_data.c (gh_scm2longs,
gh_scm2floats, gh_scm2doubles): Distinguish between 0 and NULL
for integers and pointers, respectively.
* gh_data.c (gh_scm2ulong, gh_scm2long, gh_scm2int), socket.c
(scm_fill_sockaddr), unif.c (scm_array_set_x), validate.h
(SCM_NUM2ULONG, SCM_NUM2LONG, SCM_NUM2LONG_DEF,
SCM_NUM2LONG_LONG): Don't pass argument positions as pointers.
* filesys.c (scm_open_fdes, scm_open), net_db (scm_inet_ntoa,
scm_inet_netof, scm_lnaof, scm_gethost, scm_getproto), posix.c
(scm_utime), ramap.c (scm_array_fill_int), scmsigs.c
(scm_sigaction), socket.c (scm_htonl, scm_ntohl, scm_sendto),
stime.c (scm_localtime, scm_gmtime), struct.c (scm_struct_set_x),
validate.h (SCM_VALIDATE_LONG_COPY): Whitespace fixes.
2001-04-09 Neil Jerram <neil@ossau.uklinux.net>
* strings.c (scm_read_only_string_p): Update docstring to reflect

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
/* Copyright (C) 1999,2000,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -1246,7 +1246,7 @@ eval_environment_folder (SCM extended_data, SCM symbol, SCM value, SCM tail)
if (!SCM_ENVIRONMENT_BOUND_P (local, symbol))
{
SCM proc_as_nr = SCM_CADR (extended_data);
unsigned long int proc_as_ul = scm_num2ulong (proc_as_nr, NULL, NULL);
unsigned long int proc_as_ul = scm_num2ulong (proc_as_nr, 0, NULL);
scm_environment_folder proc = (scm_environment_folder) proc_as_ul;
SCM data = SCM_CDDR (extended_data);
@ -1652,7 +1652,7 @@ import_environment_folder (SCM extended_data, SCM symbol, SCM value, SCM tail)
SCM imported_env = SCM_CADR (extended_data);
SCM owner = import_environment_lookup (import_env, symbol);
SCM proc_as_nr = SCM_CADDR (extended_data);
unsigned long int proc_as_ul = scm_num2ulong (proc_as_nr, NULL, NULL);
unsigned long int proc_as_ul = scm_num2ulong (proc_as_nr, 0, NULL);
scm_environment_folder proc = (scm_environment_folder) proc_as_ul;
SCM data = SCM_CDDDR (extended_data);

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
/* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -243,8 +243,8 @@ SCM_DEFINE (scm_open_fdes, "open-fdes", 2, 1, 0,
SCM_VALIDATE_STRING (1, path);
SCM_STRING_COERCE_0TERMINATION_X (path);
iflags = SCM_NUM2LONG(2,flags);
imode = SCM_NUM2LONG_DEF(3,mode,0666);
iflags = SCM_NUM2LONG (2, flags);
imode = SCM_NUM2LONG_DEF (3, mode, 0666);
SCM_SYSCALL (fd = open (SCM_STRING_CHARS (path), iflags, imode));
if (fd == -1)
SCM_SYSERROR;
@ -286,7 +286,7 @@ SCM_DEFINE (scm_open, "open", 2, 1, 0,
int iflags;
fd = SCM_INUM (scm_open_fdes (path, flags, mode));
iflags = SCM_NUM2LONG (2,flags);
iflags = SCM_NUM2LONG (2, flags);
if (iflags & O_RDWR)
{
if (iflags & O_APPEND)

View file

@ -229,18 +229,18 @@ gh_scm2bool (SCM obj)
unsigned long
gh_scm2ulong (SCM obj)
{
return scm_num2ulong (obj, (char *) SCM_ARG1, "gh_scm2ulong");
return scm_num2ulong (obj, SCM_ARG1, "gh_scm2ulong");
}
long
gh_scm2long (SCM obj)
{
return scm_num2long (obj, (char *) SCM_ARG1, "gh_scm2long");
return scm_num2long (obj, SCM_ARG1, "gh_scm2long");
}
int
gh_scm2int (SCM obj)
{
/* NOTE: possible loss of precision here */
return (int) scm_num2long (obj, (char *) SCM_ARG1, "gh_scm2int");
return (int) scm_num2long (obj, SCM_ARG1, "gh_scm2int");
}
double
gh_scm2double (SCM obj)
@ -395,7 +395,9 @@ gh_scm2longs (SCM obj, long *m)
for (i = 0; i < n; ++i)
{
val = SCM_VELTS (obj)[i];
m[i] = SCM_INUMP (val) ? SCM_INUM (val) : scm_num2long (val, 0, 0);
m[i] = SCM_INUMP (val)
? SCM_INUM (val)
: scm_num2long (val, 0, NULL);
}
break;
#ifdef HAVE_ARRAYS
@ -447,7 +449,7 @@ gh_scm2floats (SCM obj, float *m)
if (SCM_INUMP (val))
m[i] = SCM_INUM (val);
else if (SCM_BIGP (val))
m[i] = scm_num2long (val, 0, 0);
m[i] = scm_num2long (val, 0, NULL);
else
m[i] = SCM_REAL_VALUE (val);
}
@ -510,7 +512,7 @@ gh_scm2doubles (SCM obj, double *m)
if (SCM_INUMP (val))
m[i] = SCM_INUM (val);
else if (SCM_BIGP (val))
m[i] = scm_num2long (val, 0, 0);
m[i] = scm_num2long (val, 0, NULL);
else
m[i] = SCM_REAL_VALUE (val);
}

View file

@ -1,5 +1,5 @@
/* "net_db.c" network database support
* Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -119,7 +119,7 @@ SCM_DEFINE (scm_inet_ntoa, "inet-ntoa", 1, 0, 0,
struct in_addr addr;
char *s;
SCM answer;
addr.s_addr = htonl (SCM_NUM2ULONG (1,inetid));
addr.s_addr = htonl (SCM_NUM2ULONG (1, inetid));
s = inet_ntoa (addr);
answer = scm_makfromstr (s, strlen (s), 0);
return answer;
@ -137,7 +137,7 @@ SCM_DEFINE (scm_inet_netof, "inet-netof", 1, 0, 0,
#define FUNC_NAME s_scm_inet_netof
{
struct in_addr addr;
addr.s_addr = htonl (SCM_NUM2ULONG (1,address));
addr.s_addr = htonl (SCM_NUM2ULONG (1, address));
return scm_ulong2num ((unsigned long) inet_netof (addr));
}
#undef FUNC_NAME
@ -154,7 +154,7 @@ SCM_DEFINE (scm_lnaof, "inet-lnaof", 1, 0, 0,
#define FUNC_NAME s_scm_lnaof
{
struct in_addr addr;
addr.s_addr = htonl (SCM_NUM2ULONG (1,address));
addr.s_addr = htonl (SCM_NUM2ULONG (1, address));
return scm_ulong2num ((unsigned long) inet_lnaof (addr));
}
#undef FUNC_NAME
@ -288,7 +288,7 @@ SCM_DEFINE (scm_gethost, "gethost", 0, 1, 0,
}
else
{
inad.s_addr = htonl (SCM_NUM2ULONG (1,host));
inad.s_addr = htonl (SCM_NUM2ULONG (1, host));
entry = gethostbyaddr ((char *) &inad, sizeof (inad), AF_INET);
}
if (!entry)
@ -412,7 +412,7 @@ SCM_DEFINE (scm_getproto, "getproto", 0, 1, 0,
else
{
unsigned long protonum;
protonum = SCM_NUM2ULONG (1,protocol);
protonum = SCM_NUM2ULONG (1, protocol);
entry = getprotobynumber (protonum);
}
if (!entry)

View file

@ -4358,7 +4358,7 @@ scm_ulong2num (unsigned long sl)
long
scm_num2long (SCM num, char *pos, const char *s_caller)
scm_num2long (SCM num, unsigned long int pos, const char *s_caller)
{
if (SCM_INUMP (num)) {
return SCM_INUM (num);
@ -4402,7 +4402,7 @@ scm_num2long (SCM num, char *pos, const char *s_caller)
scm_out_of_range (s_caller, num);
}
} else {
scm_wrong_type_arg (s_caller, (int) pos, num);
scm_wrong_type_arg (s_caller, pos, num);
}
}
@ -4414,7 +4414,7 @@ scm_num2long (SCM num, char *pos, const char *s_caller)
#endif
long_long
scm_num2long_long (SCM num, char *pos, const char *s_caller)
scm_num2long_long (SCM num, unsigned long int pos, const char *s_caller)
{
if (SCM_INUMP (num)) {
return SCM_INUM (num);
@ -4453,12 +4453,12 @@ scm_num2long_long (SCM num, char *pos, const char *s_caller)
scm_out_of_range (s_caller, num);
}
} else {
scm_wrong_type_arg (s_caller, (int) pos, num);
scm_wrong_type_arg (s_caller, pos, num);
}
}
ulong_long
scm_num2ulong_long (SCM num, char *pos, const char *s_caller)
scm_num2ulong_long (SCM num, unsigned long int pos, const char *s_caller)
{
if (SCM_INUMP (num))
{
@ -4493,14 +4493,14 @@ scm_num2ulong_long (SCM num, char *pos, const char *s_caller)
scm_out_of_range (s_caller, num);
}
else
scm_wrong_type_arg (s_caller, (int) pos, num);
scm_wrong_type_arg (s_caller, pos, num);
}
#endif /* HAVE_LONG_LONGS */
unsigned long
scm_num2ulong (SCM num, char *pos, const char *s_caller)
scm_num2ulong (SCM num, unsigned long int pos, const char *s_caller)
{
if (SCM_INUMP (num)) {
long nnum = SCM_INUM (num);
@ -4531,7 +4531,7 @@ scm_num2ulong (SCM num, char *pos, const char *s_caller)
scm_out_of_range (s_caller, num);
}
} else {
scm_wrong_type_arg (s_caller, (int) pos, num);
scm_wrong_type_arg (s_caller, pos, num);
}
}

View file

@ -2,7 +2,7 @@
#ifndef NUMBERSH
#define NUMBERSH
/* Copyright (C) 1995, 1996, 1998, 2000 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996,1998,2000,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -290,15 +290,16 @@ extern SCM scm_dbl2big (double d);
extern double scm_big2dbl (SCM b);
extern SCM scm_long2num (long sl);
extern SCM scm_ulong2num (unsigned long sl);
extern long scm_num2long (SCM num, char *pos, const char *s_caller);
extern long scm_num2long (SCM num, unsigned long int pos,
const char *s_caller);
#ifdef HAVE_LONG_LONGS
extern SCM scm_long_long2num (long_long sl);
extern long_long scm_num2long_long (SCM num, char *pos,
extern long_long scm_num2long_long (SCM num, unsigned long int pos,
const char *s_caller);
extern ulong_long scm_num2ulong_long (SCM num, char *pos,
extern ulong_long scm_num2ulong_long (SCM num, unsigned long int pos,
const char *s_caller);
#endif
extern unsigned long scm_num2ulong (SCM num, char *pos,
extern unsigned long scm_num2ulong (SCM num, unsigned long int pos,
const char *s_caller);
extern void scm_init_numbers (void);

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -1095,12 +1095,12 @@ SCM_DEFINE (scm_utime, "utime", 1, 2, 0,
if (SCM_UNBNDP (actime))
SCM_SYSCALL (time (&utm_tmp.actime));
else
utm_tmp.actime = SCM_NUM2ULONG (2,actime);
utm_tmp.actime = SCM_NUM2ULONG (2, actime);
if (SCM_UNBNDP (modtime))
SCM_SYSCALL (time (&utm_tmp.modtime));
else
utm_tmp.modtime = SCM_NUM2ULONG (3,modtime);
utm_tmp.modtime = SCM_NUM2ULONG (3, modtime);
SCM_SYSCALL (rv = utime (SCM_STRING_CHARS (pathname), &utm_tmp));
if (rv != 0)

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1996, 1998, 2000, 2001 Free Software Foundation, Inc.
/* Copyright (C) 1996,1998,2000,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -551,7 +551,7 @@ scm_array_fill_int (SCM ra, SCM fill, SCM ignore)
}
case scm_tc7_uvect:
{ /* scope */
unsigned long f = SCM_NUM2ULONG (2,fill);
unsigned long f = SCM_NUM2ULONG (2, fill);
unsigned long *ve = (unsigned long *) SCM_VELTS (ra);
for (i = base; n--; i += inc)
@ -560,7 +560,7 @@ scm_array_fill_int (SCM ra, SCM fill, SCM ignore)
}
case scm_tc7_ivect:
{ /* scope */
long f = SCM_NUM2LONG (2,fill);
long f = SCM_NUM2LONG (2, fill);
long *ve = (long *) SCM_VELTS (ra);
for (i = base; n--; i += inc)
@ -582,7 +582,7 @@ scm_array_fill_int (SCM ra, SCM fill, SCM ignore)
#ifdef HAVE_LONG_LONGS
case scm_tc7_llvect:
{ /* scope */
long long f = SCM_NUM2LONG_LONG (2,fill);
long long f = SCM_NUM2LONG_LONG (2, fill);
long long *ve = (long long *) SCM_VELTS (ra);
for (i = base; n--; i += inc)

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -237,8 +237,8 @@ SCM_DEFINE (scm_sigaction, "sigaction", 1, 2, 0,
query_only = 1;
else if (SCM_EQ_P (scm_integer_p (handler), SCM_BOOL_T))
{
if (SCM_NUM2LONG (2,handler) == (long) SIG_DFL
|| SCM_NUM2LONG (2,handler) == (long) SIG_IGN)
if (SCM_NUM2LONG (2, handler) == (long) SIG_DFL
|| SCM_NUM2LONG (2, handler) == (long) SIG_IGN)
{
#ifdef HAVE_SIGACTION
action.sa_handler = (SIGRETTYPE (*) (int)) SCM_INUM (handler);

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1996,1997,1998, 2000, 2001 Free Software Foundation, Inc.
/* Copyright (C) 1996,1997,1998,2000,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -123,7 +123,7 @@ SCM_DEFINE (scm_htonl, "htonl", 1, 0, 0,
"unsigned long integer.")
#define FUNC_NAME s_scm_htonl
{
unsigned long c_in = SCM_NUM2ULONG (1,in);
unsigned long c_in = SCM_NUM2ULONG (1, in);
return scm_ulong2num (htonl (c_in));
}
#undef FUNC_NAME
@ -135,7 +135,7 @@ SCM_DEFINE (scm_ntohl, "ntohl", 1, 0, 0,
"a C unsigned long integer.")
#define FUNC_NAME s_scm_ntohl
{
unsigned long c_in = SCM_NUM2ULONG (1,in);
unsigned long c_in = SCM_NUM2ULONG (1, in);
return scm_ulong2num (ntohl (c_in));
}
#undef FUNC_NAME
@ -426,7 +426,7 @@ scm_fill_sockaddr (int fam, SCM address, SCM *args, int which_arg,
memset (soka, 0, sizeof (struct sockaddr_in));
soka->sin_family = AF_INET;
soka->sin_addr.s_addr =
htonl (scm_num2ulong (address, (char *) which_arg, proc));
htonl (scm_num2ulong (address, which_arg, proc));
*args = SCM_CDR (*args);
soka->sin_port = htons (SCM_INUM (isport));
*size = sizeof (struct sockaddr_in);
@ -874,7 +874,7 @@ SCM_DEFINE (scm_sendto, "sendto", 4, 0, 1,
else
{
SCM_VALIDATE_CONS (5,args_and_flags);
flg = SCM_NUM2ULONG (5,SCM_CAR (args_and_flags));
flg = SCM_NUM2ULONG (5, SCM_CAR (args_and_flags));
}
SCM_SYSCALL (rv = sendto (fd, SCM_STRING_CHARS (message),
SCM_STRING_LENGTH (message),

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995,1996,1997,1998, 1999, 2000, 2001 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -355,7 +355,7 @@ SCM_DEFINE (scm_localtime, "localtime", 1, 1, 0,
char **oldenv;
int err;
itime = SCM_NUM2LONG (1,time);
itime = SCM_NUM2LONG (1, time);
/* deferring interupts is essential since a) setzone may install a temporary
environment b) localtime uses a static buffer. */
@ -423,7 +423,7 @@ SCM_DEFINE (scm_gmtime, "gmtime", 1, 0, 0,
struct tm *bd_time;
SCM result;
itime = SCM_NUM2LONG (1,time);
itime = SCM_NUM2LONG (1, time);
SCM_DEFER_INTS;
bd_time = gmtime (&itime);
if (bd_time == NULL)

View file

@ -683,7 +683,7 @@ SCM_DEFINE (scm_struct_set_x, "struct-set!", 3, 0, 0,
#if 0
case 'i':
data[p] = SCM_NUM2LONG (3,val);
data[p] = SCM_NUM2LONG (3, val);
break;
case 'd':

View file

@ -1317,10 +1317,10 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
((char *) SCM_UVECTOR_BASE (v))[pos] = SCM_INUM (obj);
break;
case scm_tc7_uvect:
SCM_VELTS(v)[pos] = SCM_PACK (scm_num2ulong(obj, (char *)SCM_ARG2, FUNC_NAME));
SCM_VELTS(v)[pos] = SCM_PACK (scm_num2ulong(obj, SCM_ARG2, FUNC_NAME));
break;
case scm_tc7_ivect:
SCM_VELTS(v)[pos] = SCM_PACK (scm_num2long(obj, (char *)SCM_ARG2, FUNC_NAME));
SCM_VELTS(v)[pos] = SCM_PACK (scm_num2long (obj, SCM_ARG2, FUNC_NAME));
break;
case scm_tc7_svect:
SCM_ASRTGO (SCM_INUMP (obj), badobj);
@ -1328,7 +1328,7 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
break;
#ifdef HAVE_LONG_LONGS
case scm_tc7_llvect:
((long_long *) SCM_CELL_WORD_1 (v))[pos] = scm_num2long_long (obj, (char *)SCM_ARG2, FUNC_NAME);
((long_long *) SCM_CELL_WORD_1 (v))[pos] = scm_num2long_long (obj, SCM_ARG2, FUNC_NAME);
break;
#endif

View file

@ -1,5 +1,5 @@
/* $Id: validate.h,v 1.30 2001-03-17 13:34:21 dirk Exp $ */
/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
/* $Id: validate.h,v 1.31 2001-04-10 07:57:05 dirk Exp $ */
/* Copyright (C) 1999,2000,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -61,15 +61,15 @@
#define SCM_WRONG_TYPE_ARG(pos, obj) \
do { scm_wrong_type_arg (FUNC_NAME, pos, obj); } while (0)
#define SCM_NUM2ULONG(pos, arg) (scm_num2ulong (arg, (char *) pos, FUNC_NAME))
#define SCM_NUM2ULONG(pos, arg) (scm_num2ulong (arg, pos, FUNC_NAME))
#define SCM_NUM2LONG(pos, arg) (scm_num2long (arg, (char *) pos, FUNC_NAME))
#define SCM_NUM2LONG(pos, arg) (scm_num2long (arg, pos, FUNC_NAME))
#define SCM_NUM2LONG_DEF(pos, arg, def) \
(SCM_UNBNDP (arg) ? def : scm_num2long (arg, (char *) pos, FUNC_NAME))
(SCM_UNBNDP (arg) ? def : scm_num2long (arg, pos, FUNC_NAME))
#define SCM_NUM2LONG_LONG(pos, arg) \
(scm_num2long_long (arg, (char *) pos, FUNC_NAME))
(scm_num2long_long (arg, pos, FUNC_NAME))
#define SCM_OUT_OF_RANGE(pos, arg) \
do { scm_out_of_range_pos (FUNC_NAME, arg, SCM_MAKINUM (pos)); } while (0)
@ -162,7 +162,7 @@
#define SCM_VALIDATE_LONG_COPY(pos, k, cvar) \
do { \
cvar = SCM_NUM2LONG(pos, k); \
cvar = SCM_NUM2LONG (pos, k); \
} while (0)
#define SCM_VALIDATE_BIGINT(pos, k) SCM_MAKE_VALIDATE (pos, k, BIGP)