Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve foreign interface signed and unsigned integer conversion #724

Merged
merged 7 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions LOG
Original file line number Diff line number Diff line change
Expand Up @@ -2441,3 +2441,17 @@
wininstall/ta6nt.wxs wininstall/ti3nt.wxs
- fix (library <library reference>) import syntax
mats/8.ms release_notes/release_notes.stex s/syntax.ss
- add Sint32_t, Suint32_t, Sint64_t, Suint64_t types for cross-platform
code that uses scheme.h exports
boot/*/scheme.h c/number.c csug/foreign.stex
release_notes/release_notes.stex s/mkheader.ss
- fix handling of most-negative-fixnum in Sinteger32 and Sinteger64
c/number.c mats/foreign1.c mats/foreign.ms release_notes/release_notes.stex
- fix 32-bit C integer/unsigned to bignum conversion
c/number.c release_notes/release_notes.stex
- add functions that try to convert from Scheme to C signed and unsigned
integers without throwing exceptions; use the new functions in Sscheme_start
and run_script
boot/*/scheme.h c/externs.h c/number.c c/scheme.c csug/foreign.stex
mats/foreign1.c mats/foreign.ms release_notes/release_notes.stex
s/mkheader.ss
28 changes: 20 additions & 8 deletions boot/a6le/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ typedef void * ptr;
typedef long int iptr;
typedef unsigned long int uptr;

/* Integer typedefs */
typedef int Sint32_t;
typedef unsigned int Suint32_t;
typedef long Sint64_t;
typedef unsigned long Suint64_t;

/* String elements are 32-bit tagged char objects */
typedef unsigned int string_char;

Expand Down Expand Up @@ -107,10 +113,16 @@ typedef unsigned char octet;
#define Sunbox(x) (*((ptr *)((uptr)(x)+9)))
EXPORT iptr Sinteger_value(ptr);
#define Sunsigned_value(x) (uptr)Sinteger_value(x)
EXPORT int Sinteger32_value(ptr);
#define Sunsigned32_value(x) (unsigned int)Sinteger32_value(x)
EXPORT long Sinteger64_value(ptr);
#define Sunsigned64_value(x) (unsigned long)Sinteger64_value(x)
EXPORT Sint32_t Sinteger32_value(ptr);
#define Sunsigned32_value(x) (Suint32_t)Sinteger32_value(x)
EXPORT Sint64_t Sinteger64_value(ptr);
EXPORT int Stry_integer_value(ptr, iptr*, const char**);
EXPORT int Stry_integer32_value(ptr, Sint32_t*, const char**);
EXPORT int Stry_integer64_value(ptr, Sint64_t*, const char**);
#define Sunsigned64_value(x) (Suint64_t)Sinteger64_value(x)
EXPORT int Stry_unsigned_value(ptr, uptr*, const char**);
EXPORT int Stry_unsigned32_value(ptr, Suint32_t*, const char**);
EXPORT int Stry_unsigned64_value(ptr, Suint64_t*, const char**);

/* Mutators */
EXPORT void Sset_box(ptr, ptr);
Expand Down Expand Up @@ -146,10 +158,10 @@ EXPORT ptr Sstring_utf8(const char*, iptr);
EXPORT ptr Sbox(ptr);
EXPORT ptr Sinteger(iptr);
EXPORT ptr Sunsigned(uptr);
EXPORT ptr Sinteger32(int);
EXPORT ptr Sunsigned32(unsigned int);
EXPORT ptr Sinteger64(long);
EXPORT ptr Sunsigned64(unsigned long);
EXPORT ptr Sinteger32(Sint32_t);
EXPORT ptr Sunsigned32(Suint32_t);
EXPORT ptr Sinteger64(Sint64_t);
EXPORT ptr Sunsigned64(Suint64_t);

/* Miscellaneous */
EXPORT ptr Stop_level_value(ptr);
Expand Down
28 changes: 20 additions & 8 deletions boot/a6nt/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ typedef void * ptr;
typedef long long int iptr;
typedef unsigned long long int uptr;

