Problem with structures
Hi,
this might very well be a C problem, but maybe not, because the program compiles fine and can nicely be executed seperately, it only crashes if used together with JNI. (Anyhow, I am not a C expert.)
Okay, i am trying to make some third party C-code accessible from Java.
The problem are lines like:
for (i=0; i<linkage->num_words; ++i) {
or
for (i=0; i<linkage->num_sublinkages; ++i) {
these lines cause JVM to just crash. The problem is that I seem not to be able to access the components of the structure "linkage". The JVM just goes down. As mentioned, the code compiles, and can be run as an executable without any problems.
It might very well be that these components are not yet defined (I am checking whether "linkage != NULL" before executing the above lines, however. Is this the correct way to do it?). As mentioned, I am irritated by the fact that the program works fine as an executable but not when called from Java.
Anyone any ideas?
Thanks a lot,
Michael
[1061 byte] By [
mika03a] at [2007-11-26 22:17:40]

# 2
> What kind of error text JVM displayed after crash? I
Here's the output:
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# SIGSEGV (0xb) at pc=0xb143fb54, pid=17935, tid=3086645936
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_10-b03 mixed mode, sharing)
# Problematic frame:
# C [libde_mk_qualim_parser_LinkParser.so+0x22b54] linkage_delete+0x31
#
T H R E A D
Current thread (0x0919b7f0): JavaThread "main" [_thread_in_native, id=17935]
siginfo:si_signo=11, si_errno=0, si_code=1, si_addr=0x4c8bda89
Registers:
EAX=0x4c8bda89, EBX=0x8c930d68, ECX=0x00000006, EDX=0x00ca70b0
ESP=0xbfeb7174, EBP=0xbfeb719c, ESI=0x8c930d68, EDI=0x0919b7f0
EIP=0xb143fb54, CR2=0x4c8bda89, EFLAGS=0x00010296
Top of Stack: (sp=0xbfeb7174)
0xbfeb7174:b144f024 00000001 00000006 00ca64c0
0xbfeb7184:00000006 00000006 b7fa7ab0 8c930d68
0xbfeb7194:8c930d68 0919b7f0 bfeb71bc b142d09d
0xbfeb71a4:4c8bda89 00000001 00000006 00ca64c0
0xbfeb71b4:8c930d68 0919b7f0 bfeb71dc b142cb59
0xbfeb71c4:098f7778 bfeb721c 00000000 0919b7f0
0xbfeb71d4:bfeb720c b25823cd bfeb720c b25824eb
0xbfeb71e4:0919b8b0 bfeb7220 bfeb721c bfeb71f0
Instructions: (pc=0xb143fb54)
0xb143fb44:00 c7 04 24 24 f0 44 b1 e8 27 97 c0 56 8b 45 08
0xb143fb54:83 38 00 7e 5c bb 00 00 00 00 be 00 00 00 00 a1
Stack: [0xbfcbb000,0xbfebb000), sp=0xbfeb7174, free space=2032k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libde_mk_qualim_parser_LinkParser.so+0x22b54] linkage_delete+0x31
C [libde_mk_qualim_parser_LinkParser.so+0x1009d] LinkAPI_submitNewSentence+0x57
C [libde_mk_qualim_parser_LinkParser.so+0xfb59]
> almost sure linkage pointer is uninitialised.
Yes, I now think the same! But how can I check this in C?
And mind that the compiled executable can be run without errors.
Cheers,
Michael
# 3
>
> these lines cause JVM to just crash. The problem is
> that I seem not to be able to access the components
> of the structure "linkage". The JVM just goes down.
> As mentioned, the code compiles, and can be run as an
> executable without any problems.
>
A memory problem can manifest itself much further along in the code than where the problem originated.
> It might very well be that these components are not
> yet defined (I am checking whether "linkage != NULL"
> before executing the above lines, ...
Null would be an defined value. An uninitialized value could be anything (like for instance '1'). Checking for null will not help you to determine that.
# 7
> :)
> [code]
> int CheckPointer( void* p )
> {
>return ?;
>
>
> Feel free to write your code to check this pointer -
> is it correct or no. You can use try catch during
> access to data pointer by p but even this way is not
> 100% correct.
As I said there are many ways to do it incorrectly as well.
I have written libraries and used others that verified every single pointer usage both on creation, usage and deletion as well. Again however one has to use it correctly.