Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
error.c File Reference
#include "base.h"
#include <string.h>

Go to the source code of this file.

Classes

struct  stack_header_str
struct  error_stack_str

Defines

#define NSS_MAX_ERROR_STACK_COUNT   16 /* error codes */

Typedefs

typedef struct error_stack_str

Functions

static PRStatus error_once_function (void)
static error_stack * error_get_my_stack (void)
NSS_IMPLEMENT PRInt32 NSS_GetError (void)
NSS_IMPLEMENT PRInt32NSS_GetErrorStack (void)
NSS_IMPLEMENT void nss_SetError (PRUint32 error)
NSS_IMPLEMENT void nss_ClearErrorStack (void)

Variables

static PRUintn error_stack_index
static PRCallOnceType error_call_once

Class Documentation

struct stack_header_str

Definition at line 62 of file error.c.

Class Members
PRUint16 count
PRUint16 space
struct error_stack_str

Definition at line 67 of file error.c.

Class Members
PRInt32 stack

Define Documentation

#define NSS_MAX_ERROR_STACK_COUNT   16 /* error codes */

Definition at line 53 of file error.c.


Typedef Documentation

typedef struct error_stack_str

Definition at line 71 of file error.c.


Function Documentation

static error_stack* error_get_my_stack ( void  ) [static]

Definition at line 112 of file error.c.

{
  PRStatus st;
  error_stack *rv;
  PRUintn new_size;
  PRUint32 new_bytes;
  error_stack *new_stack;

  if( 0 == error_stack_index ) {
    st = PR_CallOnce(&error_call_once, error_once_function);
    if( PR_SUCCESS != st ) {
      return (error_stack *)NULL;
    }
  }

  rv = (error_stack *)nss_GetThreadPrivate(error_stack_index);
  if( (error_stack *)NULL == rv ) {
    /* Doesn't exist; create one */
    new_size = 16;
  } else if( rv->header.count == rv->header.space  &&
             rv->header.count  < NSS_MAX_ERROR_STACK_COUNT ) {
    /* Too small, expand it */
    new_size = PR_MIN( rv->header.space * 2, NSS_MAX_ERROR_STACK_COUNT);
  } else {
    /* Okay, return it */
    return rv;
  }

  new_bytes = (new_size * sizeof(PRInt32)) + sizeof(error_stack);
  /* Use NSPR's calloc/realloc, not NSS's, to avoid loops! */
  new_stack = PR_Calloc(1, new_bytes);
  
  if( (error_stack *)NULL != new_stack ) {
    if( (error_stack *)NULL != rv ) {
       (void)nsslibc_memcpy(new_stack,rv,rv->header.space);
    }
    new_stack->header.space = new_size;
  }

  /* Set the value, whether or not the allocation worked */
  nss_SetThreadPrivate(error_stack_index, new_stack);
  return new_stack;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRStatus error_once_function ( void  ) [static]

Definition at line 97 of file error.c.

{
  return nss_NewThreadPrivateIndex(&error_stack_index,PR_Free);
  /* return PR_NewThreadPrivateIndex(&error_stack_index, PR_Free); */
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 276 of file error.c.

{
  error_stack *es = error_get_my_stack();
  if( (error_stack *)NULL == es ) {
    /* Oh, well. */
    return;
  }

  es->header.count = 0;
  es->stack[0] = 0;
  return;
}

Definition at line 187 of file error.c.

{
  error_stack *es = error_get_my_stack();

  if( (error_stack *)NULL == es ) {
    return NSS_ERROR_NO_MEMORY; /* Good guess! */
  }

  if( 0 == es->header.count ) {
    return 0;
  }

  return es->stack[ es->header.count-1 ];
}

Here is the caller graph for this function:

Definition at line 221 of file error.c.

{
  error_stack *es = error_get_my_stack();

  if( (error_stack *)NULL == es ) {
    return (PRInt32 *)NULL;
  }

  /* Make sure it's terminated */
  es->stack[ es->header.count ] = 0;

  return es->stack;
}

Definition at line 244 of file error.c.

{
  error_stack *es;

  if( 0 == error ) {
    nss_ClearErrorStack();
    return;
  }

  es = error_get_my_stack();
  if( (error_stack *)NULL == es ) {
    /* Oh, well. */
    return;
  }

  if (es->header.count < es->header.space) {
    es->stack[ es->header.count++ ] = error;
  } else {
    memmove(es->stack, es->stack + 1, 
              (es->header.space - 1) * (sizeof es->stack[0]));
    es->stack[ es->header.space - 1 ] = error;
  }
  return;
}

Variable Documentation

Definition at line 89 of file error.c.

PRUintn error_stack_index [static]

Definition at line 80 of file error.c.