diff options
Diffstat (limited to 'main/expect/22-segfault-with-stubs.patch')
-rw-r--r-- | main/expect/22-segfault-with-stubs.patch | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/main/expect/22-segfault-with-stubs.patch b/main/expect/22-segfault-with-stubs.patch new file mode 100644 index 00000000000..3fd825575b4 --- /dev/null +++ b/main/expect/22-segfault-with-stubs.patch @@ -0,0 +1,71 @@ +Author: Sergei Golovan <sgolovan@debian.org> +Description: This dirty hack fixes segfaults if Tcl is built with stubs + and Expect is used directly from C program. +Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=588817 +Example: + #include <stdio.h> + #include <tcl8.5/expect.h> + int main() + { + FILE *pipe; + char *some_command = "uname"; + char datum; + pipe = exp_popen(some_command); + if (pipe == NULL) return 1; + while ((datum = getc (pipe)) != EOF) + printf("%c",datum); + } +Example: + #include <stdio.h> + #include "expect.h" + main() + { + int fd = 0; + fd = exp_spawnl("echo", "echo", "Hello User: Whats up?", (char*) 0); + switch (exp_expectl(fd, exp_regexp, "ser:", 1, exp_end)) { + case 1: { + printf("GOT ser:\n"); + break; + } + default: { + printf("DEFAULT\n"); + return 1; + } + } + printf("Normal Exit\n"); + return 0; + } + +--- a/exp_clib.c ++++ b/exp_clib.c +@@ -117,7 +117,11 @@ + #include <stdlib.h> /* for malloc */ + #endif + +-#include <tcl.h> ++#define ckalloc(x) Tcl_Alloc(x) ++#define ckfree(x) Tcl_Free(x) ++extern char *Tcl_ErrnoMsg(int err); ++extern char *Tcl_Alloc(unsigned int size); ++extern void Tcl_Free(char *ptr); + #include "expect.h" + #define TclRegError exp_TclRegError + +@@ -392,7 +396,7 @@ + FAIL("regexp too big"); + + /* Allocate space. */ +- r = (regexp *)ckalloc(sizeof(regexp) + (unsigned)rcstate->regsize); ++ r = (regexp *)malloc(sizeof(regexp) + (unsigned)rcstate->regsize); + if (r == NULL) + FAIL("out of space"); + +@@ -402,7 +406,7 @@ + rcstate->regcode = r->program; + regc(MAGIC, rcstate); + if (reg(0, &flags, rcstate) == NULL) { +- ckfree ((char*) r); ++ free ((char*) r); + return(NULL); + } + |