develooper Front page | perl.perl5.porters | Postings from October 2016

Nullable XS types

Thread Next
From:
Paul "LeoNerd" Evans
Date:
October 22, 2016 23:06
Subject:
Nullable XS types
Message ID:
20161023000557.4e4c5efa@shy.leonerd.org.uk
Currently I have to do somewhat awkward steps to make a type that XS is
happy to let turn perl-level undef into C-level NULL on input:
  https://metacpan.org/source/PEVANS/Tickit-0.59/typemap#L9

This is somewhat awkward as, in this typemap file, I've had to decide
what entire types are always nullable, or which ones never are. I can't
make a decision on a per-function basis what will happen.

I would like to be able to decide this at the level of individual
functions. Does anyone have any suggestions?

Ideeeeally what I'd love is to be able to simply type:

  void
  somefunc(self,rect)
    SV *self
    Tickit::Rect? rect

or some other suitable abuse of notation, to say "Hey, XS, allow a
perl-level undef to come in here, and that means the C-level value
should be NULL". Perhaps similar for OUTPUT types

  Tickit::Rect?
  anotherfunc(self)
    SV *self

to mean that if I set RETVAL = NULL then that means it should return an
undef to perl.

Short of that somewhat-pipedream, is there anything practical I can do
now, with existing technology, to make this a little less awkward?

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About