From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: hx Newsgroups: gmane.emacs.devel Subject: how to keep a copy of emacs_env or ert in module ? Date: Sun, 11 Sep 2016 12:28:49 +0800 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114ba264f08669053c33d02d X-Trace: blaine.gmane.org 1473568268 6125 195.159.176.226 (11 Sep 2016 04:31:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 11 Sep 2016 04:31:08 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Sep 11 06:31:04 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 1biwQ1-0000c2-6q for ged-emacs-devel@m.gmane.org; Sun, 11 Sep 2016 06:31:01 +0200 Original-Received: from localhost ([::1]:36483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biwPy-000311-B8 for ged-emacs-devel@m.gmane.org; Sun, 11 Sep 2016 00:30:58 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biwPJ-00030u-Ib for emacs-devel@gnu.org; Sun, 11 Sep 2016 00:30:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biwPE-00019M-HQ for emacs-devel@gnu.org; Sun, 11 Sep 2016 00:30:16 -0400 Original-Received: from mail-wm0-f51.google.com ([74.125.82.51]:38092) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biwPE-00011B-8J for emacs-devel@gnu.org; Sun, 11 Sep 2016 00:30:12 -0400 Original-Received: by mail-wm0-f51.google.com with SMTP id 1so93226572wmz.1 for ; Sat, 10 Sep 2016 21:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=hsvO30TOyEybtcXJA7NXA5CSR7Ou/Qh3IrnzZTA3L44=; b=yqZ3IVydWWyfArHNVPOiBCChcMblkSrbw2/6lEL/duCNP0C+ksPmBstn11L2wHTHwu rORBXvM4JSU2iQoqMXP1utrk8/SQh+lGWwCaTTs78xf0oH3+PzABa0mHLHWdF4wB6MvE FgYmF7bwDs1mJA7HcJnCuiTJrT0okmoXIEX5zMJkjInSnEj54ghjcDQgKO1PabAiuzIm 8IqxhhcMQZMeoq6K8SsFRYhPbUicM9A1knicG/RnJrCj5MXVDASFSD2+hgQa5z7VTY2y 2c7fE7iJWbSwuo2RCdSbYuTNrEPLtaUQMC62FE/gTgLlhzYcZcaqmw5HnGY75F7XqqNj YM0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=hsvO30TOyEybtcXJA7NXA5CSR7Ou/Qh3IrnzZTA3L44=; b=e9llov0rrkAuBVE46f15hMe61NEeThoxMFo3cqiy4HzcNjPP8Idnj/ZV1/sbAV7leR WAaI+s+pHg7HrMtwIYC8NrvYBJA285cvTXiUMwj4XJyPG2rPoLuuLzLuZ+Os0K1Z8gTy P50rJYT4ot798RYjmcwe25QT01jDz2e9GBaBr4RsOYkmoMI2Atsza+Zn61aYFlwHaM3C dHXC4fK3dG7OrteeNYW9H0dJdIG2L0c/KaAtL8AhB9g0CjbLB4ltWzYYVMnBvhk9dDUI ZQq9EFkpcZdkCDjlWYgNdT4/+4Jex8pSLczsPvHWDboBuLO56XmkYWq7mcj4EdBvPK4s cddw== X-Gm-Message-State: AE9vXwMfV3drM3vApuaj72atUkztvEwxKXGDLjXEvxAQzOR7srEyNl9e1pneCDJ0ODI9FmjZuHpWQgQ5veD1/w== X-Received: by 10.28.157.80 with SMTP id g77mr4599084wme.34.1473568129974; Sat, 10 Sep 2016 21:28:49 -0700 (PDT) Original-Received: by 10.28.38.70 with HTTP; Sat, 10 Sep 2016 21:28:49 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.51 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:207358 Archived-At: --001a114ba264f08669053c33d02d Content-Type: text/plain; charset=UTF-8 //mymodule.c #include struct emacs_runtime *gert = NULL; emacs_env *genv = NULL; void my_test(void) { genv->intern(genv, "nil"); // sig seg fault -_-! } int emacs_module_init(struct emacs_runtime *ert) { emacs_env *env = ert->get_environment(ert); gert = ert; genv = env; return 0; } // until here, the gert and genv content still correct. //EOF I want to use "env" in my_test(void) but don't want to pass it as a parameter, so I set a global genv to save the pointer. but the *genv content was changed: Breakpoint 4, emacs_module_init (ert=0xbfb904f0) at mymodule.c:411 411 return 0; (gdb) p *gert $4 = {size = 12, private_members = 0xbfb904fc, get_environment = 0x8165910 } 412 } ########### out of emacs_module_init() ####################### (gdb) s 0x081680b1 in Fmodule_load () (gdb) p *gert $5 = {size = 12, private_members = 0xbfb904fc, get_environment = 0x8165910 } (gdb) s Single stepping until exit from function Fmodule_load, which has no line number information. 0x08164610 in Fload () (gdb) p *gert $6 = {size = 12, private_members = 0xbfb904fc, get_environment = 0x8165910 } (gdb) s Single stepping until exit from function Fload, which has no line number information. 0x0814ee38 in Frequire () (gdb) p *gert $7 = {size = 12, private_members = 0xbfb904fc, get_environment = 0x8165910 } (gdb) s Single stepping until exit from function Frequire, which has no line number information. 0x08141530 in unbind_to () (gdb) p *gert $8 = {size = 12, private_members = 0xbfb904fc, get_environment = 0x8165910 } (gdb) s Single stepping until exit from function unbind_to, which has no line number information. 0x08141d8b in eval_sub () (gdb) p *gert $9 = {size = 12, private_members = 0xbfb904fc, get_environment = 0x8165910 } (gdb) s Single stepping until exit from function eval_sub, which has no line number information. 0x08143fa8 in Feval () (gdb) p *gert $10 = {size = 12, private_members = 0xbfb904fc, get_environment = 0x8165910 } (gdb) s Single stepping until exit from function Feval, which has no line number information. 0x08141530 in unbind_to () (gdb) p *gert $11 = {size = 12, private_members = 0xbfb904fc, get_environment = 0x8165910 } (gdb) s Single stepping until exit from function unbind_to, which has no line number information. 0x081427fd in Ffuncall () (gdb) p *gert $12 = {size = 12, private_members = 0xbfb904fc, get_environment = 0x8165910 } (gdb) s Single stepping until exit from function Ffuncall, which has no line number information. 0x081770bf in exec_byte_code () (gdb) p *gert $13 = {size = 12, private_members = 0xbfb904fc, get_environment = 0x8165910 } (gdb) s Single stepping until exit from function exec_byte_code, which has no line number information. 0x08142355 in funcall_lambda () (gdb) p *gert $14 = {size = 138896016, private_members = 0x0, get_environment = 0x4c38} (gdb) q A debugging session is active. what's happened after calling funcall_lambda () ? is it possible to keep a copy of the *env in module ? thanks! --001a114ba264f08669053c33d02d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
//mymodule.c

#include <emacs-module.= h>

struct emacs_runtime *gert =3D NULL;
emacs_env *genv =3D NULL;

void my_test(void= ) {
=C2=A0 =C2=A0 =C2=A0genv->intern(genv, "nil"); = =C2=A0// sig seg fault -_-!
}

i= nt emacs_module_init(struct emacs_runtime *ert) {
=C2=A0 emacs_en= v *env =3D ert->get_environment(ert);
=C2=A0 gert =3D er= t;
=C2=A0 genv =3D env;
=C2=A0=C2=A0
=C2=A0 r= eturn 0;
} =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0// until here, the gert and genv content still correct.

//EOF


I want to use "= env" in my_test(void) but don't want to pass it as a parameter,
so I set =C2=A0a global genv to save the pointer.
but the= *genv content was changed:

Breakpoint 4, ema= cs_module_init (ert=3D0xbfb904f0) at mymodule.c:411
411 =C2=A0 = =C2=A0 =C2=A0 return 0;
(gdb) p *gert
$4 =3D {size =3D = 12, private_members =3D 0xbfb904fc, get_environment =3D 0x8165910 <modul= e_get_environment>}
412 =C2=A0 =C2=A0 } =C2=A0 =C2=A0 ########= ### out of emacs_module_init() #######################
(gdb) s
0x081680b1 in Fmodule_load ()
(gdb) p *gert
$5 = =3D {size =3D 12, private_members =3D 0xbfb904fc, get_environment =3D 0x816= 5910 <module_get_environment>}
(gdb) s
Single ste= pping until exit from function Fmodule_load,
which has no line nu= mber information.
0x08164610 in Fload ()
(gdb) p *gert<= /div>
$6 =3D {size =3D 12, private_members =3D 0xbfb904fc, get_environm= ent =3D 0x8165910 <module_get_environment>}
(gdb) s
Single stepping until exit from function Fload,
which has no l= ine number information.
0x0814ee38 in Frequire ()
(gdb)= p *gert
$7 =3D {size =3D 12, private_members =3D 0xbfb904fc, get= _environment =3D 0x8165910 <module_get_environment>}
(gdb) = s
Single stepping until exit from function Frequire,
wh= ich has no line number information.
0x08141530 in unbind_to ()
(gdb) p *gert
$8 =3D {size =3D 12, private_members =3D 0x= bfb904fc, get_environment =3D 0x8165910 <module_get_environment>}
(gdb) s
Single stepping until exit from function unbind_to= ,
which has no line number information.
0x08141d8b in e= val_sub ()
(gdb) p *gert
$9 =3D {size =3D 12, private_m= embers =3D 0xbfb904fc, get_environment =3D 0x8165910 <module_get_environ= ment>}
(gdb) s
Single stepping until exit from funct= ion eval_sub,
which has no line number information.
0x0= 8143fa8 in Feval ()
(gdb) p *gert
$10 =3D {size =3D 12,= private_members =3D 0xbfb904fc, get_environment =3D 0x8165910 <module_g= et_environment>}
(gdb) s
Single stepping until exit = from function Feval,
which has no line number information.
<= div>0x08141530 in unbind_to ()
(gdb) p *gert
$11 =3D {s= ize =3D 12, private_members =3D 0xbfb904fc, get_environment =3D 0x8165910 &= lt;module_get_environment>}
(gdb) s
Single stepping = until exit from function unbind_to,
which has no line number info= rmation.
0x081427fd in Ffuncall ()
(gdb) p *gert
<= div>$12 =3D {size =3D 12, private_members =3D 0xbfb904fc, get_environment = =3D 0x8165910 <module_get_environment>}
(gdb) s
S= ingle stepping until exit from function Ffuncall,
which has no li= ne number information.
0x081770bf in exec_byte_code ()
= (gdb) p *gert
$13 =3D {size =3D 12, private_members =3D 0xbfb904f= c, get_environment =3D 0x8165910 <module_get_environment>}
= (gdb) s
Single stepping until exit from function exec_byte_code,<= /div>
which has no line number information.
0x08142355 in fun= call_lambda ()
(gdb) p *gert
$14 =3D {size =3D 13889601= 6, private_members =3D 0x0, get_environment =3D 0x4c38}
(gdb) q
A debugging session is active.

what= 's happened after calling funcall_lambda () ?
is it possible = to keep a copy of the *env in module ?

thanks!



--001a114ba264f08669053c33d02d--