gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gpsd-dev] ✘Python maidenhead fails on XCode


From: Gary E. Miller
Subject: Re: [gpsd-dev] ✘Python maidenhead fails on XCode
Date: Tue, 16 Aug 2016 17:59:00 -0700

Yo Frank!

On Tue, 16 Aug 2016 20:46:24 -0400
Frank Nicholas <address@hidden> wrote:

> > On Aug 16, 2016, at 6:05 PM, Gary E. Miller <address@hidden> wrote:
> > 
> > One line in gpsclient.d:
> > 
> > static PyObject *
> > gpsclient_maidenhead(PyObject *self UNUSED, PyObject *args)
> > {
> > -    const double lat, lon;
> > +    const double lat = 0.0, lon = 0.0;
> > 
> > Very weird, Eric helped me narrow it down.  Adding an initializer,
> > as requested by compiler warning, breaks it.  And just on OS X.
> > 
> > Hmmm..
> >   
> 
> Did you revert the code, or change something in current git head to
> fix it?  I just did a ‘git clone’ & ‘scons -j24 check’ and it was
> successful.

Yes, it is fixed in git head.  You can always do a 'git log -p' to
see recent changes.

When you see the problem you want to beat your head against the wall.

Notice that lat and ln are marked 'const'?  Then the address of those
'const' are passed to a function to change them.  Getting the idea?  C
does not allow you to change a constant!  Or at leat is not suppsed to.

So the code has been broken, silently, for a long time because XCode
and gcc were not enforcing the 'const'.  When I added the initializers,
all of a sudden XCode started enforcing the 'const'ness.

The fix, of course, was to remove the 'const'.  I also left in the
initializer a that shut up an XCode warning about uninitialized
variables.  gcc was smart enough to know they were really initialized
later before use, but too dumb to notice writing to a 'const;.

My guess is that when I added the initializers that XCode moved the
'const' to a read-only memory segment.  Interesting that the C binary
did not complain about writing to the read-only data, it just left the
data at 0.0

RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
        address@hidden  Tel:+1 541 382 8588

Attachment: pgpI3uls_83fH.pgp
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]