- Timestamp:
- 05/24/07 17:41:53 (2 years ago)
- Files:
-
- branches/py2nrn/src/nrnpython/nrnpy_hoc.cpp (modified) (4 diffs)
- branches/py2nrn/src/nrnpython/nrnpy_p2h.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/py2nrn/src/nrnpython/nrnpy_hoc.cpp
r34 r36 43 43 extern Symbol* nrnpy_pyobj_sym_; 44 44 extern PyObject* nrnpy_hoc2pyobject(Object*); 45 45 extern void nrnpy_pyobject_in_objptr(Object**, PyObject*); 46 46 /* 47 47 Because python types have so many methods, attempt to do all set and get … … 267 267 ho = *d; 268 268 //printf("Py2Nrn %lx %lx\n", (long)ho->ctemplate->sym, (long)nrnpy_pyobj_sym_); 269 if (ho->ctemplate->sym == nrnpy_pyobj_sym_) { 269 if (!ho) { 270 result = Py_BuildValue(""); 271 }else if (ho->ctemplate->sym == nrnpy_pyobj_sym_) { 270 272 result = nrnpy_hoc2pyobject(ho); 271 273 }else{ … … 539 541 hoc_pc = pcsav; 540 542 Object* ho = *hoc_objpop(); 541 if (ho->ctemplate->sym == nrnpy_pyobj_sym_) { 543 if (!ho) { 544 result = Py_BuildValue(""); 545 }else if (ho->ctemplate->sym == nrnpy_pyobj_sym_) { 542 546 result = nrnpy_hoc2pyobject(ho); 543 547 }else{ … … 658 662 Object** op; 659 663 op = hoc_objpop(); 660 if (PyArg_Parse(value, "O!", hocobject_type, &po) == 1) { 661 if (po->sym_) { 664 // if (PyArg_Parse(value, "O!", hocobject_type, &po) == 1) { 665 PyObject* po; 666 PyHocObject* pho; 667 if (PyArg_Parse(value, "O", &po) == 1) { 668 if (po == Py_None) { 669 hoc_obj_unref(*op); 670 *op = 0; 671 }else if (PyObject_TypeCheck(po, hocobject_type)) { 672 pho = (PyHocObject*)po; 673 if (pho->sym_) { 662 674 PyErr_SetString(PyExc_TypeError, "argument cannot be a hoc object intermediate"); 663 return -1; 675 return -1; 676 } 677 hoc_obj_ref(pho->ho_); 678 hoc_obj_unref(*op); 679 *op = pho->ho_; 680 }else{ // it is a PythonObject in hoc 681 nrnpy_pyobject_in_objptr(op, po); 664 682 } 665 hoc_obj_ref(po->ho_);666 hoc_obj_unref(*op);667 *op = po->ho_;668 683 }else{ 669 684 err = 1; branches/py2nrn/src/nrnpython/nrnpy_p2h.cpp
r24 r36 12 12 extern Object* hoc_new_object(Symbol*, void*); 13 13 PyObject* nrnpy_hoc2pyobject(Object*); 14 14 void nrnpy_pyobject_in_objptr(Object**, PyObject*); 15 15 extern Symbol* nrnpy_pyobj_sym_; 16 16 void (*nrnpy_py2n_component)(Object*, Symbol*, int, int); … … 59 59 PyObject* nrnpy_hoc2pyobject(Object* ho) { 60 60 return ((Py2Nrn*)ho->u.this_pointer)->po_; 61 } 62 63 void nrnpy_pyobject_in_objptr(Object** ho, PyObject* po) { 64 Py2Nrn* pn = new Py2Nrn(); 65 pn->po_ = po; 66 Py_INCREF(po); 67 pn->type_ = 1; 68 Object* on = hoc_new_object(nrnpy_pyobj_sym_, (void*)pn); 69 hoc_obj_ref(on); 70 hoc_obj_unref(*ho); 71 *ho = on; 61 72 } 62 73

