Debian Codegraph @

src/main/c/jni/org_jpy_DL.c

raw symbols SCIP
1 /*
2 * Copyright 2015 Brockmann Consult GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "org_jpy_DL.h"
18
19 #if !defined(_WIN32) && !defined(__CYGWIN__)
20
21 #include <dlfcn.h>
22
23 /*
24 * Class: org_jpy_DL
25 * Method: dlopen
26 * Signature: (Ljava/lang/String;I)J
27 */
28 JNIEXPORT jlong JNICALL Java_org_jpy_DL_dlopen
29 (JNIEnv *jenv, jclass dlClass, jstring jPath, jint mode)
30 {
31 const char* path;
32 int flags;
33
34 if (jPath == NULL) {
35 return 0;
36 }
37
38 path = (*jenv)->GetStringUTFChars(jenv, jPath, NULL);
39 if (path == NULL) {
40 return 0;
41 }
42
43 flags = 0;
44 if ((mode & org_jpy_DL_RTLD_LAZY) != 0) {
45 flags |= RTLD_LAZY;
46 }
47 if ((mode & org_jpy_DL_RTLD_NOW) != 0) {
48 flags |= RTLD_NOW;
49 }
50 if ((mode & org_jpy_DL_RTLD_LOCAL) != 0) {
51 flags |= RTLD_LOCAL;
52 }
53 if ((mode & org_jpy_DL_RTLD_GLOBAL) != 0) {
54 flags |= RTLD_GLOBAL;
55 }
56
57 return (jlong) dlopen(path, flags);
58 }
59
60 /*
61 * Class: org_jpy_DL
62 * Method: dlclose
63 * Signature: (J)I
64 */
65 JNIEXPORT jint JNICALL Java_org_jpy_DL_dlclose
66 (JNIEnv *jenv, jclass dlClass, jlong handle)
67 {
68 return dlclose((void*) handle);
69 }
70
71 /*
72 * Class: org_jpy_DL
73 * Method: dlerror
74 * Signature: ()Ljava/lang/String;
75 */
76 JNIEXPORT jstring JNICALL Java_org_jpy_DL_dlerror
77 (JNIEnv *jenv, jclass dlClass)
78 {
79 const char* message;
80
81 message = dlerror();
82 if (message != NULL) {
83 return (*jenv)->NewStringUTF(jenv, message);
84 } else {
85 return NULL;
86 }
87 }
88
89 #else /* !defined(_WIN32) && !defined(__CYGWIN__) */
90
91 // Dummy DLL entry point for Python 2.7 (Windows requires it)
92 __declspec(dllexport) void initjdl(void) { }
93
94 // Dummy DLL entry point for Python 3.3+ (Windows requires it)
95 __declspec(dllexport) void* PyInit_jdl(void) { return NULL; }
96
97 /*
98 * Class: org_jpy_DL
99 * Method: dlopen
100 * Signature: (Ljava/lang/String;I)J
101 */
102 JNIEXPORT jlong JNICALL Java_org_jpy_DL_dlopen
103 (JNIEnv *jenv, jclass dlClass, jstring jPath, jint mode)
104 {
105 return 0;
106 }
107
108 /*
109 * Class: org_jpy_DL
110 * Method: dlclose
111 * Signature: (J)I
112 */
113 JNIEXPORT jint JNICALL Java_org_jpy_DL_dlclose
114 (JNIEnv *jenv, jclass dlClass, jlong handle)
115 {
116 return 0;
117 }
118
119 /*
120 * Class: org_jpy_DL
121 * Method: dlerror
122 * Signature: ()Ljava/lang/String;
123 */
124 JNIEXPORT jstring JNICALL Java_org_jpy_DL_dlerror
125 (JNIEnv *jenv, jclass dlClass)
126 {
127 return NULL;
128 }
129
130 #endif /* !defined(_WIN32) && !defined(__CYGWIN__) */
131