longjmp问题 [英] longjmp issue
问题描述
从窗口过程调用longjmp到跳转到WinMain是否安全?
跳转是从wndproc到WinMain,通过DispatchMessage。
我很担心在DispatchMessage中是否发生了一些内存泄漏或资源泄漏
。
Is it safe to call longjmp from a window procedure to jump to WinMain?
The jump is from wndproc to WinMain , through DispatchMessage.
I''m worried about is there some memory leaks or resource leaks occured
in DispatchMessage.
推荐答案
CHU Run-min写道:
CHU Run-min wrote:
从窗口过程调用longjmp到跳转到WinMain是否安全?
跳转是从wndproc到WinMain,通过DispatchMessage。
我'我担心在DispatchMessage中是否有一些内存泄漏或资源泄漏。
Is it safe to call longjmp from a window procedure to jump to WinMain?
The jump is from wndproc to WinMain , through DispatchMessage.
I''m worried about is there some memory leaks or resource leaks occured
in DispatchMessage.
对不起,这听起来像是胡言乱语;一个新闻组
适合你的实现(平台,操作系统,编译器......)
可能是一个更好的地方询问具体细节。
>
从标准
的角度来看,有什么可以告诉setjmp / longjmp:
,----
| 7.13非局部跳跃< setjmp.h>
|
| 1标题< setjmp.h>定义宏setjmp,
|并声明一个函数和一个类型,对于
|绕过正常的函数调用并返回
|纪律.207)
+ ---
| 207)这些函数对于处理
|非常有用在低级别遇到异常情况
|程序的功能。
+ ---
|
|
| 2声明的类型是
| jmp_buf
|这是一个适合持有
|的数组类型恢复呼叫环境所需的信息。
|调用setjmp宏的环境
|包含足以拨打
|的信息longjmp函数将执行返回正确的
|阻止和调用该块,它被称为
|递归。它不包括
|的状态浮点状态标志,打开文件或
|抽象机器的任何其他组件。
|
| 3未指定setjmp是宏还是
|用外部链接声明的标识符。如果一个宏
|定义被禁止以访问实际的
|函数或程序定义外部标识符
|使用名称setjmp,行为是未定义的。
|
` ----
所以,你可以失去开放文件,即使对于
自动变量等也有内存泄漏。如果这对你来说足够安全...
干杯
Michael
-
电子邮件:我的是/ at / gmx / dot / de地址。
Sorry, this sounds like gibberish round here; a newsgroup
appropriate to your implementation (platform, os, compiler, ...)
may be a better place to ask for specifics.
What can be told about setjmp/longjmp from the standard
point of view:
,----
| 7.13 Nonlocal jumps <setjmp.h>
|
| 1 The header <setjmp.h> defines the macro setjmp,
| and declares one function and one type, for
| bypassing the normal function call and return
| discipline.207)
+---
| 207) These functions are useful for dealing with
| unusual conditions encountered in a low-level
| function of a program.
+---
|
|
| 2 The type declared is
| jmp_buf
| which is an array type suitable for holding the
| information needed to restore a calling environment.
| The environment of a call to the setjmp macro
| consists of information sufficient for a call to the
| longjmp function to return execution to the correct
| block and invocation of that block, were it called
| recursively. It does not include the state of the
| floating-point status flags, of open files, or of
| any other component of the abstract machine.
|
| 3 It is unspecified whether setjmp is a macro or an
| identifier declared with external linkage. If a macro
| definition is suppressed in order to access an actual
| function, or a program defines an external identifier
| with the name setjmp, the behavior is undefined.
|
`----
So, you can lose open files, have memory leaks even for
auto variables, etc. If this is safe enough for you...
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
"褚润民 < CH ******* @ gmail.com>写了
"CHU Run-min" <ch*******@gmail.com> wrote
从窗口过程调用longjmp到跳转到WinMain是否安全?
跳转是从wndproc到WinMain,通过DispatchMessage。
我很担心DispatchMessage中是否存在内存泄漏或资源泄漏。
Is it safe to call longjmp from a window procedure to jump to WinMain?
The jump is from wndproc to WinMain , through DispatchMessage.
I''m worried about is there some memory leaks or resource leaks occured
in DispatchMessage.
从理论上说它应该没关系 - 你真的在问它是否可以
从间接调用的例程中调用longjmp()。它是--setjmp()应该
保存堆栈状态,即使后续调用是通过指针
但是我不相信Windows系统不会搞砸东西
的方式 - 我不认为这是一个特别好的主意。
Theoretically it should be OK - really you are asking whether it is OK to
call longjmp() from an indirectly-called routine. It is - setjmp() ought to
save the stack state, even if the subsequent call is via a pointer
However I wouldn''t trust the Windows system not to mess up something along
the way - I don''t think it is a particularly good idea.
2006-02-05, Malcolm< re ******* @ btinternet.com>写道:
On 2006-02-05, Malcolm <re*******@btinternet.com> wrote:
" CHU Run-min" < CH ******* @ gmail.com>写了
"CHU Run-min" <ch*******@gmail.com> wrote
从窗口过程调用longjmp到跳转到WinMain是否安全?
跳转是从wndproc到WinMain,通过DispatchMessage。
我很担心在DispatchMessage中是否会发生内存泄漏或资源泄漏。
Is it safe to call longjmp from a window procedure to jump to WinMain?
The jump is from wndproc to WinMain , through DispatchMessage.
I''m worried about is there some memory leaks or resource leaks occured
in DispatchMessage.
从理论上讲它应该没问题 - 你真的在问它是否可以
从间接调用的例程中调用longjmp()。它是--setjmp()应该保存堆栈状态,即使后续调用是通过指针
但是我不相信Windows系统不会弄乱一些东西
方式 - 我不认为这是一个特别好的主意。
Theoretically it should be OK - really you are asking whether it is OK to
call longjmp() from an indirectly-called routine. It is - setjmp() ought to
save the stack state, even if the subsequent call is via a pointer
However I wouldn''t trust the Windows system not to mess up something along
the way - I don''t think it is a particularly good idea.
更多关于主题的问题是longjmp可以导致资源的事实
泄漏 - 即如果调用链中的例程被longjmp跳过
分配了一个资源,并打算稍后在
$中释放它b $ b相同的代码块
jmp_buf j;
c(){longjmp(j,1); }
b(){void * p = malloc(8); C();自由(); }
a(){int r; if(!(r = setjmp(j))){b(); } $
main(){a(); }
主叫a;一个电话b; b调用malloc; b叫c; c跳回到;
p永远不会被释放。
内存当然不是唯一可以泄露的资源 - 另一个
$ b标准C中的$ b示例是打开的文件。
The more on-topic issue is the fact that longjmp can cause resource
leaks - i.e. if a routine that is in the call chain which is "skipped"
by longjmp has allocated a resource, and intends to free it later in the
same block of code
jmp_buf j;
c() { longjmp(j,1); }
b() { void *p = malloc(8); c(); free(); }
a() { int r; if(!(r=setjmp(j))) { b(); } }
main() { a(); }
main calls a; a calls b; b calls malloc; b calls c; c jumps back to a;
p is never freed.
Memory is of course not the only resource that can be leaked - another
example in standard C is open files.
这篇关于longjmp问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!