Commit 5cc0a09a authored by Boxiang Sun's avatar Boxiang Sun

Add api_test extension for test C API, initially add PySet_Size test.

I think we need a place to test new added C API. And Pyston missed
PySet_Size implementation(already declared it). Add and test it.
parent 120eb242
......@@ -969,7 +969,7 @@ bench_exceptions:
zsh -c 'ulimit -m $(MAX_MEM_KB); time ./bench_exceptions'
rm bench_exceptions
TEST_EXT_MODULE_NAMES := basic_test descr_test slots_test
TEST_EXT_MODULE_NAMES := basic_test descr_test slots_test type_test api_test
TEST_EXT_MODULE_SRCS := $(TEST_EXT_MODULE_NAMES:%=test/test_extension/%.c)
TEST_EXT_MODULE_OBJS := $(TEST_EXT_MODULE_NAMES:%=test/test_extension/%.pyston.so)
......
......@@ -457,6 +457,14 @@ extern "C" int PySet_Add(PyObject* set, PyObject* key) noexcept {
}
}
extern "C" Py_ssize_t PySet_Size(PyObject* anyset) noexcept {
if (!PyAnySet_Check(anyset)) {
PyErr_BadInternalCall();
return -1;
}
BoxedSet* self = (BoxedSet*)anyset;
return self->s.size();
}
Box* setClear(BoxedSet* self) {
RELEASE_ASSERT(isSubclass(self->cls, set_cls), "");
......
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/build/lib.linux-x86_64-2.7/basic_test.so
COMMAND python setup.py build --build-lib ${CMAKE_CURRENT_BINARY_DIR}/build/lib.linux-x86_64-2.7
DEPENDS basic_test.c descr_test.c slots_test.c type_test.c
DEPENDS basic_test.c descr_test.c slots_test.c type_test.c api_test.c
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/basic_test.pyston.so
COMMAND ${CMAKE_BINARY_DIR}/pyston setup.py build --build-lib ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS pyston copy_stdlib copy_libpyston basic_test.c descr_test.c slots_test.c type_test.c
DEPENDS pyston copy_stdlib copy_libpyston basic_test.c descr_test.c slots_test.c type_test.c api_test.c
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(ext_cpython DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/build/lib.linux-x86_64-2.7/basic_test.so)
......
#include <Python.h>
static PyObject *
set_size(PyObject *self, PyObject *so)
{
return Py_BuildValue("i", PySet_Size(so));
}
static PyMethodDef TestMethods[] = {
{"set_size", set_size, METH_O, "Get set size by PySet_Size." },
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC
initapi_test(void)
{
PyObject *m;
m = Py_InitModule("api_test", TestMethods);
if (m == NULL)
return;
}
......@@ -7,6 +7,7 @@ extensions = [
Extension("descr_test", sources = ["descr_test.c"]),
Extension("slots_test", sources = ["slots_test.c"]),
Extension("type_test", sources = ["type_test.c"]),
Extension("api_test", sources = ["api_test.c"]),
]
def relpath(fn):
......
......@@ -539,3 +539,4 @@ calling __hash__
False
set([1L]) set([1]) set([1]) set([1L])
set([1])
4
......@@ -269,3 +269,8 @@ print {1, 1L}, {1L, 1}, set([1, 1L]), set([1L, 1])
s = {1}
s.add(1L)
print s
from api_test import set_size
s = set([1, 2, 3, 4])
print(set_size(s))
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