Skip to content

Commit

Permalink
another round of minor tweaks and cleanups
Browse files Browse the repository at this point in the history
Notable changes:

Many files:
- Eliminate redundant typecasts in free(3) calls

src/lib/libast/cdt/dttree.c:
- Remove unused Dttree global variable

src/lib/libast/features/lib:
- Remove unused tests for catopen(3), catclose(3), catgets(3)
  • Loading branch information
McDutchie committed Mar 23, 2024
1 parent d3fdc45 commit 97e6a52
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 45 deletions.
11 changes: 5 additions & 6 deletions src/cmd/ksh93/TYPES
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
### User-defined variable types in ksh93 ###

The ability for users to define types has been added to ksh93t.
Here is a quick summary of how types are defined and used in ksh93t.
This is still a work in progress so some changes and additions
are likely.
The ability for users to define types is available as of ksh version 93t.
Here is an overview of how types are defined and used in ksh93.

A type can be defined either by a shared library or by using the new
typeset -T option to the shell. The method for defining types via
A type can be defined either by a shared library or by using the -T option
option to the shell's typeset command. The method for defining types via
a shared library is not described here. However, the source file
bltins/enum.c is an example of a builtin that creates enumeration types.

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/bltins/cd_pwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
if(*dp && (*dp!='.'||dp[1]) && strchr(dir,'/'))
sfputr(sfstdout,dir,'\n');
nv_putval(opwdnod,oldpwd,NV_RDONLY);
free((void*)sh.pwd);
free(sh.pwd);
if(*dir == '/')
{
size_t len = strlen(dir);
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/bltins/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int b_exec(int argc,char *argv[], Shbltin_t *context)
sh_onstate(SH_EXEC);
if(sh.subshell && !sh.subshare)
{
struct dolnod *dp = stkalloc(sh.stk, sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argc*sizeof(char*));;
struct dolnod *dp = stkalloc(sh.stk, sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argc*sizeof(char*));
struct comnod *t = stkalloc(sh.stk,sizeof(struct comnod));
memset(t, 0, sizeof(struct comnod));
dp->dolnum = argc;
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/bltins/whence.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -322,7 +322,7 @@ static int whence(char **argv, int flags)
sfputr(sfstdout,is_pathbound_builtin ? "builtin" : "file",'\n');
else
sfputr(sfstdout,sh_fmtq(cp),'\n');
free((char*)cp);
free(cp);
}
else if(aflag<=1)
{
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/edit/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void hist_close(History_t *hp)
sfclose(hp->auditfp);
}
#endif /* SHOPT_AUDIT */
free((char*)hp);
free(hp);
hist_ptr = 0;
sh.hist_ptr = 0;
#if SHOPT_ACCTFILE
Expand Down Expand Up @@ -480,7 +480,7 @@ static History_t* hist_trim(History_t *hp, int n)
}
hist_cancel(hist_new);
sfclose(hist_old->histfp);
free((char*)hist_old);
free(hist_old);
return hist_ptr = hist_new;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/argnod.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct dolnod
int dolmax; /* size of dolval array */
int dolnum; /* number of elements */
int dolbot; /* current first element */
struct dolnod *dolnxt; /* used when list are chained */
struct dolnod *dolnxt; /* used when lists are chained */
char *dolval[1]; /* array of value pointers */
};

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/shnodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ static void array_copytree(Namval_t *np, Namval_t *mp)
nv_offattr(np,NV_ARRAY);
nv_clone(np,mp,0);
if(np->nvalue.cp && !nv_isattr(np,NV_NOFREE))
free((void*)np->nvalue.cp);
free(np->nvalue.cp);
np->nvalue.cp = 0;
np->nvalue.up = &mp->nvalue;
fp->nofree &= ~1;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/fcin.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int fcfopen(Sfio_t* f)
n = sfvalue(f);
fcrestore(&save);
sfread(f,buff,0);
_Fcin.fcoff = sftell(f);;
_Fcin.fcoff = sftell(f);
buff = (char*)sfreserve(f,SFIO_UNBOUND,SFIO_LOCKR);
_Fcin.fclast = (_Fcin.fcptr=_Fcin.fcbuff=(unsigned char*)buff)+n;
if(sffileno(f) >= 0)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ static void fixargs(char **argv, int mode)
/* Move the environment to make space for a larger command line buffer */
for(i=0; environ[i]; i++)
{
buffsize += strlen(environ[i]) + 1;;
buffsize += strlen(environ[i]) + 1;
environ[i] = sh_strdup(environ[i]);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/ksh93/sh/name.c
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ void nv_putval(Namval_t *np, const char *string, int flags)
if(flags&(NV_NOREF|NV_NOFREE))
{
if(np->nvalue.cp && np->nvalue.cp!=sp && !nv_isattr(np,NV_NOFREE))
free((void*)np->nvalue.cp);
free(np->nvalue.cp);
np->nvalue.cp = (char*)sp;
nv_setattr(np,(flags&~NV_RDONLY)|NV_NOFREE);
return;
Expand Down Expand Up @@ -1939,7 +1939,7 @@ void nv_putval(Namval_t *np, const char *string, int flags)
{
if(tofree)
{
free((void*)tofree);
free(tofree);
nv_offattr(np,NV_NOFREE);
}
up->cp = sp;
Expand Down Expand Up @@ -2042,7 +2042,7 @@ void nv_putval(Namval_t *np, const char *string, int flags)
if(flags&NV_APPEND)
stkseek(sh.stk,offset);
if(tofree && tofree!=Empty && tofree!=AltEmpty)
free((void*)tofree);
free(tofree);
}
if(!was_local && ((flags&NV_EXPORT) || nv_isattr(np,NV_EXPORT)))
env_change();
Expand Down Expand Up @@ -2484,7 +2484,7 @@ void _nv_unset(Namval_t *np,int flags)
if(up && up->cp)
{
if(up->cp!=Empty && up->cp!=AltEmpty && !nv_isattr(np, NV_NOFREE))
free((void*)up->cp);
free(up->cp);
up->cp = 0;
}
done:
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/sh/nvtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes)
else if(nv_isattr(np,NV_LJUST|NV_RJUST))
memset((char*)nq->nvalue.cp,' ',dsize);
if(!j)
free((void*)np->nvalue.cp);
free(np->nvalue.cp);
}
if(!nq->nvalue.cp && nq->nvfun== &pp->childfun.fun)
{
Expand Down Expand Up @@ -1327,7 +1327,7 @@ int nv_settype(Namval_t* np, Namval_t *tp, int flags)
np->nvalue.up = 0;
nv_clone(tp,np,flags|NV_NOFREE);
if(np->nvalue.cp && np->nvalue.cp!=Empty && !nv_isattr(np,NV_NOFREE))
free((void*)np->nvalue.cp);
free(np->nvalue.cp);
np->nvalue.up = 0;
nofree = ap->hdr.nofree;
ap->hdr.nofree = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ char *path_pwd(void)
{
if(*sh.pwd=='/')
return (char*)sh.pwd;
free((void*)sh.pwd);
free(sh.pwd);
}
/* First see if PWD variable is correct */
pwdnod = sh_scoped(PWDNOD);
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/ksh93/sh/subshell.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static void nv_restore(struct subshell *sp)
else
mp->nvalue = np->nvalue;
if(nofree && np->nvfun && !np->nvfun->nofree)
free((char*)np->nvfun);
free(np->nvfun);
np->nvfun = 0;
if(nv_isattr(mp,NV_EXPORT))
{
Expand Down Expand Up @@ -836,7 +836,7 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub)
else if(sp->pwd && strcmp(sp->pwd,sh.pwd))
path_newdir(sh.pathlist);
if(sh.pwd)
free((void*)sh.pwd);
free(sh.pwd);
sh.pwd = sp->pwd;
#if _lib_fchdir
if(sp->pwdclose)
Expand Down Expand Up @@ -918,7 +918,7 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub)
case 2:
/* reinit PWD as it will be wrong */
if(sh.pwd)
free((void*)sh.pwd);
free(sh.pwd);
sh.pwd = NULL;
path_pwd();
errno = saveerrno;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/tdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/tests/attributes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# #
# This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property #
# Copyright (c) 2020-2023 Contributors to ksh 93u+m #
# Copyright (c) 2020-2024 Contributors to ksh 93u+m #
# and is licensed under the #
# Eclipse Public License, Version 2.0 #
# #
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/tests/builtins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ exp='\\ \\\\'
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
case $(PATH=/opt/ast/bin:$PATH; exec cat '--???SECTION' 2>&1) in
case $(PATH=/opt/ast/bin:$PATH; exec cat '--???SECTION' </dev/null 2>&1) in
1) err_exit "'exec' runs non-external command" ;;
esac
Expand Down
5 changes: 2 additions & 3 deletions src/lib/libast/cdt/dtlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -170,8 +170,7 @@ static void* dtlist(Dt_t* dt, void* obj, int type)
goto do_insert;
}
else if(type&(DT_INSERT|DT_INSTALL|DT_APPEND|DT_ATTACH))
{
if(!(r = _dtmake(dt, obj, type)) )
{ if(!(r = _dtmake(dt, obj, type)) )
DTRETURN(obj, NULL);
dt->data->size += 1;

Expand Down
6 changes: 1 addition & 5 deletions src/lib/libast/cdt/dttree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -638,10 +638,6 @@ static Dtmethod_t _Dtobag = { dttree, DT_OBAG, treeevent, "Dtobag" };
Dtmethod_t *Dtoset = &_Dtoset;
Dtmethod_t *Dtobag = &_Dtobag;

/* backward compatibility */
#undef Dttree
Dtmethod_t *Dttree = &_Dtoset;

#ifdef NoF
NoF(dttree)
#endif
2 changes: 1 addition & 1 deletion src/lib/libast/features/lib
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dat _tzname,tzname

lib BSDsetpgrp
lib _cleanup
lib bcopy,bzero,catclose,catgets,catopen,confstr,dirread,dup2
lib bcopy,bzero,confstr,dirread,dup2
lib execlp,execve,execvp,execvpe
lib fchmod,fcntl,fmtmsg,fnmatch,fork,fsync
lib getconf,getdents,getdirentries,getdtablesize,getdate
Expand Down
3 changes: 3 additions & 0 deletions src/lib/libast/features/nl_types
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ tst output{
printf("\n");
return 0;
}
}end fail{
echo "$0: Output block failed to compile. Export IFFEFLAGS=-d1 to debug." >&2
exit 1
}end
6 changes: 3 additions & 3 deletions src/lib/libast/hash/hashlook.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -191,7 +191,7 @@ hashlook(Hash_table_t* tab, const char* name, long flags, const char* value)
if (name)
{
if (tab->root->local->region) (*tab->root->local->region)(tab->root->local->handle, (char*)name, 0, 0);
else free((char*)name);
else free(name);
}
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ hashlook(Hash_table_t* tab, const char* name, long flags, const char* value)
{
b->hash &= ~HASH_FREENAME;
if (tab->root->local->region) (*tab->root->local->region)(tab->root->local->handle, (char*)name, 0, 0);
else free((char*)name);
else free(name);
}
tab->buckets--;
tab->table[n] = b->next;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libast/regex/regclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ regclass(const char* s, char** e)
cp->size = 0;
if (!streq(cp->name, s))
{
free((char*)cp->name);
free(cp->name);
cp->name = 0;
}
}
Expand All @@ -241,7 +241,7 @@ regclass(const char* s, char** e)
/* mvs.390 needs the (char*) cast -- barf */
if (!(cp->wtype = wctype((char*)cp->name)))
{
free((char*)cp->name);
free(cp->name);
cp->name = 0;
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/sfio/sfmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static int _sfpmode(Sfio_t* f, int type)
p->ndata = f->endb-f->next;
if(p->ndata > p->size)
{ if(p->rdata)
free((char*)p->rdata);
free(p->rdata);
if((p->rdata = (uchar*)malloc(p->ndata)) )
p->size = p->ndata;
else
Expand Down

0 comments on commit 97e6a52

Please sign in to comment.