Re: AV API thoughts: AVs as proxies for other things
[email protected] (Tony Cook) Fri, 12 Jun 2026 09:26:05 +1000
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
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.
Now implenting pp_splice in terms of av_splice was optional, but it's
not ideal to have two implementations of the same operation, and it
also means that the API doesn't have the features of the OP, leading
to needing to have to call back to perl code:
# in perl land
sub my_splice($x, $start, $count, @replace):prototype(\@;$$$) {
splice(@$x, $start, $count, @replace);
}
...
/* in C land */
... /* call setup */
SSize_t count = call_sv(get_sv("my_splice", 0), G_LIST);
... /* call cleanup and handle arguments */
which is part of what the API is trying to avoid.
> that C code is often less robust vs. exceptions so maybe a warning and
Any warning can be an exception, either by being marked fatal, or by a
__WARN__ handler throwing.
Tony