• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

DjVuGlobalMemory.cpp

Go to the documentation of this file.
00001 //C-  -*- C++ -*-
00002 //C- -------------------------------------------------------------------
00003 //C- DjVuLibre-3.5
00004 //C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
00005 //C- Copyright (c) 2001  AT&T
00006 //C-
00007 //C- This software is subject to, and may be distributed under, the
00008 //C- GNU General Public License, Version 2. The license should have
00009 //C- accompanied the software or you may obtain a copy of the license
00010 //C- from the Free Software Foundation at http://www.fsf.org .
00011 //C-
00012 //C- This program is distributed in the hope that it will be useful,
00013 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //C- GNU General Public License for more details.
00016 //C- 
00017 //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
00018 //C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech 
00019 //C- Software authorized us to replace the original DjVu(r) Reference 
00020 //C- Library notice by the following text (see doc/lizard2002.djvu):
00021 //C-
00022 //C-  ------------------------------------------------------------------
00023 //C- | DjVu (r) Reference Library (v. 3.5)
00024 //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
00025 //C- | The DjVu Reference Library is protected by U.S. Pat. No.
00026 //C- | 6,058,214 and patents pending.
00027 //C- |
00028 //C- | This software is subject to, and may be distributed under, the
00029 //C- | GNU General Public License, Version 2. The license should have
00030 //C- | accompanied the software or you may obtain a copy of the license
00031 //C- | from the Free Software Foundation at http://www.fsf.org .
00032 //C- |
00033 //C- | The computer code originally released by LizardTech under this
00034 //C- | license and unmodified by other parties is deemed "the LIZARDTECH
00035 //C- | ORIGINAL CODE."  Subject to any third party intellectual property
00036 //C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
00037 //C- | non-exclusive license to make, use, sell, or otherwise dispose of 
00038 //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
00039 //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
00040 //C- | General Public License.   This grant only confers the right to 
00041 //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
00042 //C- | the extent such infringement is reasonably necessary to enable 
00043 //C- | recipient to make, have made, practice, sell, or otherwise dispose 
00044 //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
00045 //C- | any greater extent that may be necessary to utilize further 
00046 //C- | modifications or combinations.
00047 //C- |
00048 //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
00049 //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
00050 //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
00051 //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00052 //C- +------------------------------------------------------------------
00053 // 
00054 // $Id: DjVuGlobalMemory.cpp,v 1.6 2003/11/07 22:08:20 leonb Exp $
00055 // $Name: release_3_5_15 $
00056 
00057 #ifdef HAVE_CONFIG_H
00058 # include "config.h"
00059 #endif
00060 #if NEED_GNUG_PRAGMAS
00061 # pragma implementation
00062 #endif
00063 
00064 #ifdef NEED_DJVU_MEMORY
00065 #ifndef NEED_DJVU_MEMORY_IMPLEMENTATION
00066 #define NEED_DJVU_MEMORY_IMPLEMENTATION
00067 #endif /* NEED_DJVU_MEMORY_IMPLEMENTATION */
00068 
00069 #include "DjVuGlobal.h"
00070 #include "GException.h"
00071 #include <stdlib.h>
00072 #include <string.h>
00073 #include "debug.h"
00074 
00075 #ifdef UNIX
00076 djvu_delete_callback *
00077 _djvu_delete_ptr=(djvu_delete_callback *)&(operator delete);
00078 djvu_delete_callback *
00079 _djvu_deleteArray_ptr=(djvu_delete_callback *)&(operator delete []);
00080 djvu_new_callback *
00081 _djvu_new_ptr=(djvu_new_callback *)&(operator new);
00082 djvu_new_callback *
00083 _djvu_newArray_ptr=(djvu_new_callback *)&(operator new []);
00084 #endif
00085 
00086 static djvu_delete_callback *_djvu_delete_handler = 0;
00087 static djvu_new_callback *_djvu_new_handler = 0;
00088 static djvu_delete_callback *deleteArray_handler = 0;
00089 static djvu_new_callback *newArray_handler = 0;
00090 
00091 static djvu_free_callback *_djvu_free_handler = 0;
00092 static djvu_realloc_callback *_djvu_realloc_handler = 0;
00093 static djvu_calloc_callback *_djvu_calloc_handler = 0;
00094 static djvu_malloc_callback *_djvu_malloc_handler = 0;
00095 
00096 int
00097 djvu_memoryObject_callback (
00098   djvu_delete_callback* delete_handler,
00099   djvu_new_callback* new_handler
00100 ) {
00101   if(delete_handler && new_handler)
00102   {
00103 #ifdef UNIX
00104     _djvu_new_ptr=&_djvu_new;
00105     _djvu_delete_ptr=&_djvu_delete;
00106 #endif
00107     _djvu_delete_handler=delete_handler;
00108     _djvu_new_handler=new_handler;
00109     return 1;
00110   }else
00111   {
00112 #ifdef UNIX
00113     _djvu_new_ptr=(djvu_new_callback *)&(operator new);
00114     _djvu_delete_ptr=(djvu_delete_callback *)&(operator delete);
00115 #endif
00116     _djvu_delete_handler=0;
00117     _djvu_new_handler=0;
00118     return (delete_handler||new_handler)?0:1;
00119   }
00120   return 0;
00121 }
00122 
00123 int 
00124 djvu_set_memory_callbacks
00125 (
00126   djvu_free_callback *free_handler,
00127   djvu_realloc_callback *realloc_handler,
00128   djvu_malloc_callback *malloc_handler,
00129   djvu_calloc_callback *calloc_handler
00130 )
00131 {
00132   if(free_handler && realloc_handler && malloc_handler)
00133   {
00134 #ifdef UNIX
00135     _djvu_new_ptr=(djvu_new_callback *)&_djvu_new;
00136     _djvu_delete_ptr=(djvu_delete_callback *)&_djvu_delete;
00137 #endif
00138     _djvu_new_handler=(djvu_new_callback *)malloc_handler;
00139     _djvu_delete_handler=(djvu_delete_callback *)free_handler;
00140     _djvu_malloc_handler=(djvu_malloc_callback *)malloc_handler;
00141     _djvu_free_handler=(djvu_free_callback *)free_handler;
00142     _djvu_realloc_handler=(djvu_realloc_callback *)realloc_handler;
00143     if(calloc_handler)
00144     {
00145       _djvu_calloc_handler=(djvu_calloc_callback *)&calloc_handler;
00146     }else
00147     {
00148       _djvu_calloc_handler=0;
00149     }
00150     return 1;
00151   }else
00152   {
00153 #ifdef UNIX
00154     _djvu_new_ptr=(djvu_new_callback *)&(operator new);
00155     _djvu_delete_ptr=(djvu_delete_callback *)&(operator delete);
00156 #endif
00157     _djvu_delete_handler=0;
00158     _djvu_new_handler=0;
00159     _djvu_malloc_handler=0;
00160     _djvu_free_handler=0;
00161     _djvu_realloc_handler=0;
00162     _djvu_calloc_handler=0;
00163     return !(_djvu_malloc_handler
00164       ||_djvu_free_handler
00165       ||_djvu_realloc_handler
00166       ||_djvu_calloc_handler);
00167   }
00168 }
00169 
00170 DJVUAPI void *
00171 _djvu_new(size_t siz)
00172 {
00173   void *ptr;
00174 #ifndef UNIX
00175   if(_djvu_new_handler)
00176   {
00177 #endif
00178     if(!(ptr=(*_djvu_new_handler)(siz?siz:1)))
00179     {
00180       G_THROW( ERR_MSG("DjVuGlobalMemory.exhausted") );
00181     }
00182 #ifndef UNIX
00183   }else
00184   {
00185       ptr=::operator new(siz?siz:1);
00186   }
00187 #endif
00188   return ptr;
00189 }
00190 
00191 void  
00192 _djvu_delete(void *addr)
00193 {
00194   if(addr)
00195   {
00196     if(_djvu_delete_handler)
00197     {
00198       (*_djvu_delete_handler)(addr);
00199     }else
00200     {
00201       operator delete(addr);
00202     }
00203   }
00204 }
00205 
00206 void *
00207 _djvu_newArray(size_t siz)
00208 {
00209   void *ptr;
00210 #ifndef UNIX
00211   if(newArray_handler)
00212   {
00213 #endif
00214     if(!(ptr=(*newArray_handler)(siz?siz:1)))
00215     {
00216       G_THROW( ERR_MSG("DjVuGlobalMemory.exhausted") );
00217     }
00218 #ifndef UNIX
00219   }else
00220   {
00221       ptr=::new unsigned char[siz?siz:1];
00222   }
00223 #endif
00224   return ptr;
00225 }
00226 
00227 void
00228 _djvu_deleteArray(void *addr)
00229 {
00230   if(addr)
00231   {
00232     if(deleteArray_handler)
00233     {
00234       (*deleteArray_handler)(addr);
00235     }else
00236     {
00237 #ifdef WIN32
00238                 delete [] (addr) ;
00239 #else
00240         operator delete [] (addr);
00241 #endif
00242     }
00243   }
00244 }
00245 
00246 void *
00247 _djvu_malloc(size_t siz)
00248 {
00249   DEBUG_MSG("_djvu_malloc: siz="<<siz<<"\n");
00250   return _djvu_malloc_handler?(*_djvu_malloc_handler)(siz?siz:1):malloc(siz?siz:1);
00251 }
00252 
00253 void *
00254 _djvu_calloc(size_t siz, size_t items)
00255 {
00256   DEBUG_MSG("_djvu_calloc: siz="<<siz<<" items="<<items<<"\n");
00257   void *ptr;
00258   if( _djvu_calloc_handler )
00259   {
00260     ptr = (*_djvu_calloc_handler)(siz?siz:1, items?items:1);
00261   }else if( _djvu_malloc_handler )
00262   {
00263     if((ptr = (*_djvu_malloc_handler)((siz?siz:1)*(items?items:1)))&&siz&&items)
00264     {
00265       memset(ptr,0,siz*items);
00266     }
00267   }else
00268   { 
00269     ptr = calloc(siz?siz:1, items?items:1);
00270   }
00271   return ptr;    
00272 }
00273 
00274 void *
00275 _djvu_realloc(void* ptr, size_t siz)
00276 {
00277   DEBUG_MSG("_djvu_realloc: ptr="<<ptr<<" siz="<<siz<<"\n");
00278   void *newptr;
00279   if( _djvu_realloc_handler )
00280   {
00281     newptr = (*_djvu_realloc_handler)(ptr, siz);
00282   }else
00283   {
00284     newptr = realloc(ptr, siz?siz:1);
00285   }
00286   return newptr;
00287 }
00288  
00289 void
00290 _djvu_free(void *ptr)
00291 {
00292   DEBUG_MSG("_djvu_free: ptr="<<ptr<<"\n");
00293   if(ptr)
00294   {
00295     if( _djvu_free_handler )
00296     {
00297       (*_djvu_free_handler)(ptr);
00298     }else
00299     {
00300       free(ptr);
00301     }
00302   }
00303 }
00304 
00305 #endif
00306 

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal