External - Assign POINTER in parameters

2 Messages Forum Options Options
Embed this topic
Permalink
Louis M
External - Assign POINTER in parameters
Reply Threaded MoreMore options
Print post
Permalink
Hello Everyone!
I have a little problem here. I am making a wrapper for a C library and I have a function like this:
int funcAssign(objectAssign **obj)
This function assign an object to the pointer in parameter and return 0 when no error or something else when error. I create this external eiffel function to wrap this function:
frozen c_funcAssign(optr:POINTER):INTEGER is
                external
                        "C inline use <lib.h>"
                alias
                        "return (EIF_INTEGER) funcAssign((objectAssign **) &$optr);"
                end
Then I use the eiffel external fonction:
make is
                        -- Run application.
                local
                        opointer:POINTER
                        the_result:INTEGER
                do
                the_result:={OBJECT}.c_funcAssign(opointer)
                        if the_result/=0 then
                                print("Error.%N")
                        else
                                print(opointer)
                        end
                end

Then, when I run the application, I get no error, but the value of the opointer point to 0x0 (The NULL pointer). I think that the object didn't change at all. But I am sure that the pointer that was send to the C function funcAssign was change. Does anybody know how to get this kind of function working.

Thanks!

Louis Marchand  :)
Eric Bezault
Re: External - Assign POINTER in parameters
Reply Threaded MoreMore options
Print post
Permalink
Louis M wrote:

> Hello Everyone!
> I have a little problem here. I am making a wrapper for a C library and I
> have a function like this:
> int funcAssign(objectAssign **obj)
> This function assign an object to the pointer in parameter and return 0 when
> no error or something else when error. I create this external eiffel
> function to wrap this function:
> frozen c_funcAssign(optr:POINTER):INTEGER is
> external
> "C inline use <lib.h>"
> alias
> "return (EIF_INTEGER) funcAssign((objectAssign **) &$optr);"
> end
> Then I use the eiffel external fonction:
> make is
> -- Run application.
> local
> opointer:POINTER
> the_result:INTEGER
> do
> the_result:={OBJECT}.c_funcAssign(opointer)
> if the_result/=0 then
> print("Error.%N")
> else
> print(opointer)
> end
> end
>
> Then, when I run the application, I get no error, but the value of the
> opointer point to 0x0 (The NULL pointer). I think that the object didn't
> change at all. But I am sure that the pointer that was send to the C
> function funcAssign was change. Does anybody know how to get this kind of
> function working.

I think that what you pass to 'funcAssign' is the address of `optr'
(the argument of `c_funcAssign', and not the address of `opointer'
(the local variable in `make'). Try that:

~~~~~~~~~~~~~~~~~
        frozen c_funcAssign (optr:POINTER): INTEGER is
                external
                        "C inline use <lib.h>"
                alias
                        "return (EIF_INTEGER) funcAssign((objectAssign **) $optr);"
                end

        make is
                        -- Run application.
                local
                        opointer: POINTER
                        the_result: INTEGER
                do
                        the_result := {OBJECT}.c_funcAssign ($opointer)
                        if the_result /= 0 then
                                print ("Error.%N")
                        else
                                print (opointer)
                        end
                end
~~~~~~~~~~~~~~~~~


--
Eric Bezault
mailto:ericb@...
http://www.gobosoft.com