[spambayes-dev] Re: [Spambayes-checkins]spambayes/spambayesstorage.py, 1.31, 1.32

Tim Peters tim.one at comcast.net
Thu Sep 11 22:34:30 EDT 2003


[Tony Meyer]
> ...
> [1] Until Tim explained in a few messages back, I didn't realise that
> this would be a problem; the same sort of thing would happily work in
> C...

Actually not, and the failure could have been much worse in C.  A C
lookalike would be

int sys = 4;

int whatever()
{
    int sys;
    call_something(sys);
    sys = 3;
}

whatever();

That's exactly the same thing:  the file-scope "sys" and the whatever-scope
"sys" have nothing in common, and the whatever-scope sys is referenced
before a value is assigned to it.  In the case of C, the behavior is
undefined, and can easily lead to, e.g., a segfault and core dump.

The only thing that makes it hard to see the equivalence is that Python
doesn't have *explicit* local (C "auto scope") declarations.  The good news
is that Python knows when a reference to an unbound variable is made, and
raises an exception (instead of, as most C implementations end up doing,
using whatever trash bits happen to be sitting on the HW stack).




More information about the spambayes-dev mailing list