コード例 #1
0
TA_RetCode TA_TradeLogFree( TA_TradeLog *toBeFreed )
{
    TA_TradeLogPriv *tradeLogPriv;

    if( toBeFreed )
    {
        /* Make sure this is a valid object. */
        tradeLogPriv = (TA_TradeLogPriv *)toBeFreed->hiddenData;
        if( !tradeLogPriv || (tradeLogPriv->magicNb != TA_TRADELOGPRIV_MAGIC_NB) )
            return TA_BAD_OBJECT;

        /* If it currently belong to a TA_PM, prevent the de-allocation. */
        if( tradeLogPriv->nbReferenceFromTA_PM != 0 )
            return TA_PM_REFERENCE_EXIST;

        /* Free the private members */
        if( tradeLogPriv->tradeDictCAT )
            TA_DictFree(tradeLogPriv->tradeDictCAT);
        if( tradeLogPriv->tradeDictSYM )
            TA_DictFree(tradeLogPriv->tradeDictSYM);
        if( tradeLogPriv->tradeDictCATSYM )
            TA_DictFree(tradeLogPriv->tradeDictCATSYM);
        if( tradeLogPriv->tradeDictUserKey )
            TA_DictFree(tradeLogPriv->tradeDictUserKey);

        TA_AllocatorForDataLog_FreeAll( &tradeLogPriv->allocator );

        /* Free the public portion. */
        TA_Free( toBeFreed );
    }

    return TA_SUCCESS;
}
コード例 #2
0
ファイル: ta_dict.c プロジェクト: royratcliffe/ta-lib
TA_RetCode TA_DictAddPair_S2( TA_Dict *dict,
                              TA_String *key1,
                              TA_String *key2,
                              void *value )
{
   TA_PrivDictInfo *theDict;
   dnode_t *node;
   TA_String *dupKey;
   TA_Dict *subDict;
   TA_Libc *libHandle;
   dict_t  *kazlibDict;

   theDict = (TA_PrivDictInfo *)dict;

   if( (theDict == NULL) ||
       (key1 == NULL) || (key2 == NULL) || (value == NULL) )
      return TA_BAD_PARAM;
   kazlibDict = &theDict->d;
   libHandle  = theDict->libHandle;

   /* Verify if a a dictionary already exist for key1. */
   node = dict_lookup( libHandle, kazlibDict, TA_StringToChar(key1) );

   if( node )
   {
      /* A dictionary already exist with the same key1... re-use it. */
      subDict = (TA_Dict *)dnode_get( node );
   }
   else
   {
      /* Alloc a new directory corresponding to key1. */
      subDict = TA_DictAlloc( libHandle, TA_DICT_KEY_ONE_STRING, theDict->freeValueFunc );

      if( !subDict )
         return TA_ALLOC_ERR;

      dupKey = TA_StringDup( TA_GetGlobalStringCache( libHandle ), key1 );

      if( !dupKey )
      {
         TA_DictFree( subDict );
         return TA_ALLOC_ERR;
      }

      if( !dict_alloc_insert( libHandle, kazlibDict, TA_StringToChar(dupKey), subDict ) )
      {
         TA_DictFree( subDict );
         TA_StringFree( TA_GetGlobalStringCache( libHandle ), dupKey );
         return TA_ALLOC_ERR;
      }
   }

   /* Insert the string in the subDict using key2 */
   return TA_DictAddPair_S( subDict, key2, value );
}
コード例 #3
0
/* Allows to dynamically add a mini-driver. */
TA_RetCode TA_SQL_AddMinidriver( const char scheme[], const TA_SQL_Minidriver *minidriver )
{
   TA_PROLOG
   TA_String *schemeStr;
   TA_StringCache *cache;

   TA_RetCode retCode;

   TA_TRACE_BEGIN( TA_SQL_AddMinidriver );

   if( !minidriverDict )
   {
      minidriverDict = TA_DictAlloc( TA_DICT_KEY_ONE_STRING, NULL );
      if( !minidriverDict )
      {
         TA_TRACE_RETURN( TA_ALLOC_ERR );
      }
   }

   cache = TA_GetGlobalStringCache();
   TA_ASSERT( cache != NULL );
   schemeStr = TA_StringAlloc( cache, scheme );
   if( !schemeStr )
   {
      TA_DictFree(minidriverDict);
      TA_TRACE_RETURN( TA_ALLOC_ERR );
   }

   retCode = TA_DictAddPair_S( minidriverDict, schemeStr, (void *)minidriver );
   TA_StringFree( cache, schemeStr );

   TA_TRACE_RETURN( retCode );
}
コード例 #4
0
static TA_RetCode TA_TraceGlobalShutdown( void *globalAllocated )
{
   TA_TraceGlobal *global;
   TA_RetCode retCode = TA_SUCCESS;

   global = (TA_TraceGlobal *)globalAllocated;

   if( !global )
      return retCode;

   if( global->fatalError.str )
      TA_Free(  global->fatalError.str );

   #if !defined( TA_SINGLE_THREAD )      
      retCode = TA_SemaDestroy( &global->fatalSema );
      retCode = TA_SemaDestroy( &global->callSema );
   #endif

   #ifdef TA_DEBUG
      #if defined( TA_SINGLE_THREAD )
         if( global->callStack )
            TA_ListFree( global->callStack );
      #endif

      if( global->functionCalled )
         TA_DictFree( global->functionCalled );
   #endif

   TA_Free(  global );

   return retCode;
}
コード例 #5
0
ファイル: ta_dict.c プロジェクト: royratcliffe/ta-lib
TA_RetCode TA_DictFree( TA_Dict *dict )
{
   TA_PrivDictInfo *theDict;

   dnode_t   *node;
   dnode_t   *next;
   TA_String *stringToDelete;
   void      *valueToDelete;
   dict_t    *kazlibDict;
   TA_Libc   *libHandle;
   int        flags;

   theDict = (TA_PrivDictInfo *)dict;

   if( theDict == NULL )
      return TA_BAD_PARAM;

   kazlibDict = &theDict->d;
   libHandle  = theDict->libHandle;

   /* Delete all the key-value pair sequentially. */
   node = dict_first( libHandle, kazlibDict );

   while (node != NULL)
   {
      /* Get the next node. */
      next = dict_next( libHandle, kazlibDict, node );

      /* Free the 'node, the 'key' string and the 'value'. */
      flags = theDict->flags;
      valueToDelete  = dnode_get(node);
      if( flags & (TA_DICT_KEY_TWO_STRING|TA_DICT_KEY_ONE_STRING) )
      {
         stringToDelete = TA_StringFromChar(dnode_getkey(node));
         dict_delete_free( libHandle, kazlibDict, node );
         TA_StringFree( TA_GetGlobalStringCache( libHandle ), stringToDelete );
      }
      else
         dict_delete_free( libHandle, kazlibDict, node );

      if( flags & TA_DICT_KEY_TWO_STRING )
      {
         /* The value is a dictionary. Delete it. */
         TA_DictFree( (TA_Dict *)valueToDelete );
      }
      else if( theDict->freeValueFunc )
         theDict->freeValueFunc( libHandle, valueToDelete );

      node = next;
   }

   /* Free the TA_PrivDictInfo */
   TA_Free( libHandle, theDict );

   return TA_SUCCESS;
}
コード例 #6
0
ファイル: ta_dict.c プロジェクト: royratcliffe/ta-lib
TA_RetCode TA_DictDeletePair_S2( TA_Dict *dict, const char *key1, const char *key2 )
{
   TA_PrivDictInfo *theDict;
   TA_String *stringToDelete;
   dnode_t   *node;
   TA_Dict   *subDict;
   TA_RetCode retCode;
   TA_Libc   *libHandle;
   dict_t    *kazlibDict;

   theDict = (TA_PrivDictInfo *)dict;

   if( (theDict == NULL)    ||
       (key1 == NULL)       || 
       (key2 == NULL))
      return TA_BAD_PARAM;
   kazlibDict = &theDict->d;
   libHandle  = theDict->libHandle;

   /* Find the dictionary for this 'key1'. */
   node = dict_lookup( libHandle, kazlibDict, key1 );

   if( !node )
      return TA_KEY_NOT_FOUND;

   subDict = (TA_Dict *)dnode_get(node);

   retCode = TA_DictDeletePair_S( subDict, key2 );

   /* Delete the dictionary if it is empty. */
   if( (retCode == TA_SUCCESS) && (TA_DictSize(subDict) == 0) )
   {
      TA_DictFree( subDict );
      /* Free the 'node' and the 'key1' string. */
      stringToDelete = TA_StringFromChar( dnode_getkey(node) );
      dict_delete_free( theDict->libHandle, kazlibDict, node );
      TA_StringFree( TA_GetGlobalStringCache( libHandle ), stringToDelete );
   }
   return TA_SUCCESS;
}
コード例 #7
0
/* Clean-up function called on TA_Shutdown */
void TA_SQL_ShutdownMinidriver( void )
{
   if( minidriverDict )
      TA_DictFree( minidriverDict );
}