~ubuntu-branches/ubuntu/karmic/python3.0/karmic

« back to all changes in this revision

Viewing changes to Python/import.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-16 17:18:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090216171823-1d5cm5qnnjvmnzzm
Tags: 3.0.1-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
959
959
                PySys_WriteStderr("# wrote %s\n", cpathname);
960
960
}
961
961
 
 
962
static void
 
963
update_code_filenames(PyCodeObject *co, PyObject *oldname, PyObject *newname)
 
964
{
 
965
        PyObject *constants, *tmp;
 
966
        Py_ssize_t i, n;
 
967
 
 
968
        if (PyUnicode_Compare(co->co_filename, oldname))
 
969
                return;
 
970
 
 
971
        tmp = co->co_filename;
 
972
        co->co_filename = newname;
 
973
        Py_INCREF(co->co_filename);
 
974
        Py_DECREF(tmp);
 
975
 
 
976
        constants = co->co_consts;
 
977
        n = PyTuple_GET_SIZE(constants);
 
978
        for (i = 0; i < n; i++) {
 
979
                tmp = PyTuple_GET_ITEM(constants, i);
 
980
                if (PyCode_Check(tmp))
 
981
                        update_code_filenames((PyCodeObject *)tmp,
 
982
                                              oldname, newname);
 
983
        }
 
984
}
 
985
 
 
986
static int
 
987
update_compiled_module(PyCodeObject *co, char *pathname)
 
988
{
 
989
        PyObject *oldname, *newname;
 
990
 
 
991
        if (!PyUnicode_CompareWithASCIIString(co->co_filename, pathname))
 
992
                return 0;
 
993
 
 
994
        newname = PyUnicode_FromString(pathname);
 
995
        if (newname == NULL)
 
996
                return -1;
 
997
 
 
998
        oldname = co->co_filename;
 
999
        Py_INCREF(oldname);
 
1000
        update_code_filenames(co, oldname, newname);
 
1001
        Py_DECREF(oldname);
 
1002
        Py_DECREF(newname);
 
1003
        return 1;
 
1004
}
962
1005
 
963
1006
/* Load a source module from a given file and return its module
964
1007
   object WITH INCREMENTED REFERENCE COUNT.  If there's a matching
999
1042
                fclose(fpc);
1000
1043
                if (co == NULL)
1001
1044
                        return NULL;
 
1045
                if (update_compiled_module(co, pathname) < 0)
 
1046
                        return NULL;
1002
1047
                if (Py_VerboseFlag)
1003
1048
                        PySys_WriteStderr("import %s # precompiled from %s\n",
1004
1049
                                name, cpathname);
2849
2894
imp_find_module(PyObject *self, PyObject *args)
2850
2895
{
2851
2896
        char *name;
2852
 
        PyObject *path = NULL;
 
2897
        PyObject *ret, *path = NULL;
2853
2898
        if (!PyArg_ParseTuple(args, "es|O:find_module",
2854
2899
                              Py_FileSystemDefaultEncoding, &name,
2855
2900
                              &path))
2856
2901
                return NULL;
2857
 
        return call_find_module(name, path);
 
2902
        ret = call_find_module(name, path);
 
2903
        PyMem_Free(name);
 
2904
        return ret;
2858
2905
}
2859
2906
 
2860
2907
static PyObject *
3243
3290
        0,                         /*tp_print*/
3244
3291
        0,                         /*tp_getattr*/
3245
3292
        0,                         /*tp_setattr*/
3246
 
        0,                         /*tp_compare*/
 
3293
        0,                         /*tp_reserved*/
3247
3294
        0,                         /*tp_repr*/
3248
3295
        0,                         /*tp_as_number*/
3249
3296
        0,                         /*tp_as_sequence*/