Skip to content

Commit

Permalink
shells/44bsd-csh: Replace local functions with malloc functions
Browse files Browse the repository at this point in the history
Local functions called sbrk(2) directly. sbrk(2) will disappear at some
point. Removing it now reduces the sbrk footprint and allows other
architectures that do not support sbrk(2) to install this port.
  • Loading branch information
cschuber committed Feb 19, 2025
1 parent 999be5f commit b0d746a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shells/44bsd-csh/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PORTNAME= 44bsd-csh
PORTVERSION= 20001106
PORTREVISION= 6
PORTREVISION= 7
CATEGORIES= shells
MASTER_SITES= LOCAL/cy

Expand Down
64 changes: 64 additions & 0 deletions shells/44bsd-csh/files/patch-alloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
--- alloc.c.orig 2025-02-18 15:59:35.263097000 -0800
+++ alloc.c 2025-02-18 16:02:58.402654000 -0800
@@ -55,61 +55,6 @@
char *memtop = NULL; /* PWP: top of current memory */
char *membot = NULL; /* PWP: bottom of allocatable memory */

-ptr_t
-Malloc(n)
- size_t n;
-{
- ptr_t ptr;
-
- if (membot == NULL)
- memtop = membot = sbrk(0);
- if ((ptr = malloc(n)) == (ptr_t) 0) {
- child++;
- stderror(ERR_NOMEM);
- }
- return (ptr);
-}
-
-ptr_t
-Realloc(p, n)
- ptr_t p;
- size_t n;
-{
- ptr_t ptr;
-
- if (membot == NULL)
- memtop = membot = sbrk(0);
- if ((ptr = realloc(p, n)) == (ptr_t) 0) {
- child++;
- stderror(ERR_NOMEM);
- }
- return (ptr);
-}
-
-ptr_t
-Calloc(s, n)
- size_t s, n;
-{
- ptr_t ptr;
-
- if (membot == NULL)
- memtop = membot = sbrk(0);
- if ((ptr = calloc(s, n)) == (ptr_t) 0) {
- child++;
- stderror(ERR_NOMEM);
- }
-
- return (ptr);
-}
-
-void
-Free(p)
- ptr_t p;
-{
- if (p)
- free(p);
-}
-
/*
* mstats - print out statistics about malloc
*
17 changes: 17 additions & 0 deletions shells/44bsd-csh/files/patch-csh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- csh.h.orig 2025-02-18 15:59:35.265140000 -0800
+++ csh.h 2025-02-18 16:04:08.969313000 -0800
@@ -86,10 +86,10 @@
#include "char.h"
#include "errnum.h"

-#define xmalloc(i) Malloc(i)
-#define xrealloc(p, i) Realloc(p, i)
-#define xcalloc(n, s) Calloc(n, s)
-#define xfree(p) Free(p)
+#define xmalloc(i) malloc(i)
+#define xrealloc(p, i) realloc(p, i)
+#define xcalloc(n, s) calloc(n, s)
+#define xfree(p) free(p)

#include <stdio.h>
FILE *cshin, *cshout, *csherr;

0 comments on commit b0d746a

Please sign in to comment.