1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-17 23:06:25 -05:00

Compare commits

...

2 Commits

11 changed files with 114 additions and 109 deletions

View File

@ -40,17 +40,17 @@
/* Dynamic RAM tracking and reporting redefinitions */ /* Dynamic RAM tracking and reporting redefinitions */
#define RAMSIZE 0 /* dynamic RAM memory usage tracking */ #define RAMSIZE 0 /* dynamic RAM memory usage tracking */
#if RAMSIZE #if RAMSIZE
# define RAMSHOW 1 /* auto dynamic RAM reporting */ # define RAMSHOW 1 /* auto dynamic RAM reporting */
# include <stdlib.h> # include <stdlib.h> /* size_t */
void *allocate( size_t size) ; void *allocate( size_t size) ;
void release( void *ptr) ; void release( void *ptr) ;
# define malloc allocate # define malloc( sz) allocate(sz)
# define free release # define free( ptr) release( ptr)
#endif #endif
/* De-allocate memory always on exit (if the operating system or main /* De-allocate memory always on exit (if the operating system or main
program can not program can not)
*/ */
#define CLEAN 0 /* de-alloc memory on exit */ #define CLEAN 0 /* de-alloc memory on exit */
#if CLEAN #if CLEAN

View File

@ -16,6 +16,8 @@
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -26,7 +28,6 @@
#include "termio.h" #include "termio.h"
#include "terminal.h" #include "terminal.h"
#include "version.h" #include "version.h"
#include "wrapper.h"
#include "utf8.h" #include "utf8.h"
#include "window.h" #include "window.h"
@ -101,12 +102,51 @@ static int newscreensize( int h, int w) ;
#endif #endif
/* xmalloc is used at early initialization before memory usage tracking is
enabled so it bypass the memory tracking macroes.
*/
static void *xmalloc( size_t size) {
void *ret = (malloc)( size) ;
if( !ret) {
fprintf( stderr, "fatal: Out of memory\n") ;
exit( EXIT_FAILURE) ;
}
return ret ;
}
/* Initialize the data structures used by the display code. The edge /* Initialize the data structures used by the display code. The edge
vectors used to access the screens are set up. The operating system's vectors used to access the screens are set up. The operating system's
terminal I/O channel is set up. All the other things get initialized at terminal I/O channel is set up. All the other things get initialized at
compile time. The original window has "WFCHG" set, so that it will get compile time. The original window has "WFCHG" set, so that it will get
completely redrawn on the first call to "update". completely redrawn on the first call to "update".
*/ */
static int lastmrow ; /* remember mrow for later free */
static void vtalloc( int maxrow, int maxcol) {
lastmrow = maxrow ; /* remember mrow for later free */
vscreen = xmalloc( maxrow * sizeof( video_p )) ;
#if MEMMAP == 0 || SCROLLCODE
pscreen = xmalloc( maxrow * sizeof( video_p )) ;
#endif
for( int i = 0 ; i < maxrow ; ++i) {
video_p vp = xmalloc( sizeof *vp + maxcol * sizeof( unicode_t)) ;
vp->v_flag = 0 ;
#if COLOR
vp->v_rfcolor = 7 ;
vp->v_rbcolor = 0 ;
#endif
vscreen[ i] = vp ;
#if MEMMAP == 0 || SCROLLCODE
vp = xmalloc( sizeof *vp + maxcol * sizeof( unicode_t)) ;
vp->v_flag = 0 ;
pscreen[ i] = vp ;
#endif
}
}
void vtinit( void) { void vtinit( void) {
#ifdef SIGWINCH #ifdef SIGWINCH
signal( SIGWINCH, sizesignal) ; signal( SIGWINCH, sizesignal) ;
@ -116,43 +156,26 @@ void vtinit( void) {
TTopen() ; /* open the screen */ TTopen() ; /* open the screen */
TTkopen() ; /* open the keyboard */ TTkopen() ; /* open the keyboard */
TTrev( FALSE) ; TTrev( FALSE) ;
vscreen = xmalloc( term.t_maxrow * sizeof( video_p )) ; vtalloc( term.t_mrow, term.t_mcol) ;
#if MEMMAP == 0 || SCROLLCODE
pscreen = xmalloc( term.t_maxrow * sizeof( video_p )) ;
#endif
for( int i = 0 ; i < term.t_maxrow ; ++i) {
video_p vp = xmalloc( sizeof *vp + term.t_maxcol * sizeof( unicode_t)) ;
vp->v_flag = 0 ;
#if COLOR
vp->v_rfcolor = 7 ;
vp->v_rbcolor = 0 ;
#endif
vscreen[ i] = vp ;
#if MEMMAP == 0 || SCROLLCODE
vp = xmalloc( sizeof *vp + term.t_maxcol * sizeof( unicode_t)) ;
vp->v_flag = 0 ;
pscreen[ i] = vp ;
#endif
}
} }
#if CLEAN
/* free up all the dynamically allocated video structures */ /* free up all the dynamically video structures allocated by vtalloc */
void vtfree( void) { void vtfree( void) {
for( int i = 0 ; i < term.t_maxrow ; ++i ) { /* as xmalloc bypass the malloc macro, we need bypass the free macro too */
free( vscreen[ i]) ; for( int i = 0 ; i < lastmrow ; ++i ) {
(free)( vscreen[ i]) ;
#if MEMMAP == 0 || SCROLLCODE #if MEMMAP == 0 || SCROLLCODE
free( pscreen[ i]) ; (free)( pscreen[ i]) ;
#endif #endif
} }
free( vscreen) ; (free)( vscreen) ;
#if MEMMAP == 0 || SCROLLCODE #if MEMMAP == 0 || SCROLLCODE
free( pscreen) ; (free)( pscreen) ;
#endif #endif
} }
#endif
/* Clean up the virtual terminal system, in anticipation for a return to /* Clean up the virtual terminal system, in anticipation for a return to
@ -1439,6 +1462,8 @@ static int newscreensize( int h, int w) {
} }
chg_width = chg_height = 0 ; chg_width = chg_height = 0 ;
vtfree() ;
vtalloc( h, w) ;
if( h <= term.t_mrow) if( h <= term.t_mrow)
newsize( TRUE, h) ; newsize( TRUE, h) ;

2
eval.c
View File

@ -65,7 +65,7 @@ int rval = 0 ; /* return value of a subprocess */
static int saveflag = 0 ; /* Flags, saved with the $target var */ static int saveflag = 0 ; /* Flags, saved with the $target var */
long envram = 0l ; /* # of bytes current in use by malloc */ unsigned envram = 0 ; /* # of bytes current in use by malloc */
/* User variables ******************************************/ /* User variables ******************************************/

2
eval.h
View File

@ -12,7 +12,7 @@
extern int macbug ; /* macro debuging flag */ extern int macbug ; /* macro debuging flag */
extern int cmdstatus ; /* last command status */ extern int cmdstatus ; /* last command status */
extern int rval ; /* return value of a subprocess */ extern int rval ; /* return value of a subprocess */
extern long envram ; /* # of bytes current in use by malloc */ extern unsigned envram ; /* # of bytes current in use by malloc */
int readfirst_f( void) ; int readfirst_f( void) ;
int is_it_cmd( char *token) ; int is_it_cmd( char *token) ;

1
exec.c
View File

@ -13,6 +13,7 @@
#include "buffer.h" #include "buffer.h"
#include "bind.h" #include "bind.h"
#include "defines.h" /* malloc/allocate, free/release */
#include "eval.h" #include "eval.h"
#include "file.h" #include "file.h"
#include "flook.h" #include "flook.h"

10
line.c
View File

@ -37,18 +37,18 @@ static int ldelnewline( void) ;
* was taken up by the keycode structure). * was taken up by the keycode structure).
*/ */
#define KBLOCK 250 /* sizeof kill buffer chunks */ #define KBLOCK 248 /* sizeof kill buffer chunks */
typedef struct kill { typedef struct kill {
struct kill *d_next; /* Link to next chunk, NULL if last. */ struct kill *d_next ; /* Link to next chunk, NULL if last. */
char d_chunk[KBLOCK]; /* Deleted text. */ char d_chunk[ KBLOCK] ; /* Deleted text. */
} *kill_p ; } *kill_p ;
static kill_p kbufp = NULL ; /* current kill buffer chunk pointer */ static kill_p kbufp = NULL ; /* current kill buffer chunk pointer */
static kill_p kbufh = NULL ; /* kill buffer header pointer */ static kill_p kbufh = NULL ; /* kill buffer header pointer */
static int kused = KBLOCK ; /* # of bytes used in kill buffer */ static int kused = KBLOCK ; /* # of bytes used in kill buffer */
static int klen ; /* length of kill buffer content */ static int klen ; /* length of kill buffer content */
static char *value = NULL ; /* temp buffer for value */ static char *value = NULL ; /* temp buffer for value */
/* /*
* return some of the contents of the kill buffer * return some of the contents of the kill buffer

95
main.c
View File

@ -347,80 +347,67 @@ static void edinit( char *bname) {
wp->w_flag = WFMODE | WFHARD; /* Full. */ wp->w_flag = WFMODE | WFHARD; /* Full. */
} }
/***** Compiler specific Library functions ****/ /***** Compiler specific Library functions ****/
#if RAMSIZE #if RAMSIZE
/* These routines will allow me to track memory usage by placing
a layer on top of the standard system malloc() and free() calls.
with this code defined, the environment variable, $RAM, will
report on the number of bytes allocated via malloc.
with SHOWRAM defined, the number is also posted on the /* These routines will allow me to track memory usage by placing a layer on
end of the bottom mode line and is updated whenever it is changed. top of the standard system malloc() and free() calls. with this code
defined, the environment variable, $RAM, will report on the number of
bytes allocated via malloc.
with SHOWRAM defined, the number is also posted on the end of the bottom
mode line and is updated whenever it is changed.
*/ */
static void dspram( void) ;
#undef malloc
#undef free
#if 0
char *allocate(nbytes)
/* allocate nbytes and track */
unsigned nbytes; /* # of bytes to allocate */
#endif
void *allocate( size_t nbytes)
{
char *mp; /* ptr returned from malloc */
/* char *malloc(); */
mp = malloc(nbytes);
if (mp) {
envram += nbytes;
#if RAMSHOW #if RAMSHOW
dspram(); static void dspram( void) ;
#endif
void *allocate( size_t nbytes) {
nbytes += sizeof nbytes ; /* add overhead to track allocation */
size_t *mp = (malloc)( nbytes) ; /* call the function not the macro */
if( mp) {
*mp++ = nbytes ;
envram += nbytes ;
#if RAMSHOW
dspram() ;
#endif #endif
} }
return mp; return mp ;
} }
#if 0 void release( void *mp) {
release(mp) if( mp) {
/* release malloced memory and track */ size_t *sp = mp ;
char *mp; /* chunk of RAM to release */ sp-- ;
#endif
void release( void *mp)
{
unsigned *lp; /* ptr to the long containing the block size */
if (mp) {
/* update amount of ram currently malloced */ /* update amount of ram currently malloced */
lp = ((unsigned *) mp) - 1; envram -= *sp ;
envram -= (long) *lp - 2; (free)( sp) ; /* call the function not the macro */
free(mp);
#if RAMSHOW #if RAMSHOW
dspram(); dspram() ;
#endif #endif
} }
} }
#if RAMSHOW #if RAMSHOW
static void dspram( void) static void dspram( void) { /* display the amount of RAM currently malloced */
{ /* display the amount of RAM currently malloced */ char mbuf[ 20] ;
char mbuf[20];
char *sp;
TTmove(term.t_nrow - 1, 70); TTmove( term.t_nrow, term.t_ncol - 12) ;
#if COLOR #if COLOR
TTforg(7); TTforg( 7) ;
TTbacg(0); TTbacg(0) ;
#endif #endif
sprintf(mbuf, "[%lu]", envram); sprintf( mbuf, "[%10u]", envram) ;
sp = &mbuf[0]; char *sp = mbuf ;
while (*sp) while( *sp)
TTputc(*sp++); TTputc( *sp++) ;
TTmove(term.t_nrow, 0);
movecursor(term.t_nrow, 0); TTmove( term.t_nrow, 0) ;
movecursor( term.t_nrow, 0) ;
} }
#endif #endif
#endif #endif
@ -461,7 +448,7 @@ void cexit( int status) {
/* and the video buffers */ /* and the video buffers */
vtfree() ; vtfree() ;
(exit)( status) ; (exit)( status) ; /* call the function, not the macro */
} }
#endif #endif