/* Integer typedefs */
typedef int Sint32_t;
typedef unsigned int Suint32_t;
typedef long long Sint64_t;
typedef unsigned long long Suint64_t;

/* String elements are 32-bit tagged char objects */
typedef unsigned int string_char;

Expand Down Expand Up @@ -107,10 +113,16 @@ typedef unsigned char octet;
#define Sunbox(x) (*((ptr *)((uptr)(x)+9)))
EXPORT iptr Sinteger_value(ptr);
#define Sunsigned_value(x) (uptr)Sinteger_value(x)
EXPORT int Sinteger32_value(ptr);
#define Sunsigned32_value(x) (unsigned int)Sinteger32_value(x)
EXPORT long long Sinteger64_value(ptr);
#define Sunsigned64_value(x) (unsigned long long)Sinteger64_value(x)
EXPORT Sint32_t Sinteger32_value(ptr);
#define Sunsigned32_value(x) (Suint32_t)Sinteger32_value(x)
EXPORT Sint64_t Sinteger64_value(ptr);
EXPORT int Stry_integer_value(ptr, iptr*, const char**);
EXPORT int Stry_integer32_value(ptr, Sint32_t*, const char**);
EXPORT int Stry_integer64_value(ptr, Sint64_t*, const char**);
#define Sunsigned64_value(x) (Suint64_t)Sinteger64_value(x)
EXPORT int Stry_unsigned_value(ptr, uptr*, const char**);
EXPORT int Stry_unsigned32_value(ptr, Suint32_t*, const char**);
EXPORT int Stry_unsigned64_value(ptr, Suint64_t*, const char**);

/* Mutators */
EXPORT void Sset_box(ptr, ptr);
Expand Down Expand Up @@ -146,10 +158,10 @@ EXPORT ptr Sstring_utf8(const char*, iptr);
EXPORT ptr Sbox(ptr);
EXPORT ptr Sinteger(iptr);
EXPORT ptr Sunsigned(uptr);
EXPORT ptr Sinteger32(int);
EXPORT ptr Sunsigned32(unsigned int);
EXPORT ptr Sinteger64(long long);
EXPORT ptr Sunsigned64(unsigned long long);
EXPORT ptr Sinteger32(Sint32_t);
EXPORT ptr Sunsigned32(Suint32_t);
EXPORT ptr Sinteger64(Sint64_t);
EXPORT ptr Sunsigned64(Suint64_t);

/* Miscellaneous */
EXPORT ptr Stop_level_value(ptr);
Expand Down
28 changes: 20 additions & 8 deletions boot/a6osx/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ typedef void * ptr;
typedef long int iptr;
typedef unsigned long int uptr;

/* Integer typedefs */
typedef int Sint32_t;
typedef unsigned int Suint32_t;
typedef long Sint64_t;
typedef unsigned long Suint64_t;

/* String elements are 32-bit tagged char objects */
typedef unsigned int string_char;

Expand Down Expand Up @@ -107,10 +113,16 @@ typedef unsigned char octet;
#define Sunbox(x) (*((ptr *)((uptr)(x)+9)))
EXPORT iptr Sinteger_value(ptr);
#define Sunsigned_value(x) (uptr)Sinteger_value(x)
EXPORT int Sinteger32_value(ptr);
#define Sunsigned32_value(x) (unsigned int)Sinteger32_value(x)
EXPORT long Sinteger64_value(ptr);
#define Sunsigned64_value(x) (unsigned long)Sinteger64_value(x)
EXPORT Sint32_t Sinteger32_value(ptr);
#define Sunsigned32_value(x) (Suint32_t)Sinteger32_value(x)
EXPORT Sint64_t Sinteger64_value(ptr);
EXPORT int Stry_integer_value(ptr, iptr*, const char**);
EXPORT int Stry_integer32_value(ptr, Sint32_t*, const char**);
EXPORT int Stry_integer64_value(ptr, Sint64_t*, const char**);
#define Sunsigned64_value(x) (Suint64_t)Sinteger64_value(x)
EXPORT int Stry_unsigned_value(ptr, uptr*, const char**);
EXPORT int Stry_unsigned32_value(ptr, Suint32_t*, const char**);
EXPORT int Stry_unsigned64_value(ptr, Suint64_t*, const char**);

