int main(int argc, char *argv[]) { int i; Table_T identifiers = Table_new(10000, textcmp, texthash); Text_save_T mark = Text_save(); Fmt_register('T', Text_fmt); Fmt_register('D', Integer_fmt); first = Text_cat(Text_cat(Text_ucase, Text_lcase), Text_box("_", 1)); rest = Text_cat(first, Text_digits); for (i = 1; i < argc; i++) { FILE *fp = fopen(argv[i], "r"); if (fp == NULL) fprintf(stderr, "%s: can't open '%s' (%s)\n", argv[0], argv[i], strerror(errno)); else { cref(argv[i], fp, identifiers); fclose(fp); } } if (argc == 1) cref(NULL, stdin, identifiers); { int i; void **array = Table_toArray(identifiers, NULL); qsort(array, Table_length(identifiers), 2*sizeof (*array), compare); for (i = 0; array[i]; i += 2) { Fmt_print("%T", array[i]); print(array[i+1]); FREE(array[i]); } FREE(array); Table_free(&identifiers); } Text_restore(&mark); return EXIT_SUCCESS; }
static int _mas_init_pid( mas_options_t * popts, const char *shash_name ) { EVAL_PREPARE; int r = 0; char *pidpath = NULL; r = 0; pidpath = mas_strdup( popts->dir.pids ); pidpath = mas_strcat_x( pidpath, shash_name ); r = cref( pidpath, popts->dir.pids ); if ( r == -999 ) r = cref( pidpath, popts->dir.pids ); HMSG( "(%d)PIDPATH 1 : %s", r, pidpath ); if ( r < 0 ) { r = 0; IEVAL( r, mas_open( pidpath, O_RDWR | O_EXCL, S_IWUSR | S_IRUSR ) ); } if ( r >= 0 ) { CTRL_PREPARE; ctrl.pidfd = r; { int er = 0; IEVALE( r, lockf( ctrl.pidfd, F_TLOCK, 0 ), &er ); HMSG( "(%d:%d)PIDLCK : %s - %s before", r, errno, pidpath, r < 0 && ( er == EACCES || er == EAGAIN ) ? "LOCKED" : "UNLOCKED" ); } if ( r >= 0 ) { ssize_t lb; char buf[64]; lb = snprintf( buf, sizeof( buf ), "%u", getpid( ) ); IEVAL( r, ftruncate( ctrl.pidfd, 0 ) ); IEVAL( r, write( ctrl.pidfd, buf, lb ) ); HMSG( "PIDWRT: %d pid:%u W:%ld", r, ctrl.threads.n.main.pid, lb ); ctrl.pidfilesv.c = mas_add_argv_arg_nodup( ctrl.pidfilesv.c, &ctrl.pidfilesv.v, pidpath ); pidpath = NULL; } else { if ( ctrl.pidfd >= 0 ) mas_close( ctrl.pidfd ); ctrl.pidfd = r; } } if ( pidpath ) mas_free( pidpath ); HMSG( "(%d)INIT PID", r ); return r; }
void random_forest_p(const data_t& train, const vec_data_t& test, preds_t& train_preds, vec_preds_t& test_preds, args_t& args) { int trees = args.trees; int numthreads=args.processors, i, x, t; int fk = args.kfeatures; if (numthreads > trees) numthreads = trees; trees = (trees / numthreads) * numthreads; int trees_per_thread = trees / numthreads; thread** threads = new thread*[numthreads]; vector< vec_preds_t > seg; vector< preds_t > train_seg; for (i=0; i < numthreads; i++) { vec_preds_t p; init_pred_vec(test, p); seg.push_back(p); preds_t tp; init_pred(train, tp); train_seg.push_back(tp); } for (i=0;i<numthreads;i++) threads[i] = new thread(bind(multiple_forest, trees_per_thread, cref(train), cref(test), ref(train_seg[i]), ref(seg[i]), ref(args))); for (i=0;i<numthreads;i++){ threads[i]->join(); delete threads[i]; } fprintf(stderr, "done threading\n"); delete[] threads; // congregate results of the threads for (i = 0; i < numthreads; i++) for (t = 0; t < test.size(); t++) for (int j = 0; j < test[t].size(); j++) test_preds[t][j] += seg[i][t][j]; for (i = 0; i < numthreads; i++) for (int j = 0; j < train.size(); j++) train_preds[j] += train_seg[i][j]; // average results of the trees for (i = 0; i < test.size(); i++) for (int j = 0; j < test[i].size(); j++) test_preds[i][j] /= trees; for (int j = 0; j < train.size(); j++) train_preds[j] /= trees; // write results to file for (i = 0; i < test.size(); i++) { tuple::write_to_file(test_preds[i], test[i], args.test_outs[i]); } }
void RibManager::startListening(const Name& commandPrefix, const ndn::OnInterest& onRequest) { NFD_LOG_INFO("Listening on: " << commandPrefix); m_nfdController.start<ndn::nfd::FibAddNextHopCommand>( ControlParameters() .setName(commandPrefix) .setFaceId(0), bind(&RibManager::onNrdCommandPrefixAddNextHopSuccess, this, cref(commandPrefix), _1), bind(&RibManager::onNrdCommandPrefixAddNextHopError, this, cref(commandPrefix), _2)); m_face.setInterestFilter(commandPrefix, onRequest); }
int main() { tuple<> t0; tuple<int> t1(1); tuple<int, float> t2(1, 3.14159f); tuple<int, float, const char*> t3a(1, 3.14159f, "Hello, world!"); tuple<long, double, std::string> t3b(t3a); t3b = t3a; // t3a = t3b; DPG: triggers an error, as it should. tuple<int, float, std::string> t3c = make_tuple(17, 2.718281828, std::string("Fun")); int seventeen = 17; double pi = 3.14159; tuple<int&, double&> seventeen_pi = make_tuple(ref(seventeen), ref(pi)); tuple<int&, const double&> seventeen_pi2 = make_tuple(ref(seventeen), cref(pi)); tuple<int&, double&> seventeen_pi_tied = tie(seventeen, pi); assert(get<0>(t3a) == 1); assert(get<1>(t3a) == 3.14159f); assert(std::strcmp(get<2>(t3a), "Hello, world!") == 0); assert(t3a == t3b); assert(!(t3a != t3b)); assert(!(t3a < t3b)); assert(!(t3a > t3b)); assert(t3a <= t3b && t3b <= t3a); assert(t3a >= t3b && t3b >= t3a); }
/* ** subexpr -> (simpleexp | unop subexpr) { binop subexpr } ** where `binop' is any binary operator with a priority higher than `limit' */ static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { callstack_ref cref( *ls->L ); UnOpr uop = getunopr(ls->t.token); FuncState *fs = GetCurrentFuncState( ls ); if (uop != OPR_NOUNOPR) { luaX_next(ls); subexpr(ls, v, UNARY_PRIORITY); luaK_prefix(fs, uop, v); } else { simpleexp(ls, v); } /* expand while operators have priorities higher than `limit' */ BinOpr op = getbinopr(ls->t.token); while (op != OPR_NOBINOPR && priority[op].left > limit) { luaX_next(ls); luaK_infix(fs, op, v); /* read sub-expression with higher priority */ expdesc v2; BinOpr nextop = subexpr(ls, &v2, priority[op].right); luaK_posfix(fs, op, v, &v2); op = nextop; } return op; /* return first untreated operator */ }
TEST(Auto, ConstAndMutableReference) { auto foo = new_syntax::Foo{}; auto& cref = foo.cref(); // cref is a const reference auto& mref = foo.mref(); // mref is a mutable reference static_assert(std::is_const_v<std::remove_reference_t<decltype(cref)>>, ""); static_assert(!std::is_const_v<std::remove_reference_t<decltype(mref)>>, ""); }
int main(int, char**) { // LWG2485: tuple should not open a hole in the type system, get() should // imitate [expr.ref]'s rules for accessing data members { cref(std::get<0>(tup4())); // expected-error {{call to deleted function 'cref'}} } return 0; }
void unwrap_test() { int i = 3; const int ci = 2; do_unwrap(i); do_unwrap(ci); do_unwrap(ref(i)); do_unwrap(cref(ci)); do_unwrap(ref(ci)); copy_counter cc; BOOST_TEST(cc.count() == 0); do_unwrap(cc); do_unwrap(ref(cc)); do_unwrap(cref(cc)); BOOST_TEST(cc.count() == 1); BOOST_TEST(unwrap_ref(ref(cc)).count() == 1); }
bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, string const & zipFilePath) { // 2. Open zip file for writing. MY_SCOPE_GUARD(outFileGuard, bind(&my::DeleteFileX, cref(zipFilePath))); ZipHandle zip(zipFilePath); if (!zip.Handle()) return false; zip_fileinfo zipInfo = {}; CreateTMZip(zipInfo.tmz_date); string fileName = filePath; my::GetNameFromFullPath(fileName); if (!strings::IsASCIIString(fileName)) fileName = "MapsMe.kml"; if (zipOpenNewFileInZip(zip.Handle(), fileName.c_str(), &zipInfo, NULL, 0, NULL, 0, "ZIP from MapsWithMe", Z_DEFLATED, Z_DEFAULT_COMPRESSION) < 0) { return false; } // Write source file into zip file. try { my::FileData file(filePath, my::FileData::OP_READ); uint64_t const fileSize = file.Size(); uint64_t currSize = 0; char buffer[ZIP_FILE_BUFFER_SIZE]; while (currSize < fileSize) { unsigned int const toRead = min(ZIP_FILE_BUFFER_SIZE, static_cast<unsigned int>(fileSize - currSize)); file.Read(currSize, buffer, toRead); if (ZIP_OK != zipWriteInFileInZip(zip.Handle(), buffer, toRead)) return false; currSize += toRead; } } catch (Reader::Exception const & ex) { LOG(LERROR, ("Error reading file:", filePath, ex.Msg())); return false; } // Success. outFileGuard.release(); return true; }
int compare(const char* filename){ classWithComplex cref(1,2,3,4); classWithComplex ccref(11,22,33,44); auto f = TFile::Open(filename); auto c = (classWithComplex*)f->Get("classWithComplex1"); auto cc = (classWithComplex*)f->Get("classWithComplex2"); if (*c != cref && *cc != ccref){ cout << "ERROR The objects on file differ from the references!\n" << cref.GetF() << ", " << cref.GetD() << " vs onfile " << c->GetF() << ", " << c->GetD() << endl << ccref.GetF() << ", " << ccref.GetD() << " vs onfile " << cc->GetF() << ", " << cc->GetD() << endl; return 1; } return 0; }
static void chunk (LexState *ls) { /* chunk -> { stat [`;'] } */ int islast = 0; callstack_ref cref( *ls->L ); while (!islast && !block_follow(ls->t.token)) { islast = statement(ls); testnext(ls, ';'); FuncState *fs = GetCurrentFuncState( ls ); lua_assert(fs->f->maxstacksize >= fs->freereg && fs->freereg >= fs->nactvar); fs->freereg = fs->nactvar; /* free registers */ } }
int main() { // using at_key { auto xs = hana::make_map( hana::make_pair(hana::int_c<0>, 0), hana::make_pair(hana::int_c<1>, '1'), hana::make_pair(hana::int_c<2>, 2.2) ); // Make sure we return lvalue-references BOOST_HANA_RUNTIME_CHECK(hana::at_key(xs, hana::int_c<0>) == 0); BOOST_HANA_RUNTIME_CHECK(hana::at_key(xs, hana::int_c<1>) == '1'); BOOST_HANA_RUNTIME_CHECK(hana::at_key(xs, hana::int_c<2>) == 2.2); int& a = hana::at_key(xs, hana::int_c<0>); char& b = hana::at_key(xs, hana::int_c<1>); double& c = hana::at_key(xs, hana::int_c<2>); a = 9; b = '9'; c = 9.9; // Make sure we return lvalue-references to const on a const map int const& ca = hana::at_key(cref(xs), hana::int_c<0>); char const& cb = hana::at_key(cref(xs), hana::int_c<1>); double const& cc = hana::at_key(cref(xs), hana::int_c<2>); BOOST_HANA_RUNTIME_CHECK(ca == 9); BOOST_HANA_RUNTIME_CHECK(cb == '9'); BOOST_HANA_RUNTIME_CHECK(cc == 9.9); } // using operator[] { auto xs = hana::make_map( hana::make_pair(hana::int_c<0>, 0), hana::make_pair(hana::int_c<1>, '1'), hana::make_pair(hana::int_c<2>, 2.2) ); BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<0>] == 0); BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<1>] == '1'); BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<2>] == 2.2); xs[hana::int_c<0>] = 9; xs[hana::int_c<1>] = '9'; xs[hana::int_c<2>] = 9.9; BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<0>] == 9); BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<1>] == '9'); BOOST_HANA_RUNTIME_CHECK(xs[hana::int_c<2>] == 9.9); } // Make sure we return a rvalue-reference from a temporary map // (https://github.com/boostorg/hana/issues/90) { auto xs = hana::make_map( hana::make_pair(hana::int_c<0>, 0), hana::make_pair(hana::int_c<1>, '1'), hana::make_pair(hana::int_c<2>, 2.2) ); char&& c = hana::at_key(std::move(xs), hana::int_c<1>); BOOST_HANA_RUNTIME_CHECK(hana::at_key(xs, hana::int_c<1>) == '1'); c = '9'; BOOST_HANA_RUNTIME_CHECK(hana::at_key(xs, hana::int_c<1>) == '9'); } }
static type call(T const& t) { return fusion::make_cons(cref(t)); }
const value_type* operator->() const { return &cref(); }
const value_type& operator*() const { return cref(); }
virtual Vasp *do_shift(OpParam &p) { CVasp cdst(dst),cref(ref); return VaspOp::m_tilt(p,cref,arg,&cdst); }
// SingleResponse ::= SEQUENCE { // certID CertID, // certStatus CertStatus, // thisUpdate GeneralizedTime, // nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL, // singleExtensions [1] EXPLICIT Extensions{{re-ocsp-crl | // re-ocsp-archive-cutoff | // CrlEntryExtensions, ...} // } OPTIONAL } static inline Result SingleResponse(Reader& input, Context& context) { bool match = false; Result rv = der::Nested(input, der::SEQUENCE, bind(CertID, _1, cref(context), ref(match))); if (rv != Success) { return rv; } if (!match) { // This response does not reference the certificate we're interested in. // By consuming the rest of our input and returning successfully, we can // continue processing and examine another response that might have what // we want. input.SkipToEnd(); return Success; } // CertStatus ::= CHOICE { // good [0] IMPLICIT NULL, // revoked [1] IMPLICIT RevokedInfo, // unknown [2] IMPLICIT UnknownInfo } // // In the event of multiple SingleResponses for a cert that have conflicting // statuses, we use the following precedence rules: // // * revoked overrides good and unknown // * good overrides unknown if (input.Peek(static_cast<uint8_t>(CertStatus::Good))) { rv = der::ExpectTagAndEmptyValue(input, static_cast<uint8_t>(CertStatus::Good)); if (rv != Success) { return rv; } if (context.certStatus != CertStatus::Revoked) { context.certStatus = CertStatus::Good; } } else if (input.Peek(static_cast<uint8_t>(CertStatus::Revoked))) { // We don't need any info from the RevokedInfo structure, so we don't even // parse it. TODO: We should mention issues like this in the explanation of // why we treat invalid OCSP responses equivalently to revoked for OCSP // stapling. rv = der::ExpectTagAndSkipValue(input, static_cast<uint8_t>(CertStatus::Revoked)); if (rv != Success) { return rv; } context.certStatus = CertStatus::Revoked; } else { rv = der::ExpectTagAndEmptyValue(input, static_cast<uint8_t>(CertStatus::Unknown)); if (rv != Success) { return rv; } } // http://tools.ietf.org/html/rfc6960#section-3.2 // 5. The time at which the status being indicated is known to be // correct (thisUpdate) is sufficiently recent; // 6. When available, the time at or before which newer information will // be available about the status of the certificate (nextUpdate) is // greater than the current time. Time thisUpdate(Time::uninitialized); rv = der::GeneralizedTime(input, thisUpdate); if (rv != Success) { return rv; } static const uint64_t SLOP_SECONDS = Time::ONE_DAY_IN_SECONDS; Time timePlusSlop(context.time); rv = timePlusSlop.AddSeconds(SLOP_SECONDS); if (rv != Success) { return rv; } if (thisUpdate > timePlusSlop) { return Result::ERROR_OCSP_FUTURE_RESPONSE; } Time notAfter(Time::uninitialized); static const uint8_t NEXT_UPDATE_TAG = der::CONTEXT_SPECIFIC | der::CONSTRUCTED | 0; if (input.Peek(NEXT_UPDATE_TAG)) { Time nextUpdate(Time::uninitialized); rv = der::Nested(input, NEXT_UPDATE_TAG, bind(der::GeneralizedTime, _1, ref(nextUpdate))); if (rv != Success) { return rv; } if (nextUpdate < thisUpdate) { return Result::ERROR_OCSP_MALFORMED_RESPONSE; } notAfter = thisUpdate; if (notAfter.AddSeconds(context.maxLifetimeInDays * Time::ONE_DAY_IN_SECONDS) != Success) { // This could only happen if we're dealing with times beyond the year // 10,000AD. return Result::ERROR_OCSP_FUTURE_RESPONSE; } if (nextUpdate <= notAfter) { notAfter = nextUpdate; } } else { // NSS requires all OCSP responses without a nextUpdate to be recent. // Match that stricter behavior. notAfter = thisUpdate; if (notAfter.AddSeconds(Time::ONE_DAY_IN_SECONDS) != Success) { // This could only happen if we're dealing with times beyond the year // 10,000AD. return Result::ERROR_OCSP_FUTURE_RESPONSE; } } // Add some slop to hopefully handle clock-skew. Time notAfterPlusSlop(notAfter); rv = notAfterPlusSlop.AddSeconds(SLOP_SECONDS); if (rv != Success) { // This could only happen if we're dealing with times beyond the year // 10,000AD. return Result::ERROR_OCSP_FUTURE_RESPONSE; } if (context.time > notAfterPlusSlop) { context.expired = true; } rv = der::OptionalExtensions(input, der::CONTEXT_SPECIFIC | der::CONSTRUCTED | 1, ExtensionNotUnderstood); if (rv != Success) { return rv; } if (context.thisUpdate) { *context.thisUpdate = thisUpdate; } if (context.validThrough) { *context.validThrough = notAfterPlusSlop; } return Success; }
tuple< T const&, T const& > minmax(T const& a, T const& b, BinaryPredicate comp) { return comp(b,a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref(a),cref(b)); }
tuple< T const&, T const& > minmax(T const& a, T const& b) { return (b<a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref(a),cref(b)); }
bool operator()(m2::PointD const & pt) { m_regions.ForEachInRect(m2::RectD(pt, pt), bind<void>(ref(*this), _1, cref(pt))); return !m_belongs; }
static type call(T const& t) { return fusion::make_cons(cref(t) , duplicate_sequence_attribute<Attribute, T, N-1>::call(t)); }
// SingleResponse ::= SEQUENCE { // certID CertID, // certStatus CertStatus, // thisUpdate GeneralizedTime, // nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL, // singleExtensions [1] EXPLICIT Extensions{{re-ocsp-crl | // re-ocsp-archive-cutoff | // CrlEntryExtensions, ...} // } OPTIONAL } static inline der::Result SingleResponse(der::Input& input, Context& context) { bool match = false; if (der::Nested(input, der::SEQUENCE, bind(CertID, _1, cref(context), ref(match))) != der::Success) { return der::Failure; } if (!match) { // This response does not reference the certificate we're interested in. // By consuming the rest of our input and returning successfully, we can // continue processing and examine another response that might have what // we want. input.SkipToEnd(); return der::Success; } // CertStatus ::= CHOICE { // good [0] IMPLICIT NULL, // revoked [1] IMPLICIT RevokedInfo, // unknown [2] IMPLICIT UnknownInfo } // // In the event of multiple SingleResponses for a cert that have conflicting // statuses, we use the following precedence rules: // // * revoked overrides good and unknown // * good overrides unknown if (input.Peek(static_cast<uint8_t>(CertStatus::Good))) { if (ExpectTagAndLength(input, static_cast<uint8_t>(CertStatus::Good), 0) != der::Success) { return der::Failure; } if (context.certStatus != CertStatus::Revoked) { context.certStatus = CertStatus::Good; } } else if (input.Peek(static_cast<uint8_t>(CertStatus::Revoked))) { // We don't need any info from the RevokedInfo structure, so we don't even // parse it. TODO: We should mention issues like this in the explanation of // why we treat invalid OCSP responses equivalently to revoked for OCSP // stapling. if (der::Skip(input, static_cast<uint8_t>(CertStatus::Revoked)) != der::Success) { return der::Failure; } context.certStatus = CertStatus::Revoked; } else if (ExpectTagAndLength(input, static_cast<uint8_t>(CertStatus::Unknown), 0) != der::Success) { return der::Failure; } // http://tools.ietf.org/html/rfc6960#section-3.2 // 5. The time at which the status being indicated is known to be // correct (thisUpdate) is sufficiently recent; // 6. When available, the time at or before which newer information will // be available about the status of the certificate (nextUpdate) is // greater than the current time. // We won't accept any OCSP responses that are more than 10 days old, even if // the nextUpdate time is further in the future. static const PRTime OLDEST_ACCEPTABLE = INT64_C(10) * ONE_DAY; PRTime thisUpdate; if (der::GeneralizedTime(input, thisUpdate) != der::Success) { return der::Failure; } if (thisUpdate > context.time + SLOP) { return der::Fail(SEC_ERROR_OCSP_FUTURE_RESPONSE); } PRTime notAfter; static const uint8_t NEXT_UPDATE_TAG = der::CONTEXT_SPECIFIC | der::CONSTRUCTED | 0; if (input.Peek(NEXT_UPDATE_TAG)) { PRTime nextUpdate; if (der::Nested(input, NEXT_UPDATE_TAG, bind(der::GeneralizedTime, _1, ref(nextUpdate))) != der::Success) { return der::Failure; } if (nextUpdate < thisUpdate) { return der::Fail(SEC_ERROR_OCSP_MALFORMED_RESPONSE); } if (nextUpdate - thisUpdate <= OLDEST_ACCEPTABLE) { notAfter = nextUpdate; } else { notAfter = thisUpdate + OLDEST_ACCEPTABLE; } } else { // NSS requires all OCSP responses without a nextUpdate to be recent. // Match that stricter behavior. notAfter = thisUpdate + ONE_DAY; } if (context.time < SLOP) { // prevent underflow return der::Fail(SEC_ERROR_INVALID_ARGS); } if (context.time - SLOP > notAfter) { return der::Fail(SEC_ERROR_OCSP_OLD_RESPONSE); } if (!input.AtEnd()) { if (CheckExtensionsForCriticality(input) != der::Success) { return der::Failure; } } if (context.thisUpdate) { *context.thisUpdate = thisUpdate; } if (context.validThrough) { *context.validThrough = notAfter; } return der::Success; }
void Control_::ref() { count_++; cref(); }