Commit 6465cfc
committed
Further modernise the stk(3) stack routines (re: f619b48)
*** Void pointers ***
The stk(3) interface used char pointers throughout for K&R C and
C++ compatibility. I gave up all pretense of that long ago (see
a34e831) and we now use C89/C90 as our lowest common denominator,
so we're allowed to use void pointers.
The stkalloc(), stkset(), stkseek() and stkfreeze() functions now
return void* instead of char*. This should compatible with old code
as implicit typecasts are done. I scanned all the uses of these in
current code as well as the complete ast-open-history repo and
didn't find problems, nor does 'clang -Wall' throw any warnings.
So, no changes should be required. However, this change does allow
eliminating a lot of verbose/annoying typecasts from the code, as
void pointers can be assigned/passed to all sorts of types. This
commit removes those explicit typecasts, improving code legibility.
The stkcopy() and stkptr() functions continue to return char*, as
the first is purely for copying strings and the second's result is
often dereferenced directly to read individual bytes on the stack.
*** Deprecate/disuse stkinstall() ***
The old stak(3) interface did not pass stack pointers to every
function, so to use multiple stacks, one had to be "installed"
(activated) and there was only one "active" stack at the time. The
new interface has stkinstall() for backward compatibility with this
practice; it updates the stack that stkstd refers to. But this is
completely redundant as it's much more efficient to simply change
the pointer passed to the stack functions. So stkinstall() is
deprecated and its use replaced accordingly in the following files:
- src/lib/libast/misc/glob.c
- src/cmd/ksh93/sh/parse.c
- src/cmd/ksh93/sh/trestore.c
*** Add stkoverflow() ***
In typical AT&T fashion, stkinstall() had another, unrelated
function: set a pointer to a char* function called when the system
runs out of memory to allocate new stack frames. It can either find
memory somewhere and return a pointer, or error out. stkinstall()
did not allow unsetting this function pointer to restore the
default. This commit adds a replacement stkoverflow() function that
sets this function (now of type void*) or restores the default.
(The unset functionality is currently unused but may come in handy
someday and in any case it's trivial.)
This is currently used in:
- src/cmd/ksh93/sh/init.c
*** Bump libast API version ***
In src/lib/libast/features/api, the libast API version is bumped to
20240227 due to the changes above.
*** Rework stk(3) manual page ***
Rewrote parts to match current practice, e.g., removed references
to "the active stack" which never really applied to stk(3).
*** Restore stak.h ***
Perhaps it was overzealous to remove that in the referenced commit.
It's a small header file that simply maps the old stak(3) interface
onto stk(3) using some #defines. It remains unused, but the cost of
having it is negligible and restoring it restores compatbility with
old code we might want to test or backport at some point.1 parent 6628b52 commit 6465cfc
File tree
37 files changed
+316
-257
lines changed- src
- cmd/ksh93
- bltins
- edit
- features
- include
- sh
- lib
- libast
- features
- include
- man
- misc
- regex
- libcmd
37 files changed
+316
-257
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
665 | 665 | | |
666 | 666 | | |
667 | 667 | | |
668 | | - | |
| 668 | + | |
669 | 669 | | |
670 | 670 | | |
671 | 671 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | | - | |
| 236 | + | |
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| |||
1607 | 1607 | | |
1608 | 1608 | | |
1609 | 1609 | | |
1610 | | - | |
| 1610 | + | |
1611 | 1611 | | |
1612 | 1612 | | |
1613 | 1613 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
281 | | - | |
| 280 | + | |
| 281 | + | |
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
| 371 | + | |
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
681 | 681 | | |
682 | 682 | | |
683 | 683 | | |
684 | | - | |
| 684 | + | |
685 | 685 | | |
686 | 686 | | |
687 | 687 | | |
| |||
724 | 724 | | |
725 | 725 | | |
726 | 726 | | |
727 | | - | |
| 727 | + | |
728 | 728 | | |
729 | 729 | | |
730 | 730 | | |
| |||
752 | 752 | | |
753 | 753 | | |
754 | 754 | | |
755 | | - | |
| 755 | + | |
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
434 | | - | |
| 434 | + | |
435 | 435 | | |
436 | 436 | | |
437 | 437 | | |
438 | 438 | | |
439 | 439 | | |
440 | | - | |
| 440 | + | |
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
500 | | - | |
| 500 | + | |
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
| |||
0 commit comments