/* Mutators */
EXPORT void Sset_box(ptr, ptr);
Expand Down Expand Up @@ -146,10 +158,10 @@ EXPORT ptr Sstring_utf8(const char*, iptr);
EXPORT ptr Sbox(ptr);
EXPORT ptr Sinteger(iptr);
EXPORT ptr Sunsigned(uptr);
EXPORT ptr Sinteger32(int);
EXPORT ptr Sunsigned32(unsigned int);
EXPORT ptr Sinteger64(long);
EXPORT ptr Sunsigned64(unsigned long);
EXPORT ptr Sinteger32(Sint32_t);
EXPORT ptr Sunsigned32(Suint32_t);
EXPORT ptr Sinteger64(Sint64_t);
EXPORT ptr Sunsigned64(Suint64_t);

/* Miscellaneous */
EXPORT ptr Stop_level_value(ptr);
Expand Down
28 changes: 20 additions & 8 deletions boot/arm32le/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ typedef void * ptr;
typedef int iptr;
typedef unsigned int uptr;

/* Integer typedefs */
typedef int Sint32_t;
typedef unsigned int Suint32_t;
typedef long long Sint64_t;
typedef unsigned long long Suint64_t;

/* String elements are 32-bit tagged char objects */
typedef unsigned int string_char;

Expand Down Expand Up @@ -107,10 +113,16 @@ typedef unsigned char octet;
#define Sunbox(x) (*((ptr *)((uptr)(x)+5)))
EXPORT iptr Sinteger_value(ptr);
#define Sunsigned_value(x) (uptr)Sinteger_value(x)
EXPORT int Sinteger32_value(ptr);
#define Sunsigned32_value(x) (unsigned int)Sinteger32_value(x)
EXPORT long long Sinteger64_value(ptr);
#define Sunsigned64_value(x) (unsigned long long)Sinteger64_value(x)
EXPORT Sint32_t Sinteger32_value(ptr);
#define Sunsigned32_value(x) (Suint32_t)Sinteger32_value(x)
EXPORT Sint64_t Sinteger64_value(ptr);
EXPORT int Stry_integer_value(ptr, iptr*, const char**);
EXPORT int Stry_integer32_value(ptr, Sint32_t*, const char**);
EXPORT int Stry_integer64_value(ptr, Sint64_t*, const char**);
#define Sunsigned64_value(x) (Suint64_t)Sinteger64_value(x)
EXPORT int Stry_unsigned_value(ptr, uptr*, const char**);
EXPORT int Stry_unsigned32_value(ptr, Suint32_t*, const char**);
EXPORT int Stry_unsigned64_value(ptr, Suint64_t*, const char**);

/* Mutators */
EXPORT void Sset_box(ptr, ptr);
Expand Down Expand Up @@ -146,10 +158,10 @@ EXPORT ptr Sstring_utf8(const char*, iptr);
EXPORT ptr Sbox(ptr);
EXPORT ptr Sinteger(iptr);
EXPORT ptr Sunsigned(uptr);
EXPORT ptr Sinteger32(int);
EXPORT ptr Sunsigned32(unsigned int);
EXPORT ptr Sinteger64(long long);
EXPORT ptr Sunsigned64(unsigned long long);
EXPORT ptr Sinteger32(Sint32_t);
EXPORT ptr Sunsigned32(Suint32_t);
EXPORT ptr Sinteger64(Sint64_t);
EXPORT ptr Sunsigned64(Suint64_t);

/* Miscellaneous */
EXPORT ptr Stop_level_value(ptr);
Expand Down
28 changes: 20 additions & 8 deletions boot/i3le/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ typedef void * ptr;
typedef int iptr;
typedef unsigned int uptr;

