Skip to content

Commit 79db27d

Browse files
committed
perlapi: Consolidate the sv_does forms into one entry
This makes it easier to compare and contrast their behavior
1 parent 4355559 commit 79db27d

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

universal.c

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,39 @@ Perl_sv_isa_sv(pTHX_ SV *sv, SV *namesv)
253253
}
254254

255255
/*
256-
=for apidoc sv_does_sv
256+
=for apidoc sv_does
257+
=for apidoc_item sv_does_pv
258+
=for apidoc_item sv_does_pvn
259+
=for apidoc_item sv_does_sv
257260
258-
Returns a boolean indicating whether the SV performs a specific, named role.
259-
The SV can be a Perl object or the name of a Perl class.
261+
These each return a boolean indicating whether C<sv> performs a specific, named
262+
role.
263+
264+
C<sv> can be a Perl object or the name of a Perl class.
265+
266+
The forms differ in how the role is specified.
267+
268+
In C<sv_does> and C<sv_does_pv>, the role is in C<name>, which is a
269+
NUL-terminated string, which means that it may not contain embedded NUL
270+
characters.
271+
272+
In C<sv_does_pvn>, the role is in C<name> whose length is given by C<len>.
273+
Hence it may contain embedded NUL characters.
274+
275+
In C<sv_does_sv>, the role is extracted from C<namesv>. Its C<flags> argument
276+
is currently ignored.
277+
278+
You can pass C<SVf_UTF8> to the other functions that have a C<flags> argument
279+
to indicate that C<name> is encoded as UTF-8. C<sv_does> does not have a
280+
C<flags> argument, so its role is never considered to be UTF-8.
260281
261282
=cut
283+
284+
The above is based on the behavior of newSVpvn_flags at the time of this
285+
writing. It only recognizes SVs_TEMP and SVf_UTF8.
286+
287+
XXX extracted in sv_does_sv is more complicated than the hand waving above
288+
262289
*/
263290

264291
#include "XSUB.h"
@@ -318,45 +345,20 @@ Perl_sv_does_sv(pTHX_ SV *sv, SV *namesv, U32 flags)
318345
return does_it;
319346
}
320347

321-
/*
322-
=for apidoc sv_does
323-
324-
Like L</sv_does_pv>, but doesn't take a C<flags> parameter.
325-
326-
=cut
327-
*/
328-
329348
bool
330349
Perl_sv_does(pTHX_ SV *sv, const char *const name)
331350
{
332351
PERL_ARGS_ASSERT_SV_DOES;
333352
return sv_does_sv(sv, newSVpvn_flags(name, strlen(name), SVs_TEMP), 0);
334353
}
335354

336-
/*
337-
=for apidoc sv_does_pv
338-
339-
Like L</sv_does_sv>, but takes a nul-terminated string instead of an SV.
340-
341-
=cut
342-
*/
343-
344-
345355
bool
346356
Perl_sv_does_pv(pTHX_ SV *sv, const char *const name, U32 flags)
347357
{
348358
PERL_ARGS_ASSERT_SV_DOES_PV;
349359
return sv_does_sv(sv, newSVpvn_flags(name, strlen(name), SVs_TEMP | flags), flags);
350360
}
351361

352-
/*
353-
=for apidoc sv_does_pvn
354-
355-
Like L</sv_does_sv>, but takes a string/length pair instead of an SV.
356-
357-
=cut
358-
*/
359-
360362
bool
361363
Perl_sv_does_pvn(pTHX_ SV *sv, const char *const name, const STRLEN len, U32 flags)
362364
{

0 commit comments

Comments
 (0)