videoeditorengine/vedengine/videoprocessor/src/epoclib.cpp
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 5 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 * Wrappers for Symbian OS -specific system functions.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <s32file.h>
       
    23 #include "nrctyp32.h"
       
    24 #include "epoclib.h"
       
    25 
       
    26 #define NAMELEN 120
       
    27 #define EL_EXPORT
       
    28 
       
    29 
       
    30 EL_EXPORT void free(TAny *ptr)
       
    31 
       
    32     {
       
    33 #ifdef MALLOC_DEBUG        
       
    34     if ( !ptr )
       
    35         return;
       
    36 
       
    37     unsigned *p32 = (unsigned*) (((unsigned) ptr) - (NAMELEN+8));
       
    38 
       
    39     if ( p32[0] != 0xdaded1d0 )
       
    40         User::Panic(_L("BadFree"), 1);
       
    41 
       
    42     ptr = (TAny*) p32;
       
    43 #endif
       
    44     
       
    45     //  Dangling pointer check
       
    46 //    User::Free(ptr);
       
    47     unsigned count = (unsigned) User::AllocLen(ptr);
       
    48     TUint8 *p;
       
    49     
       
    50     p = (TUint8*) ptr;
       
    51     while ( count >> 2 )
       
    52     {
       
    53         *((TUint32*)p) = 0xfeedf1d0;
       
    54         p += 4;
       
    55         count -= 4;
       
    56     }
       
    57     while ( count )
       
    58     {
       
    59         *(p++) = 0x17;
       
    60         count--;
       
    61     }
       
    62 
       
    63     User::Free(ptr);
       
    64     }
       
    65 
       
    66 #ifdef MALLOC_DEBUG
       
    67 EL_EXPORT TAny *debugMalloc(u_int32 size, char *file, int line)
       
    68 #else    
       
    69 EL_EXPORT TAny *malloc(u_int32 size)
       
    70 #endif    
       
    71     {
       
    72     // Uninit checks        
       
    73 //    return User::AllocL(size);
       
    74     TAny *ptr;
       
    75     unsigned count = size;
       
    76     TUint8 *p;
       
    77 
       
    78 #ifdef MALLOC_DEBUG
       
    79     ptr = User::AllocL(size + NAMELEN+8);
       
    80     p = ((TUint8*) ptr) + NAMELEN+8;
       
    81 #else
       
    82     ptr = User::AllocL(size);
       
    83     p = (TUint8*) ptr;
       
    84 #endif    
       
    85     
       
    86     while ( count >> 2 )
       
    87     {
       
    88         *((TUint32*)p) = 0xdeadbeef;
       
    89         p += 4;
       
    90         count -= 4;
       
    91     }
       
    92     while ( count )
       
    93     {
       
    94         *(p++) = 0x42;
       
    95         count--;
       
    96     }
       
    97 
       
    98 #ifdef MALLOC_DEBUG
       
    99     unsigned *p32 = (unsigned*) ptr;
       
   100     p32[0] = 0xdaded1d0;
       
   101     p32[1] = (unsigned) line;
       
   102     char *c = (char*) &p32[2];
       
   103     int n = NAMELEN;
       
   104     while ( (*file != 0) && n )
       
   105     {
       
   106         *(c++) = *(file++);
       
   107         n--;
       
   108     }
       
   109     return (TAny*) (((unsigned) p32) + NAMELEN + 8);
       
   110 #else  
       
   111     return ptr;
       
   112 #endif    
       
   113     }
       
   114 
       
   115 EL_EXPORT TAny *realloc(void *memblock, u_int32 size)
       
   116     {
       
   117 #ifdef MALLOC_DEBUG
       
   118     unsigned *p32 = (unsigned*) (((unsigned) memblock) - NAMELEN - 8);
       
   119 
       
   120     if ( p32[0] != 0xdaded1d0 )
       
   121         User::Panic(_L("BadRealloc"), 1);
       
   122 
       
   123     p32 = (unsigned*) User::ReAllocL((void*) p32, size+NAMELEN+8);
       
   124     return (TAny*) (((unsigned) p32) + NAMELEN + 8);
       
   125 #else
       
   126     return User::ReAllocL(memblock, size);
       
   127 #endif    
       
   128     }
       
   129 
       
   130 
       
   131 #ifdef MALLOC_DEBUG
       
   132 EL_EXPORT TAny *debugCalloc(u_int32 num, u_int32 size, char *file, int line)
       
   133 {
       
   134     TAny *ptr;
       
   135     TUint8 *p;
       
   136 
       
   137     ptr = User::Alloc(num*size + NAMELEN+8);
       
   138     if ( !ptr )
       
   139         return 0;
       
   140     p = ((TUint8*) ptr) + NAMELEN+8;
       
   141     
       
   142     Mem::Fill(p, size*num, 0);
       
   143 
       
   144     unsigned *p32 = (unsigned*) ptr;
       
   145     p32[0] = 0xdaded1d0;
       
   146     p32[1] = (unsigned) line;
       
   147     char *c = (char*) &p32[2];
       
   148     int n = NAMELEN;
       
   149     while ( (*file != 0) && n )
       
   150     {
       
   151         *(c++) = *(file++);
       
   152         n--;
       
   153     }
       
   154     return (TAny*) p;
       
   155 }
       
   156 #else    
       
   157 EL_EXPORT TAny *calloc(u_int32 num, u_int32 size)
       
   158 
       
   159     {
       
   160     TAny *dest = User::Alloc(size*num);
       
   161     Mem::Fill(dest, size*num, 0);
       
   162     return dest;
       
   163     }
       
   164 #endif
       
   165 
       
   166 EL_EXPORT TAny *memset(TAny *dest, TInt c, u_int32 size)
       
   167     {
       
   168     Mem::Fill(dest, size, c);
       
   169     return dest; //returning the value of dest as in windows
       
   170     }
       
   171 EL_EXPORT TAny *memcpy(TAny *dest, const TAny *src, u_int32 size)
       
   172     {
       
   173     Mem::Copy(dest, src, size);
       
   174     return dest;
       
   175     }
       
   176 
       
   177 EL_EXPORT TAny *memmove(TAny *dest, const TAny *src, u_int32 count)
       
   178     {
       
   179     Mem::Copy(dest,src,count);
       
   180     return dest;
       
   181     }
       
   182 
       
   183 long atol(
       
   184         const char *nptr
       
   185         )
       
   186 {
       
   187         int c;              // current char 
       
   188         long total;         // current total 
       
   189         int sign;           // if '-', then negative, otherwise positive 
       
   190 
       
   191         TLex8 string((unsigned char *)nptr);
       
   192         // skip whitespace 
       
   193         string.SkipSpace();
       
   194         
       
   195         //prendre un caratere dans string lui faire le sign
       
   196         c = (int)string.Peek();
       
   197         string.Inc();
       
   198 
       
   199         sign = c;           // save sign indication 
       
   200         if (c == '-' || c == '+')
       
   201         // skip sign 
       
   202             {c = (int)string.Peek();
       
   203               string.Inc();
       
   204             }
       
   205         else //If c is not a sign, it is necessary to go increment back into the descriptors to get the right
       
   206              //number 
       
   207             {
       
   208             string.UnGet();
       
   209             }
       
   210 
       
   211         total = 0;
       
   212 
       
   213         while (string.Peek().IsDigit())
       
   214             {
       
   215             total = 10 * total + (c - '0');
       
   216             string.Inc();
       
   217             c = (int)string.Peek();
       
   218             
       
   219             }
       
   220 
       
   221         if (sign == '-')
       
   222             return -total;
       
   223         else
       
   224             return total;   /* return result, negated if necessary */
       
   225 }
       
   226 
       
   227 
       
   228 /*
       
   229 *int atoi(char *nptr) - Convert string to long
       
   230 *
       
   231 *Purpose:
       
   232 *       Converts ASCII string pointed to by nptr to binary.
       
   233 *       Overflow is not detected.  Because of this, we can just use
       
   234 *       atol().
       
   235 *
       
   236 *Entry:
       
   237 *       nptr = ptr to string to convert
       
   238 *
       
   239 *Exit:
       
   240 *       return int value of the string
       
   241 *
       
   242 *Exceptions:
       
   243 *       None - overflow is not detected.
       
   244 *
       
   245 *******************************************************************************/
       
   246 
       
   247 EL_EXPORT int atoi(
       
   248         const char *nptr
       
   249         )
       
   250 {
       
   251         return (int)atol(nptr);
       
   252 }
       
   253 // End of File