Exemplo n.º 1
0
xsbBool smIsValidStructRef(Structure_Manager smRecord, void *ptr) {

  void *pBlock, *firstStruct, *lastStruct;
  size_t structSize;


  structSize = SM_StructSize(smRecord);

  for ( pBlock = SM_CurBlock(smRecord);  IsNonNULL(pBlock);
	pBlock = SMBlk_NextBlock(pBlock) ) {
    
    firstStruct = SMBlk_FirstStruct(pBlock);
    lastStruct =
      SMBlk_LastStruct(pBlock,structSize,SM_StructsPerBlock(smRecord));

    /* Determine whether pointer lies within block
       ------------------------------------------- */
    if ( (firstStruct <= ptr) && (ptr <= lastStruct) ) {

      /* Determine whether pointer is a valid reference
	 ---------------------------------------------- */
      if ( (((char *)ptr - (char *)firstStruct) MOD structSize) == 0 )
	return TRUE;
      else
	return FALSE;
    }
  }
  return FALSE;
}
Exemplo n.º 2
0
void smFreeBlocks(Structure_Manager *pSM) {

  void *pCurBlock, *pNextBlock;

  pCurBlock = SM_CurBlock(*pSM);
  while ( IsNonNULL(pCurBlock) ) {
    pNextBlock = SMBlk_NextBlock(pCurBlock);
    free(pCurBlock);
    pCurBlock = pNextBlock;
  }
  SM_CurBlock(*pSM) = SM_NextStruct(*pSM) = SM_LastStruct(*pSM) = NULL;
  SM_AllocList(*pSM) = SM_FreeList(*pSM) = NULL;
}
Exemplo n.º 3
0
void smPrintBlocks(Structure_Manager *pSM) {

  void *pCurBlock, *pNextBlock;

  printf("blocks for SM %p size %" UIntfmt "\n",pSM,(UInteger)SM_NewBlockSize(*pSM));
  pCurBlock = SM_CurBlock(*pSM);
  while ( IsNonNULL(pCurBlock) ) {
    printf("Block %p\n",pCurBlock);
    pNextBlock = SMBlk_NextBlock(pCurBlock);
    //    mem_dealloc(pCurBlock,SM_NewBlockSize(*pSM),TABLE_SPACE);
    pCurBlock = pNextBlock;
  }
}
Exemplo n.º 4
0
void smFreeBlocks(Structure_Manager *pSM) {

  void *pCurBlock, *pNextBlock;

  pCurBlock = SM_CurBlock(*pSM);
  while ( IsNonNULL(pCurBlock) ) {
    pNextBlock = SMBlk_NextBlock(pCurBlock);
    mem_dealloc(pCurBlock,SM_NewBlockSize(*pSM),TABLE_SPACE);
    pCurBlock = pNextBlock;
  }
  SM_CurBlock(*pSM) = SM_NextStruct(*pSM) = SM_LastStruct(*pSM) = NULL;
  SM_AllocList(*pSM) = SM_FreeList(*pSM) = NULL;
}
Exemplo n.º 5
0
void smAllocateBlock(Structure_Manager *pSM) {

  void *pNewBlock;

  pNewBlock = mem_calloc(SM_NewBlockSize(*pSM),1,TABLE_SPACE);  
  //  if ( IsNULL(pNewBlock) )
  //    xsb_resource_error_nopred("memory","[smAllocateBlock] Out of memory in allocation of %s block\n",
  //			      SM_StructName(*pSM));
  SMBlk_NextBlock(pNewBlock) = SM_CurBlock(*pSM);
  SM_CurBlock(*pSM) = pNewBlock;
  SM_NextStruct(*pSM) = SMBlk_FirstStruct(pNewBlock);
  SM_LastStruct(*pSM) = SMBlk_LastStruct(pNewBlock,
					 SM_StructSize(*pSM),
					 SM_StructsPerBlock(*pSM));
  dbg_smPrint(LOG_STRUCT_MANAGER, *pSM,"after block allocation");
}
Exemplo n.º 6
0
void smAllocateBlock(Structure_Manager *pSM) {

  void *pNewBlock;

  dbg_smPrint(LOG_STRUCT_MANAGER, *pSM,"before block allocation");
  pNewBlock = malloc(SM_NewBlockSize(*pSM));
  if ( IsNULL(pNewBlock) )
    xsb_abort("[smAllocateBlock] Out of memory in allocation of %s block\n",
	      SM_StructName(*pSM));
  SMBlk_NextBlock(pNewBlock) = SM_CurBlock(*pSM);
  SM_CurBlock(*pSM) = pNewBlock;
  SM_NextStruct(*pSM) = SMBlk_FirstStruct(pNewBlock);
  SM_LastStruct(*pSM) = SMBlk_LastStruct(pNewBlock,
					 SM_StructSize(*pSM),
					 SM_StructsPerBlock(*pSM));
  dbg_smPrint(LOG_STRUCT_MANAGER, *pSM,"after block allocation");
}
Exemplo n.º 7
0
void smPrint(Structure_Manager smRecord, char *string) {

  void *pBlock;
  counter nBlocks;

  nBlocks = 0;
  for ( pBlock = SM_CurBlock(smRecord);  IsNonNULL(pBlock);
	pBlock = SMBlk_NextBlock(pBlock) )
    nBlocks++;

  fprintf(stddbg,
	  "  Structure Manager for %s (%s)\n"
	  "\tCurBlock: %p\t\tTotal Blocks: %u\n"
	  "\tNextStr:  %p\t\tFree List:   %p\n"
	  "\tLastStr:  %p\t\tAlloc List:  %p\n"
	  "\tStructs per block: %u\t\tStruct size: %u bytes\n",
	  SM_StructName(smRecord),	string,
	  SM_CurBlock(smRecord),	nBlocks,
	  SM_NextStruct(smRecord),	SM_FreeList(smRecord),
	  SM_LastStruct(smRecord),	SM_AllocList(smRecord),
	  SM_StructsPerBlock(smRecord),	SM_StructSize(smRecord));
}