View File

@ -16,6 +16,7 @@
#include "bind.h" #include "bind.h"
#include "bindable.h" #include "bindable.h"
#include "buffer.h" #include "buffer.h"
#include "defines.h" /* malloc/allocate */
#include "display.h" #include "display.h"
#include "eval.h" #include "eval.h"
#include "exec.h" #include "exec.h"

View File

@ -6,6 +6,7 @@
*/ */
#include <assert.h> #include <assert.h>
#include <stdlib.h> /* malloc(), free() */
#include "basic.h" #include "basic.h"
#include "buffer.h" #include "buffer.h"
@ -52,7 +53,7 @@ TBINDABLE( redraw) {
/* The command make the next window (next => down the screen) the current /* The command make the next window (next => down the screen) the current
window. There are no real errors, although the command does nothing if window. There are no real errors, although the command does nothing if
there is only 1 window on the screen. Bound to "C-X C-N". there is only 1 window on the screen. Bound to "C-X O".
with an argument this command finds the <n>th window from the top with an argument this command finds the <n>th window from the top
@ -318,7 +319,10 @@ BINDABLE( splitwind) {
return FALSE ; return FALSE ;
} }
wp = xmalloc( sizeof *wp) ; wp = malloc( sizeof *wp) ;
if( wp == NULL)
return mloutfail( "Out of memory") ;
++curbp->b_nwnd; /* Displayed twice. */ ++curbp->b_nwnd; /* Displayed twice. */
wp->w_bufp = curbp; wp->w_bufp = curbp;
wp->w_dotp = curwp->w_dotp; wp->w_dotp = curwp->w_dotp;

View File

@ -1,5 +1,4 @@
/* wrapper.c -- implements wrapper.h */ /* wrapper.c -- implements wrapper.h */
#include "wrapper.h" #include "wrapper.h"
#include <stdio.h> #include <stdio.h>
@ -26,12 +25,4 @@ void xmkstemp( char *template) {
close( fd) ; close( fd) ;
} }
void *xmalloc( size_t size) {
void *ret = malloc( size) ;
if( !ret)
die( "Out of memory") ;
return ret ;
}
/* end of wrapper.c */ /* end of wrapper.c */

View File

@ -2,11 +2,7 @@
#ifndef WRAPPER_H_ #ifndef WRAPPER_H_
#define WRAPPER_H_ #define WRAPPER_H_
#include <stdlib.h> /* size_t */
void xmkstemp( char *fname_template) ; void xmkstemp( char *fname_template) ;
void *xmalloc( size_t size) ;
#endif #endif
/* end of wrapper.h */ /* end of wrapper.h */