<commit_before>/* JIGSNative.h - Entering and Exiting native method implementations
   Copyright (C) 2000 Free Software Foundation, Inc.
   
   Written by:  <NAME> <<EMAIL>>
   Date: June 2000
   
   This file is part of the GNUstep Java Interface Library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
   
   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
   */ 

#ifndef __JIGSNative_h_GNUSTEP_JAVA_INCLUDE
#define __JIGSNative_h_GNUSTEP_JAVA_INCLUDE

#include <jni.h>
#include <Foundation/Foundation.h>
#include "GSJNI.h"

/*
 * Clean things upon entering and exiting a native implementation 
 * of a java method.
 *
 * Always begin *any* Java Interface native call with 
 * 
 * JIGS_ENTER;
 * 
 * (just after declaration of variables and *before* any objc code is
 * actually used)
 *
 * and finish it with 
 *
 * JIGS_EXIT;
 *
 * (just before the return statement)
 *
 * or 
 *
 * JIGS_EXIT_WITH_VALUE (ret_value);
 *
 * Important: `ret_value' must be a simple variable whose value was
 * computed inside the JIGS_ENTER/JIGS_EXIT_WITH_VALUE tags, not an
 * expression or a function call.
 * 
 * And (important) you need to call the JNIEnv * argument of your
 * native call 'env'.  
 */

#define JIGS_ENTER                                   \
BOOL registeredThread = [NSThread registerCurrentThread]; \
NSAutoreleasePool *pool = [NSAutoreleasePool new];   \
NS_DURING

#define JIGS_EXIT                                            \
NS_HANDLER                                                   \
JIGSRaiseJExceptionFromNSException (env, localException);    \
NS_ENDHANDLER                                                \
RELEASE (pool);                                              \
if (registeredThread) [NSThread unregisterCurrentThread];

#define JIGS_EXIT_WITH_VALUE(ret_value)                      \
NS_HANDLER                                                   \
JIGSRaiseJExceptionFromNSException (env, localException);    \
ret_value = 0;                                               \
NS_ENDHANDLER                                                \
RELEASE (pool);                                              \
if (registeredThread) [NSThread unregisterCurrentThread];    \
return (ret_value);
     <commit_msg>New macros to make loading libraries thread safe<commit_after>/* JIGSNative.h - Entering and Exiting native method implementations
   Copyright (C) 2000 Free Software Foundation, Inc.
   
   Written by:  <NAME> <<EMAIL>>
   Date: June 2000
   
   This file is part of the GNUstep Java Interface Library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
   
   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
   */ 

#ifndef __JIGSNative_h_GNUSTEP_JAVA_INCLUDE
#define __JIGSNative_h_GNUSTEP_JAVA_INCLUDE

#include <jni.h>
#include <Foundation/Foundation.h>
#include "GSJNI.h"

/*
 * Clean things upon entering and exiting a native implementation 
 * of a java method.
 *
 * Always begin *any* Java Interface native call with 
 * 
 * JIGS_ENTER;
 * 
 * (just after declaration of variables and *before* any objc code is
 * actually used)
 *
 * and finish it with 
 *
 * JIGS_EXIT;
 *
 * (just before the return statement)
 *
 * or 
 *
 * JIGS_EXIT_WITH_VALUE (ret_value);
 *
 * Important: `ret_value' must be a simple variable whose value was
 * computed inside the JIGS_ENTER/JIGS_EXIT_WITH_VALUE tags, not an
 * expression or a function call.
 * 
 * And (important) you need to call the JNIEnv * argument of your
 * native call 'env'.  
 */

#define JIGS_ENTER                                   \
BOOL registeredThread = [NSThread registerCurrentThread]; \
NSAutoreleasePool *pool = [NSAutoreleasePool new];   \
NS_DURING

#define JIGS_EXIT                                            \
NS_HANDLER                                                   \
JIGSRaiseJExceptionFromNSException (env, localException);    \
NS_ENDHANDLER                                                \
RELEASE (pool);                                              \
if (registeredThread) [NSThread unregisterCurrentThread];

#define JIGS_EXIT_WITH_VALUE(ret_value)                      \
NS_HANDLER                                                   \
JIGSRaiseJExceptionFromNSException (env, localException);    \
ret_value = 0;                                               \
NS_ENDHANDLER                                                \
RELEASE (pool);                                              \
if (registeredThread) [NSThread unregisterCurrentThread];    \
return (ret_value);


/*
 * Use the following when entering the JNI_OnLoad function of 
 * a library (where usually the classes and selectors of the library 
 * are registered).  It is particularly important because JNI_OnLoad  
 * might be called from an arbitrary Java thread.
 *
 */
#define JIGS_ONLOAD_ENTER                                 \
BOOL registeredThread = [NSThread registerCurrentThread]; \
NSAutoreleasePool *pool = [NSAutoreleasePool new];        

#define JIGS_ONLOAD_EXIT                                     \
RELEASE (pool);                                              \
if (registeredThread) [NSThread unregisterCurrentThread];    \
return JNI_VERSION_1_2;
{'fraction_non_alphanumeric': 0.05931938807368092, 'fraction_numerical': 0.006556353418669997, 'mean_word_length': 2.1026634382566587, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 37, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2313747', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1622, 'n_words': 629}