| OLD | NEW |
| (Empty) |
| 1 /* Licensed to the Apache Software Foundation (ASF) under one or more | |
| 2 * contributor license agreements. See the NOTICE file distributed with | |
| 3 * this work for additional information regarding copyright ownership. | |
| 4 * The ASF licenses this file to You under the Apache License, Version 2.0 | |
| 5 * (the "License"); you may not use this file except in compliance with | |
| 6 * the License. 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 /* | |
| 18 * | |
| 19 * @author Mladen Turk | |
| 20 * @version $Id: stdlib.c 1442587 2013-02-05 13:49:48Z rjung $ | |
| 21 */ | |
| 22 | |
| 23 #include "tcn.h" | |
| 24 | |
| 25 extern int tcn_parent_pid; | |
| 26 | |
| 27 TCN_IMPLEMENT_CALL(jlong, Stdlib, malloc)(TCN_STDARGS, jint size) | |
| 28 { | |
| 29 UNREFERENCED_STDARGS; | |
| 30 if (size) | |
| 31 return P2J(malloc((size_t)size)); | |
| 32 else | |
| 33 return 0; | |
| 34 } | |
| 35 | |
| 36 TCN_IMPLEMENT_CALL(jlong, Stdlib, realloc)(TCN_STDARGS, jlong mem, jint size) | |
| 37 { | |
| 38 void *ptr = J2P(mem, void *); | |
| 39 UNREFERENCED_STDARGS; | |
| 40 if (size) | |
| 41 return P2J(realloc(ptr, (size_t)size)); | |
| 42 else | |
| 43 return 0; | |
| 44 } | |
| 45 | |
| 46 TCN_IMPLEMENT_CALL(jlong, Stdlib, calloc)(TCN_STDARGS, jint num, jint size) | |
| 47 { | |
| 48 UNREFERENCED_STDARGS; | |
| 49 if (num && size) | |
| 50 return P2J(calloc((size_t)num, (size_t)size)); | |
| 51 else | |
| 52 return 0; | |
| 53 } | |
| 54 | |
| 55 TCN_IMPLEMENT_CALL(void, Stdlib, free)(TCN_STDARGS, jlong mem) | |
| 56 { | |
| 57 void *ptr = J2P(mem, void *); | |
| 58 | |
| 59 UNREFERENCED_STDARGS; | |
| 60 if (ptr) | |
| 61 free(ptr); | |
| 62 } | |
| 63 | |
| 64 TCN_IMPLEMENT_CALL(jboolean, Stdlib, memread)(TCN_STDARGS, | |
| 65 jbyteArray dst, | |
| 66 jlong src, jint sz) | |
| 67 { | |
| 68 jbyte *s = J2P(src, jbyte *); | |
| 69 jbyte *dest = (*e)->GetPrimitiveArrayCritical(e, dst, NULL); | |
| 70 | |
| 71 UNREFERENCED(o); | |
| 72 if (s && dest) { | |
| 73 memcpy(dest, s, (size_t)sz); | |
| 74 (*e)->ReleasePrimitiveArrayCritical(e, dst, dest, 0); | |
| 75 return JNI_TRUE; | |
| 76 } | |
| 77 else | |
| 78 return JNI_FALSE; | |
| 79 } | |
| 80 | |
| 81 TCN_IMPLEMENT_CALL(jboolean, Stdlib, memwrite)(TCN_STDARGS, jlong dst, | |
| 82 jbyteArray src, jint sz) | |
| 83 { | |
| 84 jbyte *dest = J2P(dst, jbyte *); | |
| 85 jbyte *s = (*e)->GetPrimitiveArrayCritical(e, src, NULL); | |
| 86 | |
| 87 UNREFERENCED(o); | |
| 88 if (s && dest) { | |
| 89 memcpy(dest, s, (size_t)sz); | |
| 90 (*e)->ReleasePrimitiveArrayCritical(e, src, s, JNI_ABORT); | |
| 91 return JNI_TRUE; | |
| 92 } | |
| 93 else | |
| 94 return JNI_FALSE; | |
| 95 } | |
| 96 | |
| 97 TCN_IMPLEMENT_CALL(jboolean, Stdlib, memset)(TCN_STDARGS, jlong dst, | |
| 98 jint c, jint sz) | |
| 99 { | |
| 100 jbyte *dest = J2P(dst, jbyte *); | |
| 101 | |
| 102 UNREFERENCED_STDARGS; | |
| 103 if (memset(dest, (int)c, (size_t)sz)) | |
| 104 return JNI_TRUE; | |
| 105 else | |
| 106 return JNI_FALSE; | |
| 107 } | |
| 108 | |
| 109 TCN_IMPLEMENT_CALL(jint, Stdlib, getpid)(TCN_STDARGS) | |
| 110 { | |
| 111 UNREFERENCED_STDARGS; | |
| 112 return (jint)getpid(); | |
| 113 } | |
| 114 | |
| 115 TCN_IMPLEMENT_CALL(jint, Stdlib, getppid)(TCN_STDARGS) | |
| 116 { | |
| 117 UNREFERENCED_STDARGS; | |
| 118 return (jint)tcn_parent_pid; | |
| 119 } | |
| 120 | |
| OLD | NEW |