Re: How run valgrind on Python C extensions?

2005-02-02 Thread System Administrator

Chris> I have Python C extensions that are giving me seg faults that I'd
Chris> like to run valgrind on.

Chris> Can I use valgrind on these through python??  HOW???

Just run Python under valgrind's control.  It will automatically take care
of it for you.

Chris> Is it easy or must I do some work like recompiling python source
Chris> with the -g extension?

Should not be necessary.

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Code Auditing Tool

2005-02-02 Thread System Administrator

>> Does anybody know of a tool that can tell me all possible exceptions
>> that might occur in each line of code?  What I'm hoping to find is
>> something like the following:

Paul> That is impossible.  The parameter to the raise statement is a
Paul> class object, which can be anything.

Sure, but in all but the rarest of cases the first arg to raise is a
specific exception, probably one of the standard exceptions.  In the Python
code in the distribution (ignoring the test directory where all sorts of
mischief is done to stress things), here are the most common words following
"raise" where "raise" is the first word on the line:

% find . -name '*.py' \
> | egrep -v '\./test' \
> | xargs egrep '^ *raise ' \
> | awk '{print $3}' \
> | sed -e 's/[(,].*//' \
> | sort \
> | uniq -c \
> | sort -rn \
> | head -15
 246 ValueError
 227 aetools.Error
 216 Error
 124 TypeError
 101 error
  75 RuntimeError
  53 IOError
  36 NotImplementedError
  36 ImportError
  36 EOFError
  31 SyntaxError
  23 KeyError
  23 AttributeError
  22 DistutilsPlatformError
  21 UnicodeError

Without checking, my guess is that #5 ("error") is one of a handful of
exception classes defined at module scope (ftplib, anydbm, sre_constants,
poplib, among others all define such an exception class), and not a variable
that accepts multiple values as in your example.

In short, while not perfect, simply grepping for '^ *(class|def|raise) ' and
printing the first and second words of each output line would probably give
you a pretty good idea of what gets raised where.

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Next step after pychecker

2005-02-02 Thread System Administrator

Francis> But Skip, I am sure that you can easily find an example by
Francis> yourself. For example, replace "+" by a function that does
Francis> different things depending on its argument type.

Sure.  I was thinking of the optimization use of type inferencing,
forgetting the subject of the note.

Coming back to this:

1- if a is None:
2-   b = 1
3- else:
4-   b = "Phew"
5- b = b + 1

pychecker should be able to warn you today (but it doesn't) that you are
using b to refer to objects of two different types.  It's not type
inferencing, but it would probably be a reasonable addition to its suite of
things it checks.

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list