static AvahiTimeout * timeout_new (const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) { SCM sec, nsec; AvahiTimeout *timeout; AvahiGuilePoll *guile_poll; guile_poll = (AvahiGuilePoll *) api->userdata; timeout = scm_malloc (sizeof (*timeout)); timeout->dead = 0; timeout->enabled = (tv != NULL); timeout->callback = callback; timeout->userdata = userdata; timeout->guile_poll = guile_poll; timeout->stuff = SCM_BOOL_F; timeout->timeout_smob = scm_from_avahi_timeout (timeout); timeout->timeout_smob = scm_gc_protect_object (timeout->timeout_smob); if (tv != NULL) { timeout->expiry = *tv; sec = scm_from_long (tv->tv_sec); nsec = scm_from_long (tv->tv_usec * 1000L); } else sec = nsec = SCM_BOOL_F; (void) scm_call_3 (guile_poll->new_timeout, timeout->timeout_smob, sec, nsec); return (timeout); }
SCM scm_ragnarok_select(SCM nfds ,SCM read_set ,SCM write_set, SCM except_set ,SCM second ,SCM msecond) #define FUNC_NAME "ragnarok-select" { int n = 0; scm_rag_fd_set *rs = NULL; scm_rag_fd_set *ws = NULL; scm_rag_fd_set *es = NULL; scm_rag_fd_set *ready_set = NULL; long s = 0L; long ms = 0L; int i; struct timeval tv; SCM ret = SCM_EOL; SCM *prev = &ret; SCM_VALIDATE_NUMBER(1 ,nfds); SCM_ASSERT_EVENT_SET(read_set); SCM_ASSERT_EVENT_SET(write_set); SCM_ASSERT_EVENT_SET(except_set); if(!SCM_UNBNDP(ms)) { SCM_VALIDATE_NUMBER(5 ,second); s = (long)scm_from_long(second); if(!SCM_UNBNDP(msecond)) { SCM_VALIDATE_NUMBER(6 ,msecond); ms = (long)scm_from_long(msecond); } } n = scm_from_int(nfds); rs = (scm_rag_event_set*)SMOB_DATA(read_set); ws = (scm_rag_event_set*)SMOB_DATA(write_set); es = (scm_rag_event_set*)SMOB_DATA(except_set); tv.tv_sec = (long)s; tv.tv_usec = (long)us; ready_set = select(n ,rs->set ,ws->set ,es->set ,&tv); for(i=0;i<n;i++) { if(FD_ISSET(i ,&ready_set)) { *prev = scm_cons(scm_from_int(i) ,SCM_EOL); prev = SCM_CDRLOC(*prev); } } return ret; }
static void timeout_update (AvahiTimeout *timeout, const struct timeval *tv) { SCM sec, nsec; if (tv) { sec = scm_from_long (tv->tv_sec); nsec = scm_from_long (tv->tv_usec * 1000L); } else sec = nsec = SCM_BOOL_F; (void) scm_call_3 (timeout->guile_poll->update_timeout_x, timeout->timeout_smob, sec, nsec); if (tv) timeout->enabled = 1, timeout->expiry = *tv; else timeout->enabled = 0; }
/* returns a (sec . usec) pair. It throws an 'a-sync-exception guile exception if the library has been configured for monotonic time at configuration time but it is not in fact supported, but this is not worth testing for by user code as it should never happen - the library configuration macros should always give the correct answer */ static SCM get_time(void) { #ifdef HAVE_MONOTONIC_CLOCK struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) { scm_throw(scm_from_latin1_symbol("a-sync-exception"), scm_list_4(scm_from_latin1_string("get-time"), scm_from_latin1_string("guile-a-sync2: ~A"), scm_list_1(scm_from_latin1_string("monotonic time not supported " "by underlying implementation")), scm_from_int(errno))); } return scm_cons(scm_from_size_t(ts.tv_sec), scm_from_long(ts.tv_nsec/1000L)); #else return scm_gettimeofday(); #endif }
/************************************************************************\ * gnc_get_credit_string * * return a credit string for a given account type * * * * Args: account_type - type of account to get credit string for * * Return: g_malloc'd credit string or NULL, must be freed with g_free * \************************************************************************/ char * gnc_get_credit_string(GNCAccountType account_type) { SCM result; SCM arg; initialize_scm_functions(); if (gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNTING_LABELS)) return g_strdup(_("Credit")); if ((account_type < ACCT_TYPE_NONE) || (account_type >= NUM_ACCOUNT_TYPES)) account_type = ACCT_TYPE_NONE; arg = scm_from_long (account_type); result = scm_call_1(getters.credit_string, arg); if (!scm_is_string(result)) return NULL; return gnc_scm_to_utf8_string(result); }
static void guile_cb(char* name, char* value) { SCM value_scm; char* tail; /* try as an integer */ long int result = strtol(value, &tail, 0); if (!(errno) && (*tail == '\0')) value_scm = scm_from_long(result); else { /* try as a float */ double result = strtod(value, &tail); if (*tail == '\0') value_scm = scm_from_double(result); else /* finally, a string */ value_scm = scm_from_locale_string(value); } scm_call_2(ship_item_cb, scm_from_locale_symbol(name), value_scm); }
SCM py2scm(PyObject *value) { if (value == Py_None) { return SCM_UNSPECIFIED; } if (PyBool_Check(value)) { int v = PyObject_IsTrue(value); if (v == -1) return NULL; return scm_from_bool(v); } if (PyInt_Check(value)) { long v = PyInt_AsLong(value); if (PyErr_Occurred()) return NULL; return scm_from_long(v); } if (PyFloat_Check(value)) { double v = PyFloat_AsDouble(value); if (PyErr_Occurred()) return NULL; return scm_from_double(v); } if (PyString_Check(value)) { const char *s = PyString_AsString(value); if (s == NULL) return NULL; return scm_from_utf8_stringn(s, PyString_Size(value)); } if (PyUnicode_Check(value)) { scm_dynwind_begin(0); PyObject *utf8_str = PyUnicode_AsUTF8String(value); if (utf8_str == NULL) { scm_dynwind_end(); return NULL; } scm_dynwind_py_decref(utf8_str); const char *s = PyString_AsString(utf8_str); if (s == NULL) { scm_dynwind_end(); return NULL; } SCM result = scm_from_utf8_stringn(s, PyString_Size(utf8_str)); scm_dynwind_end(); return result; } if (PySequence_Check(value)) { unsigned int i = PySequence_Size(value); SCM r = SCM_EOL; while (i-- > 0) { PyObject *item = PySequence_GetItem(value, i); r = scm_cons(py2scm(item), r); } return r; } if (PyObject_TypeCheck(value, &ProcedureType)) return ((Procedure *)value)->proc; if (PyCallable_Check(value)) { SCM gsubr = scm_c_make_gsubr( "<Python function>", 0, 0, 1, &call_callable); Py_INCREF(value); SCM ptr = scm_from_pointer(value, (void (*)(void *))Py_DecRef); gsubr_alist = scm_acons(gsubr, ptr, gsubr_alist); return gsubr; } char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "Python type \"%.50s\" doesn't have a " "corresponding Guile type", value->ob_type->tp_name); scm_error(scm_from_utf8_symbol("misc-error"), NULL, buf, SCM_EOL, SCM_EOL); /* does not return */ fprintf(stderr, "*** scm_error shouldn't have returned ***\n"); return SCM_UNSPECIFIED; }