[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: sqlite threadsafe

From: Fabian Knittel <fabian.knittel_at_avona.com>
Date: 2007-11-27 15:00:22 CET

Philip Martin schrieb:
> Daniel Rall <dlr@collab.net> writes:
[...]
>> +#if DARWIN
>> + status = apr_dso_load(&dso, "libsqlite3.dylib", pool);
>> +#endif
>> + if (dso == NULL)
>> + status = apr_dso_load(&dso, "libsqlite3.so", pool);
>
> If I understand this correctly you are attempting to dlopen a shared
> library that is already dynamically linked to the executable. My
> first reaction is yuck! That will only work if apr_dso_load uses the
> same search path as the linker, and I seem to recall that people have
> problems running the tests when RA/FS are loaded using apr_dso_load as
> the search path doesn't do what we want, it doesn't include the build
> tree for example.

If I'm not mistaken, Daniel doesn't actually want to load a library at
all. He's trying to determine whether the _currently loaded_ library has
a certain ability / function.

Quoting the man page of dlopen:

  void *dlopen(const char *filename, int flag);

  [...]
  If filename is a NULL pointer, then the returned handle is for the
  main program. When given to dlsym(), this handle causes a search for
  a symbol in the main program, followed by all shared libraries
  loaded at program startup, and then all shared libraries loaded by
  dlopen() with the flag RTLD_GLOBAL.

So something along the lines of

  void *lib_handle = dlopen(NULL, RTLD_LAZY);
  if (lib_handle)
    {
      int (*threadsafe_func)(void) = dlsym(lib_handle,
                                           "sqlite3_threadsafe");
  ...

should work on systems conforming to POSIX.1-2001 (again, according to
the man page).

I have no idea whether apr_dso_load supports that interface though, so
the remaining question is, whether the behaviour is sufficiently portable.

Cheers, Fabian

Received on Tue Nov 27 15:03:49 2007

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.