/* Integer typedefs */
typedef int Sint32_t;
typedef unsigned int Suint32_t;
typedef long long Sint64_t;
typedef unsigned long long Suint64_t;

/* String elements are 32-bit tagged char objects */
typedef unsigned int string_char;

Expand Down Expand Up @@ -107,10 +113,16 @@ typedef unsigned char octet;
#define Sunbox(x) (*((ptr *)((uptr)(x)+5)))
EXPORT iptr Sinteger_value(ptr);
#define Sunsigned_value(x) (uptr)Sinteger_value(x)
EXPORT int Sinteger32_value(ptr);
#define Sunsigned32_value(x) (unsigned int)Sinteger32_value(x)
EXPORT long long Sinteger64_value(ptr);
#define Sunsigned64_value(x) (unsigned long long)Sinteger64_value(x)
EXPORT Sint32_t Sinteger32_value(ptr);
#define Sunsigned32_value(x) (Suint32_t)Sinteger32_value(x)
EXPORT Sint64_t Sinteger64_value(ptr);
EXPORT int Stry_integer_value(ptr, iptr*, const char**);
EXPORT int Stry_integer32_value(ptr, Sint32_t*, const char**);
EXPORT int Stry_integer64_value(ptr, Sint64_t*, const char**);
#define Sunsigned64_value(x) (Suint64_t)Sinteger64_value(x)
EXPORT int Stry_unsigned_value(ptr, uptr*, const char**);
EXPORT int Stry_unsigned32_value(ptr, Suint32_t*, const char**);
EXPORT int Stry_unsigned64_value(ptr, Suint64_t*, const char**);

/* Mutators */
EXPORT void Sset_box(ptr, ptr);
Expand Down Expand Up @@ -146,10 +158,10 @@ EXPORT ptr Sstring_utf8(const char*, iptr);
EXPORT ptr Sbox(ptr);
EXPORT ptr Sinteger(iptr);
EXPORT ptr Sunsigned(uptr);
EXPORT ptr Sinteger32(int);
EXPORT ptr Sunsigned32(unsigned int);
EXPORT ptr Sinteger64(long long);
EXPORT ptr Sunsigned64(unsigned long long);
EXPORT ptr Sinteger32(Sint32_t);
EXPORT ptr Sunsigned32(Suint32_t);
EXPORT ptr Sinteger64(Sint64_t);
EXPORT ptr Sunsigned64(Suint64_t);

/* Miscellaneous */
EXPORT ptr Stop_level_value(ptr);
Expand Down
28 changes: 20 additions & 8 deletions boot/i3nt/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ typedef void * ptr;
typedef int iptr;
typedef unsigned int uptr;

/* Integer typedefs */
typedef int Sint32_t;
typedef unsigned int Suint32_t;
typedef long long Sint64_t;
typedef unsigned long long Suint64_t;

/* String elements are 32-bit tagged char objects */
typedef unsigned int string_char;

Expand Down Expand Up @@ -107,10 +113,16 @@ typedef unsigned char octet;
#define Sunbox(x) (*((ptr *)((uptr)(x)+5)))
EXPORT iptr Sinteger_value(ptr);
#define Sunsigned_value(x) (uptr)Sinteger_value(x)
EXPORT int Sinteger32_value(ptr);
#define Sunsigned32_value(x) (unsigned int)Sinteger32_value(x)
EXPORT long long Sinteger64_value(ptr);
#define Sunsigned64_value(x) (unsigned long long)Sinteger64_value(x)
EXPORT Sint32_t Sinteger32_value(ptr);
#define Sunsigned32_value(x) (Suint32_t)Sinteger32_value(x)
EXPORT Sint64_t Sinteger64_value(ptr);
EXPORT int Stry_integer_value(ptr, iptr*, const char**);
EXPORT int Stry_integer32_value(ptr, Sint32_t*, const char**);
EXPORT int Stry_integer64_value(ptr, Sint64_t*, const char**);
#define Sunsigned64_value(x) (Suint64_t)Sinteger64_value(x)
EXPORT int Stry_unsigned_value(ptr, uptr*, const char**);
EXPORT int Stry_unsigned32_value(ptr, Suint32_t*, const char**);
EXPORT int Stry_unsigned64_value(ptr, Suint64_t*, const char**);

