Re: AV API thoughts: AVs as proxies for other things

[email protected] (Michael Conrad) Fri, 12 Jun 2026 11:16:39 -0400
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
On 6/11/26 7:26 PM, Tony Cook wrote:
> On Thu, Jun 11, 2026 at 07:46:30AM -0400, Michael Conrad wrote:
>> IMHO if a tied array's splice implementation returns more than the number
>> you requested to delete from the array, that's a bug and should either be an
>> exception or a warning + truncation.  I would lean toward exception, except
>> that C code is often less robust vs. exceptions so maybe a warning and
>> returning the correct number of elements is less likely to crash, and
>> sufficient to help people track down the bug.
>>
>> Returning fewer than requested could happen if the thing the tied AV
>> represented had changed size asynchronously and there weren't enough
>> elements, but that's part of the splice API that it tells you how many were
>> actually removed.
> One of the possible uses for av_splice() was to implement pp_splice
> (the implementation of perl's splice() function) in terms of
> av_splice, and pp_splice does currently handle the excess elements.
>
> For backward compatibility, pp_splice can't throw on too many results.

Well that's interesting...

I've personally never written code that guarded against the possibility 
of splice() returning *more* elements than I asked it to delete, and if 
someone handed my code a tied array that had that behavior (which is 
certainly breaking the contract of that function), it would likely 
result in buggy behavior from my code as well.  I'm having a hard time 
imagining a case where silently preserving the buggy behavior would be 
to anyone's benefit.  I'd actually prefer if future perls *did* emit a 
warning on tied array implementations broken in this manner.

-Mike C.