Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/bindings/javahl/native/JNIUtil.cpp view on Meta::CPAN
"%s: error: cannot initialize APR: %s\n",
"svnjavahl", buf);
}
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())
return false;
// initialized the thread local storage
if (!JNIThreadData::initThreadData())
return false;
setEnv(env);
if (isExceptionThrown())
return false;
g_initEnv = NULL;
g_inInit = false;
return true;
}
/**
* Returns the global (not request specific) pool.
src/subversion/subversion/bindings/javahl/native/JNIUtil.cpp view on Meta::CPAN
if (data == NULL) // if that does not exists -> use the global buffer
return g_initFormatBuffer;
return data->m_formatBuffer;
}
/**
* Returns the current log level.
* @return the log level
*/
int JNIUtil::getLogLevel()
{
return g_logLevel;
}
/**
* Write a message to the log file if needed.
* @param the log message
*/
void JNIUtil::logMessage(const char *message)
{
// lock the log file
JNICriticalSection cs(*g_logMutex);
g_logStream << message << std::endl;
}
/**
* Create a java.util.Date object from an apr time.
* @param time the apr time
* @return the java.util.Date. This is a local reference. Delete as
* soon as possible
*/
jobject JNIUtil::createDate(apr_time_t time)
{
jlong javatime = time /1000;
JNIEnv *env = getEnv();
jclass clazz = env->FindClass("java/util/Date");
if (isJavaExceptionThrown())
return NULL;
static jmethodID mid = 0;
if (mid == 0)
{
mid = env->GetMethodID(clazz, "<init>", "(J)V");
if (isJavaExceptionThrown())
return NULL;
}
jobject ret = env->NewObject(clazz, mid, javatime);
if (isJavaExceptionThrown())
return NULL;
env->DeleteLocalRef(clazz);
return ret;
}
/**
* Create a Java byte array from an array of characters.
* @param data the character array
* @param length the number of characters in the array
*/
jbyteArray JNIUtil::makeJByteArray(const void *data, int length)
{
if (data == NULL)
{
// a NULL will create no Java array
return NULL;
}
JNIEnv *env = getEnv();
// Allocate the Java array.
jbyteArray ret = env->NewByteArray(length);
if (isJavaExceptionThrown() || ret == NULL)
return NULL;
// Access the bytes.
jbyte *retdata = env->GetByteArrayElements(ret, NULL);
if (isJavaExceptionThrown())
return NULL;
// Copy the bytes.
memcpy(retdata, data, length);
// Release the bytes.
env->ReleaseByteArrayElements(ret, retdata, 0);
if (isJavaExceptionThrown())
return NULL;
return ret;
}
/**
* Create a Java byte array from an svn_string_t.
* @param str the string
*/
jbyteArray JNIUtil::makeJByteArray(const svn_string_t *str)
{
return JNIUtil::makeJByteArray(str->data, static_cast<int>(str->len));
}
/**
* Build the error message from the svn error into buffer. This
* method calls itselft recursively for all the chained errors
*
* @param err the subversion error
* @param depth the depth of the call, used for formating
* @param parent_apr_err the apr of the previous level, used for formating
* @param buffer the buffer where the formated error message will
* be stored
*/
void JNIUtil::assembleErrorMessage(svn_error_t *err, int depth,
apr_status_t parent_apr_err,
std::string &buffer)
{
// buffer for a single error message
char errbuf[256];
/* Pretty-print the error */
/* Note: we can also log errors here someday. */
/* When we're recursing, don't repeat the top-level message if its
* the same as before. */
if (depth == 0 || err->apr_err != parent_apr_err)
{
/* Is this a Subversion-specific error code? */
if ((err->apr_err > APR_OS_START_USEERR)
&& (err->apr_err <= APR_OS_START_CANONERR))
buffer.append(svn_strerror(err->apr_err, errbuf, sizeof(errbuf)));
/* Otherwise, this must be an APR error code. */
else
{
/* Messages coming from apr_strerror are in the native
encoding, it's a good idea to convert them to UTF-8. */
const char* utf8_message;
apr_strerror(err->apr_err, errbuf, sizeof(errbuf));
svn_error_t* utf8_err = svn_utf_cstring_to_utf8(
&utf8_message, errbuf, err->pool);
if (utf8_err)
{
/* Use fuzzy transliteration instead. */
svn_error_clear(utf8_err);
utf8_message = svn_utf_cstring_from_utf8_fuzzy(errbuf, err->pool);
( run in 0.396 second using v1.01-cache-2.11-cpan-ceb78f64989 )