Dec 6, 1995, 4:04 PM
Post #14 of 15
(790 views)
Permalink
> From: pmarquess@bfsec.bt.co.uk (Paul Marquess)
>
> From: Graham Barr <bodg@tiuk.ti.com>
> >
> > Nick Ing-Simmons <nik@tiuk.ti.com> writes:
> > >In <9511271653.AA07939@tiuk.ti.com>
> > >On Mon, 27 Nov 95 16:53:49 GMT
> > > <bodg@tiuk.ti.com> writes:
> > >>Paul Marquess <pmarquess@bfsec.bt.co.uk> writes:
> > >
> > >>>Another possibility would be to use the VERSION macro in xsubpp, rather
> > >>>than create a new one:
> > >>>
> > >>> sv_setpv(perl_get_sv("${Module_cname}::XS_VERSION",1),VERSION);
> > >>
> > >>Agreed, it should use the VERSION macro, but as I stated in an earlier
> > >>message, How should VERSION be derived ?
> > >>
> > >In C code VERSION is -DVERSION= to Makefile.PL version.
> > >Thus if they don't match you need to use XS_VERSION.
> >
> > Hmm yes, I think I will change my opinion here, the user may want to use
> > the VERSION macro themselves. So it makes sense to introduce a new macro
> > XS_VERSION for this purpose.
An interesting thread of messages. (Thanks for the summary Paul! I might not
have bothered to read and reply without it. Too little time right now.)
> Just as well I didn't post a patch then :-)
>
> There have been a few messages bouncing around, so perhaps it would be
> a good idea if I tried to summarise the current state of play.
>
> The perceived problem:
>
> There is no automatic mechanism to detect a mismatch in the version
> numbers of a .pm & .o file at run time.
>
> Issues:
>
> 1. Although there are VERSION strings available to both the .pm
> file and the .xs file, they may not be the same thing. For
> example, the .pm VERSION might actually be an RCS/SCCS id and/or
> the .xs VERSION might be a package version.
>
> 2. To counter 1, there will be a large class of modules where the
> two VERSION strings could easily be made the same.
And I think developers would want them to be the same once standards and
checking mechanisms are defined. The current addhoc arrangements
are probably a reflection of the lack of a standard more than a desire
to do it a particular way.
> 3. There are cases where multiple .pm files (each with separate
> VERSION strings) use a single .xs file.
I think the issue here is more package and module names rather than files.
$VERSION relates to the package name it's defined in and the name of the
module the application 'use's. The Exporter checks for $VERSION in the
package of the same name as the module.
Any VERSION checking code xsubpp adds should be based on the MODULE=Foo
part of the xs declaration lines not the PACKAGE=... part.
> 4. There are cases where a .xs file doesn't have an associated .pm
> file.
Too rare to worry about other than ensuring that whatever we come up with
can be disabled on a per xs file basis.
> Current Proposed Solution:
>
> * Modify DynaLoader to add this logic along these lines:
>
> sub DynaLoader::bootstrap
> {
> ...
> my ($PKG) = (caller)[0] ;
> my ($pm_VERSION) ;
>
> $pm_VERSION = ${"${PKG}::VERSION"}
> if defined ${"${PKG}::VERSION"} ;
> $pm_VERSION = shift if @_ ;
>
> boot the .xs file
>
> croak (".pm/.xs mismatch")
> if $pm_VERSION and ${"${PKG}::XS_VERSION"} and
> $pm_VERSION ne ${"${PKG}::XS_VERSION"} ;
> }
I'd rather the logic went into the BOOT: section of XS files.
It would be faster and give the module developer more choice.
If xsubpp.h automatically #defined XS_VERSION_VAR to be the name of the
$VERSION variable that corresponds to the module, e.g., "Foo::VERSION"
then XSUB.h could simply define macros something like this:
#ifdef XS_VERSION
#define XS_VERSION_MISMATCH \
strNE(XS_VERSION, SvPV(perl_get_sv(XS_VERSION_VAR,GV_ADDWARN)))
#define XS_VERSION_CHECK \
if (XS_VERSION_MISMATCH) croak("...")
#else
#define XS_VERSION_MISMATCH 0
#define XS_VERSION_CHECK
#endif
Then xsubpp could automatically add XS_VERSION_CHECK to the boot section
of all xs files unless a -noversioncheck option was given.
After all the above we're in a position where specifying -DXS_VERSION
to xsubpp automatically enables a default version check that, because
of the GV_ADDWARN, will automatically warn the developer if they have
not defined $VERSION in Foo.pm.
Any developer wanting to avoid all this can simply not specify XS_VERSION
or add -noversioncheck to XSOPTS.
Any developer wanting to implement their own checks or failure modes can
simply add -noversioncheck to XSOPTS in Makefile.PL and then use the
XS_VERSION_MISMATCH macro but not XS_VERSION_CHECK to write their own
code into the BOOT: section.
Comments?
> Outstanding problems:
>
> 1. How to get the XS_VERSION to automatically be the same for a
> .pm/.xs pair. I feel that most modules will be the
> straightforward one .pm to one .xs pair - it therefore makes
> sense then to have the XS_VERSION strings kept in sync as easily
> as possible.
My current thinking is that MakeMaker could effectively grep $modulename.pm
for a string matching
\$VERSION\s*=.*?([\d.]*)
and if found then check it against the VERSION in the Makefile.PL.
This could be done at make-a-distribution-time rather than build-time
since it's a development issue.
Tim.