/* -*- Mode: C -*- C Stub Generator for Scheme Scheme48 Support Header Copyright (c) 2009, Taylor R. Campbell Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the names of the authors nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include /* FIXME: This should go into a separate header file, say s48-stub-unix.h. */ #define SCHEME_VOID_SYSCALL(SYSCALL, EXPRESSION) \ do { \ _scheme_void_syscall_ ## SYSCALL ## _loop: \ if ((EXPRESSION) < 0) \ SCHEME_SYSCALL_FAILURE \ (SYSCALL, errno, \ goto _scheme_void_syscall_ ## SYSCALL ## _loop); \ } while (0) #define SCHEME_UINT_SYSCALL(SYSCALL, RESULT_LOC, EXPRESSION) \ do { \ _scheme_uint_syscall_ ## SYSCALL ## _loop: \ if (((RESULT_LOC) = (EXPRESSION)) < 0) \ SCHEME_SYSCALL_FAILURE \ (SYSCALL, errno, \ goto _scheme_uint_syscall_ ## SYSCALL ## _loop); \ } while (0) #define SCHEME_SYSCALL_FAILURE(SYSCALL, ERROR_CODE, RETRY) \ do { \ if ((ERROR_CODE) == EINTR) \ SCHEME_SYSCALL_INTERRUPT (SYSCALL, RETRY); \ else \ SCHEME_SYSCALL_ERROR (SYSCALL, ERROR_CODE); \ } while (0) #define SCHEME_SYSCALL_INTERRUPT(SYSCALL, RETRY) \ RETRY #define SCHEME_SYSCALL_ERROR(SYSCALL, ERROR_CODE) \ s48_raise_os_error (ERROR_CODE) #define SCHEME_OUT_OF_MEMORY_ERROR() \ s48_raise_out_of_memory_error () /* FIXME: This should go into a separate header file, say s48-stub-enumerations.h. */ #define SCHEME_DEFINE_ENUMERAND_SCHEME_TO_C(NAME, TYPE, MAP) \ int \ NAME (s48_value index_s48, TYPE *result_location) \ { \ long index = (s48_extract_integer (index_s48)); \ if (((MAP) [index]) . available_p) \ { \ (*result_location) = (((MAP) [index]) . value); \ return (1); \ } \ else \ return (0); \ } /* It might be better to turn this into a switch. */ #define SCHEME_DEFINE_ENUMERAND_C_TO_SCHEME(NAME, TYPE, MAP, BINDING, COUNT) \ int \ NAME (TYPE value, s48_value *result_location) \ { \ int index; \ s48_value vector = (S48_SHARED_BINDING_REF (BINDING)); \ \ if (! (S48_VECTOR_P (vector))) \ s48_raise_string_os_error ("Uninitialized enumerand vector."); \ \ for (index = 0; (index < (COUNT)); index += 1) \ if ((((MAP) [index]) . available_p) \ && (value == (((MAP) [index]) . value))) \ { \ (*result_location) = (S48_UNSAFE_VECTOR_REF (vector, index)); \ return (1); \ } \ return (0); \ } extern s48_value s48_enter_signed_integer (signed long integer); extern s48_value s48_enter_unsigned_integer (unsigned long integer); extern signed long s48_extract_signed_integer (s48_value integer_s48); extern unsigned long s48_extract_unsigned_integer (s48_value integer_s48); extern char * s48_extract_and_copy_string (s48_value string_s48); extern char * s48_extract_and_copy_byte_vector (s48_value bv_s48, size_t *length_loc); extern s48_value s48_enter_asciz_substring (const char *string, size_t offset, size_t size); extern s48_value s48_enter_and_free_asciz_substring (char *string, size_t offset, size_t size); extern s48_value s48_enter_byte_subvector (const char *string, size_t offset, size_t size); extern s48_value s48_enter_and_free_byte_subvector (char *string, size_t offset, size_t size);