Re: ffi idea: strip null pointers

  • From: Cosmin Apreutesei <cosmin.apreutesei@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 4 Jun 2012 16:14:46 +0300

> I think that would break this idiom:
>
> x = some_func_that_returns_a_pointer()
> if ffi.cast(intptr_t, x) == 0

That cast returns 0 when fed a nil or a NULL:

ffi.cast('intptr_t', ffi.new('int*', nil)) == 0 -> true
ffi.cast('intptr_t', nil) == 0 -> true

>  ...
>
> If what you want is consistency, I would go the opposite way, that is
> make it an error to initialize a pointer argument from a nil value.
>

But it's exactly additional checks like that that I'm trying to get
rid of. How would that solve the problem?

Other related posts: