/* anal_power -- try to view a type as (P base) */ PUBLIC bool anal_power(type t, type *base, tree cxt) { /* The common case (where t is simply a set type) accounts for a big fraction of the frames and type variables allocated if done by unification -- so it's just about worth doing directly. */ frame f = arid; unpack(&t, &f, TRUE); switch (t->t_kind) { case POWERT: *base = seal(t->t_base, f); return TRUE; case TYPEVAR: if (f == arid) return FALSE; tv_val(t, f) = mk_power(*base = new_typevar(cxt)); return TRUE; default: *base = err_type; mark_error(); return (t == err_type); } }
/* Handle position change callbacks */ static void geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { location_geoclue2_state_t *state = user_data; /* Only handle LocationUpdated signals */ if (g_strcmp0(signal_name, "LocationUpdated") != 0) { return; } /* Obtain location path */ const gchar *location_path; g_variant_get_child(parameters, 1, "&o", &location_path); /* Obtain location */ GError *error = NULL; GDBusProxy *location = g_dbus_proxy_new_sync( g_dbus_proxy_get_connection(client), G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.GeoClue2", location_path, "org.freedesktop.GeoClue2.Location", NULL, &error); if (location == NULL) { g_printerr(_("Unable to obtain location: %s.\n"), error->message); g_error_free(error); mark_error(state); return; } g_mutex_lock(&state->lock); /* Read location properties */ GVariant *lat_v = g_dbus_proxy_get_cached_property( location, "Latitude"); state->latitude = g_variant_get_double(lat_v); GVariant *lon_v = g_dbus_proxy_get_cached_property( location, "Longitude"); state->longitude = g_variant_get_double(lon_v); state->available = 1; g_mutex_unlock(&state->lock); pipeutils_signal(state->pipe_fd_write); }
void err_print (char *s) /* prints `\..' and location of error message */ { print(*s=='!' ? "\n%s." : "%s.",s); if (web_file_open) { char *k, *l=(loc<limit) ? loc : limit; /* pointers into |buffer| */ if (changing) printf(" (l. %d of change file)\n", change_line); else if (include_depth==0) printf(" (l. %d)\n", cur_line); else printf(" (l. %d of include file %s)\n", cur_line, cur_file_name); if (l>buffer) { for (k=buffer; k<l; k++) putchar(*k=='\t' ? ' ': *k); new_line(); for (k=buffer; k<l; k++) putchar(' '); /* space out the next line */ } for (k=l; k<limit; k++) putchar(*k); /* print the part not yet read */ } update_terminal(); mark_error(); }
/* comp_type -- get component type in a schema */ PUBLIC type comp_type(type t, sym x, tree cxt, int loc) { type tt = t; frame f = arid; schema s; int i; unpack(&t, &f, TRUE); if (t->t_kind != SPRODUCT) panic("comp_type"); s = t->t_schema; for (i = 0; i < s->z_ncomps; i++) if (s->z_comp[i].z_name == x) return seal(s->z_comp[i].z_type, f); tc_error(loc, "Selecting non-existent component %z", x); if (cxt != nil) { tc_e_etc("Expression: %z", cxt); tc_e_etc("Arg type: %t", tt); } tc_e_end(); mark_error(); return err_type; }
int run_vm(void) { #if !defined(VM_CLOCKINTERRUPTHANDLER_INTERRUPT) Object temp; int32* mainMethodJavaStack; #endif int16 execp = 0; /* Required for certain compilers. */ init_compiler_specifics(); /* Function below allocates the initial heap. This is done in * initDefaultRAMAllocationPoint in allocation_point.c */ init_vm(); #if defined(ENABLE_DEBUG) connectToDebugger(); sendStartEvent(); while (awaitCommandFromDebugger(0, 0, 0) != RESUME_EVENT) {;} #endif /* Allocating the main stack is delegated to the target specific function * 'get_java_stack_base'. On some architectures/environments it is located * at fixed positions in certain compiler specific sections. The implementor * can allocate the stack in the heap if so desired. * */ mainMethodJavaStack = get_java_stack_base(JAVA_STACK_SIZE); #if defined(VM_CLOCKINTERRUPTHANDLER_INTERRUPT) /* If more threads are started we give the main thread a new C stack pointer. * In case of no other threads running the main thread just inherits the * current C stack. * * In this case we save the current C stack so we may restore it later. This * is required to terminate the process properly. */ mainStackPointer = (pointer) get_stack_pointer(); /* mainMethodJavaStack contains both Java and C stack. Java stack grows * upwards from the beginning, C stack downwards from the end. */ stackPointer = (pointer) &mainMethodJavaStack[JAVA_STACK_SIZE - 2]; /* 'set_stack_pointer' sets the C stack */ stackPointer = (pointer) & mainMethodJavaStack[JAVA_STACK_SIZE - 2]; set_stack_pointer(); #endif #if defined(REPORTCYCLES) papi_start(); papi_mark(); papi_mark(); papi_mark(); papi_mark(); papi_mark(); papi_mark(); #endif #if defined(LDC2_W_OPCODE_USED) || defined(LDC_W_OPCODE_USED) || defined(LDC_OPCODE_USED) || defined(HANDLELDCWITHINDEX_USED) execp = initializeConstants(mainMethodJavaStack); if (execp == -1) { #endif execp = initializeExceptions(mainMethodJavaStack); if (execp == -1) { #if defined(INVOKECLASSINITIALIZERS) execp = invokeClassInitializers(mainMethodJavaStack); if (execp == -1) { #endif /* This is only for testing. All tests will write 0 (null) to * '*mainMethodJavaStack' if the test is successful. */ *mainMethodJavaStack = (int32) (pointer) &temp; #if defined(VM_CLOCKINTERRUPTHANDLER_ENABLE_USED) start_system_tick(); #endif #if defined(DEVICES_SYSTEM_INITIALIZESYSTEMCLASS) execp = enterMethodInterpreter( DEVICES_SYSTEM_INITIALIZESYSTEMCLASS, mainMethodJavaStack); if (execp == -1) { #endif /* Start the VM */ execp = enterMethodInterpreter(mainMethodIndex, mainMethodJavaStack); #if defined(VM_CLOCKINTERRUPTHANDLER_ENABLE_USED) stop_system_tick(); #endif #if defined(DEVICES_SYSTEM_INITIALIZESYSTEMCLASS) } #endif } /* TODO: use executeWithStack instead */ #if defined(INVOKECLASSINITIALIZERS) } #endif #if defined(LDC2_W_OPCODE_USED) || defined(LDC_W_OPCODE_USED) || defined(LDC_OPCODE_USED) || defined(HANDLELDCWITHINDEX_USED) } #endif #if defined(REPORTCYCLES) papi_mark(); #endif mark_error(); if (execp >= 0) { #if defined(JAVA_LANG_THROWABLE_INIT_) handleException(execp); #endif #if defined(VM_CLOCKINTERRUPTHANDLER_INTERRUPT) /* Restore C stack pointer. Otherwise we could not return from here properly */ stackPointer = (pointer) mainStackPointer; set_stack_pointer(); #endif return ERROR; } #if defined(VM_CLOCKINTERRUPTHANDLER_INTERRUPT) /* Restore C stack pointer. Otherwise we could not return from here properly */ stackPointer = (pointer) mainStackPointer; set_stack_pointer(); #endif #if defined(ENABLE_DEBUG) disconnectFromDebugger(); #endif if (*mainMethodJavaStack) { return ERROR; } else { mark_success(); return SUCCESS; } return 0; }
/* tc_apply -- check a function application */ PRIVATE type tc_apply(int kind, tree t, tree fun, tree arg, env e) { type actual = tc_expr(arg, e); type fun_type, formal, result; type formarg[MAX_ARGS], actarg[MAX_ARGS]; int n_formals, n_actuals, i; frame param = arid; def d; if (! aflag && fun->x_kind == REF && (d = find_def((sym) fun->x_tag, e)) != NULL && d->d_tame && fun->x_params == nil) /* A tame function */ fun_type = seal(d->d_type, param = new_frame(d->d_nparams, fun)); else fun_type = tc_expr(fun, e); if (! anal_rel_type(fun_type, &formal, &result, fun)) { if (fun_type != err_type) { if (kind == APPLY) tc_error(t->x_loc, "Application of a non-function"); else tc_error(t->x_loc, "%s operator %n is not a function", (kind == INOP ? "Infix" : "Postfix"), fun->x_tag); tc_e_etc("Expression: %z", t); tc_e_etc("Found type: %t", fun_type); tc_e_end(); } mark_error(); return err_type; } if (arg->x_kind == TUPLE && anal_cproduct(formal, formarg, &n_formals)) { /* Special case: actual parameter is a tuple, and formal parameter type is a cproduct. Check args one by one. */ if (! anal_cproduct(actual, actarg, &n_actuals)) panic("tc_apply"); if (n_actuals != n_formals) { tc_error(t->x_loc, "Function expects %d arguments", n_formals); tc_e_etc("Expression: %z", t); tc_e_end(); mark_error(); return err_type; } for (i = 0; i < n_actuals; i++) { if (param_unify(actarg[i], formarg[i], param)) continue; if (kind == INOP) tc_error(t->x_loc, "%s argument of operator %n has wrong type", (i == 0 ? "Left" : "Right"), fun->x_tag); else tc_error(t->x_loc, "Argument %d has wrong type", i+1); tc_e_etc("Expression: %z", t); tc_e_etc("Arg type: %t", actarg[i]); tc_e_etc("Expected: %t", formarg[i]); tc_e_end(); } } else if (! param_unify(actual, formal, param)) { /* General case: check the single arg as a whole. */ tc_error(t->x_loc, "Argument of %s has wrong type", (kind == POSTOP ? "postfix operator" : "application")); tc_e_etc("Expression: %z", t); tc_e_etc("Arg type: %t", actual); tc_e_etc("Expected: %t", formal); tc_e_end(); } return result; }
PUBLIC type tc_expr(tree t, env e) #endif { switch (t->x_kind) { case REF: return ref_type((sym) t->x_tag, t->x_params, e, t); case INGEN: return ref_type((sym) t->x_tag, list2(t->x_param1, t->x_param2), e, t); case PREGEN: return ref_type((sym) t->x_tag, list1(t->x_param), e, t); case NUMBER: return nat_type; case SEXPR: { def d; frame params; if (! open_sref(t->x_ref, e, &d, ¶ms)) return err_type; if ((tok) t->x_ref->x_sref_decor != empty) { tc_error(t->x_loc, "Decoration ignored in schema reference"); tc_e_etc("Expression: %z", t); tc_e_end(); } if (t->x_ref->x_sref_renames != nil) { tc_error(t->x_loc, "Renaming ignored in schema reference"); tc_e_etc("Expression: %z", t); tc_e_end(); } if (! aflag && d->d_abbrev) return mk_power(mk_abbrev(d, params)); else return mk_power(seal(mk_sproduct(d->d_schema), params)); } case POWER: { type tt1, tt2; if (! anal_power(tt1 = tc_expr(t->x_arg, e), &tt2, t->x_arg)) { tc_error(t->x_loc, "Argument of \\power must be a set"); tc_e_etc("Expression: %z", t); tc_e_etc("Arg type: %t", tt1); tc_e_end(); } return mk_power(mk_power(tt2)); } case TUPLE : { type a[MAX_ARGS]; int n = 0; tree u; for (u = t->x_elements; u != nil; u = cdr(u)) { if (n >= MAX_ARGS) panic("tc_expr - tuple too big"); a[n++] = tc_expr(car(u), e); } return mk_cproduct(n, a); } case CROSS: { type a[MAX_ARGS]; type tt1, tt2; int n = 0; tree u; for (u = t->x_factors; u != nil; u = cdr(u)) { if (n >= MAX_ARGS) panic("tc_expr - product too big"); tt1 = tc_expr(car(u), e); if (! anal_power(tt1, &tt2, car(u))) { tc_error(t->x_loc, "Argument %d of \\cross must be a set", n+1); tc_e_etc("Expression: %z", t); tc_e_etc("Arg %d type: %t", n+1, tt1); tc_e_end(); } a[n++] = tt2; } return mk_power(mk_cproduct(n, a)); } case EXT: case SEQ: case BAG: { type elem_type; type tt; tree u; if (t->x_elements == nil) elem_type = new_typevar(t); else { elem_type = tc_expr(car(t->x_elements), e); for (u = cdr(t->x_elements); u != nil; u = cdr(u)) { if (unify(elem_type, tt = tc_expr(car(u), e))) elem_type = type_union(elem_type, arid, tt, arid); else { tc_error(t->x_loc, "Type mismatch in %s display", (t->x_kind == EXT ? "set" : t->x_kind == SEQ ? "sequence" : "bag")); tc_e_etc("Expression: %z", car(u)); tc_e_etc("Has type: %t", tt); tc_e_etc("Expected: %t", elem_type); tc_e_end(); } } } switch (t->x_kind) { case EXT: return mk_power(elem_type); case SEQ: return (aflag ? rel_type(num_type, elem_type) : mk_seq(elem_type)); case BAG: return (aflag ? rel_type(elem_type, num_type) : mk_bag(elem_type)); } } case THETA: return theta_type(t, e, (type) NULL, t); case BINDING: { tree u; env e1 = new_env(e); for (u = t->x_elements; u != nil; u = cdr(u)) add_def(VAR, (sym) car(u)->x_lhs, tc_expr(car(u)->x_rhs, e), e1); return mk_sproduct(mk_schema(e1)); } case SELECT: { type a = tc_expr(t->x_arg, e); if (type_kind(a) != SPRODUCT) { tc_error(t->x_loc, "Argument of selection must have schema type"); tc_e_etc("Expression: %z", t); tc_e_etc("Arg type: %t", a); tc_e_end(); mark_error(); return err_type; } switch (t->x_field->x_kind) { case IDENT: return (comp_type(a, (sym) t->x_field, t, t->x_loc)); case THETA: return (theta_type(t->x_field, e, a, t)); default: bad_tag("tc_expr.SELECT", t->x_field->x_kind); return (type) NULL; } } case APPLY: return tc_apply(APPLY, t, t->x_arg1, t->x_arg2, e); case INOP: return tc_apply(INOP, t, simply(t->x_op, t->x_loc), pair(t->x_rand1, t->x_rand2), e); case POSTOP: return tc_apply(POSTOP, t, simply(t->x_op, t->x_loc), t->x_rand, e); case LAMBDA: { env e1 = tc_schema(t->x_bvar, e); type dom = tc_expr(char_tuple(t->x_bvar), e1); type ran = tc_expr(t->x_body, e1); return (aflag ? rel_type(dom, ran) : mk_pfun(dom, ran)); } case COMP: case MU: { env e1 = tc_schema(t->x_bvar, e); type a = tc_expr(exists(t->x_body) ? the(t->x_body) : char_tuple(t->x_bvar), e1); return (t->x_kind == COMP ? mk_power(a) : a); } case LETEXPR: return tc_expr(t->x_body, tc_letdefs(t->x_defs, e)); case IF: { type a, b; tc_pred(t->x_if, e); a = tc_expr(t->x_then, e); b = tc_expr(t->x_else, e); if (unify(a, b)) return type_union(a, arid, b, arid); else { tc_error(t->x_loc, "Type mismatch in conditional expression"); tc_e_etc("Expression: %z", t); tc_e_etc("Then type: %t", a); tc_e_etc("Else type: %t", b); tc_e_end(); return err_type; } } default: bad_tag("tc_expr", t->x_kind); /* dummy */ return (type) NULL; } }
/* Callback when GeoClue name appears on the bus */ static void on_name_appeared(GDBusConnection *conn, const gchar *name, const gchar *name_owner, gpointer user_data) { location_geoclue2_state_t *state = user_data; /* Obtain GeoClue Manager */ GError *error = NULL; GDBusProxy *geoclue_manager = g_dbus_proxy_new_sync( conn, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.GeoClue2", "/org/freedesktop/GeoClue2/Manager", "org.freedesktop.GeoClue2.Manager", NULL, &error); if (geoclue_manager == NULL) { g_printerr(_("Unable to obtain GeoClue Manager: %s.\n"), error->message); g_error_free(error); mark_error(state); return; } /* Obtain GeoClue Client path */ error = NULL; GVariant *client_path_v = g_dbus_proxy_call_sync(geoclue_manager, "GetClient", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (client_path_v == NULL) { g_printerr(_("Unable to obtain GeoClue client path: %s.\n"), error->message); g_error_free(error); g_object_unref(geoclue_manager); mark_error(state); return; } const gchar *client_path; g_variant_get(client_path_v, "(&o)", &client_path); /* Obtain GeoClue client */ error = NULL; GDBusProxy *geoclue_client = g_dbus_proxy_new_sync( conn, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.GeoClue2", client_path, "org.freedesktop.GeoClue2.Client", NULL, &error); if (geoclue_client == NULL) { g_printerr(_("Unable to obtain GeoClue Client: %s.\n"), error->message); g_error_free(error); g_variant_unref(client_path_v); g_object_unref(geoclue_manager); mark_error(state); return; } g_variant_unref(client_path_v); /* Set desktop id (basename of the .desktop file) */ error = NULL; GVariant *ret_v = g_dbus_proxy_call_sync( geoclue_client, "org.freedesktop.DBus.Properties.Set", g_variant_new("(ssv)", "org.freedesktop.GeoClue2.Client", "DesktopId", g_variant_new("s", "redshift")), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (ret_v == NULL) { /* Ignore this error for now. The property is not available in early versions of GeoClue2. */ } else { g_variant_unref(ret_v); } /* Set distance threshold */ error = NULL; ret_v = g_dbus_proxy_call_sync( geoclue_client, "org.freedesktop.DBus.Properties.Set", g_variant_new("(ssv)", "org.freedesktop.GeoClue2.Client", "DistanceThreshold", g_variant_new("u", 50000)), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (ret_v == NULL) { g_printerr(_("Unable to set distance threshold: %s.\n"), error->message); g_error_free(error); g_object_unref(geoclue_client); g_object_unref(geoclue_manager); mark_error(state); return; } g_variant_unref(ret_v); /* Attach signal callback to client */ g_signal_connect(geoclue_client, "g-signal", G_CALLBACK(geoclue_client_signal_cb), user_data); /* Start GeoClue client */ error = NULL; ret_v = g_dbus_proxy_call_sync(geoclue_client, "Start", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (ret_v == NULL) { g_printerr(_("Unable to start GeoClue client: %s.\n"), error->message); if (g_dbus_error_is_remote_error(error)) { gchar *dbus_error = g_dbus_error_get_remote_error( error); if (g_strcmp0(dbus_error, DBUS_ACCESS_ERROR) == 0) { print_denial_message(); } g_free(dbus_error); } g_error_free(error); g_object_unref(geoclue_client); g_object_unref(geoclue_manager); mark_error(state); return; } g_variant_unref(ret_v); }