Created originally on Bitbucket by antocuni (Antonio Cuni)
As the title says, the point is to avoid declaring lltypes by hand.
I think that the final result is much easier to read and to manage. Currently, the C bits needs to be written by hand, but we can probably hack more until it can read the real universal/hpy.h
or an autogen version which is easier to parse. Another plus is that once this is merged, we can think of using C-like declarations inside @apifunc
decorators, which will make things even easier to read.
The most tricky bits of this PR are:
- the difference between
HPy
in C and RPython; I don’t think thatrffi
can handle a real struct to pass around and to be returned, so we need to stick with a primitive. Because of this, I had to play around with typedefs so that the C-idea ofHPy
and the RPython-idea ofHPy
are compatible both before and after translation - It seems that
cpyext.cparser
has a limitation for which it cannot properly digest struct types which are not part of a typedef. For now, I had to tweak a bit the headers and use typedefs everywhere. Ideally, it would be nice ifcparser
were able to do the correct thing automatically - Another limitation of
cparser
: struct fields of typeHPyMethodDef*
are translated intolltype.Ptr(HPyMethodDef)
: I had to hack it manually to transform it into theCArrayPtr
which we need. Not sure if it’s worth extendingcparser
to support also this case or it’s enough to keep this hack. - As explained by
XXX
inllapi.py:101
, the oldlltype.Struct
which we declared by hand had theeci
hint. The new ones don’t, but things still work correctly. So, why did we need theeci
in the first place, and is it the correct thing to just drop it? - I modified the repr of
lltype.Ptr
to show also the hints, elseCCHARP
andCONST_CCHARP
had the very same textual repr, which leaded to very confusing error messages.
Links to builbod builds for rpython and own tests:
http://buildbot.pypy.org/builders/rpython-linux-x86-64/builds/243
http://buildbot.pypy.org/builders/own-linux-x86-64/builds/7829