static VALUE comp_remove_items(VALUE self, VALUE items) { gint i, len; GList* list = (GList*)NULL; VALUE items_internal = rb_ivar_get(self, id_items_internal); items = rb_ary_to_ary(items); len = RARRAY_LEN(items); for (i = 0; i < len; i ++){ VALUE data = RARRAY_PTR(items)[i]; VALUE item = rb_hash_aref(items_internal, data); list = g_list_append(list, (gpointer)item); rb_hash_delete(items_internal, data); } g_completion_remove_items(_SELF(self), list); return self; }
static void rb_curl_multi_remove(ruby_curl_multi *rbcm, VALUE easy) { CURLMcode result; ruby_curl_easy *rbce; Data_Get_Struct(easy, ruby_curl_easy, rbce); rbcm->active--; //printf( "calling rb_curl_multi_remove: 0x%X, active: %d\n", (long)easy, rbcm->active ); result = curl_multi_remove_handle(rbcm->handle, rbce->curl); if (result != 0) { raise_curl_multi_error_exception(result); } ruby_curl_easy_cleanup( easy, rbce, rbce->bodybuf, rbce->headerbuf, rbce->curl_headers ); rbce->headerbuf = Qnil; rbce->bodybuf = Qnil; rb_hash_delete( rbcm->requests, rb_int_new((long)rbce->curl) ); }
/* Destroys a Call. */ static void grpc_rb_call_destroy(void *p) { grpc_call *call = NULL; VALUE ref_count = Qnil; if (p == NULL) { return; }; call = (grpc_call *)p; ref_count = rb_hash_aref(hash_all_calls, OFFT2NUM((VALUE)call)); if (ref_count == Qnil) { return; /* No longer in the hash, so already deleted */ } else if (NUM2UINT(ref_count) == 1) { rb_hash_delete(hash_all_calls, OFFT2NUM((VALUE)call)); grpc_call_destroy(call); } else { rb_hash_aset(hash_all_calls, OFFT2NUM((VALUE)call), UINT2NUM(NUM2UINT(ref_count) - 1)); } }
static void rb_curl_multi_remove(ruby_curl_multi *rbcm, VALUE easy) { CURLMcode result; ruby_curl_easy *rbce; VALUE r; Data_Get_Struct(easy, ruby_curl_easy, rbce); result = curl_multi_remove_handle(rbcm->handle, rbce->curl); if (result != 0) { raise_curl_multi_error_exception(result); } rbcm->active--; ruby_curl_easy_cleanup( easy, rbce ); // active should equal INT2FIX(RHASH(rbcm->requests)->tbl->num_entries) r = rb_hash_delete( rbcm->requests, easy ); if( r != easy || r == Qnil ) { rb_warn("Possibly lost track of Curl::Easy VALUE, it may not be reclaimed by GC"); } }
int dispatch(){ int i, s, len; while(1){ TRAP_BEG; s = asteroid_poll_wait(epoll_fd, events, EVENT_BUF_SIZE, 1); TRAP_END; if(s <= 0) break; for(i = 0; i < s; ++i){ asteroid_poll_event_t event = events[i]; int fd = AST_POLL_EVENT_SOCK(&event); VALUE Fd = rb_fix_new(fd); VALUE Server = rb_hash_aref(clients, Fd); if(AST_POLL_EVENT_CAN_READ(&event)){ VALUE Buf = rb_str_new("", 0); char buf[1024]; while((len = read(fd, buf, 1023)) > 0){ buf[len] = '\0'; rb_str_concat(Buf, rb_str_new2(buf)); } if(len == -1 && errno == EAGAIN){ if(rb_respond_to(Server, rb_intern("receive_data"))){ rb_funcall(Server, rb_intern("receive_data"), 1, Buf); } }else{ if(rb_respond_to(Server, rb_intern("unbind"))){ rb_funcall(Server, rb_intern("unbind"), 0); } asteroid_poll_remove(epoll_fd, &event, fd); rb_hash_delete(clients, Fd); close(fd); } } } } return 0; }
static void write_doc(buffer_t buffer, VALUE hash, VALUE check_keys, VALUE move_id) { buffer_position start_position = buffer_get_position(buffer); buffer_position length_location = buffer_save_space(buffer, 4); buffer_position length; int allow_id; int (*write_function)(VALUE, VALUE, VALUE) = NULL; VALUE id_str = rb_str_new2("_id"); VALUE id_sym = ID2SYM(rb_intern("_id")); if (length_location == -1) { rb_raise(rb_eNoMemError, "failed to allocate memory in buffer.c"); } // write '_id' first if move_id is true. then don't allow an id to be written. if(move_id == Qtrue) { allow_id = 0; if (rb_funcall(hash, rb_intern("has_key?"), 1, id_str) == Qtrue) { VALUE id = rb_hash_aref(hash, id_str); write_element_with_id(id_str, id, pack_extra(buffer, check_keys)); } else if (rb_funcall(hash, rb_intern("has_key?"), 1, id_sym) == Qtrue) { VALUE id = rb_hash_aref(hash, id_sym); write_element_with_id(id_sym, id, pack_extra(buffer, check_keys)); } } else { allow_id = 1; // Ensure that hash doesn't contain both '_id' and :_id if ((rb_obj_classname(hash), "Hash") == 0) { if ((rb_funcall(hash, rb_intern("has_key?"), 1, id_str) == Qtrue) && (rb_funcall(hash, rb_intern("has_key?"), 1, id_sym) == Qtrue)) { VALUE oid_sym = rb_hash_delete(hash, id_sym); rb_funcall(hash, rb_intern("[]="), 2, id_str, oid_sym); } } } if(allow_id == 1) { write_function = write_element_with_id; } else { write_function = write_element_without_id; } // we have to check for an OrderedHash and handle that specially if (strcmp(rb_obj_classname(hash), "BSON::OrderedHash") == 0) { VALUE keys = rb_funcall(hash, rb_intern("keys"), 0); int i; for(i = 0; i < RARRAY_LEN(keys); i++) { VALUE key = rb_ary_entry(keys, i); VALUE value = rb_hash_aref(hash, key); write_function(key, value, pack_extra(buffer, check_keys)); } } else if (rb_obj_is_kind_of(hash, RB_HASH) == Qtrue) { rb_hash_foreach(hash, write_function, pack_extra(buffer, check_keys)); } else { bson_buffer_free(buffer); rb_raise(InvalidDocument, "BSON.serialize takes a Hash but got a %s", rb_obj_classname(hash)); } // write null byte and fill in length SAFE_WRITE(buffer, &zero, 1); length = buffer_get_position(buffer) - start_position; // make sure that length doesn't exceed 4MB if (length > max_bson_size) { bson_buffer_free(buffer); rb_raise(InvalidDocument, "Document too large: BSON documents are limited to %d bytes.", max_bson_size); return; } SAFE_WRITE_AT_POS(buffer, length_location, (const char*)&length, 4); }
/* * Implements the Ruby method "LichXML#undefine_callback" * */ static VALUE undefine_rb_callback(VALUE self, VALUE rb_key) { VALUE cb_hash = rb_iv_get(self, "@cb_hash"); return rb_hash_delete(cb_hash, rb_key); }
static void rb_dlmem_delete(void *ptr) { rb_secure(4); rb_hash_delete(DLMemoryTable, DLLONG2NUM(ptr)); }
inline static VALUE mArray_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth) { long i, len = RARRAY_LEN(self); VALUE shift, result; long depth = NIL_P(Vdepth) ? 0 : FIX2LONG(Vdepth); VALUE delim = rb_str_new2(","); GET_STATE(Vstate); check_max_nesting(state, depth); if (state->check_circular) { VALUE self_id = rb_obj_id(self); rb_hash_aset(state->seen, self_id, Qtrue); result = rb_str_buf_new(len); if (RSTRING_LEN(state->array_nl)) rb_str_append(delim, state->array_nl); shift = rb_str_times(state->indent, LONG2FIX(depth + 1)); rb_str_buf_cat2(result, "["); OBJ_INFECT(result, self); rb_str_buf_append(result, state->array_nl); for (i = 0; i < len; i++) { VALUE element = RARRAY_PTR(self)[i]; if (RTEST(rb_hash_aref(state->seen, rb_obj_id(element)))) { rb_raise(eCircularDatastructure, "circular data structures not supported!"); } OBJ_INFECT(result, element); if (i > 0) rb_str_buf_append(result, delim); rb_str_buf_append(result, shift); element = rb_funcall(element, i_to_json, 2, Vstate, LONG2FIX(depth + 1)); Check_Type(element, T_STRING); rb_str_buf_append(result, element); } if (RSTRING_LEN(state->array_nl)) { rb_str_buf_append(result, state->array_nl); rb_str_buf_append(result, rb_str_times(state->indent, LONG2FIX(depth))); } rb_str_buf_cat2(result, "]"); rb_hash_delete(state->seen, self_id); } else { result = rb_str_buf_new(len); OBJ_INFECT(result, self); if (RSTRING_LEN(state->array_nl)) rb_str_append(delim, state->array_nl); shift = rb_str_times(state->indent, LONG2FIX(depth + 1)); rb_str_buf_cat2(result, "["); rb_str_buf_append(result, state->array_nl); for (i = 0; i < len; i++) { VALUE element = RARRAY_PTR(self)[i]; OBJ_INFECT(result, element); if (i > 0) rb_str_buf_append(result, delim); rb_str_buf_append(result, shift); element = rb_funcall(element, i_to_json, 2, Vstate, LONG2FIX(depth + 1)); Check_Type(element, T_STRING); rb_str_buf_append(result, element); } rb_str_buf_append(result, state->array_nl); if (RSTRING_LEN(state->array_nl)) { rb_str_buf_append(result, rb_str_times(state->indent, LONG2FIX(depth))); } rb_str_buf_cat2(result, "]"); } return result; }
/* * call-seq: forget(object) * * Forget _object_ for this generating run. */ static VALUE cState_forget(VALUE self, VALUE object) { GET_STATE(self); return rb_hash_delete(state->seen, rb_obj_id(object)); }
static void* ov_http_client_complete_task(void* data) { CURLM* handle; CURLMsg* message; VALUE error_class; VALUE error_instance; VALUE transfer; long code; ov_http_client_object* client_ptr; ov_http_request_object* request_ptr; ov_http_response_object* response_ptr; ov_http_transfer_object* transfer_ptr; /* The passed pointer is the libcurl message describing the completed transfer: */ message = (CURLMsg*) data; handle = message->easy_handle; /* The transfer is stored as the private data of the libcurl easy handle: */ curl_easy_getinfo(handle, CURLINFO_PRIVATE, &transfer); /* Get the pointers to the transfer, client and response: */ ov_http_transfer_ptr(transfer, transfer_ptr); ov_http_client_ptr(transfer_ptr->client, client_ptr); ov_http_request_ptr(transfer_ptr->request, request_ptr); ov_http_response_ptr(transfer_ptr->response, response_ptr); /* Remove the transfer from the pending hash: */ rb_hash_delete(client_ptr->pending, transfer_ptr->request); if (message->data.result == CURLE_OK) { /* Copy the response code and the response body to the response object: */ curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &code); response_ptr->code = LONG2NUM(code); response_ptr->body = rb_funcall(transfer_ptr->out, STRING_ID, 0); /* Put the request and the response in the completed transfers hash: */ rb_hash_aset(client_ptr->completed, transfer_ptr->request, transfer_ptr->response); /* Send a summary of the response to the log: */ ov_http_client_log_info( client_ptr->log, "Received response code %"PRIsVALUE" for %"PRIsVALUE" request to URL '%"PRIsVALUE"'.", response_ptr->code, request_ptr->method, request_ptr->url ); } else { /* Select the error class according to the kind of error returned by libcurl: */ switch (message->data.result) { case CURLE_COULDNT_CONNECT: case CURLE_COULDNT_RESOLVE_HOST: case CURLE_COULDNT_RESOLVE_PROXY: error_class = ov_connection_error_class; break; case CURLE_OPERATION_TIMEDOUT: error_class = ov_timeout_error_class; break; default: error_class = ov_error_class; } /* Put the request and error in the completed transfers hash: */ error_instance = rb_sprintf("Can't send request: %s", curl_easy_strerror(message->data.result)); error_instance = rb_class_new_instance(1, &error_instance, error_class); rb_hash_aset(client_ptr->completed, transfer_ptr->request, error_instance); } /* Now that the libcurl easy handle is released, we can release the headers as well: */ curl_slist_free_all(transfer_ptr->headers); return NULL; }
VALUE hash_spec_rb_hash_delete(VALUE self, VALUE hash, VALUE key) { return rb_hash_delete(hash, key); }
VALUE ae_remove_proc(VALUE proc_id) { AE_TRACE(); return rb_hash_delete(AE_procs, proc_id); }
VALUE ae_remove_handle(VALUE ae_handle_id) { AE_TRACE(); return rb_hash_delete(AE_handles, ae_handle_id); }
/* Unset a feature. */ static VALUE birch_unset(VALUE self, VALUE feature) { return rb_hash_delete( rb_iv_get(self, "@features"), feature ); }