/* Mutators */
EXPORT void Sset_box(ptr, ptr);
Expand Down Expand Up @@ -146,10 +158,10 @@ EXPORT ptr Sstring_utf8(const char*, iptr);
EXPORT ptr Sbox(ptr);
EXPORT ptr Sinteger(iptr);
EXPORT ptr Sunsigned(uptr);
EXPORT ptr Sinteger32(int);
EXPORT ptr Sunsigned32(unsigned int);
EXPORT ptr Sinteger64(long long);
EXPORT ptr Sunsigned64(unsigned long long);
EXPORT ptr Sinteger32(Sint32_t);
EXPORT ptr Sunsigned32(Suint32_t);
EXPORT ptr Sinteger64(Sint64_t);
EXPORT ptr Sunsigned64(Suint64_t);

/* Miscellaneous */
EXPORT ptr Stop_level_value(ptr);
Expand Down
28 changes: 20 additions & 8 deletions boot/i3osx/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ typedef void * ptr;
typedef int iptr;
typedef unsigned int uptr;

/* Integer typedefs */
typedef int Sint32_t;
typedef unsigned int Suint32_t;
typedef long long Sint64_t;
typedef unsigned long long Suint64_t;

/* String elements are 32-bit tagged char objects */
typedef unsigned int string_char;

Expand Down Expand Up @@ -107,10 +113,16 @@ typedef unsigned char octet;
#define Sunbox(x) (*((ptr *)((uptr)(x)+5)))
EXPORT iptr Sinteger_value(ptr);
#define Sunsigned_value(x) (uptr)Sinteger_value(x)
EXPORT int Sinteger32_value(ptr);
#define Sunsigned32_value(x) (unsigned int)Sinteger32_value(x)
EXPORT long long Sinteger64_value(ptr);
#define Sunsigned64_value(x) (unsigned long long)Sinteger64_value(x)
EXPORT Sint32_t Sinteger32_value(ptr);
#define Sunsigned32_value(x) (Suint32_t)Sinteger32_value(x)
EXPORT Sint64_t Sinteger64_value(ptr);
EXPORT int Stry_integer_value(ptr, iptr*, const char**);
EXPORT int Stry_integer32_value(ptr, Sint32_t*, const char**);
EXPORT int Stry_integer64_value(ptr, Sint64_t*, const char**);
#define Sunsigned64_value(x) (Suint64_t)Sinteger64_value(x)
EXPORT int Stry_unsigned_value(ptr, uptr*, const char**);
EXPORT int Stry_unsigned32_value(ptr, Suint32_t*, const char**);
EXPORT int Stry_unsigned64_value(ptr, Suint64_t*, const char**);

/* Mutators */
EXPORT void Sset_box(ptr, ptr);
Expand Down Expand Up @@ -146,10 +158,10 @@ EXPORT ptr Sstring_utf8(const char*, iptr);
EXPORT ptr Sbox(ptr);
EXPORT ptr Sinteger(iptr);
EXPORT ptr Sunsigned(uptr);
EXPORT ptr Sinteger32(int);
EXPORT ptr Sunsigned32(unsigned int);
EXPORT ptr Sinteger64(long long);
EXPORT ptr Sunsigned64(unsigned long long);
EXPORT ptr Sinteger32(Sint32_t);
EXPORT ptr Sunsigned32(Suint32_t);
EXPORT ptr Sinteger64(Sint64_t);
EXPORT ptr Sunsigned64(Suint64_t);

/* Miscellaneous */
EXPORT ptr Stop_level_value(ptr);
Expand Down
Loading