Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cqp_get_registry(): Initialization of CQP required #14

Closed
ablaette opened this issue Jun 25, 2020 · 1 comment
Closed

cqp_get_registry(): Initialization of CQP required #14

ablaette opened this issue Jun 25, 2020 · 1 comment

Comments

@ablaette
Copy link
Collaborator

Trying to implement a function in the cwbtools package that performs a testload for a corpus,
I realized some really odd behavior of the cqp_get_registry() function.

The cqp_get_registry() works as expected, if cqp_initialize() has been
called before tbe first call of cqp_get_registry(). Given the two
alternative registry directories used in the following example exist,
the following code works.

library(RcppCWB)
cqp_initialize()
cqp_reset_registry(path.expand("~/cwb2/registry"))
cqp_get_registry()

Sys.setenv(CORPUS_REGISTRY = path.expand("~/Data/cwb/registry"))
cqp_get_registry()

But if cqp_get_registry() is called before cqp_initialize(),
cqp_get_registry() will grab strings from memory in an unexpected and
definitely unintended manner.

library(RcppCWB)
cqp_get_registry() # Problems when called before cqp_initialize
cqp_initialize()
cqp_get_registry()

Looking at the C code of the cl_standard_registry() C function that is
the worker behind the R function cqp_get_registry(), I find it hard
(impossible at this stage) to understand what happens.

cl_standard_registry()
{
  if (regdir == NULL)
    regdir = getenv(REGISTRY_ENVVAR);
  if (regdir == NULL)
    regdir = REGISTRY_DEFAULT_PATH;
  return regdir;
}

A workaround might be to call cqp_initialize() by default upon loading
RcppCWB. But that would be a workaround and I am deeply dissatisfied with, as I do not
yet understand the odd behavior reported.

ablaette added a commit that referenced this issue Jul 15, 2021
@ablaette
Copy link
Collaborator Author

ablaette commented Dec 9, 2021

A new implementation of cqp_get_registry() does not reference the regdir variable which may have been overwritten, but the registry variable. I think this solved the issue.

@ablaette ablaette closed this as completed Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant