New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] 0f58732 Add a common code snippet of blessing an object into a package #14635
Comments
From yoanlin93@gmail.comThis is a bug report for perl from yoanlin93@gmail.com, From 0f58732dc162f40820e3d9e9754d18b1653c46e3 Mon Sep 17 00:00:00 2001 This is a multi-part message in MIME format. pod/perlguts.pod | 8 ++++++++ --------------2.1.2 Inline Patchdiff --git a/pod/perlguts.pod b/pod/perlguts.pod
index 0fe61a8..f227ade 100644
--- a/pod/perlguts.pod
+++ b/pod/perlguts.pod
@@ -694,6 +694,14 @@ The C<sv> argument must be a reference value. The C<stash> argument
specifies which class the reference will belong to. See
L<Stashes and Globs> for information on converting class names into stashes.
+The code below is a common snippet to bless an object into a package in the C<new>
+method of a package:
+
+ STRLEN classname_len;
+ char * classname = SvPVbyte(ST(0), classname_len);
+ HV * stash = gv_stashpvn(classname, classname_len, 0);
+ sv_bless(obj, stash); // the obj here is usually a HV
+
/* Still under construction */
The following function upgrades rv to reference if not already one.
--------------2.1.2--
---
Site configuration information for perl 5.21.10: Configured by c9s at Fri Feb 27 12:59:15 CST 2015. Summary of my perl5 (revision 5 version 21 subversion 10) configuration: @INC for perl 5.21.10: Environment for perl 5.21.10: |
From @jkeenanOn Fri Apr 03 11:10:17 2015, yoanlin93@gmail.com wrote:
Since we're past the point in the release cycle where we would be making changes in the Perl 5 core code, my feeling is that we shouldn't be making unnecessary changes in the documentation of the core code. So I've marked this patch for consideration for 5.23.1. Nonetheless, it would be good to get feedback from contributors familiar with perlguts and XS on the merits of this documentation change. Thank you very much. -- |
The RT System itself - Status changed from 'new' to 'open' |
From @dur-randirOn Fri Apr 03 11:10:17 2015, yoanlin93@gmail.com wrote:
There's a number of problems with this patch.
First, since you use the combination of SvPVbytes + gv_stashpvn with zero flags function calls, you throw away any UTF8-ness on original argument. Second, while this code is correct for non-utf8 class names, it's not the best way to fetch a stash pointer. That was the way on older perls, but since this is a documentation for a fresh release, advice readers for the fastest API available - gv_stashsv. It takes advantage of argument on the stack being possibly a shared string already, and does all UTF8 stuff for you. And the last is the wording of the comment on the last line. First argument to the sv_bless can't be non-reference, so it's not a HV*, it's a SV* holding reference to, commonly, HV*. |
Migrated from rt.perl.org#124239 (status was 'open')
Searchable as RT124239$
The text was updated successfully, but these errors were encountered: