import os.path

I moved `import` to its own file, because I think that imports are going to end up being quite a beast. To progress, you really need to understand CPython's `import.c`, which is hard to read because it deals with all sorts of platform-specific code among all the "real logic".

I left `importFrom` and `importStart` in `objmodel.cpp` because they felt more like object manipulation and getattr'ing.

Anyway, the point of this commit was to import `os.path`. It turns out this is pretty simple. When you import `os.path`, you import and run `os` first. Then, `os` adds `os.path` to `sys.modules` (choosing the module dynamically in a platform-specific way). Finally, you try to import `os.path`, see that it is already in `sys.modules`, and use that.
updated this


On Thu, Aug 28, 2014 at 2:47 PM, Kevin Modzelewski <notifications@github.com
> wrote:

> In src/runtime/import.cpp:
>
> > +    size_t periodIndex = name->rfind('.');
> > +    if (periodIndex != std::string::npos) {
> > +        std::string parent_name(*name, 0, periodIndex);
> > +        parent_module = import(&parent_name);
> > +    }
> > +
> > +    BoxedDict* sys_modules = getSysModulesDict();
> > +    Box* s = boxStringPtr(name);
> > +    if (sys_modules->d.find(s) != sys_modules->d.end())
> > +        return sys_modules->d[s];
> > +
> > +    BoxedList* path_list;
> > +    if (parent_module == NULL) {
> > +        path_list = getSysPath();
> > +    } else {
> > +        path_list = static_cast<BoxedList*>(parent_module->getattr("__path__", NULL));
>
> Does the __path__ attribute always exist? If it doesn't, this line will
> return NULL and then segfault in a few lines -- for example import os.asdf
> does that for me.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/dropbox/pyston/pull/141/files#r16870004>.
>