OCILIB (C Driver for Oracle) 3.12.1
|
00001 /* 00002 +-----------------------------------------------------------------------------------------+ 00003 | | 00004 | OCILIB - C Driver for Oracle | 00005 | | 00006 | (C Wrapper for Oracle OCI) | 00007 | | 00008 | Website : http://www.ocilib.net | 00009 | | 00010 | Copyright (c) 2007-2013 Vincent ROGIER <vince.rogier@ocilib.net> | 00011 | | 00012 +-----------------------------------------------------------------------------------------+ 00013 | | 00014 | This library is free software; you can redistribute it and/or | 00015 | modify it under the terms of the GNU Lesser General Public | 00016 | License as published by the Free Software Foundation; either | 00017 | version 2 of the License, or (at your option) any later version. | 00018 | | 00019 | This library is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 00022 | Lesser General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU Lesser General Public | 00025 | License along with this library; if not, write to the Free | 00026 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 00027 | | 00028 +-----------------------------------------------------------------------------------------+ 00029 */ 00030 00031 /* --------------------------------------------------------------------------------------------- * 00032 * $Id: memory.c, Vincent Rogier $ 00033 * --------------------------------------------------------------------------------------------- */ 00034 00035 #include "ocilib_internal.h" 00036 00037 /* ********************************************************************************************* * 00038 * PRIVATE FUNCTIONS 00039 * ********************************************************************************************* */ 00040 00041 /* --------------------------------------------------------------------------------------------- * 00042 * OCI_MemAlloc 00043 * --------------------------------------------------------------------------------------------- */ 00044 00045 void * OCI_MemAlloc 00046 ( 00047 int ptr_type, 00048 size_t block_size, 00049 size_t block_count, 00050 boolean zero_fill 00051 ) 00052 { 00053 void * ptr = NULL; 00054 size_t size = (size_t) (block_size * block_count); 00055 00056 ptr = (void *) malloc(size); 00057 00058 if (ptr != NULL) 00059 { 00060 if (zero_fill == TRUE) 00061 { 00062 memset(ptr, 0, size); 00063 } 00064 } 00065 else 00066 { 00067 OCI_ExceptionMemory(ptr_type, size, NULL, NULL); 00068 } 00069 00070 return ptr; 00071 } 00072 00073 /* --------------------------------------------------------------------------------------------- * 00074 * OCI_MemRealloc 00075 * --------------------------------------------------------------------------------------------- */ 00076 00077 void * OCI_MemRealloc 00078 ( 00079 void * ptr_mem, 00080 int ptr_type, 00081 size_t block_size, 00082 size_t block_count 00083 ) 00084 { 00085 size_t size = (size_t) (block_size * block_count); 00086 void * ptr = (void *) realloc(ptr_mem, size); 00087 00088 if (ptr == NULL && ptr_mem != NULL) 00089 { 00090 OCI_MemFree(ptr_mem); 00091 00092 OCI_ExceptionMemory(ptr_type, size, NULL, NULL); 00093 } 00094 00095 return ptr; 00096 } 00097 00098 /* --------------------------------------------------------------------------------------------- * 00099 * OCI_MemFree 00100 * --------------------------------------------------------------------------------------------- */ 00101 00102 void OCI_MemFree 00103 ( 00104 void * ptr_mem 00105 ) 00106 { 00107 if (ptr_mem != NULL) 00108 { 00109 free(ptr_mem); 00110 } 00111 } 00112 00113 /* --------------------------------------------------------------------------------------------- * 00114 * OCI_HandleAlloc 00115 * --------------------------------------------------------------------------------------------- */ 00116 00117 sword OCI_HandleAlloc 00118 ( 00119 CONST dvoid *parenth, 00120 dvoid **hndlpp, 00121 CONST ub4 type, 00122 CONST size_t xtramem_sz, 00123 dvoid **usrmempp 00124 ) 00125 { 00126 sword ret = OCIHandleAlloc(parenth, hndlpp, type, xtramem_sz, usrmempp); 00127 00128 if (ret == OCI_SUCCESS) 00129 { 00130 OCILib.nb_hndlp++; 00131 } 00132 00133 return ret; 00134 } 00135 00136 /* --------------------------------------------------------------------------------------------- * 00137 * OCI_HandleFree 00138 * --------------------------------------------------------------------------------------------- */ 00139 00140 sword OCI_HandleFree 00141 ( 00142 dvoid *hndlp, 00143 CONST ub4 type 00144 ) 00145 { 00146 sword ret = OCI_SUCCESS; 00147 00148 if (hndlp != NULL) 00149 { 00150 OCILib.nb_hndlp--; 00151 00152 ret = OCIHandleFree(hndlp, type); 00153 } 00154 00155 return ret; 00156 } 00157 00158 /* --------------------------------------------------------------------------------------------- * 00159 * OCI_DescriptorAlloc 00160 * --------------------------------------------------------------------------------------------- */ 00161 00162 sword OCI_DescriptorAlloc 00163 ( 00164 CONST dvoid *parenth, 00165 dvoid **descpp, 00166 CONST ub4 type, 00167 CONST size_t xtramem_sz, 00168 dvoid **usrmempp 00169 ) 00170 { 00171 sword ret = OCIDescriptorAlloc(parenth, descpp, type, xtramem_sz, usrmempp); 00172 00173 if (ret == OCI_SUCCESS) 00174 { 00175 OCILib.nb_descp++; 00176 } 00177 00178 return ret; 00179 } 00180 00181 /* --------------------------------------------------------------------------------------------- * 00182 * OCI_DescriptorArrayAlloc 00183 * --------------------------------------------------------------------------------------------- */ 00184 00185 sword OCI_DescriptorArrayAlloc 00186 ( 00187 CONST dvoid *parenth, 00188 dvoid **descpp, 00189 CONST ub4 type, 00190 ub4 nb_elem, 00191 CONST size_t xtramem_sz, 00192 dvoid **usrmempp 00193 ) 00194 { 00195 sword ret = OCI_SUCCESS; 00196 00197 #if OCI_VERSION_COMPILE >= OCI_11_1 00198 00199 if (OCILib.version_runtime >= OCI_11_1) 00200 { 00201 ret = OCIArrayDescriptorAlloc(parenth, descpp, type, nb_elem, xtramem_sz, usrmempp); 00202 00203 } 00204 else 00205 00206 #endif 00207 00208 { 00209 ub4 i; 00210 00211 for(i = 0; (i < nb_elem) && (ret == OCI_SUCCESS); i++) 00212 { 00213 ret = OCIDescriptorAlloc(parenth, &descpp[i], type, xtramem_sz, usrmempp); 00214 } 00215 } 00216 00217 if (ret == OCI_SUCCESS) 00218 { 00219 OCILib.nb_descp += nb_elem; 00220 } 00221 00222 return ret; 00223 } 00224 00225 /* --------------------------------------------------------------------------------------------- * 00226 * OCI_DescriptorFree 00227 * --------------------------------------------------------------------------------------------- */ 00228 00229 sword OCI_DescriptorFree 00230 ( 00231 dvoid *descp, 00232 CONST ub4 type 00233 ) 00234 { 00235 sword ret = OCI_SUCCESS; 00236 00237 if (descp != NULL) 00238 { 00239 OCILib.nb_descp--; 00240 00241 ret = OCIDescriptorFree(descp, type); 00242 } 00243 00244 return ret; 00245 } 00246 00247 /* --------------------------------------------------------------------------------------------- * 00248 * OCI_DescriptorFree 00249 * --------------------------------------------------------------------------------------------- */ 00250 00251 sword OCI_DescriptorArrayFree 00252 ( 00253 dvoid **descp, 00254 CONST ub4 type, 00255 ub4 nb_elem 00256 ) 00257 { 00258 sword ret = OCI_SUCCESS; 00259 00260 if (descp != NULL) 00261 { 00262 00263 #if OCI_VERSION_COMPILE >= OCI_11_1 00264 00265 if (OCILib.version_runtime >= OCI_11_1) 00266 { 00267 ret = OCIArrayDescriptorFree(descp, type); 00268 00269 } 00270 else 00271 00272 #endif 00273 00274 { 00275 ub4 i; 00276 00277 for(i = 0; (i < nb_elem) && (ret == OCI_SUCCESS); i++) 00278 { 00279 ret = OCIDescriptorFree(descp[i], type); 00280 } 00281 } 00282 00283 OCILib.nb_descp -= nb_elem; 00284 } 00285 00286 return ret; 00287 } 00288 00289 /* --------------------------------------------------------------------------------------------- * 00290 * OCI_ObjectNew 00291 * --------------------------------------------------------------------------------------------- */ 00292 00293 sword OCI_ObjectNew 00294 ( 00295 OCIEnv *env, 00296 OCIError *err, 00297 CONST OCISvcCtx *svc, 00298 OCITypeCode typecode, 00299 OCIType *tdo, 00300 dvoid *table, 00301 OCIDuration duration, 00302 boolean value, 00303 dvoid **instance 00304 ) 00305 { 00306 sword ret = OCIObjectNew(env, err, svc, typecode, tdo, table, duration, value, instance); 00307 00308 if (ret == OCI_SUCCESS) 00309 { 00310 OCILib.nb_objinst++; 00311 } 00312 00313 return ret; 00314 } 00315 00316 /* --------------------------------------------------------------------------------------------- * 00317 * OCI_OCIObjectFree 00318 * --------------------------------------------------------------------------------------------- */ 00319 00320 sword OCI_OCIObjectFree 00321 ( 00322 OCIEnv *env, 00323 OCIError *err, 00324 dvoid *instance, 00325 ub2 flags 00326 ) 00327 { 00328 sword ret = OCI_SUCCESS; 00329 00330 if (instance != NULL) 00331 { 00332 OCILib.nb_objinst--; 00333 00334 ret = OCIObjectFree(env, err, instance, flags); 00335 } 00336 00337 return ret; 00338 } 00339