Exemplo n.º 1
0
void PopulateTableFromQuery(lua_State* state, Query* query)
{
	Results results = query->GetResults();

	int resultid = 1;

	for (Results::iterator it = results.begin(); it != results.end(); ++it) {
		Result* result = *it;

		LUA->PushNumber(resultid++);

		LUA->CreateTable();
		{
			bool status = result->GetErrorID() == 0;
			LUA->PushBool(status);
			LUA->SetField(-2, "status");
			if (!status) {
				LUA->PushString(result->GetError().c_str());
				LUA->SetField(-2, "error");
				LUA->PushNumber(result->GetErrorID());
				LUA->SetField(-2, "errorid");
			}
			else {
				LUA->PushNumber(result->GetAffected());
				LUA->SetField(-2, "affected");
				LUA->PushNumber(result->GetLastID());
				LUA->SetField(-2, "lastid");
				LUA->CreateTable();
				PopulateTableFromResult(state, result->GetResult(), query->GetUseNumbers());
				LUA->SetField(-2, "data");
			}
#ifdef ENABLE_QUERY_TIMERS
			LUA->PushNumber(query->GetQueryTime());
			LUA->SetField(-2, "time");
#endif
		}

		LUA->SetTable(-3);
	}
}
Exemplo n.º 2
0
// Create a new results by computing sums for equivalent names ("foo" and "foo@plt").
static Results combineLikeNames(SgAsmInterpretation *interp, const Results &separate) {

    // Index of functions by canonical name
    std::vector<SgAsmFunction*> funcList = SageInterface::querySubTree<SgAsmFunction>(interp);
    Map<std::string, std::vector<SgAsmFunction*> > funcMap;
    BOOST_FOREACH (SgAsmFunction *func, funcList)
        funcMap[canonicalName(func)].push_back(func);

    // Scan through the analysis results and sum by canonical function name
    Map<std::string, UsageCounts> byName;
    for (Results::const_iterator ri=separate.begin(); ri!=separate.end(); ++ri)
        byName[canonicalName(ri->first)] += ri->second;

    // Create a new return value for all the functions.
    Results retval;
    for (Map<std::string, UsageCounts>::iterator i=byName.begin(); i!=byName.end(); ++i) {
        BOOST_FOREACH (SgAsmFunction *func, funcMap[i->first])
            retval[func] = i->second;
    }

    return retval;
}
Exemplo n.º 3
0
Test::Results
TestSampleRates::test(string key, Options options)
{
    int rates[] =
        { 111, 800, 10099, 11024, 44100, 48000, 96000, 192000, 201011, 1094091 };

    Results r;

    if (options & Verbose) {
        cout << "    ";
    }

    for (int i = 0; i < int(sizeof(rates)/sizeof(rates[0])); ++i) {
    
        int rate = rates[i];

        if (options & Verbose) {
            cout << "[" << rate << "Hz] " << flush;
        }

        auto_ptr<Plugin> p(load(key, rate));
        Plugin::FeatureSet f;
        float **data = 0;
        size_t channels = 0;

        // Aim to feed the plugin a roughly fixed input duration in secs
        const float seconds = 10.f;
        size_t step = 1000;
        size_t count = (seconds * rate) / step;
        if (count < 1) count = 1;

        Results subr;
        if (!initAdapted(p.get(), channels, step, step, subr)) {
            // This is not an error; the plugin can legitimately
            // refuse to initialise at weird settings and that's often
            // the most acceptable result
            if (!subr.empty()) {
                r.push_back(note(subr.begin()->message()));
            }
            continue;
        }

        data = createTestAudio(channels, step, count);
        for (size_t j = 0; j < count; ++j) {
#ifdef __GNUC__
            float *ptr[channels];
#else
            float **ptr = (float **)alloca(channels * sizeof(float));
#endif
            size_t idx = j * step;
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
            appendFeatures(f, fs);
        }
        Plugin::FeatureSet fs = p->getRemainingFeatures();
        appendFeatures(f, fs);
        destroyTestAudio(data, channels);
    }

    if (options & Verbose) cout << endl;

    // We can't actually do anything meaningful with our results.
    // We're really just testing to see whether the plugin crashes.  I
    // wonder whether it's possible to do any better?  If not, we
    // should probably report our limitations

    return r;
}