Why failed in process of Prolog call C call Prolog?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Why failed in process of Prolog call C call Prolog?

Shuai Wang
Hello gnu-prolog users,


On my 64bit x86 Linux,  I am trying to implement this process.
 
I have two source code, written in C and Prolog. 
In the Prolog code, I have two functions foo and foo1.

So basically inside Prolog function foo, it calls function foo1 through a C wrapper, then after function foo1 finished, it will return through wrapper back to foo

it is something like :

---------------------------------------------------
           Prolog                |         C 
---------------------------------------------------                                
         foo      ----- call ---- >  foo1_wrapper       normal             
         foo1    <-----call -----   foo1_wrapper       normal
         foo1   -------return---> foo1_wrapper       normal
         foo     <-----return----   foo1_wrapper       fail!


The problem is that, it can never return back to function foo after foo1_wrapper returns..

I have done several test(printf, write, valgrind and others...), and I am pretty sure that foo1 returns right value, and foo1_wrapper returns foo1's return value as well.

I am really confused right now, I should be able to look into the details, however, I just don't know which way to go...

Has anyone have certain problems like this...?


Best Regards,
Shuai

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Why failed in process of Prolog call C call Prolog?

emacstheviking
Hi,

It would greatly help if you could attach *ALL* source code and the commands you are using to compile and link.

I have written C extensions that are called from Prolog and they work just fine so there must be something in your code that’s not right yet!

Show us your code and we will try to help!

Sean.



On 24 Jul 2014, at 03:26, Shuai Wang <[hidden email]> wrote:

Hello gnu-prolog users,


On my 64bit x86 Linux,  I am trying to implement this process.
 
I have two source code, written in C and Prolog. 
In the Prolog code, I have two functions foo and foo1.

So basically inside Prolog function foo, it calls function foo1 through a C wrapper, then after function foo1 finished, it will return through wrapper back to foo

it is something like :

---------------------------------------------------
           Prolog                |         C 
---------------------------------------------------                                
         foo      ----- call ---- >  foo1_wrapper       normal             
         foo1    <-----call -----   foo1_wrapper       normal
         foo1   -------return---> foo1_wrapper       normal
         foo     <-----return----   foo1_wrapper       fail!


The problem is that, it can never return back to function foo after foo1_wrapper returns..

I have done several test(printf, write, valgrind and others...), and I am pretty sure that foo1 returns right value, and foo1_wrapper returns foo1's return value as well.

I am really confused right now, I should be able to look into the details, however, I just don't know which way to go...

Has anyone have certain problems like this...?


Best Regards,
Shuai
_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Why failed in process of Prolog call C call Prolog?

Shuai Wang
Hello Sean,


I attached all the source code and Makefile here.

The Prolog function foo is called by ssa_c.c function, (babel_foo_wrapper)

Then at line 57 of test_pl.pl, it calls function foo3 through c wrapper.
The program can never reach line 58 of test_pl.pl, even though I am sure 
it successfully return from foo3, as well as babel_c_0 (which is line 63 of test_c.c)


Yes, I myself also write several Prolog call C, C call prolog code before, and it could work..
That's why I feel so weird this time..

Thank you!

Best,
Shuai


On Thu, Jul 24, 2014 at 2:13 AM, Sean Charles <[hidden email]> wrote:
Hi,

It would greatly help if you could attach *ALL* source code and the commands you are using to compile and link.

I have written C extensions that are called from Prolog and they work just fine so there must be something in your code that’s not right yet!

Show us your code and we will try to help!

Sean.



On 24 Jul 2014, at 03:26, Shuai Wang <[hidden email]> wrote:

Hello gnu-prolog users,


On my 64bit x86 Linux,  I am trying to implement this process.
 
I have two source code, written in C and Prolog. 
In the Prolog code, I have two functions foo and foo1.

So basically inside Prolog function foo, it calls function foo1 through a C wrapper, then after function foo1 finished, it will return through wrapper back to foo

it is something like :

---------------------------------------------------
           Prolog                |         C 
---------------------------------------------------                                
         foo      ----- call ---- >  foo1_wrapper       normal             
         foo1    <-----call -----   foo1_wrapper       normal
         foo1   -------return---> foo1_wrapper       normal
         foo     <-----return----   foo1_wrapper       fail!


The problem is that, it can never return back to function foo after foo1_wrapper returns..

I have done several test(printf, write, valgrind and others...), and I am pretty sure that foo1 returns right value, and foo1_wrapper returns foo1's return value as well.

I am really confused right now, I should be able to look into the details, however, I just don't know which way to go...

Has anyone have certain problems like this...?


Best Regards,
Shuai
_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog



_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog

test_c.c (3K) Download Attachment
test_pl.pl (7K) Download Attachment
ssa_c.cil.c (17K) Download Attachment
Makefile.bak (90 bytes) Download Attachment