пн, 17 авг. 2026 г. в 23:08, Tom Lane <[email protected]>: > Looking a bit more at the issue of standardizing our > perl-array-scanning code, I noticed that av_len returns SSize_t > not int, creating an overflow risk since we aren't consistent > about assigning the result to something wider than int. This > would only result in truncating the output not anything more > exciting, but it's still bad. Also, it seems from looking at > the Perl sources that they prefer to use av_count() to compute > the loop limit. That's the same as av_len()+1 (except it returns > Size_t), but I think that's a better habit to be in since it > removes the risk of forgetting to add 1. So here is a patch > that just cleans up those issues. > > The patch looks good to me.
Apparently av_fetch works as follows: av_fetch returns SV** pointing to the real array element (for regular arrays) OR mortal SV (for tied arrays) - for regular arrays, the returned SV is NOT mortal — it lives in the array - for tied arrays, the returned SV MAY be mortal (temporary) because it's created on the fly as a proxy Calling SvGETMAGIC is critical because it: - for regular SV: does nothing - for magical SV: calls the FETCH method and turns the temporary "proxy" into a real value. -- Regards, Rachitskiy Andrey
