Skip to content

Commit

Permalink
error if not match grid-allocating and -freeing routine
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Apr 21, 2024
1 parent 92f36b9 commit 815d890
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- add perldl demo
- fix plFreeGrid to use free that matches the allocator
- pl{Alloc,Free}{,2d}Grid error if not match allocating and freeing routine
- minimum PDL 2.083 due to output OtherPars

0.83 2022-07-17
- immediate re-release to fix packaging problem
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ my @pack = ([qw(plplot.pd PLplot PDL::Graphics::PLplot), undef, 1]);
my %hash = pdlpp_stdargs(@pack);
$hash{PREREQ_PM} = { PDL => 0 };
$hash{CONFIGURE_REQUIRES} = {
'PDL::Core::Dev' => 0,
'PDL' => '2.083', # output OtherPars
'Devel::CheckLib' => 0,
'Alien::PLplot' => 0,
};
Expand Down
23 changes: 13 additions & 10 deletions plplot.pd
Original file line number Diff line number Diff line change
Expand Up @@ -2312,10 +2312,11 @@ pp_addhdr(<<'EOH');
Core* PDL = NULL; PDL_COMMENT("Structure hold core C functions")
#endif

#define PLPTR_DEFINE(t) typedef t *t ## Ptr;
#define PLPTR_DEFINE(t) typedef t *t ## Ptr; typedef t *t ## Ptr__OUT;
PLPTR_DEFINE(PLcGrid)
PLPTR_DEFINE(PLcGrid2)
#define PLPTR_RECEIVE_IN(t, v, v_in) t *v = (t *)v_in;
#define PLPTR_RECEIVE_SV(v) ((PLPointer) (SvROK(v) ? SvIV((SV*)SvRV(v)) : (IV)NULL))
EOH

# The create_low_level_constants function is used to make the #define'd
Expand Down Expand Up @@ -3872,7 +3873,8 @@ EOC

pp_def ('plAllocGrid',
NoPthread => 1,
Pars => 'double xg(nx); double yg(ny); indx [o] grid()',
Pars => 'double xg(nx); double yg(ny)',
OtherPars => '[o] PLcGridPtr__OUT grid',
GenericTypes => [D],
Doc => 'Allocates a PLcGrid object for use in pltr1',
Code => '
Expand All @@ -3890,7 +3892,7 @@ pp_def ('plAllocGrid',
grid->xg[i] = $xg(nx => i);
for (i = 0; i < ny; i++)
grid->yg[i] = $yg(ny => i);
$grid() = (IV) grid;'
$COMP(grid) = (PLcGridPtr__OUT)grid;'
);


Expand All @@ -3911,7 +3913,8 @@ pp_add_exported (plFreeGrid);

pp_def ('plAlloc2dGrid',
NoPthread => 1,
Pars => 'double xg(nx,ny); double yg(nx,ny); indx [o] grid()',
Pars => 'double xg(nx,ny); double yg(nx,ny)',
OtherPars => '[o] PLcGrid2Ptr__OUT grid',
GenericTypes => [D],
Doc => 'Allocates a PLcGrid2 object for use in pltr2',
Code => '
Expand All @@ -3927,7 +3930,7 @@ pp_def ('plAlloc2dGrid',
}
grid->nx = nx;
grid->ny = ny;
$grid() = (IV) grid;'
$COMP(grid) = grid;'
);


Expand Down Expand Up @@ -4066,7 +4069,7 @@ pp_def ('plshades',

pltrcb = get_standard_pltrcb ($COMP(pltr));
if (pltrcb != pltr_callback)
pltrdt = (PLPointer) SvIV($COMP(pltr_data));
pltrdt = PLPTR_RECEIVE_SV($COMP(pltr_data));
else
pltrdt = $COMP(pltr_data);

Expand Down Expand Up @@ -4106,7 +4109,7 @@ pp_def ('plcont',

pltrcb = get_standard_pltrcb ($COMP(pltr));
if (pltrcb != pltr_callback)
pltrdt = (PLPointer) SvIV($COMP(pltr_data));
pltrdt = PLPTR_RECEIVE_SV($COMP(pltr_data));
else
pltrdt = $COMP(pltr_data);

Expand Down Expand Up @@ -4265,7 +4268,7 @@ pp_def ('plshade1',

pltrcb = get_standard_pltrcb ($COMP(pltr));
if (pltrcb != pltr_callback)
pltrdt = (PLPointer) SvIV($COMP(pltr_data));
pltrdt = PLPTR_RECEIVE_SV($COMP(pltr_data));
else
pltrdt = $COMP(pltr_data);

Expand Down Expand Up @@ -4329,7 +4332,7 @@ pp_def ('plimagefr',

pltrcb = get_standard_pltrcb ($COMP(pltr));
if (pltrcb != pltr_callback)
pltrdt = (PLPointer) SvIV($COMP(pltr_data));
pltrdt = PLPTR_RECEIVE_SV($COMP(pltr_data));
else
pltrdt = $COMP(pltr_data);

Expand Down Expand Up @@ -5185,7 +5188,7 @@ pp_def ('plvect',

pltrcb = get_standard_pltrcb ($COMP(pltr));
if (pltrcb != pltr_callback)
pltrdt = (PLPointer) SvIV($COMP(pltr_data));
pltrdt = PLPTR_RECEIVE_SV($COMP(pltr_data));
else
pltrdt = $COMP(pltr_data);

Expand Down
27 changes: 25 additions & 2 deletions typemap
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
PLcGridPtr T_PTR
PLcGrid2Ptr T_PTR
PLcGridPtr T_PLPTROBJ
PLcGridPtr__OUT T_PLPTROBJ__OUT
PLcGrid2Ptr T_PLPTROBJ
PLcGrid2Ptr__OUT T_PLPTROBJ__OUT

INPUT

T_PLPTROBJ
if (!(SvROK($arg) && sv_derived_from($arg, \"$ntype\")))
Perl_croak_nocontext(\"%s: %s is not of type %s but %s, did you match allocate and free?\",
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
\"$var\", \"$ntype\", sv_reftype(SvROK($arg) ? SvRV($arg) : $arg, 1));
IV tmp = SvIV((SV*)SvRV($arg));
$var = INT2PTR($type,tmp);

T_PLPTROBJ__OUT
if (SvROK($arg) && sv_derived_from($arg, \"${(my $ntype = $type) =~ s:__OUT$::; \$ntype}\")) {
IV tmp = SvIV((SV*)SvRV($arg));
$var = INT2PTR($type,tmp);
}

OUTPUT

T_PLPTROBJ__OUT
sv_setref_pv($arg, \"${(my $ntype = $type) =~ s:__OUT$::; \$ntype}\", (void*)$var);

0 comments on commit 815d890

Please sign in to comment.