Commit 59479580 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Get rid of runtime/capi.h

parent 0809576c
......@@ -21,7 +21,6 @@
#include "core/types.h"
#include "core/util.h"
#include "gc/collector.h"
#include "runtime/capi.h"
#include "runtime/dict.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -15,7 +15,6 @@
#ifndef PYSTON_CAPI_TYPES_H
#define PYSTON_CAPI_TYPES_H
#include "runtime/capi.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -34,7 +34,6 @@
#include "core/stats.h"
#include "core/thread_utils.h"
#include "core/util.h"
#include "runtime/capi.h"
#include "runtime/generator.h"
#include "runtime/import.h"
#include "runtime/inline/boxing.h"
......
......@@ -38,7 +38,6 @@
#include "core/stats.h"
#include "core/types.h"
#include "core/util.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -33,7 +33,6 @@
#include "core/types.h"
#include "core/util.h"
#include "gc/collector.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -27,7 +27,6 @@
#include "core/ast.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/capi.h"
#include "runtime/classobj.h"
#include "runtime/file.h"
#include "runtime/ics.h"
......
......@@ -21,7 +21,6 @@
#include "capi/typeobject.h"
#include "core/threading.h"
#include "core/types.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <dlfcn.h>
#include <fcntl.h>
#include <stdarg.h>
#include <string.h>
......@@ -1458,56 +1457,6 @@ extern "C" char* PyModule_GetFilename(PyObject* m) noexcept {
return PyString_AsString(fileobj);
}
BoxedModule* importCExtension(const std::string& full_name, const std::string& last_name, const std::string& path) {
void* handle = dlopen(path.c_str(), RTLD_NOW);
if (!handle) {
// raiseExcHelper(ImportError, "%s", dlerror());
fprintf(stderr, "%s\n", dlerror());
exit(1);
}
assert(handle);
std::string initname = "init" + last_name;
void (*init)() = (void (*)())dlsym(handle, initname.c_str());
char* error;
if ((error = dlerror()) != NULL) {
// raiseExcHelper(ImportError, "%s", error);
fprintf(stderr, "%s\n", error);
exit(1);
}
assert(init);
// Let the GC know about the static variables.
uintptr_t bss_start = (uintptr_t)dlsym(handle, "__bss_start");
uintptr_t bss_end = (uintptr_t)dlsym(handle, "_end");
RELEASE_ASSERT(bss_end - bss_start < 100000, "Large BSS section detected - there maybe something wrong");
// only track void* aligned memory
bss_start = (bss_start + (sizeof(void*) - 1)) & ~(sizeof(void*) - 1);
bss_end -= bss_end % sizeof(void*);
gc::registerPotentialRootRange((void*)bss_start, (void*)bss_end);
char* packagecontext = strdup(full_name.c_str());
char* oldcontext = _Py_PackageContext;
_Py_PackageContext = packagecontext;
(*init)();
_Py_PackageContext = oldcontext;
free(packagecontext);
checkAndThrowCAPIException();
BoxedDict* sys_modules = getSysModulesDict();
Box* s = boxString(full_name);
Box* _m = sys_modules->d[s];
RELEASE_ASSERT(_m, "dynamic module not initialized properly");
assert(_m->cls == module_cls);
BoxedModule* m = static_cast<BoxedModule*>(_m);
m->setattr("__file__", boxString(path), NULL);
return m;
}
Box* BoxedCApiFunction::callInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpec argspec,
Box* arg1, Box* arg2, Box* arg3, Box** args,
const std::vector<BoxedString*>* keyword_names) {
......
// Copyright (c) 2014-2015 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef PYSTON_RUNTIME_CAPI_H
#define PYSTON_RUNTIME_CAPI_H
#include <string>
namespace pyston {
class Box;
class BoxedModule;
BoxedModule* importCExtension(const std::string& full_name, const std::string& last_name, const std::string& path);
void checkAndThrowCAPIException();
void throwCAPIException() __attribute__((noreturn));
struct ExcInfo;
void setCAPIException(const ExcInfo& e);
#define fatalOrError(exception, message) \
do { \
if (CONTINUE_AFTER_FATAL) \
PyErr_SetString((exception), (message)); \
else \
Py_FatalError((message)); \
} while (0)
}
#endif
......@@ -13,7 +13,6 @@
// limitations under the License.
#include "codegen/compvars.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h"
#include "runtime/rewrite_args.h"
#include "runtime/types.h"
......
......@@ -14,6 +14,7 @@
#include "runtime/import.h"
#include <dlfcn.h>
#include <limits.h>
#include "llvm/Support/FileSystem.h"
......@@ -23,7 +24,6 @@
#include "codegen/parser.h"
#include "codegen/unwinding.h"
#include "core/ast.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h"
namespace pyston {
......@@ -777,6 +777,56 @@ Box* impLoadDynamic(Box* _name, Box* _pathname, Box* _file) {
return importCExtension(name->s(), shortname, pathname->s());
}
BoxedModule* importCExtension(const std::string& full_name, const std::string& last_name, const std::string& path) {
void* handle = dlopen(path.c_str(), RTLD_NOW);
if (!handle) {
// raiseExcHelper(ImportError, "%s", dlerror());
fprintf(stderr, "%s\n", dlerror());
exit(1);
}
assert(handle);
std::string initname = "init" + last_name;
void (*init)() = (void (*)())dlsym(handle, initname.c_str());
char* error;
if ((error = dlerror()) != NULL) {
// raiseExcHelper(ImportError, "%s", error);
fprintf(stderr, "%s\n", error);
exit(1);
}
assert(init);
// Let the GC know about the static variables.
uintptr_t bss_start = (uintptr_t)dlsym(handle, "__bss_start");
uintptr_t bss_end = (uintptr_t)dlsym(handle, "_end");
RELEASE_ASSERT(bss_end - bss_start < 100000, "Large BSS section detected - there maybe something wrong");
// only track void* aligned memory
bss_start = (bss_start + (sizeof(void*) - 1)) & ~(sizeof(void*) - 1);
bss_end -= bss_end % sizeof(void*);
gc::registerPotentialRootRange((void*)bss_start, (void*)bss_end);
char* packagecontext = strdup(full_name.c_str());
char* oldcontext = _Py_PackageContext;
_Py_PackageContext = packagecontext;
(*init)();
_Py_PackageContext = oldcontext;
free(packagecontext);
checkAndThrowCAPIException();
BoxedDict* sys_modules = getSysModulesDict();
Box* s = boxString(full_name);
Box* _m = sys_modules->d[s];
RELEASE_ASSERT(_m, "dynamic module not initialized properly");
assert(_m->cls == module_cls);
BoxedModule* m = static_cast<BoxedModule*>(_m);
m->setattr("__file__", boxString(path), NULL);
return m;
}
Box* impGetSuffixes() {
BoxedList* list = new BoxedList;
// For now only add *.py
......
......@@ -21,6 +21,7 @@ namespace pyston {
extern "C" Box* import(int level, Box* from_imports, llvm::StringRef module_name);
extern Box* importModuleLevel(llvm::StringRef module_name, Box* globals, Box* from_imports, int level);
BoxedModule* importCExtension(const std::string& full_name, const std::string& last_name, const std::string& path);
}
#endif
......@@ -13,7 +13,6 @@
// limitations under the License.
#include "core/types.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -24,7 +24,6 @@
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/capi.h"
#include "runtime/float.h"
#include "runtime/inline/boxing.h"
#include "runtime/long.h"
......
......@@ -27,7 +27,6 @@
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/capi.h"
#include "runtime/inline/boxing.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
......@@ -39,7 +39,6 @@
#include "core/types.h"
#include "gc/collector.h"
#include "gc/heap.h"
#include "runtime/capi.h"
#include "runtime/classobj.h"
#include "runtime/dict.h"
#include "runtime/file.h"
......
......@@ -17,7 +17,6 @@
#include <llvm/Support/raw_ostream.h>
#include "gc/collector.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h"
namespace pyston {
......
......@@ -29,7 +29,6 @@
#include "core/types.h"
#include "core/util.h"
#include "gc/collector.h"
#include "runtime/capi.h"
#include "runtime/dict.h"
#include "runtime/long.h"
#include "runtime/objmodel.h"
......
......@@ -24,7 +24,6 @@
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
#include "runtime/util.h"
......
......@@ -32,7 +32,6 @@
#include "core/stats.h"
#include "core/types.h"
#include "gc/collector.h"
#include "runtime/capi.h"
#include "runtime/classobj.h"
#include "runtime/complex.h"
#include "runtime/dict.h"
......
......@@ -962,6 +962,19 @@ AST* unboxAst(Box* b);
// Our default for tp_alloc:
extern "C" PyObject* PystonType_GenericAlloc(BoxedClass* cls, Py_ssize_t nitems) noexcept;
void checkAndThrowCAPIException();
void throwCAPIException() __attribute__((noreturn));
struct ExcInfo;
void setCAPIException(const ExcInfo& e);
#define fatalOrError(exception, message) \
do { \
if (CONTINUE_AFTER_FATAL) \
PyErr_SetString((exception), (message)); \
else \
Py_FatalError((message)); \
} while (0)
// A descriptor that you can add to your class to provide instances with a __dict__ accessor.
// Classes created in Python get this automatically, but builtin types (including extension types)
// are supposed to add one themselves. type_cls and function_cls do this, for example.
......
......@@ -15,7 +15,6 @@
#include "runtime/util.h"
#include "core/options.h"
#include "runtime/capi.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment