Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.14 KB | None | 0 0
  1. cat foo.h foo.c make-shared-lib.sh foo.l example-foo.l
  2. #ifndef foo_h__
  3. #define foo_h__
  4.  
  5. struct Rect
  6. {
  7.   int x,y;
  8.   int w,h;
  9. };
  10.  
  11. void foo(struct Rect *r);
  12.  
  13. #endif  // foo_h__
  14. /* module foo.c */
  15. #include <stdio.h>
  16. #include "foo.h"
  17.  
  18. void foo(struct Rect *r)
  19. {
  20.     printf("Hello from foo!\n");
  21.     printf("rect.x=%d\n", r->x);
  22.     printf("rect.y=%d\n", r->y);
  23.     printf("rect.w=%d\n", r->w);
  24.     printf("rect.h=%d\n", r->h);
  25. }
  26. /* module foo.c */
  27. #!/bin/sh
  28. rm -f libfoo.so foo.o
  29. gcc -c -Wall -Werror -fpic foo.c && gcc -shared -o libfoo.so foo.o
  30. #end of script make-share-foolib.sh
  31. ######### foo.l ########################
  32. (default
  33.    *foolib "./libfoo.so")
  34.  
  35.  
  36. (de foo (x y w h)
  37.     #segfaults on calling of foo with params
  38.     #(native `*foolib "foo" 'N (list NIL (16) (list (x . 4) (y . 4) (cons w 4) (cons h 4)))))
  39.    
  40.     #calls foo, but values are incorrect
  41.     (native `*foolib "foo" 'N (list NIL (16) (list (4 . x) (4 . y) (cons 4 w) (cons 4 h)))))
  42.  
  43. ######### foo.l ########################
  44. ####### example-foo.l ##################
  45. (load "foo.l")
  46. (foo 2132 32321 43432 43433)
  47. ########################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement