atexit() and on_exit()

new topic     » topic index » view thread      » older message » newer message

I wrapped these routines just to see what they would do.

Turns out, wrapping them does nothing. (I suppose thats a lot better than
what I originally expected tho, interpreter crash. Heh.)

The idea is to allow the routines to be called after the program has
offically exited.

I don't understand how the interpreter is causing them to avoid being called
after it has quit.

Example attached below.

jbrown

-- 
 /"\  ASCII ribbon              | http://www.geocities.com/jbrown1050/
 \ /  campain against           | Linux User:190064
  X   HTML in e-mail and        | Linux Machine:84163
 /*\  news, and unneeded MIME   | http://verify.stanford.edu/evote.html

----EXAMPLE here-------------

include dll.e

global constant stdlib = open_dll(""),
atexit_ = define_c_func(stdlib, "atexit", {C_POINTER}, C_INT),
on_exit_ = define_c_func(stdlib, "on_exit", {C_POINTER, C_POINTER}, C_INT)

--if it returns -1 there was an error, but errno is not set so we dont know
--what the h*** went wrong.
global function atexit(integer id) --pass a routine id instead of an address
    --since this is to provide an atexit for eu, dont let the programmer
    --worry about call_back(), we do that ourselves in the wrapper
    return c_func(atexit_, {call_back(id)})
end function

--if it returns -1 there was an error, but errno is not set so we dont know
--what the h*** went wrong.
global function on_exit(integer id, atom p) --pass a routine id instead of an
address
    --since this is to provide an atexit for eu, dont let the programmer
    --worry about call_back(), we do that ourselves in the wrapper
    return c_func(on_exit_, {call_back(id), p})
end function

function heh()
    puts(1, "heh\n")
    return 0
end function
function hey(atom ret, atom p)
    printf(1, "heh: %d %d\n", {ret, p})
    return 0
end function

--functions passed to atexit take no parameters and return nothing
? atexit(routine_id("hey"))
--functions passed to on_exit take 2 parameters and return nothing
--the parameters are an int and the void pointer that was passed (as atom p)
--to on_exit()
? on_exit(routine_id("hey"), NULL)

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu