~james-page/ubuntu/oneiric/jcc/fix-library-linking

« back to all changes in this revision

Viewing changes to jcc/sources/JCCEnv.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ludovico Cavedon
  • Date: 2011-07-07 22:03:05 UTC
  • mfrom: (3.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110707220305-44qgdatqsoieybog
Tags: 2.9-1
* New upstream release.
* Update Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
                            "shortValue", "()S");
161
161
}
162
162
 
 
163
int JCCEnv::attachCurrentThread(char *name, int asDaemon)
 
164
{
 
165
    JNIEnv *jenv = NULL;
 
166
    JavaVMAttachArgs attach = {
 
167
        JNI_VERSION_1_4, name, NULL
 
168
    };
 
169
    int result;
 
170
 
 
171
    if (asDaemon)
 
172
        result = vm->AttachCurrentThreadAsDaemon((void **) &jenv, &attach);
 
173
    else
 
174
        result = vm->AttachCurrentThread((void **) &jenv, &attach);
 
175
 
 
176
    set_vm_env(jenv);
 
177
 
 
178
    return result;
 
179
}
 
180
 
163
181
#if defined(_MSC_VER) || defined(__WIN32)
164
182
 
165
183
void JCCEnv::set_vm_env(JNIEnv *vm_env)
318
336
                {
319
337
                    if (iter->second.count == 1)
320
338
                    {
321
 
                        get_vm_env()->DeleteGlobalRef(iter->second.global);
 
339
                        JNIEnv *vm_env = get_vm_env();
 
340
 
 
341
                        if (!vm_env)
 
342
                        {
 
343
                            /* Python's cyclic garbage collector may remove
 
344
                             * an object inside a thread that is not attached
 
345
                             * to the JVM. This makes sure the JVM doesn't
 
346
                             * segfault.
 
347
                             */
 
348
                            attachCurrentThread(NULL, 0);
 
349
                            vm_env = get_vm_env();
 
350
                        }
 
351
 
 
352
                        vm_env->DeleteGlobalRef(iter->second.global);
322
353
                        refs.erase(iter);
323
354
                    }
324
355
                    else