
The lltype's are very strict about types. If I declare an llexternal that takes a Float arg, I cannot call it with an int arg. Well maybe that's not so bad. But in rlib.rsdl there are functions that take Unsigned, and these don't work even if called with a non-negative constant int... Can we loosen up these restrictions ? Maybe put an "is_compatable(self, other)" method on LowLevelType's ? Simon. using py lib: /home/simon/local/pypy-latest/py <rev 45205> test/test_SDL.py[2] FF __________________________________________________________________________________________________________________________________________________________________________________________________________ entrypoint: test_run ____________________________________________________________ def test_run():
demo()
[/home/simon/local/pypy-latest/pypy/rlib/rsdl/test/test_SDL.py:48] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def demo():
if SDL.Init(SDL.INIT_VIDEO) < 0:
[/home/simon/local/pypy-latest/pypy/rlib/rsdl/test/test_SDL.py:13] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __call__(self, *args): if isinstance(self._T, FuncType): if len(args) != len(self._T.ARGS): raise TypeError,"calling %r with wrong argument number: %r" % (self._T, args) for a, ARG in zip(args, self._T.ARGS): if typeOf(a) != ARG: E raise TypeError,"calling %r with wrong argument types: %r" % (self._T, args)
TypeError: calling <Func ( Unsigned ) -> Signed> with wrong argument types: (32,)
...

Hi Simon, On Thu, Jul 19, 2007 at 06:31:17PM -0700, Simon Burton wrote:
The lltype's are very strict about types.
Indeed, it seems worthwhile to loosen this restriction at least for the purpose of calling external functions... Not sure how, but there are possible hacks at least. Armin

On Fri, 20 Jul 2007 14:52:54 +0200 Armin Rigo <arigo@tunes.org> wrote:
Following some hints from Samuele, I am trying to wrap such functions in another function that does some casting. Here is my first attempt. It does no casting, but i already can't get it to work. def softwrapper(funcptr, arg_tps): unrolling_arg_tps = unrolling_iterable(enumerate(arg_tps)) def softfunc(*args): real_args = tuple([args[i] for i, tp in unrolling_arg_tps]) result = funcptr(*real_args) return softfunc where funcptr comes from a call to llexternal. It seems the tuple construction should not work (each args[i] is a different type), but instead i get: CallPatternTooComplex': '*' argument must be SomeTuple. Um.. My only guess now is to malloc a TUPLE_TYPE.. ?!? no idea.. (I am really sick of code generation and hope it doesn't come to that). Simon.

On Wed, 22 Aug 2007 15:23:40 -0700 Simon Burton <simon@arrowtheory.com> wrote:
Following some hints from Samuele, I am trying to wrap such functions in another function that does some casting.
Here is the latest: def softwrapper(funcptr, arg_tps): unrolling_arg_tps = unrolling_iterable(enumerate(arg_tps)) def softfunc(*args): real_args = () for i, tp in unrolling_arg_tps: real_args = real_args + (args[i],) result = funcptr(*real_args) return result return softfunc When applied to llexternal's that have pointer-to-struct args the generated c code breaks; it decides to declare&use anonymous structs: long pypy_g_softfunc_star2_1(struct pypy__cairo_surface0 *l_stararg0_7, struct pypy_array3 *l_stararg1_7) { long l_v492; block0: l_v492 = cairo_surface_write_to_png(l_stararg0_7, l_stararg1_7); goto block1; block1: RPY_DEBUG_RETURN(); return l_v492; } where cairo_surface_write_to_png is declared: cairo_surface_write_to_png (cairo_surface_t *surface, const char *filename); I wonder if the annotator is getting confused by the real_args tuple growing...

On Thu, 23 Aug 2007 19:13:26 +0200 Maciek Fijalkowski <fijal@genesilico.pl> wrote:
You need to create the structure which you push by hand. As well as array argument.
No, structure comes from a call to another llexternal. It makes no sense to clone it. It should be an opaque struct anyway. Simon.

Hi Simon, On Thu, Jul 19, 2007 at 06:31:17PM -0700, Simon Burton wrote:
The lltype's are very strict about types.
Indeed, it seems worthwhile to loosen this restriction at least for the purpose of calling external functions... Not sure how, but there are possible hacks at least. Armin

On Fri, 20 Jul 2007 14:52:54 +0200 Armin Rigo <arigo@tunes.org> wrote:
Following some hints from Samuele, I am trying to wrap such functions in another function that does some casting. Here is my first attempt. It does no casting, but i already can't get it to work. def softwrapper(funcptr, arg_tps): unrolling_arg_tps = unrolling_iterable(enumerate(arg_tps)) def softfunc(*args): real_args = tuple([args[i] for i, tp in unrolling_arg_tps]) result = funcptr(*real_args) return softfunc where funcptr comes from a call to llexternal. It seems the tuple construction should not work (each args[i] is a different type), but instead i get: CallPatternTooComplex': '*' argument must be SomeTuple. Um.. My only guess now is to malloc a TUPLE_TYPE.. ?!? no idea.. (I am really sick of code generation and hope it doesn't come to that). Simon.

On Wed, 22 Aug 2007 15:23:40 -0700 Simon Burton <simon@arrowtheory.com> wrote:
Following some hints from Samuele, I am trying to wrap such functions in another function that does some casting.
Here is the latest: def softwrapper(funcptr, arg_tps): unrolling_arg_tps = unrolling_iterable(enumerate(arg_tps)) def softfunc(*args): real_args = () for i, tp in unrolling_arg_tps: real_args = real_args + (args[i],) result = funcptr(*real_args) return result return softfunc When applied to llexternal's that have pointer-to-struct args the generated c code breaks; it decides to declare&use anonymous structs: long pypy_g_softfunc_star2_1(struct pypy__cairo_surface0 *l_stararg0_7, struct pypy_array3 *l_stararg1_7) { long l_v492; block0: l_v492 = cairo_surface_write_to_png(l_stararg0_7, l_stararg1_7); goto block1; block1: RPY_DEBUG_RETURN(); return l_v492; } where cairo_surface_write_to_png is declared: cairo_surface_write_to_png (cairo_surface_t *surface, const char *filename); I wonder if the annotator is getting confused by the real_args tuple growing...

On Thu, 23 Aug 2007 19:13:26 +0200 Maciek Fijalkowski <fijal@genesilico.pl> wrote:
You need to create the structure which you push by hand. As well as array argument.
No, structure comes from a call to another llexternal. It makes no sense to clone it. It should be an opaque struct anyway. Simon.
participants (3)
-
Armin Rigo
-
Maciek Fijalkowski
-
Simon Burton