Skip to content

Commit 1dd9b26

Browse files
committedApr 21, 2024·
better grid pointers in and out, plFreeGrid to use right free
1 parent bd9e97d commit 1dd9b26

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed
 

‎Changes

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- add perldl demo
2+
- fix plFreeGrid to use free that matches the allocator
23

34
0.83 2022-07-17
45
- immediate re-release to fix packaging problem

‎MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ t/x31.pl
7676
t/x31c.c
7777
t/x33.pl
7878
t/x33c.c
79+
typemap

‎plplot.pd

+20-18
Original file line numberDiff line numberDiff line change
@@ -2311,6 +2311,11 @@ pp_addhdr(<<'EOH');
23112311
#define PDL PDL_Graphics_PLplot
23122312
Core* PDL = NULL; PDL_COMMENT("Structure hold core C functions")
23132313
#endif
2314+
2315+
#define PLPTR_DEFINE(t) typedef t *t ## Ptr;
2316+
PLPTR_DEFINE(PLcGrid)
2317+
PLPTR_DEFINE(PLcGrid2)
2318+
#define PLPTR_RECEIVE_IN(t, v, v_in) t *v = (t *)v_in;
23142319
EOH
23152320

23162321
# The create_low_level_constants function is used to make the #define'd
@@ -3847,25 +3852,22 @@ pp_def ('plrandd',
38473852
# pltr1: Linear interpolation from singly dimensioned coord arrays
38483853
# Linear interpolation from doubly dimensioned coord arrays
38493854

3850-
for my $func ('pltr0', 'pltr1', 'pltr2') {
3851-
3855+
for my $t ([qw(pltr0 SV*)], [qw(pltr1 PLcGridPtr)], [qw(pltr2 PLcGrid2Ptr)]) {
3856+
my ($func, $type) = @$t;
38523857
pp_addxs (<<"EOC");
38533858
void
3854-
$func (x, y, grid)
3859+
$func(x, y, grid)
38553860
double x
38563861
double y
3857-
long grid
3862+
$type grid
38583863
PPCODE:
38593864
PLFLT tx, ty;
3860-
3861-
$func (x, y, &tx, &ty, (PLPointer) grid);
3862-
3865+
$func(x, y, &tx, &ty, (PLPointer) grid);
38633866
EXTEND (SP, 2);
3864-
PUSHs (sv_2mortal (newSVnv ((double) tx)));
3865-
PUSHs (sv_2mortal (newSVnv ((double) ty)));
3867+
PUSHs(sv_2mortal(newSVnv((double) tx)));
3868+
PUSHs(sv_2mortal(newSVnv((double) ty)));
38663869
EOC
3867-
3868-
pp_add_exported ($func);
3870+
pp_add_exported($func);
38693871
}
38703872

38713873
pp_def ('plAllocGrid',
@@ -3897,12 +3899,12 @@ pp_def ('plAllocGrid',
38973899
pp_addxs (<<"EOC");
38983900
void
38993901
plFreeGrid (pg)
3900-
long pg
3902+
PLcGridPtr pg
39013903
PPCODE:
3902-
PLcGrid* grid = (PLcGrid*) pg;
3903-
free (grid->xg);
3904-
free (grid->yg);
3905-
free (grid);
3904+
PLPTR_RECEIVE_IN(PLcGrid, grid, pg)
3905+
Safefree(grid->xg);
3906+
Safefree(grid->yg);
3907+
Safefree(grid);
39063908
EOC
39073909

39083910
pp_add_exported (plFreeGrid);
@@ -3934,9 +3936,9 @@ pp_def ('plAlloc2dGrid',
39343936
pp_addxs (<<"EOC");
39353937
void
39363938
plFree2dGrid(pg)
3937-
long pg
3939+
PLcGrid2Ptr pg
39383940
PPCODE:
3939-
PLcGrid2* grid = (PLcGrid2*) pg;
3941+
PLPTR_RECEIVE_IN(PLcGrid2, grid, pg)
39403942
plFree2dGrid(grid->xg, grid->nx, grid->ny);
39413943
plFree2dGrid(grid->yg, grid->nx, grid->ny);
39423944
free(grid);

‎typemap

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PLcGridPtr T_PTR
2+
PLcGrid2Ptr T_PTR

0 commit comments

Comments
 (0)
Please sign in to comment.