Changeset 30
- Timestamp:
- 05/22/07 16:36:02 (2 years ago)
- Files:
-
- branches/pygetsetcall/src/nrnpython/nrnpy_hoc.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/pygetsetcall/src/nrnpython/nrnpy_hoc.cpp
r28 r30 39 39 extern PyObject* nrnpy_cas(PyObject*, PyObject*); 40 40 extern int section_object_seen; 41 extern int vector_capacity(void*); 41 42 /* 42 43 Because python types have so many methods, attempt to do all set and get … … 656 657 } 657 658 659 static Symbol* sym_vec_x; 660 static Symbol* sym_mat_x; 661 662 static int araychk(Arrayinfo* a, PyHocObject* po, int ix) { 663 assert(a->nsub > po->nindex_); 664 int n; 665 // Hoc Vector and Matrix are special cases because the sub[] 666 // do not get filled in til just before hoc_araypt is called. 667 // at least check the vector 668 if (po->sym_ == sym_vec_x) { 669 n = vector_capacity(po->ho_->u.this_pointer); 670 }else if (po->sym_ == sym_mat_x) { 671 if (ix >= 0) return 0; 672 }else{ 673 n = a->sub[po->nindex_]; 674 } 675 if (ix < 0 || n <= ix) { 676 //printf("ix=%d nsub=%d nindex=%d sub[nindex]=%d\n", ix, a->nsub, po->nindex_, a->sub[po->nindex_]); 677 char e[200]; 678 sprintf(e, "%s%s%s", po->ho_?hoc_object_name(po->ho_):"", 679 (po->ho_ && po->sym_) ? "." : "", 680 po->sym_ ? po->sym_->name : ""); 681 PyErr_SetString(PyExc_IndexError, e); 682 return -1; 683 } 684 return 0; 685 } 686 658 687 /* 659 688 Had better be an array. But the same ambiguity as with getattro … … 672 701 assert(po->type_ == 3); 673 702 Arrayinfo* a = hocobj_aray(po->sym_, po->ho_); 703 if (araychk(a, po, ix)) { 704 return NULL; 705 } 674 706 if (a->nsub - 1 > po->nindex_) { // another intermediate 675 707 PyHocObject* ponew = intermediate(po, po->sym_, ix); … … 726 758 if (a->nsub - 1 != po->nindex_) { 727 759 PyErr_SetString(PyExc_TypeError, "wrong number of subscripts"); 760 return -1; 761 } 762 if (araychk(a, po, i)) { 728 763 return -1; 729 764 } … … 1026 1061 PyModule_AddObject(m, "HocObject", (PyObject*)hocobject_type); 1027 1062 1063 Symbol* s; 1064 s = hoc_lookup("Vector"); assert(s); 1065 sym_vec_x = hoc_table_lookup("x", s->u.ctemplate->symtable); assert(sym_vec_x); 1066 s = hoc_lookup("Matrix"); assert(s); 1067 sym_mat_x = hoc_table_lookup("x", s->u.ctemplate->symtable); assert(sym_mat_x); 1068 1028 1069 #ifdef WITH_NUMPY 1029 1070

