Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/bindings/javahl/native/JNIUtil.cpp view on Meta::CPAN
/**
* @copyright
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
* @endcopyright
*
* @file JNIUtil.cpp
* @brief Implementation of the class JNIUtil
*/
#include "JNIUtil.h"
#include "Array.h"
#include <sstream>
#include <vector>
#include <locale.h>
#include <apr_strings.h>
#include <apr_tables.h>
#include <apr_general.h>
#include <apr_lib.h>
#include "svn_pools.h"
#include "svn_fs.h"
#include "svn_ra.h"
#include "svn_utf.h"
#include "svn_wc.h"
#include "svn_dso.h"
#include "svn_path.h"
#include "svn_cache_config.h"
#include <apr_file_info.h>
#include "svn_private_config.h"
#ifdef WIN32
/* FIXME: We're using an internal APR header here, which means we
have to build Subversion with APR sources. This being Win32-only,
that should be fine for now, but a better solution must be found in
combination with issue #850. */
extern "C" {
#include <arch/win32/apr_arch_utf8.h>
};
#endif
#include "SVNBase.h"
#include "JNIMutex.h"
#include "JNICriticalSection.h"
#include "JNIThreadData.h"
#include "JNIStringHolder.h"
#include "Pool.h"
// Static members of JNIUtil are allocated here.
apr_pool_t *JNIUtil::g_pool = NULL;
std::list<SVNBase*> JNIUtil::g_finalizedObjects;
JNIMutex *JNIUtil::g_finalizedObjectsMutex = NULL;
JNIMutex *JNIUtil::g_logMutex = NULL;
bool JNIUtil::g_initException;
bool JNIUtil::g_inInit;
JNIEnv *JNIUtil::g_initEnv;
char JNIUtil::g_initFormatBuffer[formatBufferSize];
int JNIUtil::g_logLevel = JNIUtil::noLog;
std::ofstream JNIUtil::g_logStream;
/**
* Initialize the environment for all requests.
* @param env the JNI environment for this request
*/
bool JNIUtil::JNIInit(JNIEnv *env)
{
// Clear all standing exceptions.
env->ExceptionClear();
// Remember the env parameter for the remainder of the request.
setEnv(env);
// Lock the list of finalized objects.
JNICriticalSection cs(*g_finalizedObjectsMutex) ;
if (isExceptionThrown())
src/subversion/subversion/bindings/javahl/native/JNIUtil.cpp view on Meta::CPAN
return FALSE;
}
/* This has to happen before any pools are created. */
if ((err = svn_dso_initialize2()))
{
if (stderr && err->message)
fprintf(stderr, "%s", err->message);
svn_error_clear(err);
return FALSE;
}
if (0 > atexit(apr_terminate))
{
if (stderr)
fprintf(stderr,
"%s: error: atexit registration failed\n",
"svnjavahl");
return FALSE;
}
/* Create our top-level pool. */
g_pool = svn_pool_create(NULL);
apr_allocator_t* allocator = apr_pool_allocator_get(g_pool);
if (allocator)
{
/* Keep a maximum of 1 free block, to release memory back to the JVM
(and other modules). */
apr_allocator_max_free_set(allocator, 1);
}
svn_utf_initialize2(FALSE, g_pool); /* Optimize character conversions */
svn_fs_initialize(g_pool); /* Avoid some theoretical issues */
svn_ra_initialize(g_pool);
/* We shouldn't fill the JVMs memory with FS cache data unless explictly
requested. */
{
svn_cache_config_t settings = *svn_cache_config_get();
settings.cache_size = 0;
settings.file_handle_count = 0;
settings.single_threaded = FALSE;
svn_cache_config_set(&settings);
}
#ifdef ENABLE_NLS
#ifdef WIN32
{
WCHAR ucs2_path[MAX_PATH];
char *utf8_path;
const char *internal_path;
apr_pool_t *pool;
apr_status_t apr_err;
apr_size_t inwords, outbytes;
unsigned int outlength;
pool = svn_pool_create(g_pool);
/* get dll name - our locale info will be in '../share/locale' */
inwords = sizeof(ucs2_path) / sizeof(ucs2_path[0]);
HINSTANCE moduleHandle = GetModuleHandle("libsvnjavahl-1");
GetModuleFileNameW(moduleHandle, ucs2_path, inwords);
inwords = lstrlenW(ucs2_path);
outbytes = outlength = 3 * (inwords + 1);
utf8_path = reinterpret_cast<char *>(apr_palloc(pool, outlength));
apr_err = apr_conv_ucs2_to_utf8((const apr_wchar_t *) ucs2_path,
&inwords, utf8_path, &outbytes);
if (!apr_err && (inwords > 0 || outbytes == 0))
apr_err = APR_INCOMPLETE;
if (apr_err)
{
if (stderr)
fprintf(stderr, "Can't convert module path to UTF-8");
return FALSE;
}
utf8_path[outlength - outbytes] = '\0';
internal_path = svn_dirent_internal_style(utf8_path, pool);
/* get base path name */
internal_path = svn_dirent_dirname(internal_path, pool);
internal_path = svn_dirent_join(internal_path, SVN_LOCALE_RELATIVE_PATH,
pool);
bindtextdomain(PACKAGE_NAME, internal_path);
svn_pool_destroy(pool);
}
#else
bindtextdomain(PACKAGE_NAME, SVN_LOCALE_DIR);
#endif
#endif
#if defined(WIN32) || defined(__CYGWIN__)
/* See http://svn.apache.org/repos/asf/subversion/trunk/notes/asp-dot-net-hack.txt */
/* ### This code really only needs to be invoked by consumers of
### the libsvn_wc library, which basically means SVNClient. */
if (getenv("SVN_ASP_DOT_NET_HACK"))
{
err = svn_wc_set_adm_dir("_svn", g_pool);
if (err)
{
if (stderr)
{
fprintf(stderr,
"%s: error: SVN_ASP_DOT_NET_HACK failed: %s\n",
"svnjavahl", err->message);
}
svn_error_clear(err);
return FALSE;
}
}
#endif
svn_error_set_malfunction_handler(svn_error_raise_on_malfunction);
// Build all mutexes.
g_finalizedObjectsMutex = new JNIMutex(g_pool);
if (isExceptionThrown())
return false;
g_logMutex = new JNIMutex(g_pool);
if (isExceptionThrown())
( run in 0.662 second using v1.01-cache-2.11-cpan-ceb78f64989 )