diff --git a/libtest.c b/libtest.c index 90eb329..e565fc0 100644 --- a/libtest.c +++ b/libtest.c @@ -152,23 +152,37 @@ EXPORT struct test* init_struct(struct test* test) { EXPORT int test_check(struct test* test) { print_offsets(); + printf("C: Value of a is %c\n", test->a); assert(test->a == 1); + printf("C: Value of b is %c\n", test->b); assert(test->b == 'b'); + printf("C: Value of c is %lf\n", test->c); assert(test->c == 3.0); + printf("C: Value of d is %c\n", test->d); assert(test->d == 'd'); + printf("C: Value of e is %s\n", test->e); assert(test->e == NULL); + printf("C: Value of f is %f\n", test->f); assert(test->f == 6.0); + printf("C: Value of g is %f\n", test->g); assert(strcmp(test->g, "foo") == 0); + printf("C: Value of g is %i\n", test->h); assert(test->h == 8); + printf("C: Value of i is %s\n", test->i); assert(test->i == NULL); + printf("C: Value of j is %i\n", test->j); assert(test->j == 10); + printf("C: Value of k is %i\n", test->k); assert(test->k == 11); + printf("C: Value of l is %i\n", test->l); assert(test->l == 12); + printf("C: Value of m is %i\n", test->m); assert(test->m == 13); + printf("C: Value of n is %i\n", test->n); assert(test->n == 14); } -EXPORT struct test* test_new(struct test* test) { +EXPORT struct test* test_n1ew(struct test* test) { print_offsets(); struct test* t = malloc(sizeof(struct test)); t->a = 1; diff --git a/retropikzel/r7rs-pffi/r7rs-pffi-chibi.stub b/retropikzel/r7rs-pffi/r7rs-pffi-chibi.stub index 89d1ae2..bde16cd 100644 --- a/retropikzel/r7rs-pffi/r7rs-pffi-chibi.stub +++ b/retropikzel/r7rs-pffi/r7rs-pffi-chibi.stub @@ -65,47 +65,47 @@ (define-c void (pointer-free pointer_free) ((maybe-null void*))) ;; pffi-pointer-set! -(c-declare "void pointer_set_c_int8_t(void* pointer, int offset, int8_t value) { int8_t* p = (int8_t*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_int8_t(void* pointer, int offset, int8_t value) { *(int8_t*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-int8_t! pointer_set_c_int8_t) ((pointer void*) int int8_t)) -(c-declare "void pointer_set_c_uint8_t(void* pointer, int offset, uint8_t value) { uint8_t* p = (uint8_t*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_uint8_t(void* pointer, int offset, uint8_t value) { *(uint8_t*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-uint8_t! pointer_set_c_uint8_t) ((pointer void*) int uint8_t)) -(c-declare "void pointer_set_c_int16_t(void* pointer, int offset, int16_t value) { int16_t* p = (int16_t*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_int16_t(void* pointer, int offset, int16_t value) { *(int16_t*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-int16_t! pointer_set_c_int16_t) ((pointer void*) int int16_t)) -(c-declare "void pointer_set_c_uint16_t(void* pointer, int offset, uint16_t value) { uint16_t* p = (uint16_t*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_uint16_t(void* pointer, int offset, uint16_t value) { *(uint16_t*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-uint16_t! pointer_set_c_uint16_t) ((pointer void*) int uint16_t)) -(c-declare "void pointer_set_c_int32_t(void* pointer, int offset, int32_t value) { int32_t* p = (int32_t*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_int32_t(void* pointer, int offset, int32_t value) { *(int32_t*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-int32_t! pointer_set_c_int32_t) ((pointer void*) int int32_t)) -(c-declare "void pointer_set_c_uint32_t(void* pointer, int offset, uint32_t value) { uint32_t* p = (uint32_t*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_uint32_t(void* pointer, int offset, uint32_t value) { *(uint32_t*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-uint32_t! pointer_set_c_uint32_t) ((pointer void*) int uint32_t)) -(c-declare "void pointer_set_c_int64_t(void* pointer, int offset, int64_t value) { int64_t* p = (int64_t*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_int64_t(void* pointer, int offset, int64_t value) { *(int64_t*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-int64_t! pointer_set_c_int64_t) ((pointer void*) int int64_t)) -(c-declare "void pointer_set_c_uint64_t(void* pointer, int offset, uint64_t value) { uint64_t* p = (uint64_t*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_uint64_t(void* pointer, int offset, uint64_t value) { *(uint64_t*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-uint64_t! pointer_set_c_uint64_t) ((pointer void*) int uint64_t)) -(c-declare "void pointer_set_c_char(void* pointer, int offset, char value) { char* p = (char*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_char(void* pointer, int offset, char value) { *((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-char! pointer_set_c_char) ((pointer void*) int char)) -(c-declare "void pointer_set_c_unsigned_char(void* pointer, int offset, unsigned char value) { unsigned char* p = (unsigned char*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_unsigned_char(void* pointer, int offset, unsigned char value) { *(unsigned char*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-unsigned-char! pointer_set_c_unsigned_char) ((pointer void*) int unsigned-char)) -(c-declare "void pointer_set_c_short(void* pointer, int offset, short value) { short* p = (short*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_short(void* pointer, int offset, short value) { *(short*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-short! pointer_set_c_short) ((pointer void*) int short)) -(c-declare "void pointer_set_c_unsigned_short(void* pointer, int offset, unsigned short value) { short* p = (unsigned short*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_unsigned_short(void* pointer, int offset, unsigned short value) { *(unsigned short*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-unsigned-short! pointer_set_c_unsigned_short) ((pointer void*) int unsigned-short)) -(c-declare "void pointer_set_c_int(void* pointer, int offset, int value) { int* p = (int*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_int(void* pointer, int offset, int value) { *(int*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-int! pointer_set_c_int) ((pointer void*) int int)) -(c-declare "void pointer_set_c_unsigned_int(void* pointer, int offset, unsigned int value) { int* p = (unsigned int*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_unsigned_int(void* pointer, int offset, unsigned int value) { *(unsigned int*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-unsigned-int! pointer_set_c_unsigned_int) ((pointer void*) int unsigned-int)) -(c-declare "void pointer_set_c_long(void* pointer, int offset, long value) { long* p = (long*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_long(void* pointer, int offset, long value) { *(long*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-long! pointer_set_c_long) ((pointer void*) int long)) -(c-declare "void pointer_set_c_unsigned_long(void* pointer, int offset, unsigned long value) { long* p = (unsigned long*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_unsigned_long(void* pointer, int offset, unsigned long value) { *(unsigned long*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-unsigned-long! pointer_set_c_unsigned_long) ((pointer void*) int unsigned-long)) -(c-declare "void pointer_set_c_float(void* pointer, int offset, float value) { float* p = (float*)pointer; p[offset] = value; }") +(c-declare "void pointer_set_c_float(void* pointer, int offset, float value) { *(float*)((char*)pointer + offset) = value; }") (define-c void (pointer-set-c-float! pointer_set_c_float) ((pointer void*) int float)) (c-declare "void pointer_set_c_double(void* pointer, int offset, double value) { *(double*)((char*)pointer + offset) = value; }") @@ -115,7 +115,7 @@ (define-c void (pointer-set-c-pointer! pointer_set_c_pointer) ((pointer void*) int (maybe-null void*))) ;; pffi-pointer-get -(c-declare "int8_t pointer_ref_c_int8_t(void* pointer, int offset) { return *(int8_t*)((char*)pointer + offset); }") +(c-declare "int8_t pointer_ref_c_int8_t(void* pointer, int offset) { return *(int8_t*)((char*)pointer + offset); }") (define-c int8_t (pointer-ref-c-int8_t pointer_ref_c_int8_t) ((pointer void*) int)) (c-declare "uint8_t pointer_ref_c_uint8_t(void* pointer, int offset) { return *(uint8_t*)((char*)pointer + offset); }") (define-c uint8_t (pointer-ref-c-uint8_t pointer_ref_c_uint8_t) ((pointer void*) int)) diff --git a/test.scm b/test.scm index 9995f80..56c34b9 100644 --- a/test.scm +++ b/test.scm @@ -646,9 +646,9 @@ (debug (pffi-struct-get struct-test 'l)) (assert = (pffi-struct-get struct-test 'l) 12) (debug (pffi-struct-get struct-test 'm)) -(assert = (pffi-struct-get struct-test 'm) 13) +(assert = (pffi-struct-get struct-test 'm) 13.0) (debug (pffi-struct-get struct-test 'n)) -(assert = (pffi-struct-get struct-test 'n) 14) +(assert = (pffi-struct-get struct-test 'n) 14.0) ;; pffi-struct-set! @@ -672,7 +672,7 @@ (float . n)))) (pffi-struct-set! struct-test1 'a 1) (pffi-struct-set! struct-test1 'b #\b) -;(pffi-struct-set! struct-test1 'c 3) ;FIXME +(pffi-struct-set! struct-test1 'c 3.0) (pffi-struct-set! struct-test1 'd #\d) (pffi-struct-set! struct-test1 'e (pffi-pointer-null)) (pffi-struct-set! struct-test1 'f 6.0) @@ -682,13 +682,13 @@ (pffi-struct-set! struct-test1 'j 10) (pffi-struct-set! struct-test1 'k 11) (pffi-struct-set! struct-test1 'l 12) -;(pffi-struct-set! struct-test1 'm 13) ;FIXME -;(pffi-struct-set! struct-test1 'n 14) ;FIXME +(pffi-struct-set! struct-test1 'm 13.0) +(pffi-struct-set! struct-test1 'n 14.0) (c-test-check (pffi-struct-pointer struct-test1)) ;; pffi-struct-make with pointer -(print-header 'pffi-struct-pointer-set!) +(print-header "pffi-struct-make with pointer") (pffi-define c-test-new c-testlib 'test_new 'pointer (list)) (define struct-test2 (pffi-struct-make 'test @@ -713,32 +713,33 @@ (assert = (pffi-struct-get struct-test2 'a) 1) (debug (pffi-struct-get struct-test2 'b)) (assert char=? (pffi-struct-get struct-test2 'b) #\b) -;(debug (pffi-struct-get struct-test2 'c)) ; FIXME -;(assert = (pffi-struct-get struct-test2 'c) 3) ; FIXME +(debug (pffi-struct-get struct-test2 'c)) +(assert = (pffi-struct-get struct-test2 'c) 3) (debug (pffi-struct-get struct-test2 'd)) (assert char=? (pffi-struct-get struct-test2 'd) #\d) -;(debug (pffi-struct-get struct-test2 'e)) ; FIXME -;(debug (pffi-pointer-null? (pffi-struct-get struct-test2 'e))) ; FIXME -; (assert (lambda (p t) (pffi-pointer-null? p)) (pffi-struct-get struct-test2 'e) #t) ; FIXME +(debug (pffi-struct-get struct-test2 'e)) +(debug (pffi-pointer-null? (pffi-struct-get struct-test2 'e))) +(assert equal? (pffi-pointer-null? (pffi-struct-get struct-test2 'e)) #t) (debug (pffi-struct-get struct-test2 'f)) (assert = (pffi-struct-get struct-test2 'f) 6.0) -;(debug (pffi-struct-get struct-test2 'g)) ; FIXME -;(assert (lambda (p t) (string=? (pffi-pointer->string p) "foo")) (pffi-struct-get struct-test2 'g) #t) ; FIXME +(debug (pffi-pointer->string (pffi-struct-get struct-test2 'g))) +(assert equal? (string=? (pffi-pointer->string (pffi-struct-get struct-test2 'g)) "FOOBAR") #t) (debug (pffi-struct-get struct-test2 'h)) (assert = (pffi-struct-get struct-test2 'h) 8) -;(debug (pffi-struct-get struct-test2 'i)) ; FIXME -;(debug (pffi-pointer-null? (pffi-struct-get struct-test2 'i))) ; FIXME -; (assert (lambda (p t) (pffi-pointer-null? p)) (pffi-struct-get struct-test2 'i) #t) ; FIXME +(debug (pffi-struct-get struct-test2 'i)) +(debug (pffi-pointer-null? (pffi-struct-get struct-test2 'i))) +(assert (lambda (p t) (pffi-pointer-null? p)) (pffi-struct-get struct-test2 'i) #t) (debug (pffi-struct-get struct-test2 'j)) (assert = (pffi-struct-get struct-test2 'j) 10) (debug (pffi-struct-get struct-test2 'k)) (assert = (pffi-struct-get struct-test2 'k) 11) (debug (pffi-struct-get struct-test2 'l)) (assert = (pffi-struct-get struct-test2 'l) 12) -;(debug (pffi-struct-get struct-test2 'm)) ; FIXME -;(assert = (pffi-struct-get struct-test2 'm) 13) ; FIXME +(debug (pffi-struct-get struct-test2 'm)) +(assert = (pffi-struct-get struct-test2 'm) 13.0) (debug (pffi-struct-get struct-test2 'n)) -(assert = (pffi-struct-get struct-test2 'n) 14) +(assert = (pffi-struct-get struct-test2 'n) 14.0) + ;; pffi-define-callback (print-header 'pffi-define-callback)