Skip to content

Commit

Permalink
Removed C_alloc/C_free and support functions/data structures.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@15321 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
luke committed Aug 7, 2001
1 parent 561d372 commit 132dcb3
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 78 deletions.
10 changes: 6 additions & 4 deletions src/gnuwin32/devga.c
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,8 @@ static void GA_Line(double x1, double y1, double x2, double y2,

static void GA_Polyline(int n, double *x, double *y, int coords, DevDesc *dd)
{
point *p = (point *) C_alloc(n, sizeof(point));
char *vmax = vmaxget();
point *p = (point *) R_alloc(n, sizeof(point));
double devx, devy;
int i;
gadesc *xd = (gadesc *) dd->deviceSpecific;
Expand All @@ -1880,7 +1881,7 @@ static void GA_Polyline(int n, double *x, double *y, int coords, DevDesc *dd)
SetColor(dd->gp.col, dd),
SetLinetype(dd->gp.lty, dd->gp.lwd, dd);
DRAW(gdrawpolyline(_d, xd->lwd, xd->lty, xd->fgcolor, p, n, 0, 0));
C_free((char *) p);
vmaxset(vmax);
}

/********************************************************/
Expand All @@ -1898,13 +1899,14 @@ static void GA_Polyline(int n, double *x, double *y, int coords, DevDesc *dd)
static void GA_Polygon(int n, double *x, double *y, int coords,
int bg, int fg, DevDesc *dd)
{
char *vmax = vmaxget();
point *points;
double devx, devy;
int i;
gadesc *xd = (gadesc *) dd->deviceSpecific;

TRACEDEVGA("plg");
points = (point *) C_alloc(n , sizeof(point));
points = (point *) R_alloc(n , sizeof(point));
if (!points)
return;
for (i = 0; i < n; i++) {
Expand All @@ -1923,7 +1925,7 @@ static void GA_Polygon(int n, double *x, double *y, int coords,
SetLinetype(dd->gp.lty, dd->gp.lwd, dd);
DRAW(gdrawpolygon(_d, xd->lwd, xd->lty, xd->fgcolor, points, n, 0 ));
}
C_free((char *) points);
vmaxset(vmax);
}


Expand Down
2 changes: 0 additions & 2 deletions src/include/Defn.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ extern SEXP R_NHeap; /* Start of the cons cell heap */
extern SEXP R_FreeSEXP; /* Cons cell free list */
extern long R_Collected; /* Number of free cons cells (after gc) */
extern SEXP R_PreciousList; /* List of Persistent Objects */
void Init_C_alloc(void);
void Reset_C_alloc(void);

/* The Pointer Protection Stack */
extern int R_PPStackSize INI_as(R_PPSSIZE); /* The stack size (elements) */
Expand Down
4 changes: 0 additions & 4 deletions src/include/R_ext/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ char* R_alloc(long, int);
char* S_alloc(long, int);
char* S_realloc(char*, long, long, int);

/* C Memory Management Interface */
char* C_alloc(long, int);
void C_free(char *);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/main/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,7 @@ static void CScliplines(int n, double *x, double *y, int coords, DevDesc *dd)
double *xx, *yy, temp;
double x1, y1, x2, y2;
cliprect cr;
char *vmax = vmaxget();

setClipRect(&cr.xl, &cr.yb, &cr.xr, &cr.yt, coords, dd);
if (cr.xr < cr.xl) {
Expand All @@ -2599,8 +2600,8 @@ static void CScliplines(int n, double *x, double *y, int coords, DevDesc *dd)
cr.yt = temp;
}

xx = (double *) C_alloc(n, sizeof(double));
yy = (double *) C_alloc(n, sizeof(double));
xx = (double *) R_alloc(n, sizeof(double));
yy = (double *) R_alloc(n, sizeof(double));
if (xx == NULL || yy == NULL)
error("out of memory while clipping polyline");

Expand Down Expand Up @@ -2647,8 +2648,7 @@ static void CScliplines(int n, double *x, double *y, int coords, DevDesc *dd)
y1 = y[i];
}

C_free((char *) xx);
C_free((char *) yy);
vmaxset(vmax);
}

/* Clip the line
Expand Down
4 changes: 0 additions & 4 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ static void R_ReplFile(FILE *fp, SEXP rho, int savestack, int browselevel)
int status, count=0;

for(;;) {
Reset_C_alloc();
R_PPStackTop = savestack;
R_CurrentExpr = R_Parse1File(fp, 1, &status);
switch (status) {
Expand Down Expand Up @@ -151,8 +150,6 @@ static void R_ReplConsole(SEXP rho, int savestack, int browselevel)
R_IoBufferPutc(c, &R_ConsoleIob);
if(c == ';' || c == '\n') break;
}
if (browselevel)
Reset_C_alloc();

R_PPStackTop = savestack;
R_CurrentExpr = R_Parse1Buffer(&R_ConsoleIob, 0, &status);
Expand Down Expand Up @@ -375,7 +372,6 @@ void setup_Rmainloop(void)
InitArithmetic();
InitColors();
InitGraphics();
Init_C_alloc();
R_Is_Running = 1;

/* gc_inhibit_torture = 0; */
Expand Down
52 changes: 0 additions & 52 deletions src/main/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1836,58 +1836,6 @@ void initStack(void)
}


