[Pyrex] Total newbie needs code review

Grant McDonald gmcdonald at infocomp.com
Fri Sep 9 01:06:45 CEST 2005


Chris,

Overall your code looks fine.  A few things to consider though:

> class Analyzer:
>   def __init__(self, fname):
>     ret = init(fname)
>     if ret != 0:
>       raise "init failed, returned %d" % ret

raising string exceptions is deprecated and will be removed in python 3. The
preferred method of raising exceptions is:

	raise ExceptionClass(*args **kwargs)

so your call should be:

	raise Exception("init failed, returned %d" % ret)

or preferably define your own exception as a trivial subclass of Exception
giving it a more meaningful name.

Second, be aware that when assigning python strings to char pointers in
Pyrex the reference returned points to the memory where the python string is
stored. This memory should not be modified external to calls using the
python/c api so any functions that modify it must malloc the string pointer
and copy the python string into it instead.

Regards,

Grant M.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.copyleft.no/pipermail/pyrex/attachments/20050909/d0936f38/attachment.html


More information about the Pyrex mailing list