VALUE rb_hps_delete(VALUE self, VALUE vkey) { hashpipe_status_t *s; char save = '\0'; char * key; VALUE val; // Get current value (to be returned) val = rb_hps_hgets(self, vkey); // If found, if(RTEST(val)) { // Delete key key = StringValueCStr(vkey); if(strlen(key) > 8) { // Already warned save = key[8]; key[8] = '\0'; } Data_Get_HPStruct_Ensure_Attached(self, s); hdel(s->buf, key); if(save) key[8] = save; } return val; }
bool test_segfault_during_delete() { Table * t = makeTable(); char * key1 = "0"; char * key2 = "8"; ASSERT( (hash(key1) % t->size) == (hash(key2) % t->size), "Keys will not collide. Update keys for this test.") hset(t, key1, "asdf"); hset(t, key2, "asdf"); hdel(t, key2); hdel(t, key1); // This segfaults freeTable(t); return true; }
STATIC void freeData(htab *t) { if (t == NULL) return; while (hcount(t)) { Utils_Free(hkey(t)); Utils_Free(hstuff(t)); hdel(t); } hdestroy(t); }
int redis_hash::hdel(const char* key, const char* first_name, ...) { const char* name; std::vector<const char*> names; names.push_back(first_name); va_list ap; va_start(ap, first_name); while((name = va_arg(ap, const char*)) != NULL) names.push_back(name); return hdel(key, names); }
bool test_remove() { Table * t = makeTable(); hset(t, "Key", "A"); char *returned = hget(t, "Key"); ASSERT(returned != 0, "Table returned null after setting"); hdel(t, "Key"); returned = hget(t, "Key"); //missing key returns empty string? ASSERT(returned[0] == 0, "Table returned non-null"); return true; }
uint64_t CRedisClient::hdel( const string &key, const CRedisClient::VecString &fields ) { CResult result; hdel( key, fields, result ); ReplyType type = result.getType(); if ( REDIS_REPLY_ERROR == type ) { throw ReplyErr( result.getErrorString() ); }else if ( REDIS_REPLY_INTEGERER != type ) { throw ProtocolErr( "HDEL: data recv is not intgerer" ); } return result.getInt(); }
int main() { int (**table)[2] = hnew(); hset(table, 10, 20); hset(table, 20, 30); hset(table, 30, 40); int (**a)[2] = hget(table, 10); int (**b)[2] = hget(table, 20); int (**c)[2] = hget(table, 30); printf("%d:%d\n", (**a)[0], (**a)[1]); printf("%d:%d\n", (**b)[0], (**b)[1]); printf("%d:%d\n", (**c)[0], (**c)[1]); hdel(table); }
STATIC bool clearKey(const SecureStorageS *storage, const unsigned char *key) { int16_t len = 0; htab *t = NULL; if (storage == NULL || key == NULL) { assert(LIB_NAME "Storage structure and key string must not be NULL" && (false || Storage_TestMode)); return false; } t = storage->Data; if (Utils_GetCharArrayLen(key, &len, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN) == false) return false; if (key != NULL && hfind(t, key, len + UTILS_STR_LEN_SIZE) == true) { // override existing item Utils_Free(hkey(t)); Utils_Free(hstuff(t)); hdel(t); return true; } return false; }
int main(int argc, char *argv[]) { int instance_id = 0; hashpipe_status_t *s; /* Loop over cmd line to fill in params */ static struct option long_opts[] = { {"help", 0, NULL, 'h'}, {"shmkey", 1, NULL, 'K'}, {"key", 1, NULL, 'k'}, {"get", 1, NULL, 'g'}, {"string", 1, NULL, 's'}, {"float", 1, NULL, 'f'}, {"double", 1, NULL, 'd'}, {"int", 1, NULL, 'i'}, {"verbose", 0, NULL, 'v'}, {"clear", 0, NULL, 'C'}, {"del", 0, NULL, 'D'}, {"query", 1, NULL, 'Q'}, {"instance", 1, NULL, 'I'}, {0,0,0,0} }; int opt,opti; char *key=NULL; char value[81]; float flttmp; double dbltmp; int inttmp; int verbose=0, clear=0; char keyfile[1000]; while ((opt=getopt_long(argc,argv,"hk:g:s:f:d:i:vCDQ:K:I:",long_opts,&opti))!=-1) { switch (opt) { case 'K': // Keyfile snprintf(keyfile, sizeof(keyfile), "HASHPIPE_KEYFILE=%s", optarg); keyfile[sizeof(keyfile)-1] = '\0'; putenv(keyfile); break; case 'I': instance_id = atoi(optarg); break; case 'k': key = optarg; break; case 'Q': s = get_status_buffer(instance_id); hashpipe_status_lock(s); hgets(s->buf, optarg, 80, value); hashpipe_status_unlock(s); value[80] = '\0'; printf("%s\n", value); break; case 'g': s = get_status_buffer(instance_id); hashpipe_status_lock(s); hgetr8(s->buf, optarg, &dbltmp); hashpipe_status_unlock(s); printf("%g\n", dbltmp); break; case 's': if (key) { s = get_status_buffer(instance_id); hashpipe_status_lock(s); hputs(s->buf, key, optarg); hashpipe_status_unlock(s); } break; case 'f': flttmp = atof(optarg); if (key) { s = get_status_buffer(instance_id); hashpipe_status_lock(s); hputr4(s->buf, key, flttmp); hashpipe_status_unlock(s); } break; case 'd': dbltmp = atof(optarg); if (key) { s = get_status_buffer(instance_id); hashpipe_status_lock(s); hputr8(s->buf, key, dbltmp); hashpipe_status_unlock(s); } break; case 'i': inttmp = atoi(optarg); if (key) { s = get_status_buffer(instance_id); hashpipe_status_lock(s); hputi4(s->buf, key, inttmp); hashpipe_status_unlock(s); } break; case 'D': if (key) { s = get_status_buffer(instance_id); hashpipe_status_lock(s); hdel(s->buf, key); hashpipe_status_unlock(s); } break; case 'C': clear=1; break; case 'v': verbose=1; break; case 'h': usage(); return 0; case '?': // Command line parsing error default: usage(); exit(1); break; } } s = get_status_buffer(instance_id); /* If verbose, print out buffer */ if (verbose) { hashpipe_status_lock(s); printf("%s\n", s->buf); hashpipe_status_unlock(s); } if (clear) hashpipe_status_clear(s); exit(0); }
int main(int argc, char *argv[]) { int rv; struct vegas_status s; rv = vegas_status_attach(&s); if (rv!=VEGAS_OK) { fprintf(stderr, "Error connecting to shared mem.\n"); perror(NULL); exit(1); } vegas_status_lock(&s); /* Loop over cmd line to fill in params */ static struct option long_opts[] = { {"key", 1, NULL, 'k'}, {"get", 1, NULL, 'g'}, {"string", 1, NULL, 's'}, {"float", 1, NULL, 'f'}, {"double", 1, NULL, 'd'}, {"int", 1, NULL, 'i'}, {"quiet", 0, NULL, 'q'}, {"clear", 0, NULL, 'C'}, {"del", 0, NULL, 'D'}, {0,0,0,0} }; int opt,opti; char *key=NULL; float flttmp; double dbltmp; int inttmp; int quiet=0, clear=0; while ((opt=getopt_long(argc,argv,"k:g:s:f:d:i:qCD",long_opts,&opti))!=-1) { switch (opt) { case 'k': key = optarg; break; case 'g': hgetr8(s.buf, optarg, &dbltmp); printf("%g\n", dbltmp); break; case 's': if (key) hputs(s.buf, key, optarg); break; case 'f': flttmp = atof(optarg); if (key) hputr4(s.buf, key, flttmp); break; case 'd': dbltmp = atof(optarg); if (key) hputr8(s.buf, key, dbltmp); break; case 'i': inttmp = atoi(optarg); if (key) hputi4(s.buf, key, inttmp); break; case 'D': if (key) hdel(s.buf, key); break; case 'C': clear=1; break; case 'q': quiet=1; break; default: break; } } /* If not quiet, print out buffer */ if (!quiet) { printf(s.buf); printf("\n"); } vegas_status_unlock(&s); if (clear) vegas_status_clear(&s); exit(0); }
void type() { int i, j, jjbo, icount,ncarbon, nhyd; icount = 0; ncarbon = 0; nhyd = 0; for (i=1; i <= natom; i++) { if (atom[i].atomnum == 6) { jjbo = 0; for (j=0; j < MAXIAT; j++) { if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9) jjbo += atom[i].bo[j]; if (atom[atom[i].iat[j]].atomnum == 1) nhyd++; } if ( jjbo < 3 && atom[i].mmx_type == 40 && icount > 0 ) { quick_type(); set_atomtypes(field.type); return; } else if (jjbo < 4 && atom[i].mmx_type != 40 && icount > 0) { quick_type(); set_atomtypes(field.type); return; } else { icount++; ncarbon++; } if (icount > 15) break; } else if (atom[i].atomnum == 8) { jjbo = 0; for (j=0; j < MAXIAT; j++) { if (atom[i].iat[j] != 0 && atom[i].bo[j] != 9) jjbo += atom[i].bo[j]; } if (jjbo < 1 && icount > 0) { quick_type(); set_atomtypes(field.type); return; } else if (jjbo == 1 && icount > 0 && atom[i].mmx_type == 6) { quick_type(); set_atomtypes(field.type); return; } else icount++; if (icount > 15) break; } } if (ncarbon > 0 && nhyd == 0) // pathological cases where there are no carbons, or no carbons that normally have hydrogens { type_mmx(); set_atomtypes(field.type); return; } // normal typing routines if (field.type == MMX) { type_mmx(); set_atomtypes(MMX); } else if (field.type == MM3) { for (i=1; i <= natom; i++) { if (atom[i].mmx_type == 20) { hdel(1); break; } } type_mmx(); set_atomtypes(MM3); } else if (field.type == MMFF94) { for (i=1; i <= natom; i++) { if (atom[i].mmx_type == 20) { hdel(1); break; } } type_mmx(); set_atomtypes(MMFF94); } else if (field.type == AMBER) { for (i=1; i <= natom; i++) { if (atom[i].mmx_type == 20) { hdel(1); break; } } type_mmx(); set_atomtypes(AMBER); } else if (field.type == OPLSAA) { for (i=1; i <= natom; i++) { if (atom[i].mmx_type == 20) { hdel(1); break; } } type_mmx(); set_atomtypes(OPLSAA); } else message_alert("No typing rules for this force field are implemented!","ERROR"); }
// ================================================== void pcmfout(int mode) { FILE *wfile; int icoord, imetflag, ispin,lps; int i,j, itype; /* Mode = 1 normal packed write operation * Mode = 2 fast no questions asked unpacked write of pcmod.bak * Mode = 3 fast no questions ot file = wfile * mode = 4 start of minim to pcmod.bak but ask questions about pi */ wfile = NULL; itype = 0; if( mode == 1 ) { /* assume append is set when we get a filename that exists */ /* put up dialog box with current structure title, pi flags and added constants question */ if( files.append ) wfile = fopen_path(Savebox.path,Savebox.fname,"a"); else wfile = fopen_path(Savebox.path,Savebox.fname,"w"); } else if( mode == 2 || mode == 4 ) { wfile = fopen_path(pcwindir,"pcmod.bak","w"); } else if( mode == 3 ) { if( files.append ) wfile = fopen_path(Savebox.path,Savebox.fname,"a"); else wfile = fopen_path(Savebox.path,Savebox.fname,"w"); } if (wfile == NULL) { message_alert("Error opening file in PCMFOUT. Cannot create file","PCM File"); return; } // remove lone pairs if not writing mmx types lps = FALSE; if (default_outtype != MMX) { for (i=1; i <= natom; i++) { if (atom[i].mmx_type == 20) { lps = TRUE; break; } } } if (lps == TRUE) hdel(1); /* start of file writing */ fprintf(wfile,"{PCM %s\n",Struct_Title); fprintf(wfile,"NA %d\n",natom); // optimization information fprintf(wfile,"OPT PARA %d CONV %d IE %8.3f FE %8.3f IH %8.3f FH %8.3f\n",optimize_data.param_avail, optimize_data.converge,optimize_data.initial_energy,optimize_data.final_energy, optimize_data.initial_heat,optimize_data.final_heat); /* flags */ fprintf(wfile,"FL "); fprintf(wfile,"EINT%d ",minim_values.ndc); if( pistuf.iuv ) fprintf(wfile,"UV%d ",pistuf.iuv); if( pistuf.nplane ) fprintf(wfile,"PIPL%d ",pistuf.nplane); if( pistuf.jprint ) fprintf(wfile,"PIPR%d ",pistuf.jprint); if( units.dielec != 1.5 ) fprintf(wfile,"DIELC%f ",units.dielec); fprintf(wfile,"\n"); // default output filetypes fprintf(wfile,"ATOMTYPES %d\n",default_outtype); /* if( minim_values.nconst && mode > 1 ) fprintf(wfile,"CO FILE %s\n",constf.cname);*/ /* atoms and bonds lists */ for( i = 1; i <= natom; i++ ) { if (default_outtype == MMX) { itype = atom[i].mmx_type; } else if (default_outtype == MM3) { itype = atom[i].mm3_type; } else if (default_outtype == MMFF94) { itype = atom[i].mmff_type; } fprintf(wfile,"AT %d %d %8.4f %8.4f %8.4f",i,itype,atom[i].x, atom[i].y, atom[i].z); // bonds fprintf(wfile," B"); for( j = 0; j < MAXIAT; j++ ) { if( atom[i].iat[j]) { fprintf(wfile," %d %d",atom[i].iat[j],atom[i].bo[j]); } } if( atom[i].flags & (1L << HBOND_MASK) ) fprintf(wfile," H "); if( atom[i].flags & (1L << PI_MASK) ) fprintf(wfile," P "); if( atom[i].mmx_type >= 300 ) { icoord = 0; ispin = -1; imetflag = 0; if( atom[i].flags & (1L << SATMET_MASK) ) imetflag += 2; if( atom[i].flags & (1L << GT18e_MASK) ) imetflag += 1; if( imetflag == 2 ) icoord = 0; if( imetflag == 1 ) icoord = 2; if( imetflag == 3 ) { icoord = 1; imetflag = 0; if( atom[i].flags & (1L << LOWSPIN_MASK) ) imetflag += 2; if( atom[i].flags & (1L << SQPLAN_MASK) ) imetflag += 1; if( imetflag == 2 ) ispin = 0; if( imetflag == 3 ) ispin = 2; if( imetflag == 1 ) ispin = 1; } if( icoord ) { fprintf(wfile," M %d",icoord); if( ispin >= 0 ) fprintf(wfile," %d",ispin); } fprintf(wfile," R %g",atom[i].radius); } if( atom[i].charge ) { fprintf(wfile," C %g",atom[i].charge); } fprintf(wfile,"\n"); } if( fxtor.nfxtor == 1 || fxtor.nfxtor == 2 ) { fprintf(wfile,"DD %d %d %d %d FROM %d TO %d BY %d\n",fxtor.iatom[0][0], fxtor.iatom[0][1], fxtor.iatom[0][2], fxtor.iatom[0][3], fxtor.start_ang[0], fxtor.final_ang[0], fxtor.step[0] ); if( fxtor.nfxtor == 2 ) { fprintf(wfile,"DD %d %d %d %d FROM %d TO %d BY %d\n",fxtor.iatom[1][0], fxtor.iatom[1][1], fxtor.iatom[1][2], fxtor.iatom[1][3], fxtor.start_ang[1], fxtor.final_ang[1], fxtor.step[1] ); } } if (fixdis.nfxstr) { for( i = 0; i < fixdis.nfxstr; i++ ) { fprintf(wfile,"FIX DIS %d %d R %7.3f K %7.3f\n",fixdis.ifxstr[i][0], fixdis.ifxstr[i][1], fixdis.fxstrd[i], fixdis.fxstrc[i] ); } } for (i=0; i < 15; i++) { if (ts_bondorder.fbnd[i] > 0.0F) { fprintf(wfile,"FBND"); for (j=0; j<15; j++) { fprintf(wfile," %5.3f",ts_bondorder.fbnd[j]); } fprintf(wfile,"\n"); break; } } fprintf(wfile,"}\n"); fclose(wfile); } /* end of function */
static void *run(hashpipe_thread_args_t * args) { // Local aliases to shorten access to args fields // Our output buffer happens to be a paper_input_databuf hashpipe_status_t st = args->st; const char * status_key = args->thread_desc->skey; st_p = &st; // allow global (this source file) access to the status buffer // Get inital value for crc32 function uint32_t init_crc = crc32(0,0,0); // Flag that holds off the crc thread int holdoff = 1; // Force ourself into the hold off state hashpipe_status_lock_safe(&st); hputi4(st.buf, "CRCHOLD", 1); hashpipe_status_unlock_safe(&st); while(holdoff) { // We're not in any hurry to startup sleep(1); hashpipe_status_lock_safe(&st); // Look for CRCHOLD value hgeti4(st.buf, "CRCHOLD", &holdoff); if(!holdoff) { // Done holding, so delete the key hdel(st.buf, "CRCHOLD"); } hashpipe_status_unlock_safe(&st); } /* Read network params */ struct hashpipe_udp_params up = { .bindhost = "0.0.0.0", .bindport = 8511, .packet_size = 8200 }; hashpipe_status_lock_safe(&st); // Get info from status buffer if present (no change if not present) hgets(st.buf, "BINDHOST", 80, up.bindhost); hgeti4(st.buf, "BINDPORT", &up.bindport); // Store bind host/port info etc in status buffer hputs(st.buf, "BINDHOST", up.bindhost); hputi4(st.buf, "BINDPORT", up.bindport); hputu4(st.buf, "CRCPKOK", 0); hputu4(st.buf, "CRCPKERR", 0); hputs(st.buf, status_key, "running"); hashpipe_status_unlock_safe(&st); struct hashpipe_udp_packet p; /* Give all the threads a chance to start before opening network socket */ sleep(1); /* Set up UDP socket */ int rv = hashpipe_udp_init(&up); if (rv!=HASHPIPE_OK) { hashpipe_error("paper_crc_thread", "Error opening UDP socket."); pthread_exit(NULL); } pthread_cleanup_push((void *)hashpipe_udp_close, &up); /* Main loop */ uint64_t packet_count = 0; uint64_t good_count = 0; uint64_t error_count = 0; uint64_t elapsed_wait_ns = 0; uint64_t elapsed_recv_ns = 0; uint64_t elapsed_proc_ns = 0; float ns_per_wait = 0.0; float ns_per_recv = 0.0; float ns_per_proc = 0.0; struct timespec start, stop; struct timespec recv_start, recv_stop; packet_header_t hdr; while (run_threads()) { /* Read packet */ clock_gettime(CLOCK_MONOTONIC, &recv_start); do { clock_gettime(CLOCK_MONOTONIC, &start); p.packet_size = recv(up.sock, p.data, HASHPIPE_MAX_PACKET_SIZE, 0); clock_gettime(CLOCK_MONOTONIC, &recv_stop); } while (p.packet_size == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && run_threads()); // Break out of loop if stopping if(!run_threads()) break; // Increment packet count packet_count++; // Check CRC if(crc32(init_crc, (/*const?*/ uint8_t *)p.data, p.packet_size) == 0xffffffff) { // CRC OK! Increment good counter good_count++; } else { // CRC error! Increment error counter error_count++; // Log message get_header(&p, &hdr); hashpipe_warn("paper_crc", "CRC error mcnt %llu ; fid %u ; xid %u", hdr.mcnt, hdr.fid, hdr.xid); } clock_gettime(CLOCK_MONOTONIC, &stop); elapsed_wait_ns += ELAPSED_NS(recv_start, start); elapsed_recv_ns += ELAPSED_NS(start, recv_stop); elapsed_proc_ns += ELAPSED_NS(recv_stop, stop); if(packet_count % 1000 == 0) { // Compute stats get_header(&p, &hdr); ns_per_wait = (float)elapsed_wait_ns / packet_count; ns_per_recv = (float)elapsed_recv_ns / packet_count; ns_per_proc = (float)elapsed_proc_ns / packet_count; // Update status hashpipe_status_lock_busywait_safe(&st); hputu8(st.buf, "CRCMCNT", hdr.mcnt); // Gbps = bits_per_packet / ns_per_packet // (N_BYTES_PER_PACKET excludes header, so +8 for the header) hputr4(st.buf, "CRCGBPS", 8*(N_BYTES_PER_PACKET+8)/(ns_per_recv+ns_per_proc)); hputr4(st.buf, "CRCWATNS", ns_per_wait); hputr4(st.buf, "CRCRECNS", ns_per_recv); hputr4(st.buf, "CRCPRCNS", ns_per_proc); // TODO Provide some way to recognize request to zero out the // CRCERR and CRCOK fields. hputu8(st.buf, "CRCPKOK", good_count); hputu8(st.buf, "CRCPKERR", error_count); hashpipe_status_unlock_safe(&st); // Start new average elapsed_wait_ns = 0; elapsed_recv_ns = 0; elapsed_proc_ns = 0; packet_count = 0; } /* Will exit if thread has been cancelled */ pthread_testcancel(); } /* Have to close all push's */ pthread_cleanup_pop(1); /* Closes push(hashpipe_udp_close) */ return NULL; } static hashpipe_thread_desc_t crc_thread = { name: "paper_crc_thread", skey: "CRCSTAT", init: NULL, run: run, ibuf_desc: {NULL},