Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The idea of male and female are universal constants. -- Kirk, "Metamorphosis", stardate 3219.8


devel / comp.lang.tcl / What is the correct way to initialize Tcl from a C program?

SubjectAuthor
* What is the correct way to initialize Tcl from a C program?Helmut Giese
+- What is the correct way to initialize Tcl from a C program?Dave
+- What is the correct way to initialize Tcl from a C program?Harald Oehlmann
`* What is the correct way to initialize Tcl from a C program?Ralf Fassel
 `* What is the correct way to initialize Tcl from a C program?Helmut Giese
  `* What is the correct way to initialize Tcl from a C program?Nicolas
   `- What is the correct way to initialize Tcl from a C program?Helmut Giese

1
What is the correct way to initialize Tcl from a C program?

<qse0shdpl57rmf1a05ngd58de8dj0rt0f5@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10520&group=comp.lang.tcl#10520

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: hgi...@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: What is the correct way to initialize Tcl from a C program?
Date: Thu, 12 Jan 2023 17:57:01 +0100
Organization: ratiosoft
Lines: 27
Message-ID: <qse0shdpl57rmf1a05ngd58de8dj0rt0f5@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader01.eternal-september.org; posting-host="d618368683de53c2e581244ad5dec68e";
logging-data="1400982"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JDvaqAgjtW1LbMTVMl2Pc"
Cancel-Lock: sha1:sperr5iGS2oG5KLuRXvp7IKXHzY=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Thu, 12 Jan 2023 16:57 UTC

Hello out there,
I used to build and use DLLs regularly - about 15 to 20 years ago, and
now I am not quite sure how to do it. I create a function 'initTcl'
which is called by 'main' like this
error = initTcl(argv[0]);
practically immediately. It looks like this:
---
int initTcl(char* argv0) {
TclpSetInitialEncodings();
Tcl_FindExecutable(argv0);
ourInterp = Tcl_CreateInterp();
if (Tcl_Init(ourInterp) != TCL_OK) {
return TCL_ERROR;
}
return TCL_OK;
} ---
'argv0' is well the name of my program. It fails in 'FindExecutable'
with the error
'Exception thrown at 0x0000000000000000 in StmtParserExe.exe'

Q: What is wrong in 'initTcl'?
I am on Windows using Visual Studio and a .lib file and a 64 bit DLL
from Ashok.

Any help will be greatly appreciated
Helmut

Re: What is the correct way to initialize Tcl from a C program?

<tpphb1$4dd$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10521&group=comp.lang.tcl#10521

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!9mqibcuZ3IqbHui3f2bcQQ.user.46.165.242.75.POSTED!not-for-mail
From: nore...@nohost.com (Dave)
Newsgroups: comp.lang.tcl
Subject: Re: What is the correct way to initialize Tcl from a C program?
Date: Thu, 12 Jan 2023 11:51:28 -0600
Organization: Aioe.org NNTP Server
Message-ID: <tpphb1$4dd$1@gioia.aioe.org>
References: <qse0shdpl57rmf1a05ngd58de8dj0rt0f5@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="4525"; posting-host="9mqibcuZ3IqbHui3f2bcQQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101
Thunderbird/45.5.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dave - Thu, 12 Jan 2023 17:51 UTC

Look at tclAppInit.c in either of the source distributions:
win/tclAppInit.c or unix/tclAppInit.c

--
computerjock AT mail DOT com

Re: What is the correct way to initialize Tcl from a C program?

<tpphhi$17gt9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10522&group=comp.lang.tcl#10522

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: What is the correct way to initialize Tcl from a C program?
Date: Thu, 12 Jan 2023 18:54:58 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <tpphhi$17gt9$1@dont-email.me>
References: <qse0shdpl57rmf1a05ngd58de8dj0rt0f5@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 12 Jan 2023 17:54:58 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="68c7d509e76e8dc38dd765947cccaaa2";
logging-data="1295273"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mxw/HgX1DmF463oHH3PLn"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:/AfayFzlHCEa+snj1/vSI03UkpE=
Content-Language: en-GB
In-Reply-To: <qse0shdpl57rmf1a05ngd58de8dj0rt0f5@4ax.com>
 by: Harald Oehlmann - Thu, 12 Jan 2023 17:54 UTC

Am 12.01.2023 um 17:57 schrieb Helmut Giese:
> Hello out there,
> I used to build and use DLLs regularly - about 15 to 20 years ago, and
> now I am not quite sure how to do it. I create a function 'initTcl'
> which is called by 'main' like this
> error = initTcl(argv[0]);
> practically immediately. It looks like this:
> ---
> int initTcl(char* argv0) {
> TclpSetInitialEncodings();
> Tcl_FindExecutable(argv0);
> ourInterp = Tcl_CreateInterp();
> if (Tcl_Init(ourInterp) != TCL_OK) {
> return TCL_ERROR;
> }
> return TCL_OK;
> }
> ---
> 'argv0' is well the name of my program. It fails in 'FindExecutable'
> with the error
> 'Exception thrown at 0x0000000000000000 in StmtParserExe.exe'
>
> Q: What is wrong in 'initTcl'?
> I am on Windows using Visual Studio and a .lib file and a 64 bit DLL
> from Ashok.
>
> Any help will be greatly appreciated
> Helmut

