From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: Re: how to keep a copy of emacs_env or ert in module ? Date: Tue, 13 Sep 2016 06:18:26 +0000 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b86e9923987e2053c5d95fa X-Trace: blaine.gmane.org 1473747604 30689 195.159.176.226 (13 Sep 2016 06:20:04 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 13 Sep 2016 06:20:04 +0000 (UTC) To: hx , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 13 08:19:59 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bjh4P-0006hG-Rt for ged-emacs-devel@m.gmane.org; Tue, 13 Sep 2016 08:19:50 +0200 Original-Received: from localhost ([::1]:46751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjh4O-00077q-0k for ged-emacs-devel@m.gmane.org; Tue, 13 Sep 2016 02:19:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjh4H-00077a-Tf for emacs-devel@gnu.org; Tue, 13 Sep 2016 02:19:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjh4D-00033m-MO for emacs-devel@gnu.org; Tue, 13 Sep 2016 02:19:40 -0400 Original-Received: from mail-wm0-f54.google.com ([74.125.82.54]:35931) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjh4D-00033Q-DH for emacs-devel@gnu.org; Tue, 13 Sep 2016 02:19:37 -0400 Original-Received: by mail-wm0-f54.google.com with SMTP id b187so169025596wme.1 for ; Mon, 12 Sep 2016 23:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=bXSGyOdr0PGbkEAlvyxwPq88y4eRY4IkVhZOEKJCFuU=; b=EPtR78CoHdlfMlSYBJsYUFo5B+CoVWEO6eojdBEbdggt3C3r5mF56dtlVF/BrCxeP4 /3jn7YcsMfaPw9ZTGkLRXvxpgAeQl3cwS2Y29XweZuPbo8pgLyVsjU9NkD/wOgBw5QPW hNnmy94zOkcUVjx61xnFsWiOhhCV5NTfUq7j3K1gOIhAkiSxhP8JSQVGUZo00vvVHdju fuwGRztQyWrnUnT6q25Wffy2JZeMDf0uPvt29FRKtEWVoACuPu4VAyacmKAtz2O46x+O VFQrZ7DhY+cgKvxNGGURvjUdFAwmgqraESAp3fRUMBDzBQlpioS5sy3X12IwgEunQ1Ni pNWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=bXSGyOdr0PGbkEAlvyxwPq88y4eRY4IkVhZOEKJCFuU=; b=OWnuhbNKCbEjS2bY5KGxsZqKLkQa/ezhpCDFjlYhrRTJq3kK7z97yo30Soo4Yx5O/I 4RDVe/tLgQwJx1q6TWG7chnDR1ynv3PyOVgQJabMoy+jx18+YtnMrO3xImiZnWQPqTjr vYrJ+hx8ljnxlF8bHSVd2a+2aJ0v67b78TasetDZAsByYiGti6d/74xG8ZxRLCe1TQaj fBtAicYp/PWw+4JTBjIf39WM2av4gxEod5id9TY33ETfANf3allyiNdu/wpjb1Cfi3aX BYr3DhCBltKSx5s7PhRzO9fVpMsSXeK49XB5hxlDnesIfeD1eJmu4eneCK7c/v3dNGx0 LkKQ== X-Gm-Message-State: AE9vXwPHCQ3zen/okfxHDrLKIvynFgGWF6zpDiLlLYDOxoJ+jgh72S/6Itw0zAY84JFqO1FUuia1N419xD4dqQ== X-Received: by 10.194.47.101 with SMTP id c5mr21581266wjn.67.1473747516751; Mon, 12 Sep 2016 23:18:36 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.54 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:207411 Archived-At: --047d7b86e9923987e2053c5d95fa Content-Type: text/plain; charset=UTF-8 hx schrieb am Di., 13. Sep. 2016 um 02:02 Uhr: > > > On Sun, Sep 11, 2016 at 4:02 PM, Philipp Stephani > wrote: > > > > hx schrieb am So., 11. Sep. 2016 um 06:30 Uhr: > > is it possible to keep a copy of the *env in module ? > > > No. emacs_env, emacs_runtime, and emacs_value objects are only valid > within the dynamic extent of the function they are created/passed in. You > can't keep them around. The only exception are global references, created > by make_global_ref. > > > instead of copy the pointer, I copy the struct content: > > emacs_env genvo; > emacs_env *genv = &genvo; > > int > emacs_module_init(struct emacs_runtime *ert) > { > emacs_env *env = ert->get_environment(ert); > genvo = *env; > ... > } > > it is working. > Only by accident in the current implementation. Please don't do this; it's not guaranteed to work, and may stop working at any time. --047d7b86e9923987e2053c5d95fa Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


hx <= ;silent2600@gmail.com> schri= eb am Di., 13. Sep. 2016 um 02:02=C2=A0Uhr:


On Sun, Sep 11, 2016 at 4:02 PM, Philipp Stephani <p.stephani2@gmail.com>= wrote:


hx <silent2600@gmail.com> schrieb am So., 11. Sep. 2016 = um 06:30=C2=A0Uhr:
is it possible to keep a copy of the *env in module ?


No. emacs_env, emacs_runtime, and emacs_value objects are on= ly valid within the dynamic extent of the function they are created/passed = in. You can't keep them around. The only exception are global reference= s, created by make_global_ref.

instead of copy the p= ointer, I copy the struct content:
emacs_env genvo;
emacs_env *genv =3D &genvo;

int
emacs_m= odule_init(struct emacs_runtime *ert)
{
=C2=A0 emacs_env *env =3D = ert->get_environment(ert);
=C2=A0 genvo =3D *env;
...
}

it is working.= =C2=A0

Only by accident in the curr= ent implementation. Please don't do this; it's not guaranteed to wo= rk, and may stop working at any time.=C2=A0
--047d7b86e9923987e2053c5d95fa--