Commit 67e746b9 authored by Marius Wachtler's avatar Marius Wachtler

Add SHA256/512 module support.

Add basic support for C API attr members
parent 36192fb0
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
typedef ssize_t Py_ssize_t; typedef ssize_t Py_ssize_t;
#define Py_FORMAT_PARSETUPLE(func,p1,p2) #define Py_FORMAT_PARSETUPLE(func,p1,p2)
#define Py_GCC_ATTRIBUTE(x) __attribute__(x) #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
#define HAVE_LONG_LONG 1
#define PY_LONG_LONG long long
// Pyston change: the rest of these have just been copied from CPython's pyport.h, in an arbitrary order: // Pyston change: the rest of these have just been copied from CPython's pyport.h, in an arbitrary order:
...@@ -126,6 +129,13 @@ typedef ssize_t Py_ssize_t; ...@@ -126,6 +129,13 @@ typedef ssize_t Py_ssize_t;
#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE) #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
#endif #endif
#ifndef Py_LL
#define Py_LL(x) x##LL
#endif
#ifndef Py_ULL
#define Py_ULL(x) Py_LL(x##U)
#endif
#endif /* Py_PYPORT_H */ #endif /* Py_PYPORT_H */
...@@ -268,7 +268,7 @@ SRCS := $(MAIN_SRCS) $(STDLIB_SRCS) ...@@ -268,7 +268,7 @@ SRCS := $(MAIN_SRCS) $(STDLIB_SRCS)
STDLIB_OBJS := stdlib.bc.o stdlib.stripped.bc.o STDLIB_OBJS := stdlib.bc.o stdlib.stripped.bc.o
STDLIB_RELEASE_OBJS := stdlib.release.bc.o STDLIB_RELEASE_OBJS := stdlib.release.bc.o
STDMODULE_SRCS := errnomodule.c shamodule.c md5.c md5module.c $(EXTRA_STDMODULE_SRCS) STDMODULE_SRCS := errnomodule.c shamodule.c sha256module.c sha512module.c md5.c md5module.c $(EXTRA_STDMODULE_SRCS)
STDMODULE_SRCS := $(addprefix ../lib_python/2.7_Modules/,$(STDMODULE_SRCS)) STDMODULE_SRCS := $(addprefix ../lib_python/2.7_Modules/,$(STDMODULE_SRCS))
# The stdlib objects have slightly longer dependency chains, # The stdlib objects have slightly longer dependency chains,
......
...@@ -225,7 +225,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) { ...@@ -225,7 +225,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) {
RELEASE_ASSERT(cls->tp_weaklistoffset == 0, ""); RELEASE_ASSERT(cls->tp_weaklistoffset == 0, "");
RELEASE_ASSERT(cls->tp_iter == NULL, ""); RELEASE_ASSERT(cls->tp_iter == NULL, "");
RELEASE_ASSERT(cls->tp_iternext == NULL, ""); RELEASE_ASSERT(cls->tp_iternext == NULL, "");
RELEASE_ASSERT(cls->tp_members == NULL, "");
RELEASE_ASSERT(cls->tp_base == NULL, ""); RELEASE_ASSERT(cls->tp_base == NULL, "");
RELEASE_ASSERT(cls->tp_dict == NULL, ""); RELEASE_ASSERT(cls->tp_dict == NULL, "");
RELEASE_ASSERT(cls->tp_descr_get == NULL, ""); RELEASE_ASSERT(cls->tp_descr_get == NULL, "");
...@@ -254,13 +253,13 @@ extern "C" int PyType_Ready(PyTypeObject* cls) { ...@@ -254,13 +253,13 @@ extern "C" int PyType_Ready(PyTypeObject* cls) {
// tp_basicsize, tp_itemsize // tp_basicsize, tp_itemsize
// tp_doc // tp_doc
if (cls->tp_methods) {
PyMethodDef* method = cls->tp_methods; for (PyMethodDef* method = cls->tp_methods; method && method->ml_name; ++method) {
while (method->ml_name) { cls->giveAttr(method->ml_name, new BoxedMethodDescriptor(method));
auto desc = new BoxedMethodDescriptor(method); }
cls->giveAttr(method->ml_name, desc);
method++; for (PyMemberDef* member = cls->tp_members; member && member->name; ++member) {
} cls->giveAttr(member->name, new BoxedMemberDescriptor(member));
} }
if (cls->tp_getset) { if (cls->tp_getset) {
......
...@@ -695,6 +695,10 @@ static Box* _handleClsAttr(Box* obj, Box* attr) { ...@@ -695,6 +695,10 @@ static Box* _handleClsAttr(Box* obj, Box* attr) {
bool rtn = reinterpret_cast<bool*>(obj)[member_desc->offset]; bool rtn = reinterpret_cast<bool*>(obj)[member_desc->offset];
return boxBool(rtn); return boxBool(rtn);
} }
case BoxedMemberDescriptor::INT: {
int rtn = reinterpret_cast<int*>(obj)[member_desc->offset/sizeof(int)];
return boxInt(rtn);
}
default: default:
RELEASE_ASSERT(0, "%d", member_desc->type); RELEASE_ASSERT(0, "%d", member_desc->type);
} }
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
extern "C" void initerrno(); extern "C" void initerrno();
extern "C" void init_sha(); extern "C" void init_sha();
extern "C" void init_sha256();
extern "C" void init_sha512();
extern "C" void init_md5(); extern "C" void init_md5();
namespace pyston { namespace pyston {
...@@ -734,7 +736,9 @@ void setupRuntime() { ...@@ -734,7 +736,9 @@ void setupRuntime() {
initerrno(); initerrno();
init_sha(); init_sha();
// init_md5(); init_sha256();
init_sha512();
init_md5();
setupSysEnd(); setupSysEnd();
......
...@@ -324,12 +324,14 @@ public: ...@@ -324,12 +324,14 @@ public:
enum MemberType { enum MemberType {
BOOL = T_BOOL, BOOL = T_BOOL,
BYTE = T_BYTE, BYTE = T_BYTE,
INT = T_INT,
OBJECT = T_OBJECT, OBJECT = T_OBJECT,
} type; } type;
int offset; int offset;
BoxedMemberDescriptor(MemberType type, int offset) : Box(member_cls), type(type), offset(offset) {} BoxedMemberDescriptor(MemberType type, int offset) : Box(member_cls), type(type), offset(offset) {}
BoxedMemberDescriptor(PyMemberDef* member) : Box(member_cls), type((MemberType)member->type), offset(member->offset) {}
}; };
// TODO is there any particular reason to make this a Box, ie a python-level object? // TODO is there any particular reason to make this a Box, ie a python-level object?
......
import hashlib
#for m in [hashlib.md5(), hashlib.sha1(), hashlib.sha256(), hashlib.sha512()]:
for m in [hashlib.sha256(), hashlib.sha512()]:
m.update("pyston")
print m.digest_size, m.hexdigest()
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