Skip to content

Commit 3006cdb

Browse files
author
kalibera
committed
Use GEcreateDD() and GEfreeDD() on Windows graphic device (related to 88803,
from Paul Murrell). git-svn-id: https://svn.r-project.org/R/trunk@88814 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 8e0ac11 commit 3006cdb

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/library/grDevices/src/devWindows.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,13 @@ static void PrivateCopyDevice(pDevDesc dd, pDevDesc ndd, const char *name)
347347
static void SaveAsWin(pDevDesc dd, const char *display,
348348
Rboolean restoreConsole)
349349
{
350-
pDevDesc ndd = (pDevDesc) calloc(1, sizeof(DevDesc));
350+
pDevDesc ndd = GEcreateDD();
351351
if (!ndd) {
352352
R_ShowMessage(_("Not enough memory to copy graphics window"));
353353
return;
354354
}
355355
if(!R_CheckDeviceAvailableBool()) {
356-
free(ndd);
356+
GEfreeDD(ndd);
357357
R_ShowMessage(_("No device available to copy graphics window"));
358358
return;
359359
}
@@ -392,7 +392,7 @@ static void init_PS_PDF(void)
392392
static void SaveAsPostscript(pDevDesc dd, const char *fn)
393393
{
394394
SEXP s;
395-
pDevDesc ndd = (pDevDesc) calloc(1, sizeof(DevDesc));
395+
pDevDesc ndd = GEcreateDD();
396396
pGEDevDesc gdd = desc2GEDesc(dd);
397397
gadesc *xd = (gadesc *) dd->deviceSpecific;
398398
char family[256], encoding[256], paper[256], bg[256], fg[256];
@@ -403,7 +403,7 @@ static void SaveAsPostscript(pDevDesc dd, const char *fn)
403403
return;
404404
}
405405
if(!R_CheckDeviceAvailableBool()) {
406-
free(ndd);
406+
GEfreeDD(ndd);
407407
R_ShowMessage(_("No device available to copy graphics window"));
408408
return;
409409
}
@@ -462,7 +462,7 @@ static void SaveAsPostscript(pDevDesc dd, const char *fn)
462462
static void SaveAsPDF(pDevDesc dd, const char *fn)
463463
{
464464
SEXP s;
465-
pDevDesc ndd = (pDevDesc) calloc(1, sizeof(DevDesc));
465+
pDevDesc ndd = GEcreateDD();
466466
pGEDevDesc gdd = desc2GEDesc(dd);
467467
gadesc *xd = (gadesc *) dd->deviceSpecific;
468468
char family[256], encoding[256], bg[256], fg[256];
@@ -477,7 +477,7 @@ static void SaveAsPDF(pDevDesc dd, const char *fn)
477477
return;
478478
}
479479
if(!R_CheckDeviceAvailableBool()) {
480-
free(ndd);
480+
GEfreeDD(ndd);
481481
R_ShowMessage(_("No device available to copy graphics window"));
482482
return;
483483
}
@@ -644,13 +644,14 @@ static char* translateFontFamily(const char* family) {
644644
PROTECT(graphicsNS = R_FindNamespace(ScalarString(mkChar("grDevices"))));
645645
PROTECT_WITH_INDEX(windowsenv = findVar(install(".WindowsEnv"),
646646
graphicsNS), &xpi);
647-
if(TYPEOF(windowsenv) == PROMSXP)
647+
if(TYPEOF(windowsenv) == PROMSXP) {
648648
if (NoDevices()) {
649649
REPROTECT(windowsenv = eval(windowsenv, graphicsNS), xpi);
650650
} else {
651651
REPROTECT(windowsenv = Rf_eval_with_gd(windowsenv, graphicsNS,
652652
NULL), xpi);
653653
}
654+
}
654655
PROTECT(fontdb = findVar(install(".Windows.Fonts"), windowsenv));
655656
PROTECT(fontnames = getAttrib(fontdb, R_NamesSymbol));
656657
nfonts = LENGTH(fontdb);
@@ -3337,7 +3338,7 @@ Rboolean GADeviceDriver(pDevDesc dd, const char *display, double width,
33373338
int quality, double xpinch, double ypinch)
33383339
{
33393340
/* if need to bail out with some sort of "error" then */
3340-
/* must free(dd) */
3341+
/* must GEfreeDD(dd) */
33413342

33423343
int ps; /* This really is in (big) points */
33433344
gadesc *xd;
@@ -3349,9 +3350,6 @@ Rboolean GADeviceDriver(pDevDesc dd, const char *display, double width,
33493350
return FALSE;
33503351
}
33513352

3352-
/* from here on, if need to bail out with "error", must also */
3353-
/* free(xd) */
3354-
33553353
/* Allow user override of ppi */
33563354
xd->xpinch = 0.0;
33573355
xd->ypinch = 0.0;
@@ -3856,13 +3854,13 @@ SEXP devga(SEXP args)
38563854
if(p && strncmp(display, "win.metafile", 12)) *p = '\0';
38573855
}
38583856
/* Allocate and initialize the device driver data */
3859-
if (!(dev = (pDevDesc) calloc(1, sizeof(DevDesc)))) return 0;
3857+
if (!(dev = GEcreateDD())) return 0;
38603858
if (!GADeviceDriver(dev, display, width, height, ps,
38613859
(Rboolean)recording, resize, bg, canvas, gamma,
38623860
xpos, ypos, (Rboolean)buffered, psenv,
38633861
restoreConsole, title, clickToConfirm,
38643862
fillOddEven, family, quality, xpinch, ypinch)) {
3865-
free(dev);
3863+
GEfreeDD(dev);
38663864
error(_("unable to start %s() device"), type);
38673865
}
38683866
gdd = GEcreateDevDesc(dev);

0 commit comments

Comments
 (0)