From: <sm...@us...> - 2009-08-13 19:17:04
|
Revision: 10244 http://plplot.svn.sourceforge.net/plplot/?rev=10244&view=rev Author: smekal Date: 2009-08-13 19:16:56 +0000 (Thu, 13 Aug 2009) Log Message: ----------- Fixed D example 14. Fixed memory bugs in plplot.d introduced in the last commits regarding plgver(), etc. Modified Paths: -------------- trunk/bindings/d/plplot.d trunk/examples/d/x14d.d trunk/plplot_test/test_d.sh.in Modified: trunk/bindings/d/plplot.d =================================================================== --- trunk/bindings/d/plplot.d 2009-08-13 18:25:21 UTC (rev 10243) +++ trunk/bindings/d/plplot.d 2009-08-13 19:16:56 UTC (rev 10244) @@ -2,7 +2,6 @@ module plplot; private import std.string; -private import std.c.stdlib; // improved D interface @@ -251,19 +250,17 @@ /* Get the current device (keyword) name */ void plgdev(out string p_dev) { - char* temp = cast(char*)malloc(1024); - c_plgdev(temp); - p_dev=toString(temp); - free(temp); + p_dev.length = 1024; + c_plgdev(p_dev.ptr); + p_dev=toString(p_dev.ptr); } /* Get the (current) output file name. Must be preallocated to >80 bytes */ void plgfnam(out string fnam) { - char* temp = cast(char*)malloc(1024); - c_plgfnam(temp); - fnam=toString(temp); - free(temp); + fnam.length = 1024; + c_plgfnam(fnam.ptr); + fnam=toString(fnam.ptr); } /* grid irregularly sampled data */ @@ -284,10 +281,9 @@ /* Get the current library version number */ void plgver(out string p_ver) { - char* temp = cast(char*)malloc(1024); - c_plgver(temp); - p_ver=toString(temp); - free(temp); + p_ver.length = 1024; + c_plgver(p_ver.ptr); + p_ver=toString(p_ver.ptr); } /* Draws a histogram of n values of a variable in array data[0..n-1] */ Modified: trunk/examples/d/x14d.d =================================================================== --- trunk/examples/d/x14d.d 2009-08-13 18:25:21 UTC (rev 10243) +++ trunk/examples/d/x14d.d 2009-08-13 19:16:56 UTC (rev 10244) @@ -140,18 +140,28 @@ } +/* special variables for plot5() and mypltr */ +const int XPTS=35; +const int YPTS=46; +const double XSPA=2.0/(XPTS-1); +const double YSPA=2.0/(YPTS-1); + +/* Transformation function */ +extern (C) { + PLFLT[] tr = [ XSPA, 0.0, -1.0, 0.0, YSPA, -1.0 ]; + + void mypltr(PLFLT x, PLFLT y, PLFLT* tx, PLFLT* ty, void* pltr_data) + { + *tx = tr[0]*x + tr[1]*y + tr[2]; + *ty = tr[3]*x + tr[4]*y + tr[5]; + } +} + class plot { private PLFLT[] x, y, x0, y0; private PLFLT[6] xs, ys; private PLINT[1] space1 = [ 1500 ], mark1 = [ 1500 ]; - // special variables for plot5() and mypltr - private const int XPTS=35; - private const int YPTS=46; - private const double XSPA=2.0/(XPTS-1); - private const double YSPA=2.0/(YPTS-1); - private PLFLT[6] tr = [ XSPA, 0.0, -1.0, 0.0, YSPA, -1.0 ]; - public void plot1(PLFLT xscale, PLFLT yscale, PLFLT xoff, PLFLT yoff) { x.length=60; @@ -316,15 +326,9 @@ /* =============================================================== */ /* Demonstration of contour plotting */ - private void mypltr(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data) - { - *tx = tr[0]*x + tr[1]*y + tr[2]; - *ty = tr[3]*x + tr[4]*y + tr[5]; - } - public void plot5() { - PLFLT[11] clevel = [ -1., -.8, -.6, -.4, -.2, 0, .2, .4, .6, .8, 1. ]; + PLFLT[] clevel = [ -1., -.8, -.6, -.4, -.2, 0, .2, .4, .6, .8, 1. ]; /* Set up function arrays */ PLFLT[][] z, w; @@ -343,10 +347,10 @@ plenv(-1.0, 1.0, -1.0, 1.0, 0, 0); plcol0(2); - //plcont(z, 1, XPTS, 1, YPTS, clevel, mypltr, null); + plcont(z, 1, XPTS, 1, YPTS, clevel, &mypltr); plstyl(mark1, space1); plcol0(3); - //plcont(w, 1, XPTS, 1, YPTS, clevel, mypltr, null); + plcont(w, 1, XPTS, 1, YPTS, clevel, &mypltr); plcol0(1); pllab("X Coordinate", "Y Coordinate", "Streamlines of flow"); plflush(); Modified: trunk/plplot_test/test_d.sh.in =================================================================== --- trunk/plplot_test/test_d.sh.in 2009-08-13 18:25:21 UTC (rev 10243) +++ trunk/plplot_test/test_d.sh.in 2009-08-13 19:16:56 UTC (rev 10244) @@ -31,7 +31,7 @@ # 20-22, 28, and 31 not implemented yet. # example 14 excluded until plgdev fixed since the bad driver information # causes run-time errors. -for index in 01 02 03 04 05 06 07 08 09 10 11 12 13 15 16 17 18 19 23 24 25 26 27 29 30; do +for index in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 23 24 25 26 27 29 30; do if [ "$verbose_test" ] ; then echo "x${index}${lang}" fi This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |