Changeset 9 in libcf for trunk/src


Ignore:
Timestamp:
01/30/13 17:39:07 (11 years ago)
Author:
cheese
Message:

#1 add more omitted code and enhance stability

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cf_debug.c

    r8 r9  
    99#include <ctype.h>
    1010#include <stdarg.h>
     11#include <string.h>
    1112
    1213#ifdef _WIN32
     
    2829typedef struct __cf_debug_callstack__
    2930{
     31    char    file[NAME_LENGTH + 1];
    3032    char    func[NAME_LENGTH + 1];
    3133    int     line;
     
    187189int
    188190CF_Debug_CallStackPush (CF_Debug_Ctx    ctx,
     191                        const char      * file,
    189192                        const char      * func,
    190193                        const int       line)
     
    199202        return CF_ERROR_DEBUG_PUSH_CALLSTACK;
    200203
     204    /* push to callstack */
     205    sprintf (push->file, "%s", file);
    201206    sprintf (push->func, "%s", func);
    202207    push->line = line;
    203208    push->caller = context->callstack.caller;
    204 
    205209    context->callstack.caller = push;
     210
     211    /* set current context */
     212    sprintf (context->file, "%s", file);
     213    sprintf (context->func, "%s", func);
     214    context->line = line;
    206215
    207216    return CF_OK;
     
    216225
    217226    CHECK_INVALID_CTX (ctx);
    218 
    219     if (callstack == NULL)
    220         return CF_ERROR_DEBUG_INVALID_ARGS;
    221227
    222228    pop = context->callstack.caller;
     
    224230        return CF_ERROR_DEBUG_POP_CALLSTACK;
    225231
    226     sprintf (callstack->function, "%s", pop->func);
    227     callstack->line = pop->line;
    228 
    229     context->callstack.caller = pop->caller;
     232    if (callstack != NULL)
     233    {
     234        sprintf (callstack->function, "%s", pop->func);
     235        callstack->line = pop->line;
     236    }
     237
     238    memset (context->file, 0x00, sizeof (context->file));
     239    memset (context->func, 0x00, sizeof (context->func));
     240    context->line = 0;
     241
     242    /* restore current context */
     243    if (pop->caller != NULL)
     244    {
     245        sprintf (context->file, "%s", pop->caller->file);
     246        sprintf (context->func, "%s", pop->caller->func);
     247        context->line = pop->caller->line;
     248        context->callstack.caller = pop->caller;
     249    }
     250
    230251    free (pop);
    231252
Note: See TracChangeset for help on using the changeset viewer.