Yep.  Sorry, I should've been more specific.  As long as you only are
passing integers to ovs_retval_to_string, it will behave as you expect.

If that is fine, stop reading here.

  -Reid

Some examples of possibly unexpected behavior could be:

  retval   | ovs_retval_to_string(retval)
 ----------+------------------------------
  None     | returns ""
  {}       | returns ""
  "foo"    | TypeError("an integer is required") via 'os.strerror(retval)'
  set([1]) | TypeError("can only compare to a set") via 'retval > 0'
  <?>      | TypeError: %d format: a number is required, not <?> via '%d'

Where <?> is some hypothetical value that is boolean True and
compares as <= 0, couldn't find any though, everything besides None
seemed to sort above integer types.


On Mon, Mar 5, 2012 at 1:59 PM, Ben Pfaff <b...@nicira.com> wrote:

> I think Reid is just saying that "if not retval:" accepts more than
> just 0.  It also treats None, "", (), and [], for example, as false.
>
> On Mon, Mar 05, 2012 at 01:57:05PM -0800, Ethan Jackson wrote:
> > I'm sorry, I don't fully understand what you're suggesting.  Could you
> > please give an example of a piece of code that should change?
> >
> > Based on my reading of the code, when there's an error we return a
> > non-zero errno.  The errno is always an integer type.  Sometimes in
> > addition to the errno we return some additional information, but that
> > isn't used for checking error conditions.
> >
> > Ethan
> >
> > On Sun, Mar 4, 2012 at 21:23, Reid Price <r...@nicira.com> wrote:
> > > One other note, are you deliberately allowing None (along with other
> python
> > > expressions that are False as booleans) to equate to a 0 return code?
>  You
> > > may just want to check for integer type at the beginning of the
> function,
> > > since
> > > things compare across type without error (for error-free sorting
> purposes,
> > > ostensibly).  E.g.:
> > >
> > > {1: 2} > 0 == True
> > > "string" > 0 == True
> > >
> > > Some things will throw TypeErrors for the >0, like sets and complex
> numbers.
> > >
> > >   -Reid
> > >
> > > On Thu, Mar 1, 2012 at 5:40 PM, Ethan Jackson <et...@nicira.com>
> wrote:
> > >>
> > >> > In the final case in ovs_retval_to_string(), I think I'd use %s
> > >> > instead of %d: maybe some non-integer value got passed in and my
> > >> > instinct is that it's probably better to convert it to a string than
> > >> > to throw an exception.
> > >>
> > >> Sounds good, I've folded the change in.
> > >>
> > >> Ethan
> > >> _______________________________________________
> > >> dev mailing list
> > >> dev@openvswitch.org
> > >> http://openvswitch.org/mailman/listinfo/dev
> > >
> > >
>
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to