{
assert( NULL != p_pginfo );
- if(( p_pginfo->objinfo.i_maxid <= i_oid ) || ( 0 > i_oid ))
+ if(( p_pginfo->objinfo.i_alloced <= i_oid ) || ( 0 > i_oid ))
{ return NULL; }
+
return OBJINFO(p_pginfo, i_oid);
}
ObjectInfo_ClearObjectInfo(
LibGoblin_ObjectInfo *p_objinfo )
{
+ int i_id;
+
assert( NULL != p_objinfo );
+ i_id = p_objinfo->i_id;
memset( p_objinfo, 0x00, sizeof( LibGoblin_ObjectInfo ) );
- p_objinfo->i_id = NO_OBJ;
+ p_objinfo->i_id = i_id;
+ p_objinfo->b_status = LIBGOBLIN_OBJINFO_INVALID;
p_objinfo->grplink.i_parent_id = NO_OBJ;
p_objinfo->grplink.i_child_topid = NO_OBJ;
LibGoblin_ProgramInfo *p_pginfo )
{
int i_cnt;
- int i_id_now;
- LibGoblin_ObjectInfo *p_objinfo_base;
- LibGoblin_ObjectInfo *p_objinfo_now;
+ int i_id;
+ int i_items;
+ LibGoblin_ObjectInfo *p_objbase;
+ LibGoblin_ObjectInfo *p_objinfo;
+ LibGoblin_ObjectInfo *p_objtemp;
assert( NULL != p_pginfo );
- p_objinfo_now = NULL;
- i_id_now = -1;
+ p_objinfo = NULL;
+ i_id = -1;
- // Search Non-used ObjectInfo ---
- if( p_pginfo->objinfo.i_used < p_pginfo->objinfo.i_maxid ) {
- for( i_cnt = 0; i_cnt < p_pginfo->objinfo.i_maxid; i_cnt++ ) {
-
- if( -1 == OBJINFO(p_pginfo, i_cnt)->i_id ) {
- p_objinfo_now = OBJINFO(p_pginfo, i_cnt);
- i_id_now = i_cnt;
- p_pginfo->objinfo.i_used++;
- break;
- }
- }
- }
- else if( p_pginfo->objinfo.i_used == p_pginfo->objinfo.i_alloced ) {
-
- p_objinfo_base = realloc( p_pginfo->objinfo.p_objinfo,
- sizeof( LibGoblin_ObjectInfo ) *
- (p_pginfo->objinfo.i_alloced + LIBGOBLIN_OBJINFO_UNITS) );
- if( NULL == p_objinfo_base ) {
+ // Expand ObjectInfo Memory when Empty ObjectInfo isn't exist. ---
+ if( NO_OBJ == p_pginfo->objinfo.i_empty ) {
+ assert( p_pginfo->objinfo.i_used == p_pginfo->objinfo.i_alloced );
+
+ i_items = p_pginfo->objinfo.i_alloced + LIBGOBLIN_OBJINFO_UNITS;
+ p_objbase = realloc( p_pginfo->objinfo.p_objinfo,
+ sizeof( LibGoblin_ObjectInfo ) * i_items);
+ if( NULL == p_objbase ) {
return NULL;
}
- for( i_cnt = p_pginfo->objinfo.i_alloced;
- i_cnt < (p_pginfo->objinfo.i_alloced + LIBGOBLIN_OBJINFO_UNITS); i_cnt++ ) {
- ObjectInfo_ClearObjectInfo( p_objinfo_base + i_cnt );
+ for( i_cnt = (i_items - 1); i_cnt >= p_pginfo->objinfo.i_alloced; i_cnt-- ) {
+ p_objtemp = p_objbase + i_cnt;
+ ObjectInfo_ClearObjectInfo( p_objtemp );
+
+ p_objtemp->i_id = i_cnt;
+ p_objtemp->grplink.i_next_id = ((i_cnt < (i_items - 1)) ? (i_cnt + 1): NO_OBJ);
}
- p_pginfo->objinfo.p_objinfo = p_objinfo_base;
+ p_pginfo->objinfo.p_objinfo = p_objbase;
p_pginfo->objinfo.i_alloced += LIBGOBLIN_OBJINFO_UNITS;
+ p_pginfo->objinfo.i_empty = p_objtemp->i_id;
+ }
- p_objinfo_now = OBJINFO(p_pginfo, p_pginfo->objinfo.i_used);
- i_id_now = p_pginfo->objinfo.i_used++;
- if( i_id_now == p_pginfo->objinfo.i_maxid )
- { p_pginfo->objinfo.i_maxid++; }
- }
- else {
- p_objinfo_now = OBJINFO(p_pginfo, p_pginfo->objinfo.i_used);
- i_id_now = p_pginfo->objinfo.i_used++;
- if( i_id_now == p_pginfo->objinfo.i_maxid )
- { p_pginfo->objinfo.i_maxid++; }
- }
+ assert( NO_OBJ != p_pginfo->objinfo.i_empty );
- assert( NULL != p_objinfo_now );
+ i_id = p_pginfo->objinfo.i_empty;
+ p_objinfo = OBJINFO( p_pginfo, i_id );
+ p_pginfo->objinfo.i_empty = p_objinfo->grplink.i_next_id;
+ ObjectInfo_ClearObjectInfo( p_objinfo );
- ObjectInfo_ClearObjectInfo( p_objinfo_now );
- p_objinfo_now->i_id = i_id_now;
+ p_objinfo->b_status = LIBGOBLIN_OBJINFO_VALID;
+ p_pginfo->objinfo.i_used++;
- return p_objinfo_now;
+ return p_objinfo;
}
return 0x01;
}
+ assert( 0 == p_objinfo->i_id );
+
p_objinfo->ptr_address = 0x0000000000000000;
p_objinfo->qw_size = 0xffffffffffffffff;
return 0x01;
}
- if( NO_OBJ == p_objinfo->i_id ) {
+ if( LIBGOBLIN_OBJINFO_INVALID == p_objinfo->b_status ) {
return 0x02;
}
i_objid = p_objinfo->i_id;
ObjectInfo_ClearObjectInfo( p_objinfo );
+ p_objinfo->grplink.i_next_id = p_pginfo->objinfo.i_empty;
+ p_pginfo->objinfo.i_empty = p_objinfo->i_id;
- if( p_pginfo->objinfo.i_maxid == (i_objid + 1) )
- { p_pginfo->objinfo.i_maxid--; }
p_pginfo->objinfo.i_used--;
- if( 0 == p_pginfo->objinfo.i_used )
- { p_pginfo->objinfo.i_maxid = 0; }
return 0x00;
}
assert( NULL != p_pginfo );
- if( 0 != p_pginfo->objinfo.i_maxid ) {
- return NO_OBJ;
- }
-
if( 0 == i_init_objnums )
{ i_items = LIBGOBLIN_OBJINFO_UNITS * LIBGOBLIN_OBJINFO_INITALLOCRATE; }
else
return -0x02;
}
- for( i_cnt = 0; i_cnt < LIBGOBLIN_OBJINFO_UNITS; i_cnt++ ) {
+ for( i_cnt = (i_items - 1); 0 <= i_cnt; i_cnt-- ) {
p_objinfo = OBJINFO(p_pginfo, i_cnt);
ObjectInfo_ClearObjectInfo( p_objinfo );
+
+ p_objinfo->i_id = i_cnt;
+ p_objinfo->grplink.i_next_id = ((i_cnt < (i_items - 1)) ? (i_cnt + 1) : NO_OBJ);
}
p_pginfo->objinfo.i_alloced = i_items;
- p_pginfo->objinfo.i_maxid = 0;
p_pginfo->objinfo.i_used = 0;
p_pginfo->objinfo.i_topid = NO_OBJ;
+ p_pginfo->objinfo.i_empty = 0;
return 0x00;
}
p_pginfo->objinfo.p_objinfo = NULL;
p_pginfo->objinfo.i_alloced = 0;
- p_pginfo->objinfo.i_maxid = 0;
p_pginfo->objinfo.i_used = 0;
p_pginfo->objinfo.i_topid = NO_OBJ;
+ p_pginfo->objinfo.i_empty = NO_OBJ;
return 0x00;
}
// Alloc ---
qw_size = 0x0000000000000001;
p_objinfo = ObjectInfo_InsetObject( p_pginfo, 0x1000000000000000, qw_size, NULL, 0x00 );
- Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, 1, 0, NO_OBJ, NO_OBJ, NO_OBJ );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, 9999, 0, NO_OBJ, NO_OBJ, NO_OBJ );
for( i_cnt = 2; i_cnt < 10; i_cnt++ ) {
qw_size <<= 1;
p_objinfo = ObjectInfo_InsetObject( p_pginfo, 0x1000000000000000, qw_size, NULL, 0x00 );
- Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, i_cnt, 0, NO_OBJ, NO_OBJ, i_cnt - 1 );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, (10000 - i_cnt), 0, NO_OBJ, NO_OBJ, (10001 - i_cnt) );
}
// Check ---
p_objmaster = OBJINFO( p_pginfo, 0 );
- Test_ObjectInfo_CUAssert_GrpLink( p_objmaster, 0, NO_OBJ, 9, NO_OBJ, NO_OBJ );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objmaster, 0, NO_OBJ, 9991, NO_OBJ, NO_OBJ );
// Delete ---
- for( i_cnt = 9; i_cnt > 1; i_cnt-- ) {
+ //for( i_cnt = 9; i_cnt > 1; i_cnt-- ) {
+ for( i_cnt = 9991; i_cnt < 9999; i_cnt++ ) {
p_objinfo = OBJINFO( p_pginfo, i_cnt );
- Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, i_cnt, 0, NO_OBJ, NO_OBJ, (i_cnt - 1) );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, i_cnt, 0, NO_OBJ, NO_OBJ, (i_cnt + 1) );
ObjectInfo_DeleteObjectInfo( p_pginfo, p_objinfo );
- CU_ASSERT( (i_cnt - 1) == p_objmaster->grplink.i_child_topid );
+ CU_ASSERT( (i_cnt + 1) == p_objmaster->grplink.i_child_topid );
}
- p_objinfo = OBJINFO( p_pginfo, 1 );
- Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, 1, 0, NO_OBJ, NO_OBJ, NO_OBJ );
+ p_objinfo = OBJINFO( p_pginfo, 9999 );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, 9999, 0, NO_OBJ, NO_OBJ, NO_OBJ );
ObjectInfo_DeleteObjectInfo( p_pginfo, p_objinfo );
CU_ASSERT( NO_OBJ == p_objmaster->grplink.i_child_topid );
// Alloc ---
qw_addr = 0x10000000;
p_objinfo = ObjectInfo_InsetObject( p_pginfo, qw_addr, 0x20000000, NULL, 0x00 );
- Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, 1, 0, NO_OBJ, NO_OBJ, NO_OBJ );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, 9999, 0, NO_OBJ, NO_OBJ, NO_OBJ );
for( i_cnt = 2; i_cnt < 10; i_cnt++ ) {
qw_addr += 0x10000000;
p_objinfo = ObjectInfo_InsetObject( p_pginfo, qw_addr, 0x20000000, NULL, 0x00 );
- Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, i_cnt, 0, NO_OBJ, (i_cnt - 1), NO_OBJ );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, (10000 - i_cnt), 0, NO_OBJ, (10001 - i_cnt), NO_OBJ );
}
// Check ---
p_objmaster = OBJINFO( p_pginfo, 0 );
- Test_ObjectInfo_CUAssert_GrpLink( p_objmaster, 0, NO_OBJ, 1, NO_OBJ, NO_OBJ );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objmaster, 0, NO_OBJ, 9999, NO_OBJ, NO_OBJ );
// Delete ---
- for( i_cnt = 0; i_cnt < 7; i_cnt++ ) {
- p_objinfo = OBJINFO( p_pginfo, (2 + i_cnt) );
- Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, (2 + i_cnt), 0, NO_OBJ, 1, (3 + i_cnt) );
+ //for( i_cnt = 0; i_cnt < 7; i_cnt++ ) {
+ for( i_cnt = 2; i_cnt < 9; i_cnt++ ) {
+ p_objinfo = OBJINFO( p_pginfo, (10000 - i_cnt) );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, (10000 - i_cnt), 0, NO_OBJ, 9999, (9999 - i_cnt) );
ObjectInfo_DeleteObjectInfo( p_pginfo, p_objinfo );
- CU_ASSERT( 1 == p_objmaster->grplink.i_child_topid );
+ CU_ASSERT( 9999 == p_objmaster->grplink.i_child_topid );
}
- p_objinfo = OBJINFO( p_pginfo, 1 );
- Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, 1, 0, NO_OBJ, NO_OBJ, 9 );
+ p_objinfo = OBJINFO( p_pginfo, 9999 );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, 9999, 0, NO_OBJ, NO_OBJ, 9991 );
ObjectInfo_DeleteObjectInfo( p_pginfo, p_objinfo );
- CU_ASSERT( 9 == p_objmaster->grplink.i_child_topid );
+ CU_ASSERT( 9991 == p_objmaster->grplink.i_child_topid );
- p_objinfo = OBJINFO( p_pginfo, 9 );
- Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, 9, 0, NO_OBJ, NO_OBJ, NO_OBJ );
+ p_objinfo = OBJINFO( p_pginfo, 9991 );
+ Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, 9991, 0, NO_OBJ, NO_OBJ, NO_OBJ );
ObjectInfo_DeleteObjectInfo( p_pginfo, p_objinfo );
CU_ASSERT( NO_OBJ == p_objmaster->grplink.i_child_topid );
Test_ObjectInfo_CUAssert_GrpLink( p_objinfo, i_cnt, p_objparent->i_id, NO_OBJ, NO_OBJ, NO_OBJ );
Test_ObjectInfo_CUAssert_GrpLink( p_objparent, (i_cnt - 1), (i_cnt - 2), i_cnt, NO_OBJ, NO_OBJ );
}
-
+/*
for( ; i_cnt < 10; i_cnt++ ) {
qw_addr += 0x00010000;
qw_size >>= 1;
p_objinfo = OBJINFO( p_pginfo, 0 );
ObjectInfo_DeleteObjectInfo( p_pginfo, p_objinfo );
CU_ASSERT( NO_OBJ == p_pginfo->objinfo.i_topid );
-
+*/
return;
}
p_pginfo = ProgInfo_AllocProgInfo();
CU_ASSERT( NULL != p_pginfo );
+
i_result = ObjectInfo_Init( p_pginfo, 0 );
CU_ASSERT( 0x00 == i_result );
- // Alloc Test ---
Test_ObjectInfo_InsetDelete_test00_001( p_pginfo );
Test_ObjectInfo_InsetDelete_test00_002( p_pginfo );
+
+ i_result = ObjectInfo_Term( p_pginfo );
+ CU_ASSERT( 0x00 == i_result );
+
+
+ i_result = ObjectInfo_Init( p_pginfo, 0 );
+ CU_ASSERT( 0x00 == i_result );
+
Test_ObjectInfo_InsetDelete_test00_003( p_pginfo );
+
+ i_result = ObjectInfo_Term( p_pginfo );
+ CU_ASSERT( 0x00 == i_result );
+
+
+ i_result = ObjectInfo_Init( p_pginfo, 0 );
+ CU_ASSERT( 0x00 == i_result );
+
Test_ObjectInfo_InsetDelete_test00_004( p_pginfo );
- // Term ---
i_result = ObjectInfo_Term( p_pginfo );
CU_ASSERT( 0x00 == i_result );
i_result = ObjectInfo_Init( p_pginfo, 0 );
CU_ASSERT( 0x00 == i_result );
CU_ASSERT( i_max == p_pginfo->objinfo.i_alloced );
+ CU_ASSERT( NO_OBJ == p_pginfo->objinfo.i_topid );
+ CU_ASSERT( 0x00 == p_pginfo->objinfo.i_empty );
// Alloc Test ---
- for( i_cnt = 0; i_cnt <= i_max; i_cnt++ ) {
+ for( i_cnt = 0; i_cnt < (i_max - 1); i_cnt++ ) {
p_objinfo = ObjectInfo_AllocObjectInfo( p_pginfo );
CU_ASSERT( NULL != p_objinfo );
CU_ASSERT( i_cnt == p_objinfo->i_id );
- CU_ASSERT( (i_cnt + 1) == p_pginfo->objinfo.i_maxid );
CU_ASSERT( (i_cnt + 1) == p_pginfo->objinfo.i_used );
+ CU_ASSERT( (i_cnt + 1) == p_pginfo->objinfo.i_empty );
}
+
+ p_objinfo = ObjectInfo_AllocObjectInfo( p_pginfo );
+ CU_ASSERT( NULL != p_objinfo );
+ CU_ASSERT( i_cnt == p_objinfo->i_id );
+ CU_ASSERT( (i_cnt + 1) == p_pginfo->objinfo.i_used );
+ CU_ASSERT( NO_OBJ == p_pginfo->objinfo.i_empty );
+
+ i_cnt++;
+ p_objinfo = ObjectInfo_AllocObjectInfo( p_pginfo );
+ CU_ASSERT( NULL != p_objinfo );
+ CU_ASSERT( i_cnt == p_objinfo->i_id );
+ CU_ASSERT( (i_cnt + 1) == p_pginfo->objinfo.i_used );
+ CU_ASSERT( (i_cnt + 1) == p_pginfo->objinfo.i_empty );
+
CU_ASSERT( (i_max + LIBGOBLIN_OBJINFO_UNITS) == p_pginfo->objinfo.i_alloced );
i_used = i_max + 1;
i_result = ObjectInfo_FreeObjectInfo( p_pginfo, p_objinfo );
CU_ASSERT( 0x00 == i_result );
i_used--;
- CU_ASSERT( (i_max + 1) == p_pginfo->objinfo.i_maxid );
CU_ASSERT( i_used == p_pginfo->objinfo.i_used );
+ CU_ASSERT( i_cnt == p_pginfo->objinfo.i_empty );
}
CU_ASSERT( (i_max + LIBGOBLIN_OBJINFO_UNITS) == p_pginfo->objinfo.i_alloced );
- for( i_cnt = 0; i_cnt <= (i_max/2); i_cnt++ ) {
+ for( i_cnt = 0; i_cnt < (i_max/2); i_cnt++ ) {
p_objinfo = ObjectInfo_AllocObjectInfo( p_pginfo );
CU_ASSERT( NULL != p_objinfo );
CU_ASSERT( p_objinfo->i_id == i_cnt );
- CU_ASSERT( (i_max + 1) == p_pginfo->objinfo.i_maxid );
i_used++;
CU_ASSERT( i_used == p_pginfo->objinfo.i_used );
+ CU_ASSERT( (i_cnt + 1) == p_pginfo->objinfo.i_empty );
}
+
+ p_objinfo = ObjectInfo_AllocObjectInfo( p_pginfo );
+ CU_ASSERT( NULL != p_objinfo );
+ CU_ASSERT( p_objinfo->i_id == i_cnt );
+ i_used++;
+ CU_ASSERT( i_used == p_pginfo->objinfo.i_used );
+ CU_ASSERT( (i_max + 1) == p_pginfo->objinfo.i_empty );
+
CU_ASSERT( (i_max + LIBGOBLIN_OBJINFO_UNITS) == p_pginfo->objinfo.i_alloced );
for( i_cnt = i_max; i_cnt >= 0; i_cnt-- ) {
i_result = ObjectInfo_FreeObjectInfo( p_pginfo, p_objinfo );
CU_ASSERT( 0x00 == i_result );
i_used--;
- CU_ASSERT( i_used == p_pginfo->objinfo.i_maxid );
CU_ASSERT( i_used == p_pginfo->objinfo.i_used );
}
CU_ASSERT( (i_max + LIBGOBLIN_OBJINFO_UNITS) == p_pginfo->objinfo.i_alloced );
Test_ObjectInfo_InitTerm_test00_001 );
CU_add_test( pt_goblin, "ObjectInfo_AllocFree_test00_001",
Test_ObjectInfo_AllocFree_test00_001 );
+
CU_add_test( pt_goblin, "ObjectInfo_InsetDelete_test00",
Test_ObjectInfo_InsetDelete_test00 );