int main(int argc, char **argv) { arguments args; int status = arguments_init(&args, &argc, &argv); switch (status) { case STATUS_OK: // Всё задано корректно break; case STATUS_INCORRECT_ARGUMENT: usage(); exit(STATUS_INCORRECT_ARGUMENT); // Неизвестный аргумент default: // Этого не случится error_str("Unknown error!"); exit(STATUS_ERROR); } status = 0; if (argc == 0) { status = ls(&args, "./"); } else { for ( ; argc > 0; --argc, ++argv) { int tmp = ls(&args, *argv); if (status == 0) status = tmp; } } exit(status); }
int main(int argc, char **argv){ struct argument_s arguments; ssh_session session; int i; arguments_init(&arguments); cmdline_parse(argc, argv, &arguments); if (arguments.nhosts==0){ fprintf(stderr,"At least one host (-h) must be specified\n"); return EXIT_FAILURE; } if (arguments.ntests==0){ for(i=0; i < BENCHMARK_NUMBER ; ++i){ benchmarks[i].enabled=1; } arguments.ntests=BENCHMARK_NUMBER; } buffer=malloc(arguments.chunksize > 1024 ? arguments.chunksize : 1024); if(buffer == NULL){ fprintf(stderr,"Allocation of chunk buffer failed\n"); return EXIT_FAILURE; } if (arguments.verbose > 0){ fprintf(stdout, "Will try hosts "); for(i=0;i<arguments.nhosts;++i){ fprintf(stdout,"\"%s\" ", arguments.hosts[i]); } fprintf(stdout,"with benchmarks "); for(i=0;i<BENCHMARK_NUMBER;++i){ if(benchmarks[i].enabled) fprintf(stdout,"\"%s\" ",benchmarks[i].name); } fprintf(stdout,"\n"); } for(i=0; i<arguments.nhosts;++i){ if(arguments.verbose > 0) fprintf(stdout,"Connecting to \"%s\"...\n",arguments.hosts[i]); session=connect_host(arguments.hosts[i], arguments.verbose, arguments.cipher); if(session != NULL && arguments.verbose > 0) fprintf(stdout,"Success\n"); if(session == NULL){ fprintf(stderr,"Errors occurred, stopping\n"); return EXIT_FAILURE; } do_benchmarks(session, &arguments, arguments.hosts[i]); ssh_disconnect(session); ssh_free(session); } return EXIT_SUCCESS; }
static void ffi_closure_callback(G_GNUC_UNUSED ffi_cif *cif, void *result, void **raw_args, void *data) { RBGICallback *callback = data; RBGICallbackData *callback_data = NULL; GArray *in_args; GArray *out_args; GPtrArray *args_metadata; VALUE rb_results; arguments_init(&in_args, &out_args, &args_metadata); allocate_arguments(callback->callback_info, in_args, out_args, args_metadata); fill_metadata(args_metadata, callback->callback_info); arguments_from_raw_data(callback->callback_info, raw_args, in_args, out_args, args_metadata); { guint i; for (i = 0; i < args_metadata->len; i++) { RBGIArgMetadata *metadata; metadata = g_ptr_array_index(args_metadata, i); if (!metadata->closure_p) { continue; } callback_data = *((RBGICallbackData **)(raw_args[i])); break; } } { ID id_call; GArray *rb_args; rb_args = g_array_new(FALSE, FALSE, sizeof(VALUE)); in_arguments_to_ruby(in_args, out_args, args_metadata, rb_args); CONST_ID(id_call, "call"); /* TODO: use rb_protect() */ rb_results = rb_funcallv(callback_data->rb_callback, id_call, rb_args->len, (VALUE *)(rb_args->data)); g_array_free(rb_args, TRUE); } out_arguments_to_raw_data(callback->callback_info, rb_results, result, out_args, args_metadata); if (callback_data->metadata->scope_type == GI_SCOPE_TYPE_ASYNC) { rb_gi_callback_data_free(callback_data); } }
VALUE rb_gi_function_info_invoke_raw(GIFunctionInfo *info, VALUE rb_info, VALUE rb_receiver, VALUE rb_arguments, GIArgument *return_value, VALUE *rb_return_value) { GICallableInfo *callable_info; GIArgument receiver; GArray *in_args, *out_args; GPtrArray *args_metadata; VALUE rb_out_args = Qnil; gboolean succeeded; GError *error = NULL; gboolean unlock_gvl = FALSE; gboolean rb_receiver_is_class = FALSE; unlock_gvl = RVAL2CBOOL(rb_funcall(rb_info, rb_intern("unlock_gvl?"), 0)); if (NIL_P(rb_receiver)) { receiver.v_pointer = NULL; } else { if (gobject_based_p((GIBaseInfo *)info)) { receiver.v_pointer = RVAL2GOBJ(rb_receiver); } else if (RVAL2CBOOL(rb_obj_is_kind_of(rb_receiver, rb_cClass)) && rb_respond_to(rb_receiver, rb_intern("gtype"))) { GObjectClass *object_class; rb_receiver_is_class = TRUE; object_class = g_type_class_ref(CLASS2GTYPE(rb_receiver)); receiver.v_pointer = object_class; } else { receiver.v_pointer = DATA_PTR(rb_receiver); } } rb_arguments = rbg_to_array(rb_arguments); callable_info = (GICallableInfo *)info; arguments_init(&in_args, &out_args, &args_metadata); if (receiver.v_pointer) { g_array_append_val(in_args, receiver); } arguments_from_ruby(callable_info, rb_receiver, rb_arguments, in_args, out_args, args_metadata); { InvokeData data; data.info = info; data.in_args = in_args; data.out_args = out_args; data.error = &error; if (unlock_gvl) { rb_thread_call_without_gvl( rb_gi_function_info_invoke_raw_call_without_gvl_body, &data, NULL, NULL); } else { rb_gi_function_info_invoke_raw_call(&data); } succeeded = data.succeeded; if (rb_receiver_is_class) { g_type_class_unref(receiver.v_pointer); } if (return_value) { *return_value = data.return_value; } if (rb_return_value) { if (succeeded) { *rb_return_value = GI_RETURN_ARGUMENT2RVAL(callable_info, &(data.return_value), in_args, out_args, args_metadata); } else { *rb_return_value = Qnil; } } } if (succeeded) { rb_out_args = out_arguments_to_ruby(callable_info, in_args, out_args, args_metadata); } arguments_free(rb_arguments, in_args, out_args, args_metadata); if (!succeeded) { RG_RAISE_ERROR(error); } if (!NIL_P(rb_out_args) && RARRAY_LEN(rb_out_args) == 1) { VALUE rb_out_arg; rb_out_arg = RARRAY_PTR(rb_out_args)[0]; if (rb_obj_is_kind_of(rb_out_arg, rb_eException)) { rb_exc_raise(rb_out_arg); } } return rb_out_args; }
VALUE rb_gi_function_info_invoke_raw(GIFunctionInfo *info, VALUE rb_options, GIArgument *return_value) { GICallableInfo *callable_info; GIArgument receiver; GArray *in_args, *out_args; GPtrArray *args_metadata; VALUE rb_out_args = Qnil; gboolean succeeded; GError *error = NULL; gboolean unlock_gvl = FALSE; VALUE rb_receiver, rb_arguments, rb_unlock_gvl; if (RB_TYPE_P(rb_options, RUBY_T_ARRAY)) { rb_receiver = Qnil; rb_arguments = rb_options; rb_unlock_gvl = Qnil; } else if (NIL_P(rb_options)) { rb_receiver = Qnil; rb_arguments = rb_ary_new(); rb_unlock_gvl = Qnil; } else { rb_options = rbg_check_hash_type(rb_options); rbg_scan_options(rb_options, "receiver", &rb_receiver, "arguments", &rb_arguments, "unlock_gvl", &rb_unlock_gvl, NULL); } if (NIL_P(rb_receiver)) { receiver.v_pointer = NULL; } else { if (gobject_based_p((GIBaseInfo *)info)) { receiver.v_pointer = RVAL2GOBJ(rb_receiver); } else { receiver.v_pointer = DATA_PTR(rb_receiver); } } rb_arguments = rbg_to_array(rb_arguments); if (!NIL_P(rb_unlock_gvl) && RVAL2CBOOL(rb_unlock_gvl)) { unlock_gvl = TRUE; } callable_info = (GICallableInfo *)info; arguments_init(&in_args, &out_args, &args_metadata); if (receiver.v_pointer) { g_array_append_val(in_args, receiver); } arguments_from_ruby(callable_info, rb_arguments, in_args, out_args, args_metadata); { InvokeData data; data.info = info; data.in_args = in_args; data.out_args = out_args; data.return_value = return_value; data.error = &error; if (unlock_gvl) { rb_thread_call_without_gvl( rb_gi_function_info_invoke_raw_call_without_gvl_body, &data, NULL, NULL); } else { rb_gi_function_info_invoke_raw_call(&data); } succeeded = data.succeeded; } if (succeeded) { rb_out_args = out_arguments_to_ruby(callable_info, in_args, out_args, args_metadata); } arguments_free(in_args, out_args, args_metadata); if (!succeeded) { RG_RAISE_ERROR(error); } if (!NIL_P(rb_out_args) && RARRAY_LEN(rb_out_args) == 1) { VALUE rb_out_arg; rb_out_arg = RARRAY_PTR(rb_out_args)[0]; if (rb_obj_is_kind_of(rb_out_arg, rb_eException)) { rb_exc_raise(rb_out_arg); } } return rb_out_args; }