Hi Helmut,

Your stuff is ok. "TclpSetInitialEncodings();" is your function, right ?

I don't see why it should crash there, sorry.

https://wiki.tcl-lang.org/page/How+to+embed+Tcl+in+C+applications

All ok.
When I made dll embedding, I traced through Tcl_FindExecutable.
So, a debug build may help...

Sorry,
Harald

Re: What is the correct way to initialize Tcl from a C program?

<ygapmbjaaet.fsf@akutech.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10523&group=comp.lang.tcl#10523

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: What is the correct way to initialize Tcl from a C program?
Date: Thu, 12 Jan 2023 19:13:30 +0100
Lines: 42
Message-ID: <ygapmbjaaet.fsf@akutech.de>
References: <qse0shdpl57rmf1a05ngd58de8dj0rt0f5@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net OSSdIj7qOZW4afp1yEkR6gL3S8KgHP+h8rWKJR/j1ek/5c1KQ=
Cancel-Lock: sha1:6h574+bloNXS3pgT9QMMyFElH5w= sha1:hNrelLbIubD1emLdrVocHlPKhVU=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Thu, 12 Jan 2023 18:13 UTC

* Helmut Giese <hgiese@ratiosoft.com>
| Hello out there,
| I used to build and use DLLs regularly - about 15 to 20 years ago, and
| now I am not quite sure how to do it. I create a function 'initTcl'
| which is called by 'main' like this
| error = initTcl(argv[0]);
| practically immediately. It looks like this:
| ---
| int initTcl(char* argv0) {
| TclpSetInitialEncodings();
| Tcl_FindExecutable(argv0);

The manpage of Tcl_FindExecutable says:

On UNIX platforms this procedure is typically invoked as the very first
thing in the application's main program; it must be passed argv[0] as
its argument.
--<snip-snip>--
On Windows platforms this procedure is typically invoked as the very
first thing in the application's main program as well;

Looking at the function body of Tcl_FindExecutable, we see that it calls
TclpSetInitialEncodings() itself, but only after calling TclInitSubsystems():

tcl8.6.12/generic/tclEncoding.c

void
Tcl_FindExecutable(
const char *argv0) /* The value of the application's argv[0]
* (native). */
{
TclInitSubsystems();
TclpSetInitialEncodings();
TclpFindExecutable(argv0);
}

So just do as the manpage says, get rid of the TclpSetInitialEncodings()
and only call Tcl_FindExecutable(argv0).

HTH
R'

Re: What is the correct way to initialize Tcl from a C program?

<fkt0sh5pev6dvb488ej02ka5lbo3as4rsr@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10524&group=comp.lang.tcl#10524

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: hgi...@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: What is the correct way to initialize Tcl from a C program?
Date: Thu, 12 Jan 2023 22:11:46 +0100
Organization: ratiosoft
Lines: 19
Message-ID: <fkt0sh5pev6dvb488ej02ka5lbo3as4rsr@4ax.com>
References: <qse0shdpl57rmf1a05ngd58de8dj0rt0f5@4ax.com> <ygapmbjaaet.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader01.eternal-september.org; posting-host="d618368683de53c2e581244ad5dec68e";
logging-data="1449421"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XqWE9vW5qQqP2vNApUg3b"
Cancel-Lock: sha1:kq/ZaKnxFdC92wFJPaMbETJeduQ=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Thu, 12 Jan 2023 21:11 UTC

Hallo Ralf,
>
> void
> Tcl_FindExecutable(
> const char *argv0) /* The value of the application's argv[0]
> * (native). */
> {
> TclInitSubsystems();
> TclpSetInitialEncodings();
> TclpFindExecutable(argv0);
> }
>
>So just do as the manpage says, get rid of the TclpSetInitialEncodings()
>and only call Tcl_FindExecutable(argv0).
spot on, that was it. Many thanks to you and to Dave and Harald of
course, too. Now my program crashes well into its main parts - but
that's a different story :(
Best regards
Helmut

Re: What is the correct way to initialize Tcl from a C program?

<6b4a9d53-2edd-458d-9e64-519cf533ce9fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10525&group=comp.lang.tcl#10525

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:548f:0:b0:50c:bbc4:12f7 with SMTP id pv15-20020ad4548f000000b0050cbbc412f7mr3176330qvb.87.1673589399590;
Thu, 12 Jan 2023 21:56:39 -0800 (PST)
X-Received: by 2002:ac8:4a03:0:b0:3b2:80fb:fd0 with SMTP id
x3-20020ac84a03000000b003b280fb0fd0mr133038qtq.40.1673589399402; Thu, 12 Jan
2023 21:56:39 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 12 Jan 2023 21:56:39 -0800 (PST)
In-Reply-To: <fkt0sh5pev6dvb488ej02ka5lbo3as4rsr@4ax.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a01:cb05:80b3:5c00:196f:bc1c:8db:300b;
posting-account=QVKs0woAAAA2s0yTpj3jArwE8jRk2SUp
NNTP-Posting-Host: 2a01:cb05:80b3:5c00:196f:bc1c:8db:300b
References: <qse0shdpl57rmf1a05ngd58de8dj0rt0f5@4ax.com> <ygapmbjaaet.fsf@akutech.de>
<fkt0sh5pev6dvb488ej02ka5lbo3as4rsr@4ax.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6b4a9d53-2edd-458d-9e64-519cf533ce9fn@googlegroups.com>
Subject: Re: What is the correct way to initialize Tcl from a C program?
From: sl1200...@gmail.com (Nicolas)
Injection-Date: Fri, 13 Jan 2023 05:56:39 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 87
 by: Nicolas - Fri, 13 Jan 2023 05:56 UTC

Le jeudi 12 janvier 2023 à 22:11:53 UTC+1, Helmut Giese a écrit :
> Hallo Ralf,
> >
> > void
> > Tcl_FindExecutable(
> > const char *argv0) /* The value of the application's argv[0]
> > * (native). */
> > {
> > TclInitSubsystems();
> > TclpSetInitialEncodings();
> > TclpFindExecutable(argv0);
> > }
> >
> >So just do as the manpage says, get rid of the TclpSetInitialEncodings()
> >and only call Tcl_FindExecutable(argv0).
> spot on, that was it. Many thanks to you and to Dave and Harald of
> course, too. Now my program crashes well into its main parts - but
> that's a different story :(
> Best regards
> Helmut
Hi, for what it worth (and maybe it can help) here's mine:

int Tk_AppInit(Tcl_Interp *interp) {
#ifdef WIN32
wchar_t* tmp = NULL;
#else
char* tmp = NULL;
#endif
size_t nFP_Length;
Tcl_DString ds4Argv;

/*
* Initialize packages
*/
if (Tcl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
if (Tk_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}

/*
this is the place to create the exit handler, I do it like that:
Tcl_CreateExitHandler(dL_exitHandler, x);
where x is a pointer of mine
*/

Tcl_SetSystemEncoding(interp, "utf-8");

/*many other stuff goes here...*/

return TCL_OK;
}

#ifdef WIN32
int wmain(int argc, wchar_t **argv) {
/*
use fflush(NULL) to reset everything in case of crashes
*/
fflush(NULL);
#else
int main (int argc, char* argv[]) {
#endif
int i, noprefs;
for (i = noprefs = 0; i < argc; i++) /* prescan ... */
{
#ifdef WIN32
if (wcscmp(argv[i], L"") && i == 1) {
#else
if (strcmp(argv[i], "") && i == 1) {
#endif
user_prefbuf = user_initloadpreferences_file(argv[i]);
argv[i] = user_prefbuf;
}
else if (i > 0) noprefs = 1;
}

#ifndef __MACOSX_CORE__
TclZipfs_AppHook(&argc, &argv);
#endif
//mainLoop
Tk_Main(argc, argv, Tk_AppInit);

exit(EXIT_SUCCESS);
}

Re: What is the correct way to initialize Tcl from a C program?

<fm83sh1hujfr9ckm3vouhr830u927dmiu2@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10526&group=comp.lang.tcl#10526

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: hgi...@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: What is the correct way to initialize Tcl from a C program?
Date: Fri, 13 Jan 2023 19:38:43 +0100
Organization: ratiosoft
Lines: 29
Message-ID: <fm83sh1hujfr9ckm3vouhr830u927dmiu2@4ax.com>
References: <qse0shdpl57rmf1a05ngd58de8dj0rt0f5@4ax.com> <ygapmbjaaet.fsf@akutech.de> <fkt0sh5pev6dvb488ej02ka5lbo3as4rsr@4ax.com> <6b4a9d53-2edd-458d-9e64-519cf533ce9fn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Info: reader01.eternal-september.org; posting-host="f5582b8434dfbdd061729e6012283926";
logging-data="1776170"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EmSb/LSWMF8hrayBpiUBz"
Cancel-Lock: sha1:VFo0+BAoMlmS2wEz2sBxb+8Mf0I=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Fri, 13 Jan 2023 18:38 UTC

Hello Nicolas,
>#ifdef WIN32
>int wmain(int argc, wchar_t **argv) {
> /*
> use fflush(NULL) to reset everything in case of crashes
> */
> fflush(NULL);
>#else
>int main (int argc, char* argv[]) {
>#endif
<snip>
> //mainLoop
> Tk_Main(argc, argv, Tk_AppInit);
>
> exit(EXIT_SUCCESS);
> }
calling Tcl_Main (or Tk_Main) is good if Tcl is the base of your
program. From the doc (Tcl_Main.html):
---
Tcl_Main can serve as the main program for Tcl-based shell
applications. A “shell application” is a program like tclsh or wish
that supports both interactive interpretation of Tcl and evaluation of
a script ...
---
My program, however, is a C program which occasionally needs to call
Tcl procs, so I needed a different approach - and with Ralf's
suggestion it worked.
Best regards
Helmut

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor