On Mon, 28 Apr 2008, Erland Sommarskog wrote: > > I have this piece of code in my XS module: > > if (sv = get_sv("Win32::SqlServer::Version", TRUE)) > { > char buff[256]; > sprintf_s(buff, 256, > "This is Win32::SqlServer, version %s\n\nCopyright (c) > 2005-2008 Erland Sommarskog\n", > XS_VERSION); > sv_setnv(sv, atof(XS_VERSION)); > sv_setpv(sv, buff); > SvNOK_on(sv); > } > > In Perl 5.10 this yields: > > Name "Win32::SqlServer::Version" used only once: possible typo at > F:/Perl/AS1002-AMD64/lib/DynaLoader.pm line 224. > > Indeed, this variable is not referred elsewhere, but this did not happen in > Perl 5.8. > > Is this an incidental or accidental change?
You were always supposed to get the warning; that you got away without one is a bug. :) > The workaround seems to be to add a reference in the PM module, although > I have not come around to try that yet. Or should I do the above in some > better way? Use the GV_ADDMULTI flag: if (sv = get_sv("Win32::SqlServer::Version", TRUE | GV_ADDMULTI)) Look it up in perlguts.pod: | =head2 Creating New Variables | | To create a new Perl variable with an undef value which can be accessed from | your Perl script, use the following routines, depending on the variable type. | | SV* get_sv("package::varname", TRUE); | AV* get_av("package::varname", TRUE); | HV* get_hv("package::varname", TRUE); | | Notice the use of TRUE as the second parameter. The new variable can now | be set, using the routines appropriate to the data type. | | There are additional macros whose values may be bitwise OR'ed with the | C<TRUE> argument to enable certain extra features. Those bits are: | | =over | | =item GV_ADDMULTI | | Marks the variable as multiply defined, thus preventing the: | | Name <varname> used only once: possible typo warning. | | =item GV_ADDWARN | | Issues the warning: | | Had to create <varname> unexpectedly | | if the variable did not exist before the function was called. | | =back Cheers, -Jan