1. ariovistus
  2. pyd

Commits

ariovistus  committed 49e3a9f

Py_DECREF caused link to break.
now it doesn't.
dedicate a suite of unittests for deimos headers. really necessary, as this
is some weird voodoo, getting stuff to link sans object file

  • Participants
  • Parent commits 6bc121e
  • Branches default

Comments (0)

Files changed (4)

File examples/deimos_unittests/makefile

View file
+PYD_DIR = ../../infrastructure/
+PYTHON_2_7 = -version=Python_2_7_Or_Later \
+             -version=Python_2_6_Or_Later \
+	     -version=Python_2_5_Or_Later \
+	     -version=Python_2_4_Or_Later \
+	     -L-lpython2.7
+DC = dmd -unittest -property -debug -gc
+
+all: object_.x
+
+clean:
+	rm -f *.x
+	rm -f *.o
+
+%.x: %.d
+	$(DC) $(PYTHON_2_7) $< -of$@  -I$(PYD_DIR)

File examples/deimos_unittests/object_.d

View file
+import deimos.python.object;
+
+unittest {
+    // breaks linking?
+    Py_XINCREF(Py_None());
+    // breaks linking?
+    Py_XDECREF(cast(PyObject*) null);
+}
+
+
+void main() {}

File examples/pyind/pyind.d

View file
 
 import std.stdio;
 import pyd.pyd;
-//import deimos.python.unicodeobject;
 import deimos.python.Python: Py_ssize_t, Py_Initialize;
-import deimos.python.pyport;
-
-//import python: Py_ssize_t,Py_Initialize;
 import pyd.embedded;
 
 
 }
 
 void main() {
-    import deimos.python.object;
-    Py_XINCREF(Py_None());
     // simple expressions can be evaluated
     int i = py_eval!int("1+2", "office");
     writeln(i);

File infrastructure/deimos/python/object.d

View file
 
 // D translation of C macro:
 int PyType_Check()(PyObject* op) {
-    return PyObject_TypeCheck(op, PyType_Type_p);
+    return PyObject_TypeCheck(op, &PyType_Type);
 }
 // D translation of C macro:
 int PyType_CheckExact()(PyObject* op) {
-    return op.ob_type == PyType_Type_p;
+    return op.ob_type == &PyType_Type;
 }
 
 int PyType_Ready(PyTypeObject*);
     // EMN: this is a horrible idea because it takes forever to figure out 
     //      what's going on if this is being called from within the garbage 
     //      collector.
-    assert (op.ob_refcnt >= 0);
+    
+    // EMN: if we do keep it, don't change the assert! 
+    // assert(0) or assert(condition) mess up linking somehow.
+    if(op.ob_refcnt < 0) assert (0, "refcount negative");
     if(op.ob_refcnt != 0) {
         // version(PY_REF_DEBUG) _Py_NegativeRefcount(__FILE__, __LINE__, cast(PyObject*)op);
     }else {
 
 __gshared PyObject _Py_NoneStruct;
 
-PyObject* Py_None()() {
-    return &_Py_NoneStruct;
+Borrowed!PyObject* Py_None()() {
+    return borrowed(&_Py_NoneStruct);
 }
 /* Rich comparison opcodes */
 enum int Py_LT = 0;