emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Module support: No environment in pointer release function


From: Philipp Stephani
Subject: Re: Module support: No environment in pointer release function
Date: Tue, 07 Feb 2017 12:54:32 +0000



Elias Mårtenson <address@hidden> schrieb am Di., 7. Feb. 2017 um 04:16 Uhr:
On 6 February 2017 at 13:33, Paul Eggert <address@hidden> wrote:
Elias Mårtenson wrote:
In
addition to the pointer itself, the ‘emacs_env’ pointer is needed. An
arbitrary ‘void *data’ pointer would be useful too.

Can you package up these pointers into a single data structure, and pass a pointer to that structure? That's what's usually done in situations like this, and is why a single 'void *' should suffice.

I could do this, but as far as I understood, the emacs_env pointer is not guaranteed to be immutable. If it isn't immutable, then I might just as well save it to a global variable and not have to pass it through every function that needs it.

What are the guarantees with regards to the emacs_env value?

The big restriction is that its lifetime is limited to the lifetime (storage duration) of the argument that is used to obtain the pointer. I.e. in a function

emacs_value module_fun(emacs_env* env, ...) { ... }

the environment represented by env is only valud in the body of module_fun; reusing env or *env once the body is finished is undefined behavior.
(I'm aware that this is not documented at all, and I've been meaning to write some documentation for a while.)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]