KvpValue * gnc_scm_to_kvp_value_ptr(SCM val) { if (scm_is_rational(val)) { if (scm_is_exact(val) && (scm_is_signed_integer(val, INT64_MIN, INT64_MAX) || scm_is_unsigned_integer(val, INT64_MIN, INT64_MAX))) { return new KvpValue{scm_to_int64(val)}; } else if (scm_is_exact(val) && (scm_is_signed_integer(scm_numerator(val), INT64_MIN, INT64_MAX) || scm_is_unsigned_integer(scm_numerator(val), INT64_MIN, INT64_MAX)) && (scm_is_signed_integer(scm_denominator(val), INT64_MIN, INT64_MAX) || (scm_is_unsigned_integer(scm_denominator(val), INT64_MIN, INT64_MAX)))) { return new KvpValue{gnc_scm_to_numeric(val)}; } else { return new KvpValue{scm_to_double(val)}; } } else if (gnc_guid_p(val)) { auto guid = gnc_scm2guid(val); auto tmpguid = guid_copy(&guid); return new KvpValue{tmpguid}; } else if (gnc_timepair_p(val)) { Timespec ts = gnc_timepair2timespec(val); return new KvpValue{ts}; } else if (scm_is_string(val)) { return new KvpValue{gnc_scm_to_utf8_string(val)}; } else if (SWIG_IsPointerOfType(val, SWIG_TypeQuery("_p_KvpFrame"))) { #define FUNC_NAME G_STRFUNC auto vp_frame = SWIG_MustGetPtr(val, SWIG_TypeQuery("_p_KvpFrame"), 1, 0); KvpFrame *frame = static_cast<KvpFrame*>(vp_frame); #undef FUNC_NAME return new KvpValue{frame}; } /* FIXME: add list handler here */ return NULL; }
static int port_seek (void *cookie, off64_t * pos, int whence) { SCM port = PTR2SCM (cookie); SCM new_pos; new_pos = scm_seek (port, scm_from_int64 (*pos), scm_from_int (whence)); *pos = scm_to_int64 (new_pos); return PORT_OK; }
KvpValue * gnc_scm_to_kvp_value_ptr(SCM val) { if (scm_is_number(val)) { /* in guile 1.8 (exact? ) only works on numbers */ if (scm_is_exact (val) && gnc_gh_gint64_p(val)) { return new KvpValue{scm_to_int64(val)}; } else { return new KvpValue{scm_to_double(val)}; } } else if (gnc_numeric_p(val)) { return new KvpValue{gnc_scm_to_numeric(val)}; } else if (gnc_guid_p(val)) { auto guid = gnc_scm2guid(val); auto tmpguid = guid_copy(&guid); return new KvpValue{tmpguid}; } else if (gnc_timepair_p(val)) { Timespec ts = gnc_timepair2timespec(val); return new KvpValue{ts}; } else if (scm_is_string(val)) { return new KvpValue{gnc_scm_to_utf8_string(val)}; } else if (SWIG_IsPointerOfType(val, SWIG_TypeQuery("_p_KvpFrame"))) { #define FUNC_NAME G_STRFUNC auto vp_frame = SWIG_MustGetPtr(val, SWIG_TypeQuery("_p_KvpFrame"), 1, 0); KvpFrame *frame = static_cast<KvpFrame*>(vp_frame); #undef FUNC_NAME return new KvpValue{frame}; } /* FIXME: add list handler here */ return NULL; }
static LLVMValueRef scm_to_llvm_value(int type, SCM scm_value) { switch (type) { case SCM_FOREIGN_TYPE_FLOAT: case SCM_FOREIGN_TYPE_DOUBLE: return LLVMConstReal(llvm_type(type), scm_to_double(scm_value)); case SCM_FOREIGN_TYPE_BOOL: return LLVMConstInt(llvm_type(type), scm_is_true(scm_value), 0); case SCM_FOREIGN_TYPE_UINT8: case SCM_FOREIGN_TYPE_UINT16: case SCM_FOREIGN_TYPE_UINT32: case SCM_FOREIGN_TYPE_UINT64: return LLVMConstInt(llvm_type(type), scm_to_uint64(scm_value), 0); case SCM_FOREIGN_TYPE_INT8: case SCM_FOREIGN_TYPE_INT16: case SCM_FOREIGN_TYPE_INT32: case SCM_FOREIGN_TYPE_INT64: return LLVMConstInt(llvm_type(type), scm_to_int64(scm_value), 1); default: return NULL; }; }
SCM DLL_PUBLIC cl_easy_setopt (SCM handle, SCM option, SCM param, SCM big) { handle_post_t *c_handle; CURLoption c_option; CURLcode code = CURLE_UNSUPPORTED_PROTOCOL; SCM_ASSERT (_scm_is_handle (handle), handle, SCM_ARG1, "curl-easy-setopt"); SCM_ASSERT (scm_is_integer (option), option, SCM_ARG2, "curl-easy-setopt"); c_handle = _scm_to_handle (handle); c_option = (CURLoption) scm_to_int (option); if (c_option == CURLOPT_POSTFIELDS) { if (_scm_can_convert_to_byte_data (param)) { size_t len; uint8_t *m = _scm_convert_to_byte_data (param, &len); free (c_handle->postfields); c_handle->postfields = m; curl_easy_setopt (c_handle->handle, CURLOPT_POSTFIELDSIZE, len); c_handle->postfieldsize = len; code = curl_easy_setopt (c_handle->handle, CURLOPT_POSTFIELDS, (char *) m); } else scm_error (SCM_BOOL_F, "cl-easy-setopt", "CURLOPT_POSTFIELDS requires 8-bit string or bytevector data", SCM_BOOL_F, SCM_BOOL_F); } else if (c_option == CURLOPT_HTTPHEADER) { if (_scm_can_convert_to_slist (param)) { /* slists require special handling to free them properly, so they are stored with the Curl handle. */ struct curl_slist *sl = _scm_convert_to_slist (param); if (c_handle->httpheader) curl_slist_free_all (c_handle->httpheader); c_handle->httpheader = sl; code = curl_easy_setopt (c_handle->handle, CURLOPT_HTTPHEADER, sl); } else scm_error (SCM_BOOL_F, "cl-easy-setopt", "CURLOPT_HTTPHEADER requires a list of strings", SCM_BOOL_F, SCM_BOOL_F); } else if (scm_is_integer (param)) { if (scm_is_true (big)) code = curl_easy_setopt (c_handle->handle, c_option, scm_to_int64 (param)); else code = curl_easy_setopt (c_handle->handle, c_option, scm_to_long (param)); } else if (scm_is_string (param)) { /* Strings are copied by curl, so they can be freed here. */ char *str; str = scm_to_locale_string (param); code = curl_easy_setopt (c_handle->handle, c_option, str); free (str); } else if (_scm_can_convert_to_slist (param)) { /* slists require special handling to free them properly, so they are stored with the Curl handle. */ struct curl_slist *sl = _scm_convert_to_slist (param); int ok = 1; if (c_option == CURLOPT_HTTP200ALIASES) { if (c_handle->http200aliases) curl_slist_free_all (c_handle->http200aliases); c_handle->http200aliases = sl; } else if (c_option == CURLOPT_MAIL_RCPT) { if (c_handle->mail_rcpt) curl_slist_free_all (c_handle->mail_rcpt); c_handle->mail_rcpt = sl; } else if (c_option == CURLOPT_QUOTE) { if (c_handle->quote) curl_slist_free_all (c_handle->quote); c_handle->quote = sl; } else if (c_option == CURLOPT_POSTQUOTE) { if (c_handle->postquote) curl_slist_free_all (c_handle->postquote); c_handle->postquote = sl; } else if (c_option == CURLOPT_PREQUOTE) { if (c_handle->prequote) curl_slist_free_all (c_handle->prequote); c_handle->prequote = sl; } else if (c_option == CURLOPT_RESOLVE) { if (c_handle->resolve) curl_slist_free_all (c_handle->resolve); c_handle->resolve = sl; } else if (c_option == CURLOPT_TELNETOPTIONS) { if (c_handle->telnetoptions) curl_slist_free_all (c_handle->telnetoptions); c_handle->telnetoptions = sl; } else { // Bad slist option ok = 0; } if (ok) code = curl_easy_setopt (c_handle->handle, c_option, sl); } else if (_scm_can_convert_to_httppost (param)) { if (c_option == CURLOPT_HTTPPOST) { struct curl_httppost *p; p = _scm_convert_to_httppost (param); free (c_handle->httppost); c_handle->httppost = p; code = curl_easy_setopt (c_handle, CURLOPT_HTTPPOST, p); } } else if (scm_is_true (scm_input_port_p (param))) { if (c_option == CURLOPT_READDATA) { curl_easy_setopt (c_handle->handle, CURLOPT_READFUNCTION, read_callback); code = curl_easy_setopt (c_handle->handle, CURLOPT_READDATA, SCM2PTR (param)); } } else scm_error (SCM_BOOL_F, "curl-easy-setopt", "unimplemented option type", SCM_BOOL_F, SCM_BOOL_F); if (code != CURLE_OK) scm_error (SCM_BOOL_F, "curl-easy-setopt", "bad handle", SCM_BOOL_F, SCM_BOOL_F); return SCM_UNSPECIFIED; }