static SCM guile_sock_no_delay (SCM sock, SCM enable) { svz_socket_t *xsock; int old = 0, set = 0; scm_assert_smob_type (guile_svz_socket_tag, sock); xsock = (svz_socket_t *) SCM_SMOB_DATA (sock); if (xsock->proto & PROTO_TCP) { if (!SCM_UNBNDP (enable)) { SCM_ASSERT (scm_is_bool (enable) || scm_is_integer (enable), enable, SCM_ARG2, FUNC_NAME); if ((scm_is_bool (enable) && scm_is_true (enable)) || (scm_is_integer (enable) && scm_to_int (enable) != 0)) set = 1; } if (svz_tcp_nodelay (xsock->sock_desc, set, &old) < 0) old = 0; else if (SCM_UNBNDP (enable)) svz_tcp_nodelay (xsock->sock_desc, old, NULL); } return SCM_BOOL (old); }
static Expr* boolean(Expr* args) { assert(args); if(scm_list_len(args) != 1) return scm_mk_error("boolean? expects 1 arg"); return scm_is_bool(scm_car(args)) ? TRUE : FALSE; }
int xscm_val_to_int (SCM x) { if (SCM_UNBNDP (x)) return 0; else if (scm_is_bool (x)) { if (scm_is_false(x)) return 0; else return 1; } else if (scm_is_integer (x)) return scm_to_int (x); return 0; }
/* Convert mouse coordinates to screen coordinates */ SCM gucu_wmouse_trafo (SCM win, SCM sy, SCM sx, SCM to_screen) { SCM_ASSERT (_scm_is_window (win), win, SCM_ARG1, "mouse-trafo"); SCM_ASSERT (scm_is_integer (sy), sy, SCM_ARG2, "mouse-trafo"); SCM_ASSERT (scm_is_integer (sx), sx, SCM_ARG3, "mouse-trafo"); SCM_ASSERT (scm_is_bool (to_screen), to_screen, SCM_ARG4, "mouse-trafo"); int x, y, ret; x = scm_to_int (sx); y = scm_to_int (sy); ret = wmouse_trafo (_scm_to_window (win), &y, &x, scm_to_bool (to_screen)); if (ret) { return scm_list_2 (scm_from_int (y), scm_from_int (x)); } else return SCM_BOOL_F; }
inline bool tmscm_is_bool (tmscm obj) { return scm_is_bool (obj); }
PyObject *scm2py(SCM value) { if (value == NULL) return NULL; if (value == SCM_UNSPECIFIED) { Py_INCREF(Py_None); return Py_None; } if (scm_is_exact_integer(value)) return PyInt_FromLong(scm_to_long(value)); if (scm_is_real(value)) return PyFloat_FromDouble(scm_to_double(value)); if (scm_is_bool(value)) { PyObject *result = scm_to_bool(value) ? Py_True : Py_False; Py_INCREF(result); return result; } if (value == SCM_EOL) return PyTuple_New(0); if (scm_is_string(value)) { size_t len = 0; char *s = scm_to_utf8_stringn(value, &len); PyObject *result = PyUnicode_FromStringAndSize(s, len); free(s); return result; } if (scm_is_pair(value)) { unsigned int len = scm_to_uint(scm_length(value)); PyObject *result = PyTuple_New(len); scm_dynwind_begin(0); scm_dynwind_unwind_handler( (void (*)(void *))Py_DecRef, result, 0); unsigned int i; for (i = 0; i < len; i++) { PyObject *item = scm2py(scm_car(value)); if (item == NULL) { scm_dynwind_end(); Py_DECREF(result); return NULL; } PyTuple_SET_ITEM(result, i, item); value = scm_cdr(value); } scm_dynwind_end(); return result; } if (scm_to_bool(scm_procedure_p(value))) { SCM ptr = scm_assq_ref(gsubr_alist, value); if (!scm_is_false(ptr)) { PyObject *result = scm_to_pointer(ptr); Py_INCREF(result); return result; } Procedure *result = (Procedure *)ProcedureType.tp_alloc(&ProcedureType, 0); if (result == NULL) return NULL; result->proc = value; return (PyObject *)result; } char *msg = scm_to_utf8_stringn( scm_simple_format( SCM_BOOL_F, scm_from_utf8_string( "Guile expression ~S doesn't have a " "corresponding Python value"), scm_list_1(value)), NULL); PyErr_SetString(PyExc_TypeError, msg); free(msg); return NULL; }