]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Save static pointer to malloc'ed buffer
authorGuido van Rossum <guido@python.org>
Wed, 5 Oct 1994 12:25:12 +0000 (12:25 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 5 Oct 1994 12:25:12 +0000 (12:25 +0000)
Modules/config.c.in

index 7843f14ca7fda26fa47e35c4c7f8bdd213c45a4c..981a19f8d202effaf58957022e494cf42317ced5 100644 (file)
@@ -149,27 +149,27 @@ extern char *getenv();
 char *
 getpythonpath()
 {
-#ifdef macintosh
-       return PYTHONPATH;
-#else /* !macintosh */
        char *path = getenv("PYTHONPATH");
        char *defpath = PYTHONPATH;
-       char *buf;
+       static char *buf = NULL;
        char *p;
        int n;
 
-       if (path == 0 || *path == '\0')
-               return defpath;
+       if (path == NULL)
+               path = "";
        n = strlen(path) + strlen(defpath) + 2;
+       if (buf != NULL) {
+               free(buf);
+               buf = NULL;
+       }
        buf = malloc(n);
        if (buf == NULL)
-               return path; /* XXX too bad -- but not likely */
+               fatal("not enough memory to copy module search path");
        strcpy(buf, path);
        p = buf + strlen(buf);
        *p++ = DELIM;
        strcpy(p, defpath);
        return buf;
-#endif /* !macintosh */
 }