Skip to content

Commit 4b15844

Browse files
committed
perlapi: Update pod for utf8_to_bytes_new_pv;
1 parent 3fce3a2 commit 4b15844

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

utf8.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,9 +2865,24 @@ automatically freed, via a call to C<L</SAVEFREEPV>>.
28652865
28662866
For C<utf8_to_bytes_new_pv>, C<*free_me> has been set to C<*s_ptr>, and it is
28672867
the caller's responsibility to free the new memory when done using it.
2868-
The results of this parameter can simply be passed to C<L</Safefree>> when
2869-
done, as that handles a C<NULL> parameter, and/or it can be used as a boolean
2870-
(non-NULL meaning C<true>) to indicate that the input was indeed changed.
2868+
The following paradigm is convenient to use for this:
2869+
2870+
void * free_me;
2871+
if (utf8_to_bytes_new_pv(&s, &len, &free_me) {
2872+
...
2873+
}
2874+
else {
2875+
...
2876+
}
2877+
2878+
...
2879+
2880+
Safefree(free_me);
2881+
2882+
C<free_me> can be used as a boolean (non-NULL meaning C<true>) to indicate that
2883+
the input was indeed changed if you need to revisit that later in the code.
2884+
Your design is likely flawed if you find yourself using C<free_me> for any
2885+
other purpose.
28712886
28722887
=back
28732888

0 commit comments

Comments
 (0)