Author: ArcRiley Date: 2009-01-02 10:34:30 -0500 (Fri, 02 Jan 2009) New Revision: 1406
Modified: trunk/concordance/src/Core.c trunk/concordance/src/Core.h trunk/concordance/src/__init__.c Log: Core type creation now handled mostly proper, dir() no longer segfaults Modified: trunk/concordance/src/Core.c =================================================================== --- trunk/concordance/src/Core.c 2009-01-02 07:44:26 UTC (rev 1405) +++ trunk/concordance/src/Core.c 2009-01-02 15:34:30 UTC (rev 1406) @@ -25,10 +25,10 @@ /* cdef class Core : */ - char conCore_Doc[] = ""; + char conCore_Doc[] = "Test"; PyObject* - conCore_New(PyObject* self, PyObject* args) { + conCore_new(PyObject* self, PyObject* args) { conCoreObject* new; new = PyObject_New(conCoreObject, &conCore_Type); if (new != NULL) { @@ -73,20 +73,32 @@ return PyDict_SetItemString(self->attrs, name, v); } + static PyObject* + conCore_demo(conCoreObject* self, PyObject* args) { + if (!PyArg_ParseTuple(args, ":demo")) + return NULL; + Py_INCREF(Py_None); + return Py_None; + } + static PyMethodDef conCore_methods[] = { - { NULL, NULL } + { "demo", + (PyCFunction)conCore_demo, + METH_VARARGS, + PyDoc_STR("demo() -> None")}, + { NULL, NULL }, }; - static PyTypeObject conCore_Type = { + PyTypeObject conCore_Type = { PyVarObject_HEAD_INIT(NULL, 0) "concordance.Core", /*tp_name*/ sizeof(conCoreObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ /* methods */ - (destructor)conCore_dealloc, /*tp_dealloc*/ + (destructor) conCore_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ - (getattrfunc)0, /*tp_getattr*/ - (setattrfunc)conCore_setattr, /*tp_setattr*/ + (getattrfunc) 0, /*tp_getattr*/ + (setattrfunc) conCore_setattr, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ @@ -95,10 +107,11 @@ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ - (getattrofunc)conCore_getattro, /*tp_getattro*/ + (getattrofunc) conCore_getattro, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ + Py_TPFLAGS_DEFAULT | /*tp_flags*/ + Py_TPFLAGS_BASETYPE, 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ @@ -116,7 +129,7 @@ 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - 0, /*tp_new*/ + (newfunc) conCore_new, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ }; Modified: trunk/concordance/src/Core.h =================================================================== --- trunk/concordance/src/Core.h 2009-01-02 07:44:26 UTC (rev 1405) +++ trunk/concordance/src/Core.h 2009-01-02 15:34:30 UTC (rev 1406) @@ -27,9 +27,8 @@ PyObject *attrs; } conCoreObject; -static PyTypeObject conCore_Type; - PyObject* conCore_New (PyObject*, PyObject*); -extern char conCore_Doc[]; - +PyTypeObject conCore_Type; + #define conCoreObject_Check(v) (Py_TYPE(v) == &conCore_Type) + #endif Modified: trunk/concordance/src/__init__.c =================================================================== --- trunk/concordance/src/__init__.c 2009-01-02 07:44:26 UTC (rev 1405) +++ trunk/concordance/src/__init__.c 2009-01-02 15:34:30 UTC (rev 1406) @@ -23,10 +23,6 @@ #include "Core.h" static PyMethodDef concordanceMethods[] = { - { "Core", - conCore_New, - METH_VARARGS, - PyDoc_STR(conCore_Doc)}, { NULL, NULL } }; @@ -41,6 +37,12 @@ PyMODINIT_FUNC PyInit_concordance(void) { + PyObject* module; + if (PyType_Ready(&conCore_Type) < 0) return NULL; - return PyModule_Create(&concordanceModule); + module = PyModule_Create(&concordanceModule); + + Py_INCREF(&conCore_Type); + PyModule_AddObject(module, "Core", (PyObject*) &conCore_Type); + return module; } _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn