C:/Users/vincent/Data/Perso/dev/ocilib/ocilib/src/memory.c

00001 /*
00002    +----------------------------------------------------------------------+   
00003    |                                                                      |
00004    |                     OCILIB - C Driver for Oracle                     |
00005    |                                                                      |
00006    |                      (C Wrapper for Oracle OCI)                      |
00007    |                                                                      |
00008    +----------------------------------------------------------------------+
00009    |                      Website : http://www.ocilib.net                 |
00010    +----------------------------------------------------------------------+
00011    |               Copyright (c) 2007-2009 Vincent ROGIER                 |
00012    +----------------------------------------------------------------------+
00013    | This library is free software; you can redistribute it and/or        |
00014    | modify it under the terms of the GNU Lesser General Public           |
00015    | License as published by the Free Software Foundation; either         |
00016    | version 2 of the License, or (at your option) any later version.     |
00017    |                                                                      |
00018    | This library is distributed in the hope that it will be useful,      |
00019    | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
00020    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
00021    | Lesser General Public License for more details.                      |
00022    |                                                                      |
00023    | You should have received a copy of the GNU Lesser General Public     |
00024    | License along with this library; if not, write to the Free           |
00025    | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   |
00026    +----------------------------------------------------------------------+
00027    |          Author: Vincent ROGIER <vince.rogier@gmail.com>             |
00028    +----------------------------------------------------------------------+ 
00029 */
00030 
00031 /* ------------------------------------------------------------------------ *
00032  * $Id: memory.c, v 3.4.0 2009-07-30 17:40 Vince $
00033  * ------------------------------------------------------------------------ */
00034 
00035 #include "ocilib_internal.h"
00036 
00037 /* ************************************************************************ *
00038  *                             PRIVATE FUNCTIONS
00039  * ************************************************************************ */
00040 
00041 /* ------------------------------------------------------------------------ *
00042  * OCI_MemAlloc
00043  * ------------------------------------------------------------------------ */
00044 
00045 void * OCI_MemAlloc(int ptr_type, int block_size, int block_count, 
00046                     boolean zero_fill)
00047 {
00048     void * ptr  = NULL;
00049     size_t size = (size_t) (block_size * block_count);
00050 
00051     ptr = (void *) malloc(size);
00052      
00053     if (ptr != NULL)                                        
00054     {
00055         if (zero_fill == TRUE)
00056             memset(ptr, 0, size);
00057     }
00058     else
00059         OCI_ExceptionMemory(ptr_type, size, NULL, NULL);
00060 
00061     return ptr;
00062 }
00063 
00064 /* ------------------------------------------------------------------------ *
00065  * OCI_MemRealloc
00066  * ------------------------------------------------------------------------ */
00067 
00068 void * OCI_MemRealloc(void * ptr_mem, int ptr_type, int block_size, 
00069                       int block_count)
00070 {
00071     void * ptr  = NULL;
00072     size_t size = (size_t) (block_size * block_count);
00073 
00074     ptr = (void *) realloc(ptr_mem, size);
00075      
00076     if (ptr == NULL)
00077     {
00078         OCI_MemFree(ptr_mem);
00079 
00080         OCI_ExceptionMemory(ptr_type, size, NULL, NULL);
00081     }
00082 
00083     return ptr;
00084 }
00085 
00086 /* ------------------------------------------------------------------------ *
00087  * OCI_MemFree
00088  * ------------------------------------------------------------------------ */
00089 
00090 void OCI_MemFree(void * ptr_mem)
00091 {
00092     if (ptr_mem != NULL)
00093         free(ptr_mem);
00094 }
00095 
00096 /* ------------------------------------------------------------------------ *
00097  * OCI_HandleAlloc
00098  * ------------------------------------------------------------------------ */
00099 
00100 sword OCI_HandleAlloc(CONST dvoid *parenth, dvoid **hndlpp, CONST ub4 type,
00101                       CONST size_t xtramem_sz, dvoid **usrmempp)
00102 {     
00103     sword ret = OCI_SUCCESS;
00104 
00105     ret = OCIHandleAlloc(parenth, hndlpp, type, xtramem_sz, usrmempp);
00106 
00107     if (ret == OCI_SUCCESS)
00108     {
00109         OCILib.nb_hndlp++;   
00110     }
00111 
00112     return ret;
00113 }
00114 
00115 /* ------------------------------------------------------------------------ *
00116  * OCI_HandleFree
00117  * ------------------------------------------------------------------------ */
00118 
00119 sword OCI_HandleFree(dvoid *hndlp, CONST ub4 type)
00120 {                
00121     sword ret = OCI_SUCCESS;
00122 
00123     if (hndlp != NULL)
00124     {
00125         OCILib.nb_hndlp--;  
00126 
00127         ret = OCIHandleFree(hndlp, type);
00128     }
00129 
00130     return ret;
00131 }
00132 
00133 /* ------------------------------------------------------------------------ *
00134  * OCI_DescriptorAlloc
00135  * ------------------------------------------------------------------------ */
00136 
00137 sword OCI_DescriptorAlloc(CONST dvoid *parenth, dvoid **descpp, CONST ub4 type,
00138                           CONST size_t xtramem_sz,  dvoid **usrmempp)
00139 {
00140     sword ret = OCI_SUCCESS;
00141 
00142     ret = OCIDescriptorAlloc(parenth, descpp, type, xtramem_sz, usrmempp);
00143 
00144     if (ret == OCI_SUCCESS)
00145     {
00146         OCILib.nb_descp++;   
00147     }
00148 
00149     return ret;
00150 }
00151 
00152 /* ------------------------------------------------------------------------ *
00153  * OCI_DescriptorFree
00154  * ------------------------------------------------------------------------ */
00155 
00156 sword OCI_DescriptorFree(dvoid *descp, CONST ub4 type)
00157 {                                                    
00158     sword ret = OCI_SUCCESS;
00159 
00160     if (descp != NULL)
00161     {
00162         OCILib.nb_descp--;  
00163 
00164         ret = OCIDescriptorFree(descp, type);
00165     }
00166 
00167     return ret;
00168 }
00169 
00170 /* ------------------------------------------------------------------------ *
00171  * OCI_fob
00172  * ------------------------------------------------------------------------ */
00173 
00174 sword OCI_ObjectNew(OCIEnv *env, OCIError *err, CONST OCISvcCtx *svc,
00175                     OCITypeCode typecode, OCIType *tdo, dvoid *table, 
00176                     OCIDuration duration, boolean value, 
00177                     dvoid **instance)
00178 {
00179     sword ret = OCI_SUCCESS;
00180 
00181     ret = OCIObjectNew(env, err, svc, typecode, tdo, table, duration, value, instance);
00182 
00183     if (ret == OCI_SUCCESS)
00184     {
00185         OCILib.nb_objinst++;  
00186     }
00187 
00188     return ret;
00189 }
00190 
00191 /* ------------------------------------------------------------------------ *
00192  * OCI_OCIObjectFree
00193  * ------------------------------------------------------------------------ */
00194 
00195 sword OCI_OCIObjectFree(OCIEnv *env, OCIError *err, dvoid *instance, ub2 flags)
00196 {
00197     sword ret = OCI_SUCCESS;
00198 
00199     if (instance != NULL)
00200     {
00201         OCILib.nb_objinst--;  
00202 
00203         ret = OCIObjectFree(env, err, instance, flags);
00204     }
00205 
00206     return ret;
00207 }
00208 
00209 

Generated on Thu Jul 30 17:41:52 2009 for OCILIB (C Driver for Oracle) by  doxygen 1.5.4