/* Wrappers for malloc/alloc/free */
/* These allow automatic freeing of malloc-ed */
/* blocks during error recovery. */

#define MAXPOINTERS 100
static char *C_Pointers[MAXPOINTERS];

void Init_C_alloc()
{
int i;
for(i=0 ; i<MAXPOINTERS ; i++)
C_Pointers[i] = NULL;
}

void Reset_C_alloc()
{
int i;
for(i=0 ; i<MAXPOINTERS ; i++) {
if(C_Pointers[i] != NULL)
free(C_Pointers[i]);
C_Pointers[i] = NULL;
}
}

char *C_alloc(long nelem, int eltsize)
{
int i;
for(i=0 ; i<MAXPOINTERS ; i++) {
if(C_Pointers[i] == NULL) {
C_Pointers[i] = malloc(nelem * eltsize);
if(C_Pointers[i] == NULL)
error("C_alloc(): unable to malloc memory");
else return C_Pointers[i];
}
}
error("C_alloc(): all pointers in use (sorry)");
/*-Wall:*/return C_Pointers[0];
}

void C_free(char *p)
{
int i;
for(i=0 ; i<MAXPOINTERS ; i++) {
if(C_Pointers[i] == p) {
free(p);
C_Pointers[i] = NULL;
return;
}
}
error("C_free(): attempt to free pointer not allocated by C_alloc()");
}

/* S-like wrappers for calloc, realloc and free that check for error
conditions */

Expand Down
10 changes: 6 additions & 4 deletions src/main/plot3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ static void contour(SEXP x, int nx, SEXP y, int ny, SEXP z,
* for preventing infinite loops -- shouldn't be needed --> warning */
#define MAX_ns 25000

char *vmax;

double f, xl, xh, yl, yh, zll, zhl, zlh, zhh, xx[4], yy[4];
double xend, yend;
int i, ii, j, jj, k, l, m, nacode, ns, ns2, dir;
Expand Down Expand Up @@ -720,8 +722,9 @@ static void contour(SEXP x, int nx, SEXP y, int ny, SEXP z,
/* countour midpoint : use for labelling sometime (not yet!) */
if (ns > 3) ns2 = ns/2; else ns2 = -1;

xxx = (double *) C_alloc(ns + 1, sizeof(double));
yyy = (double *) C_alloc(ns + 1, sizeof(double));
vmax = vmaxget();
xxx = (double *) R_alloc(ns + 1, sizeof(double));
yyy = (double *) R_alloc(ns + 1, sizeof(double));
/* now have the space, go through again: */
s = start;
ns = 0;
Expand Down Expand Up @@ -1046,8 +1049,7 @@ static void contour(SEXP x, int nx, SEXP y, int ny, SEXP z,
}

GMode(0, dd);
C_free((char *) xxx);
C_free((char *) yyy);
vmaxset(vmax);
} /* while */
} /* for(i .. ) for(j ..) */
UNPROTECT_PTR(label1); /* pwwwargh! This is messy, but last thing
Expand Down
11 changes: 7 additions & 4 deletions src/modules/X11/devX11.c
Original file line number Diff line number Diff line change
Expand Up @@ -1661,11 +1661,13 @@ static void X11_Line(double x1, double y1, double x2, double y2,

static void X11_Polyline(int n, double *x, double *y, int coords, DevDesc *dd)
{
char *vmax = vmaxget();
XPoint *points;
double devx, devy;
int i, j;
x11Desc *xd = (x11Desc *) dd->deviceSpecific;
points = (XPoint *) C_alloc(n, sizeof(XPoint));

points = (XPoint *) R_alloc(n, sizeof(XPoint));

for(i=0 ; i<n ; i++) {
devx = x[i]; devy = y[i];
Expand All @@ -1686,7 +1688,7 @@ static void X11_Polyline(int n, double *x, double *y, int coords, DevDesc *dd)
if (xd->type == WINDOW) XSync(display, 0);
#endif

C_free((char *) points);
vmaxset(vmax);
}

/********************************************************/
Expand All @@ -1704,12 +1706,13 @@ static void X11_Polyline(int n, double *x, double *y, int coords, DevDesc *dd)
static void X11_Polygon(int n, double *x, double *y, int coords,
int bg, int fg, DevDesc *dd)
{
char *vmax = vmaxget();
XPoint *points;
double devx, devy;
int i;
x11Desc *xd = (x11Desc *) dd->deviceSpecific;

points = (XPoint *) C_alloc(n+1, sizeof(XPoint));
points = (XPoint *) R_alloc(n+1, sizeof(XPoint));

for (i=0 ; i<n ; i++) {
devx = x[i]; devy = y[i];
Expand Down Expand Up @@ -1737,7 +1740,7 @@ static void X11_Polygon(int n, double *x, double *y, int coords,
#endif
}

C_free((char *) points);
vmaxset(vmax);
}


Expand Down

0 comments on commit 132dcb3

Please sign in to comment.