MXS-2026 Use qc_init(...)/qc_end()

Use qc_init(...)/qc_end() for initializing QC in test-programs.
This commit is contained in:
Johan Wikman 2018-08-27 16:15:16 +03:00
parent ce715e03aa
commit a29851a42c
7 changed files with 52 additions and 64 deletions

View File

@ -44,9 +44,7 @@ int main()
set_libdir(strdup("../qc_sqlite"));
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL) &&
qc_process_init(QC_INIT_BOTH) &&
qc_thread_init(QC_INIT_BOTH))
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL))
{
const char s[] = "SELECT @@global.max_allowed_packet";
@ -58,7 +56,7 @@ int main()
// code generator.
qc_parse(stmt, QC_COLLECT_ALL);
qc_process_end(QC_INIT_BOTH);
qc_end();
rv = EXIT_SUCCESS;
}

View File

@ -131,16 +131,11 @@ int main(int argc, char* argv[])
set_libdir(strdup(LIBDIR));
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, QC_LIB, NULL))
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, QC_LIB, NULL))
{
if (qc_process_init(QC_INIT_BOTH) && qc_thread_init(QC_INIT_BOTH))
{
rc = test();
}
else
{
cerr << "error: Could not perform process/thread initialization for " << QC_LIB << "." << endl;
}
rc = test();
qc_end();
}
else
{

View File

@ -31,10 +31,12 @@ using std::endl;
int main(int argc, char** argv)
{
int rc = EXIT_FAILURE;
if (argc != 3)
{
cout << "Usage: canonizer <input file> <output file>" << endl;
return 1;
return rc;
}
mxs_log_init(NULL, NULL, MXS_LOG_TARGET_STDOUT);
@ -43,7 +45,7 @@ int main(int argc, char** argv)
if (!utils_init())
{
cout << "Utils library init failed." << endl;
return 1;
return rc;
}
set_libdir(strdup("../../../../query_classifier/qc_sqlite/"));
@ -51,43 +53,46 @@ int main(int argc, char** argv)
set_langdir(strdup("."));
set_process_datadir(strdup("/tmp"));
qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL);
qc_process_init(QC_INIT_BOTH);
qc_thread_init(QC_INIT_BOTH);
std::ifstream infile(argv[1]);
std::ofstream outfile(argv[2]);
if (!infile || !outfile)
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL))
{
cout << "Opening files failed." << endl;
return 1;
}
std::ifstream infile(argv[1]);
std::ofstream outfile(argv[2]);
for (std::string line; getline(infile, line);)
{
while (*line.rbegin() == '\n')
if (infile && outfile)
{
line.resize(line.size() - 1);
for (std::string line; getline(infile, line);)
{
while (*line.rbegin() == '\n')
{
line.resize(line.size() - 1);
}
if (!line.empty())
{
size_t psize = line.size() + 1;
mxs::Buffer buf(psize + 4);
auto it = buf.begin();
*it++ = (uint8_t)psize;
*it++ = (uint8_t)(psize >> 8);
*it++ = (uint8_t)(psize >> 16);
*it++ = 0;
*it++ = 3;
std::copy(line.begin(), line.end(), it);
char* tok = qc_get_canonical(buf.get());
outfile << tok << endl;
free(tok);
}
}
rc = EXIT_SUCCESS;
}
else
{
cout << "Opening files failed." << endl;
}
if (!line.empty())
{
size_t psize = line.size() + 1;
mxs::Buffer buf(psize + 4);
auto it = buf.begin();
*it++ = (uint8_t)psize;
*it++ = (uint8_t)(psize >> 8);
*it++ = (uint8_t)(psize >> 16);
*it++ = 0;
*it++ = 3;
std::copy(line.begin(), line.end(), it);
char* tok = qc_get_canonical(buf.get());
outfile << tok << endl;
free(tok);
}
qc_end();
}
qc_process_end(QC_INIT_BOTH);
return 0;
return rc;
}

View File

@ -186,9 +186,7 @@ int main(int argc, char* argv[])
set_libdir(strdup("../../../query_classifier/qc_sqlite"));
// We have to setup something in order for the regexes to be compiled.
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL)
&& qc_process_init(QC_INIT_BOTH)
&& qc_thread_init(QC_INIT_BOTH))
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL))
{
Tester tester(verbosity);
@ -218,8 +216,7 @@ int main(int argc, char* argv[])
}
}
qc_thread_end(QC_INIT_BOTH);
qc_process_end(QC_INIT_BOTH);
qc_end();
}
else
{

View File

@ -423,9 +423,7 @@ int main(int argc, char* argv[])
set_libdir(strdup("../../../query_classifier/qc_sqlite"));
// We have to setup something in order for the regexes to be compiled.
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL)
&& qc_process_init(QC_INIT_BOTH)
&& qc_thread_init(QC_INIT_BOTH))
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL))
{
rc = EXIT_SUCCESS;
@ -451,8 +449,7 @@ int main(int argc, char* argv[])
cout << endl;
}
qc_thread_end(QC_INIT_BOTH);
qc_process_end(QC_INIT_BOTH);
qc_end();
}
else
{

View File

@ -397,15 +397,12 @@ int main()
pConfig->n_threads = 1;
set_libdir(MXS_STRDUP_A("../../../../../query_classifier/qc_sqlite/"));
if (qc_setup(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", "")
&& qc_process_init(QC_INIT_BOTH)
&& qc_thread_init(QC_INIT_BOTH))
if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", ""))
{
set_libdir(MXS_STRDUP_A("../"));
rc = test();
qc_thread_end(QC_INIT_BOTH);
qc_process_end(QC_INIT_BOTH);
qc_end();
}
else
{

View File

@ -112,8 +112,7 @@ int main(int argc, char **argv)
set_libdir(MXS_STRDUP_A("../../../../../query_classifier/qc_sqlite/"));
load_module("qc_sqlite", MODULE_QUERY_CLASSIFIER);
qc_setup(NULL, QC_SQL_MODE_DEFAULT, NULL, NULL);
qc_process_init(QC_INIT_BOTH);
qc_init(NULL, QC_SQL_MODE_DEFAULT, NULL, NULL);
hkinit();
CONFIG_CONTEXT ctx{(char*)""};