Hello everyone,

I know that a similar topic was brought up many years ago, and I don't
know if that was anything other than one developers little pet project,
or even if anyone who reads this is interested in this. But I had some
free time and a desire to see if I could do it, so here it is. If there
is no interest, that's quite alright - I'll just keep plugging away here
:). I've run into a confusing problem and I had hoped someone in here
might be able to help me out. Unfortunately C/C++ is not my native
language - I know how to write some small programs but most of the Lejos
code is beyond me.

I've managed to write/copy enough code to get Lejos to compile using
DevKitPro/DevKitArm. I've been through a couple days of debugging,
making steady progress until today. I'm in threads.c, in init_threads(
Thread *thread ). What happens is:

1. A successful call is made to new_primitive_array, assigning to
thread->stackFrameArray.
2. A successful call is made to new_primitive_array, assigning to
thread->stackArray
3. An assertion exception 20 is thrown.

I've been printfing my way around the code, and I've determined that
thread->stackFrameArray is somehow corrupted between the second call to
new_primitive_array and the first line of this call. There is no code
except the two printfs between the point of corruption. I fixed this
problem by assigning to a temporary variable and then after the second
call to new_primitive_array, I assign that temporary variable to
thread->stackFrameArray.

Still with me? :) This work-around keeps the pointers from being
corrupted, but doesn't solve the problem! If I do this, a call to
is_array still returns false, throwing the assertion 20. A few more
printfs give me the reason I'm writing this - a strange situation that
is beyond my knowledge.

1. A call to is_array just after the assignment to thread->stackArray
returns 1.
2. A call to is_array just after THAT call to is_array returns 0!

Here is the offending section of code, including the "work-around"
(which is a problem I don't understand by itself), and the final two
printfs. The first displays "1 1", the second displays "0 0".

  JINT stackFrameArray = ptr2word (new_primitive_array (T_STACKFRAME,
INITIAL_STACK_FRAMES));
  if (stackFrameArray == JNULL)
    return false;
        
  // Allocate actual stack storage (INITIAL_STACK_SIZE * 4 bytes)
  thread->stackArray = ptr2word (new_primitive_array (T_INT,
INITIAL_STACK_SIZE));
  thread->stackFrameArray = stackFrameArray;
  printf( "%d %d\n", is_array( word2obj(thread->stackFrameArray) ),
is_array( word2obj(thread->stackArray) ) );
  printf( "%d %d\n", is_array( word2obj(thread->stackFrameArray) ),
is_array( word2obj(thread->stackArray) ) );
  if (thread->stackArray == JNULL)
  {
    free_array (ref2obj(thread->stackFrameArray));
    thread->stackFrameArray = JNULL;
    return false;    
  }
 
  gThreadCounter++;
  
  #ifdef VERIFY
  assert (is_array (word2obj (thread->stackFrameArray)), THREADS0);
  assert (is_array (word2obj (thread->stackArray)), THREADS1);
  #endif

Thanks for reading. 

Craig

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Lejos-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lejos-discussion

Reply via email to