static void scm_error_internal(const char *func_name, ScmObj obj, const char *msg, va_list args) { ScmObj reason, err_obj; if (l_error_looped) scm_fatal_error("bug: double error on preparing error object"); /* It is supposed that no continuation switching occurs on this guarded * duration. So the global variable based guard works properly. */ l_error_looped = scm_true; #if (SCM_USE_FORMAT && SCM_USE_SRFI6) reason = scm_vformat(SCM_FALSE, SCM_FMT_INTERNAL, msg, args); if (func_name) { reason = scm_format(SCM_FALSE, SCM_FMT_RAW_C, "in ~S: ~S~S", func_name, SCM_STRING_STR(reason), (EQ(obj, NO_ERR_OBJ) ? "" : ":")); } #else reason = CONST_STRING(msg); #endif err_obj = scm_make_error_obj(reason, (EQ(obj, NO_ERR_OBJ)) ? SCM_NULL : LIST_1(obj)); l_error_looped = scm_false; scm_raise_error(err_obj); /* NOTREACHED */ }
//get scm symbols: scm_from_utf8_symbol(name) SCM scm_connect_tls(SCM host, SCM port){ char hostbuf[256], portbuf[16]; //Assume the current locale is utf8, as the only function that lets //use use our own buffers implicitly uses the current locale if(!scm_is_string(host)){ scm_raise_error("wrong-type-arg", "expected string in position 1"); } else { size_t len = scm_to_locale_stringbuf(host, hostbuf, 256); if(len >= 256){ scm_raise_error("too-long", "hostname too long"); } else { hostbuf[len] = '\0'; } } if(scm_is_string(port)){ //make sure port looks like a number if(scm_is_false(scm_string_to_number(port, scm_from_int(10)))){ scm_raise_error("wrong-type-arg", "expected number or number as string in position 2"); } size_t len = scm_to_locale_stringbuf(port, portbuf, 32); if(len >= 16){ scm_raise_error("out-of-range", "Maximum port number is 65535"); } else { portbuf[len] = '\0'; } } else if(scm_is_integer(port)){ uint16_t portno = scm_to_uint16(port); snprintf(portbuf, 16, "%d", portno); } else { scm_raise_error("wrong-type-arg", "expected number or number as string in position 2"); } BIO *bio = connect_tls(hostbuf, portbuf); if(!bio){ scm_raise_error("system-error", "Failed to make tls connection"); } return scm_new_smob(tls_tag, (scm_t_bits)bio); }