Example #1
0
static int t_lm_dict_set(t_lm *self, PyObject *key, PyObject *value)
{
    if (value == NULL)
        return PyDict_DelItem(self->dict, key);
    else
    {
        if (!PyObject_TypeCheck(value, &LinkType))
        {
            PyErr_SetObject(PyExc_TypeError, value);
            return -1;
        }
        else
        {
            t_link *link = (t_link *) value;
            t_link *head = (t_link *) self->head;
            PyObject *previousKey = head->nextKey;

            if (previousKey != Py_None && PyObject_Compare(previousKey, key))
            {
                t_link *previous = _t_lm__get(self, previousKey, 1, 0);

                if (!previous)
                    return -1;
                if (_t_link_setNextKey(previous, key, previousKey) < 0)
                    return -1;
            }

            PyDict_SetItem(self->dict, key, value);
            self->count += 1;

            if (previousKey == Py_None || PyObject_Compare(previousKey, key))
            {
                if (_t_link_setPreviousKey(link, previousKey, key) < 0)
                    return -1;
            }

            if (_t_link_setNextKey(link, Py_None, key) < 0)
                return -1;

            if (link->alias != Py_None)
            {
                if (self->aliases == Nil)
                {
                    Py_DECREF(self->aliases);
                    self->aliases = PyDict_New();
                }

                PyDict_SetItem(self->aliases, link->alias, key);
            }

            return 0;
        }
    }
}
Example #2
0
static int Nuitka_Method_tp_compare( struct Nuitka_MethodObject *a, struct Nuitka_MethodObject *b )
{
    if ( a->m_function->m_counter < b->m_function->m_counter )
    {
        return -1;
    }
    else if ( a->m_function->m_counter > b->m_function->m_counter )
    {
        return 1;
    }
    else if ( a->m_object == b->m_object )
    {
        return 0;
    }
    else if ( a->m_object == NULL )
    {
        return -1;
    }
    else if ( b->m_object == NULL )
    {
        return 1;
    }
    else
    {
        return PyObject_Compare( a->m_object, b->m_object );
    }
}
Example #3
0
static int Node_Contains(Node *self, PyObject *key)
{
    Node *s;
    
    s = Node__search(self, key);    
    return !PyObject_Compare(key, s->key);
}
Example #4
0
static Node * Node__search(Node *self, PyObject *key)
{
    /*
        Returns the corresponding node if found, the last checked otherwise
    */

    Node *n = self;
    Node *last = NULL;

    while (NOT_NONE(n)) {
        last = n;

        switch (PyObject_Compare(key, n->key)) {
            case -1:
                n = n->left;
                break;
            case 1:
                n = n->right;
                break;
            default:
                return n;
        }
    }

    return last;
}
Example #5
0
	_item_compare(avl_tree_Object * compare_arg, const void *lhs,
			  const void *rhs)
{
	PyObject *lo = objectAt(lhs), *ro = objectAt(rhs);
	PyObject *arglist;
	int rv = 0;

	if (compare_arg->compare_func == Py_None) {
		/* on error, the return value of PyObject_Compare() is undefined */
		rv = PyObject_Compare(lo, ro);
		compare_arg->compare_err = (PyErr_Occurred() != NULL);
	} else if ((arglist = Py_BuildValue("(OO)", lo, ro)) == NULL) {
		compare_arg->compare_err = 1;
	} else {
		PyObject *pyres;

		pyres = PyObject_CallObject(compare_arg->compare_func, arglist);
		Py_DECREF(arglist);
		if (pyres == NULL)
			compare_arg->compare_err = 1;
		else {
			rv = PyInt_AsLong(pyres);
			Py_DECREF(pyres);
			compare_arg->compare_err = 0;
		}
	}

	return rv;
}
static int
proxy_compare(PyObject *proxy, PyObject *v)
{
    UNWRAP_I(proxy);
    UNWRAP_I(v);
    return PyObject_Compare(proxy, v);
}
static void
cedit_init_pygtk (void)
{
	PyObject *gtk, *mdict, *version, *required_version;

	init_pygtk ();

	/* there isn't init_pygtk_check(), do the version
	 * check ourselves */
	gtk = PyImport_ImportModule("gtk");
	mdict = PyModule_GetDict(gtk);
	version = PyDict_GetItemString (mdict, "pygtk_version");
	if (!version)
	{
		PyErr_SetString (PyExc_ImportError,
				 "PyGObject version too old");
		return;
	}

	required_version = Py_BuildValue ("(iii)", 2, 4, 0); /* FIXME */

	if (PyObject_Compare (version, required_version) == -1)
	{
		PyErr_SetString (PyExc_ImportError,
				 "PyGObject version too old");
		Py_DECREF (required_version);
		return;
	}

	Py_DECREF (required_version);
}
Example #8
0
static int struct_compare(PyObject *rhs, PyObject *lhs)
{
	StructObject * const right = (StructObject*) rhs;
	StructObject * const left = (StructObject*) lhs;

	return PyObject_Compare(right->dict, left->dict);
}
/*
    def _verify(self):
        if ([r._generation for r in self._verify_ro]
            != self._verify_generations):
            self.changed(None)
*/
static int
_verify(verify *self)
{
    PyObject *changed_result;

    if (self->_verify_ro != NULL && self->_verify_generations != NULL)
    {
        PyObject *generations;
        int changed;

        generations = _generations_tuple(self->_verify_ro);
        if (generations == NULL)
            return -1;

        changed = PyObject_Compare(self->_verify_generations, generations);
        Py_DECREF(generations);
        if (PyErr_Occurred())
            return -1;

        if (changed == 0)
            return 0;
    }

    changed_result = PyObject_CallMethodObjArgs(OBJECT(self), strchanged,
                     Py_None, NULL);
    if (changed_result == NULL)
        return -1;

    Py_DECREF(changed_result);
    return 0;
}
Example #10
0
static int
wrapper_compare(wrapperobject *a, wrapperobject *b)
{
	if (a->descr == b->descr)
		return PyObject_Compare(a->self, b->self);
	else
		return (a->descr < b->descr) ? -1 : 1;
}
Example #11
0
static int
func_compare(PyFunctionObject *f, PyFunctionObject *g)
{
	int c;
	if (f->func_globals != g->func_globals)
		return (f->func_globals < g->func_globals) ? -1 : 1;
	if (f->func_defaults != g->func_defaults) {
		if (f->func_defaults == NULL)
			return -1;
		if (g->func_defaults == NULL)
			return 1;
		c = PyObject_Compare(f->func_defaults, g->func_defaults);
		if (c != 0)
			return c;
	}
	return PyObject_Compare(f->func_code, g->func_code);
}
Example #12
0
static int
code_compare(PyCodeObject *co, PyCodeObject *cp)
{
	int cmp;
	cmp = PyObject_Compare(co->co_name, cp->co_name);
	if (cmp) return cmp;
	cmp = co->co_argcount - cp->co_argcount;
	if (cmp) return (cmp<0)?-1:1;
	cmp = co->co_nlocals - cp->co_nlocals;
	if (cmp) return (cmp<0)?-1:1;
	cmp = co->co_flags - cp->co_flags;
	if (cmp) return (cmp<0)?-1:1;
	cmp = PyObject_Compare(co->co_code, cp->co_code);
	if (cmp) return cmp;
	cmp = PyObject_Compare(co->co_consts, cp->co_consts);
	if (cmp) return cmp;
	cmp = PyObject_Compare(co->co_names, cp->co_names);
	if (cmp) return cmp;
	cmp = PyObject_Compare(co->co_varnames, cp->co_varnames);
	if (cmp) return cmp;
	cmp = PyObject_Compare(co->co_freevars, cp->co_freevars);
	if (cmp) return cmp;
	cmp = PyObject_Compare(co->co_cellvars, cp->co_cellvars);
	return cmp;
}
Example #13
0
static int
code_compare(PyCodeObject *co, PyCodeObject *cp)
{
    int cmp;
    cmp = PyObject_Compare(co->co_name, cp->co_name);
    if (cmp) return cmp;
    cmp = co->co_argcount - cp->co_argcount;
    if (cmp) goto normalize;
    cmp = co->co_nlocals - cp->co_nlocals;
    if (cmp) goto normalize;
    cmp = co->co_flags - cp->co_flags;
    if (cmp) goto normalize;
    cmp = co->co_firstlineno - cp->co_firstlineno;
    if (cmp) goto normalize;
    cmp = PyObject_Compare(co->co_code, cp->co_code);
    if (cmp) return cmp;
    cmp = PyObject_Compare(co->co_consts, cp->co_consts);
    if (cmp) return cmp;
    cmp = PyObject_Compare(co->co_names, cp->co_names);
    if (cmp) return cmp;
    cmp = PyObject_Compare(co->co_varnames, cp->co_varnames);
    if (cmp) return cmp;
    cmp = PyObject_Compare(co->co_freevars, cp->co_freevars);
    if (cmp) return cmp;
    cmp = PyObject_Compare(co->co_cellvars, cp->co_cellvars);
    return cmp;

 normalize:
    if (cmp > 0)
        return 1;
    else if (cmp < 0)
        return -1;
    else
        return 0;
}
Example #14
0
_item_compare_default(avl_tree_Object * compare_arg, const void *lhs,
					  const void *rhs)
{
	int rv;

	rv = PyObject_Compare(objectAt(lhs), objectAt(rhs));
	compare_arg->compare_err = (PyErr_Occurred() != NULL);
	return rv;
}
static int
cell_compare(PyCellObject *a, PyCellObject *b)
{
	if (a->ob_ref == NULL) {
		if (b->ob_ref == NULL)
			return 0;
		return -1;
	} else if (b->ob_ref == NULL)
		return 1;
	return PyObject_Compare(a->ob_ref, b->ob_ref);
}
Example #16
0
void eActionMap::unbindAction(const std::string &context, ePyObject function)
{
	//eDebug("[eActionMap] unbind function from %s", context.c_str());
	for (std::multimap<long long int, eActionBinding>::iterator i(m_bindings.begin()); i != m_bindings.end(); ++i)
		if (i->second.m_fnc && (PyObject_Compare(i->second.m_fnc, function) == 0))
		{
			Py_DECREF(i->second.m_fnc);
			m_bindings.erase(i);
			return;
		}
	eFatal("[eActionMap] unbindAction with illegal python reference");
}
Example #17
0
/** Convert Python bool to Matlab bool
 * :param obj: Object to convert [Borrow reference]
 */
mxArray *mx_from_py_bool(PyObject* obj)
{
    mxArray *r;
    int dims[1] = { 1 };
    r = mxCreateNumericArray(1, dims, mxLOGICAL_CLASS, mxREAL);
    if (PyObject_Compare(obj, Py_True) == 0) {
        *((char*)mxGetData(r)) = 1;
    } else {
        *((char*)mxGetData(r)) = 0;
    }
    return r;
}
Example #18
0
int
PyObject_Cmp(PyObject *o1, PyObject *o2, int *result)
{
	int r;

	if (o1 == NULL || o2 == NULL) {
		null_error();
		return -1;
	}
	r = PyObject_Compare(o1, o2);
	if (PyErr_Occurred())
		return -1;
	*result = r;
	return 0;
}
Example #19
0
static int
cell_compare(PyCellObject *a, PyCellObject *b)
{
	/* Py3K warning for comparisons  */
	if (PyErr_WarnPy3k("cell comparisons not supported in 3.x",
					   1) < 0) {
		return -2;
	}

	if (a->ob_ref == NULL) {
		if (b->ob_ref == NULL)
			return 0;
		return -1;
	} else if (b->ob_ref == NULL)
		return 1;
	return PyObject_Compare(a->ob_ref, b->ob_ref);
}
Example #20
0
static int Node__insert(Node *self, PyObject *key)
{
    Node *p, *n;

    p = Node__search(self, key);

    if (!PyObject_Compare(p->key, key)) {
        PyErr_SetString(PyExc_KeyError, "key already present");
        return -1;
    } else {
        n = Node__new(self->ob_type, key, (Node *)Py_None, (Node *)Py_None, self);
        Node__update_bf_on_increase(p, Node__connect_to_parent(n, p), 0);
        Py_DECREF(n);
    }

    return 0;
}
Example #21
0
static Node * Node_search(Node *self, PyObject *args)
{
    Node *n;
    PyObject *key;

    if (!PyArg_ParseTuple(args, "O", &key))
        return NULL;

    n = Node__search(self, key);
    if (!PyObject_Compare(n->key, key)) {
        Py_INCREF(n);
        return n;
    } else {
        PyErr_SetString(PyExc_KeyError, "key not found");
        return NULL;
    }
}
static int PySilcUser_Compare(PyObject *self, PyObject *other)
{
    if (!PyObject_IsInstance(other, (PyObject *)&PySilcUser_Type)) {
        PyErr_SetString(PyExc_TypeError, "Can only compare with SilcUser.");
        return -1;
    }
    
    int result = 0;
    PyObject *user_name = PyObject_GetAttrString(self, "user_name");
    PyObject *other_name = PyObject_GetAttrString(self, "user_name");
    if (!user_name || !other_name) {
        PyErr_SetString(PyExc_RuntimeError, "Does not have user name");
        return -1;
    }
    
    result = PyObject_Compare(user_name, other_name);
    Py_DECREF(user_name);
    Py_DECREF(other_name);
    return result;
}
Example #23
0
static void
check_pygtk_version(void)
{
    PyObject *m, *d, *pygtk_version, *pygtk_required_version;

    m = PyImport_AddModule("gobject");
    d = PyModule_GetDict(m);
    pygtk_version = PyDict_GetItemString(d, "pygtk_version");
    pygtk_required_version = Py_BuildValue("(iii)",
                                           PYGTK_REQUIRED_MAJOR_VERSION,
                                           PYGTK_REQUIRED_MINOR_VERSION,
                                           PYGTK_REQUIRED_MICRO_VERSION);
    if (PyObject_Compare(pygtk_version, pygtk_required_version) < 0) {
        g_error("PyGTK %s required, but %s found.",
                PyString_AsString(PyObject_Repr(pygtk_required_version)),
                PyString_AsString(PyObject_Repr(pygtk_version)));
    }
    Py_DECREF(pygtk_required_version);
    return;
}
static void
cedit_init_pygtksourceview (void)
{
	PyObject *gtksourceview, *mdict, *version, *required_version;

	gtksourceview = PyImport_ImportModule("gtksourceview2");
	if (gtksourceview == NULL)
	{
		PyErr_SetString (PyExc_ImportError,
				 "could not import gtksourceview");
		return;
	}

	mdict = PyModule_GetDict (gtksourceview);
	version = PyDict_GetItemString (mdict, "pygtksourceview2_version");
	if (!version)
	{
		PyErr_SetString (PyExc_ImportError,
				 "PyGtkSourceView version too old");
		return;
	}

	required_version = Py_BuildValue ("(iii)", 0, 8, 0); /* FIXME */

	if (PyObject_Compare (version, required_version) == -1)
	{
		PyErr_SetString (PyExc_ImportError,
				 "PyGtkSourceView version too old");
		Py_DECREF (required_version);
		return;
	}

	Py_DECREF (required_version);

	/* Create a dummy 'gtksourceview' module to prevent
	 * loading of the old 'gtksourceview' modules that
	 * has conflicting symbols with the gtksourceview2 module.
	 * Raise an exception when trying to import it.
	 */
	PyImport_AppendInittab ("gtksourceview", old_gtksourceview_init);
}
Example #25
0
int
PySequence_Contains(PyObject *w, PyObject *v) /* v in w */
{
	int i, cmp;
	PyObject *x;
	PySequenceMethods *sq;

	if(PyType_HasFeature(w->ob_type, Py_TPFLAGS_HAVE_SEQUENCE_IN)) {
		sq = w->ob_type->tp_as_sequence;
	        if(sq != NULL && sq->sq_contains != NULL)
			return (*sq->sq_contains)(w, v);
	}
	
	/* If there is no better way to check whether an item is is contained,
	   do it the hard way */
	sq = w->ob_type->tp_as_sequence;
	if (sq == NULL || sq->sq_item == NULL) {
		PyErr_SetString(PyExc_TypeError,
			"'in' or 'not in' needs sequence right argument");
		return -1;
	}

	for (i = 0; ; i++) {
		x = (*sq->sq_item)(w, i);
		if (x == NULL) {
			if (PyErr_ExceptionMatches(PyExc_IndexError)) {
				PyErr_Clear();
				break;
			}
			return -1;
		}
		cmp = PyObject_Compare(v, x);
		Py_XDECREF(x);
		if (cmp == 0)
			return 1;
		if (PyErr_Occurred())
			return -1;
	}

	return 0;
}
Example #26
0
static int
GPIO_set_trigger(GPIO *self, PyObject *val, void *closure)
{
	char * trigger;
	char cdir;

	if (val == NULL) {
		PyErr_SetString(PyExc_TypeError,
			"Cannot delete attribute");
		return -1;
	}

	if ( setTrigger(self, val) == NULL )
		return -1;

	if ( PyObject_Compare(val, getTrigger( self ) ) != 0 ) {
		PyErr_SetString(PyExc_IOError, "setting trigger failed");
		return -1;
	}

	self->trigger = val;

	return 0;
}
Example #27
0
static int
proxy_compare(proxyobject *v, PyObject *w)
{
	return PyObject_Compare(v->dict, w);
}
Example #28
0
// takes one arg: Params
int smds_core_init(PyObject *self, PyObject *args, PyObject *kwds)
{
  static  char *kwlist[] = { "p", NULL };
  smds_core *c = (smds_core*)self;
  PyObject *p = NULL, *o = NULL;
  double dT, dX, channelR, capH, capW;
  int i;
  
  if (!ParamsType)
  {
    PyErr_SetString(PyExc_SystemError, "Unable to find Params type.");
    return -1;
  }

  seedRnd(Random(NULL), &c->rs);

  // p is borrowed
  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", kwlist, 
  					&PyInstance_Type, &p))
    return -1;
  {
    PyObject *cls = PyObject_GetAttrString(p, "__class__");
    if (!cls) return -1;
    i = PyObject_Compare(cls, ParamsType);
    Py_DECREF(cls);
    if (PyErr_Occurred()) return -1;
    if (i != 0)
    {
      PyErr_SetString(PyExc_TypeError,
           "Argument must be an instance of the correct smds.Params type.");
      return -1;
    }
  }

  c->ready = 0;
  c->num = c->hits = c->misses = 0;
  c->timeToHitDist = smds_AHL_extent_new(500);
  if (c->timeToHitDist == NULL)
  {
    PyErr_SetString(PyExc_MemoryError, "Memory allocation error.");
    return -1;
  }

  o = PyObject_GetAttrString(p, "dT");
  if (!o) return -1;
  dT = PyFloat_AsDouble(o);			// ns
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;

  o = PyObject_GetAttrString(p, "binWidth");
  if (!o) return -1;
  c->bw = PyFloat_AsDouble(o);			// ns
  c->stepsPerBin = (int)(c->bw/dT+0.5);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;

  o = PyObject_GetAttrString(p, "D");		// cm^2/s
  if (!o) return -1;
  dX = sqrt(6*PyFloat_AsDouble(o)*dT*1e-9)*1e7;	// nm
#ifdef CORE_FP
  c->stepsize = dX;
#endif
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "channelRadius");
  if (!o) return -1;
  channelR = PyFloat_AsDouble(o);
  c->channelRadius = (PosType)(channelR*channelR/dX/dX + ROUND);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "capWidth");
  if (!o) return -1;
  capW = PyFloat_AsDouble(o);
  c->capRadius = (PosType)((channelR + capW)*(channelR + capW)/dX/dX + ROUND);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "capHeight");
  if (!o) return -1;
  capH = PyFloat_AsDouble(o);
  c->capHeight = (PosType)(capH/dX+ROUND);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "initHeight");
  if (!o) return -1;
  c->initHeight = (PosType)((capH+PyFloat_AsDouble(o))/dX+ROUND);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "hitPoint");
  if (!o) return -1;
  c->hitPoint = (PosType)((capH-PyFloat_AsDouble(o))/dX+ROUND);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "timeToMiss");		// ms
  if (!o) return -1;
  c->stepsToMiss = (Int64)(PyFloat_AsDouble(o)*1e6/dT+0.5);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  c->ready = 1;
  return 0;
}
Example #29
0
/***
   Tabulate the next set of data.
     Takes an smds.Task.RTR
***/
PyObject * smds_IPCH_Tabulator_tabulate(PyObject *self, PyObject *args)
{
  smds_IPCH_Tabulator *t = (smds_IPCH_Tabulator*)self;
  PyObject *o;
  PyArrayObject *a;
  int i, pos = 0;		// _i_ is input pos, _pos_ is rebinned pos
  int numBins;
  Int16 *data;
  extent *p;

  if (!PyArg_ParseTuple(args, "O!", &PyInstance_Type, &o))  return NULL;
  // o is borrowed
  {
    PyObject *c = PyObject_GetAttrString(o, "__class__");
    if (!c) return NULL;
    i = PyObject_Compare(c, RTRType);
    Py_DECREF(c);
    if (PyErr_Occurred()) return NULL;
    if (i != 0)
    {
      PyErr_SetString(PyExc_TypeError, 
      		"Argument must be an instance of smds.Task.RTR.");
      return NULL;
    }
  }
  o = PyObject_GetAttrString(o, "data");
  // o is owned
  a = (PyArrayObject*)PyArray_ContiguousFromObject(o, PyArray_SHORT, 1, 1);
  if (!a)
  {
    Py_DECREF(o);
    return NULL;
  }

  numBins = a->dimensions[0];
  data = (Int16*)a->data;

  for (i=0; i < numBins; i++)
  {
    t->reBinPool += data[i];
    if (--t->reBinRemaining) continue;
    
    if (!t->in_event && t->reBinPool > t->threshold)   // Start event
      t->in_event = 1;
    
    if (t->in_event && t->reBinPool <= t->threshold)  // End event
    {
      t->in_event = 0;
      p = t->head;
      while (t->eventPool >= p->num)
      {
        if (p->next) p = p->next;
        else p->next = smds_IPCH_Tabulator_extent_new(500);
        t->eventPool -= p->num;
      }
      p->data[t->eventPool]++;
      t->eventPool = 0;
    }
    
    if (t->in_event)
      t->eventPool += t->reBinPool;
    
    t->reBinPool = 0;				// Increment rebin pos
    t->reBinRemaining = t->reBin;
    pos++;
  }
  
  Py_DECREF(o);
  Py_RETURN_NONE;
}
Example #30
0
// takes one arg: Params
int smds_core_init(PyObject *self, PyObject *args, PyObject *kwds)
{
  static  char *kwlist[] = { "p", NULL };
  smds_core *c = (smds_core*)self;
  PyObject *p = NULL, *o = NULL;
  double dT, dX, channelR, capH, capW, potA, potB, potC, mobility;
#ifdef CORE_CHARGE
  double chargeRadius;
#endif  
  int i;
  
  if (!ParamsType)
  {
    PyErr_SetString(PyExc_SystemError, "Unable to find Params type.");
    return -1;
  }

  seedRnd(Random(NULL), &c->rs);

  // p is borrowed
  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", kwlist, 
  					&PyInstance_Type, &p))
    return -1;
  {
    PyObject *cls = PyObject_GetAttrString(p, "__class__");
    if (!cls) return -1;
    i = PyObject_Compare(cls, ParamsType);
    Py_DECREF(cls);
    if (PyErr_Occurred()) return -1;
    if (i != 0)
    {
      PyErr_SetString(PyExc_TypeError,
           "Argument must be an instance of the correct smds.Params type.");
      return -1;
    }
  }

  c->ready = 0;
  c->dur = 0;

  o = PyObject_GetAttrString(p, "macro_dT");
  if (!o) return -1;
  dT = PyFloat_AsDouble(o);			// ns
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;

  o = PyObject_GetAttrString(p, "binWidth");
  if (!o) return -1;
  c->bw = PyFloat_AsDouble(o);			// us
  c->stepsPerBin = (int)(c->bw*1e3/dT+0.5);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;

  o = PyObject_GetAttrString(p, "numMolecs");
  if (!o) return -1;
  c->numMolecs = PyInt_AsLong(o);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;

  o = PyObject_GetAttrString(p, "D");		// cm^2/s
  if (!o) return -1;
  dX = sqrt(6*PyFloat_AsDouble(o)*dT*1e-9)*1e7;	// nm
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "concentration");
  if (!o) return -1;
  c->size = (PosType)(pow(c->numMolecs/PyFloat_AsDouble(o), 1./3.) * 1e3
                      / dX) / 2;
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;

  o = PyObject_GetAttrString(p, "micro_dT");		// ns
  if (!o) return -1;
  c->microSteps = (int)(dT / PyFloat_AsDouble(o) + 0.5);
  dT /= c->microSteps;
  c->microStepSize = 1/sqrt(c->microSteps);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;

  free(c->m);  c->m = (smds_molec*)malloc(sizeof(smds_molec)*c->numMolecs);
  if (!c->m)
  {
    PyErr_SetString(PyExc_MemoryError, "Memory allocation error.");
    return -1;
  }
  for (i=0; i < c->numMolecs; i++)
    smds_core_create_molec(c->m+i, c, 0);

  o = PyObject_GetAttrString(p, "channelRadius");
  if (!o) return -1;
  channelR = PyFloat_AsDouble(o);
  c->channelR = (PosType)(channelR/dX);
  c->channelRadius = (PosType)(channelR*channelR/dX/dX);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "capWidth");
  if (!o) return -1;
  capW = PyFloat_AsDouble(o);
  c->capRadius = (PosType)((channelR + capW)*(channelR + capW)/dX/dX);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "capHeight");
  if (!o) return -1;
  capH = PyFloat_AsDouble(o);
  c->capHeight = (PosType)(capH/dX);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "hitPoint");
  if (!o) return -1;
  c->hitPoint = (PosType)((capH-PyFloat_AsDouble(o))/dX);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "vestibuleRadius");
  if (!o) return -1;
  c->vestibuleRadius = (PosType)(PyFloat_AsDouble(o)/dX);
  c->vestibuleRadius *= c->vestibuleRadius;
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "vestibulePos");
  if (!o) return -1;
  c->vestibuleTop = c->capHeight - (PosType)(PyFloat_AsDouble(o)/dX);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "vestibuleHeight");
  if (!o) return -1;
  c->vestibuleDepth = c->vestibuleTop - (PosType)(PyFloat_AsDouble(o)/dX);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "potExtent");
  if (!o) return -1;
  c->potExtent = -PyFloat_AsDouble(o)/dX;
  c->threshold = c->potExtent*c->potExtent * 64;
  if (c->threshold < 1) c->threshold = 1;
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "potA");
  if (!o) return -1;
  potA = PyFloat_AsDouble(o) * 1e-3;
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "potB");
  if (!o) return -1;
  potB = PyFloat_AsDouble(o) * 1e-3;
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  
  o = PyObject_GetAttrString(p, "potC");
  if (!o) return -1;
  potC = PyFloat_AsDouble(o) * 1e-3;
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;

  o = PyObject_GetAttrString(p, "mobility");		// nm^2 / Vs
  if (!o) return -1;
  mobility = PyFloat_AsDouble(o) / (dX*dX);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;

#ifdef CORE_CHARGE
  o = PyObject_GetAttrString(p, "chargeRadius");	// nm
  if (!o) return -1;
  chargeRadius = (PyFloat_AsDouble(o)/dX);
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
  for (i=0; i < N_CHARGES; i++)
  {
    c->charge_x[i] = chargeRadius * cos(2*M_PI/N_CHARGES * i);
    c->charge_y[i] = chargeRadius * sin(2*M_PI/N_CHARGES * i);
  }

  o = PyObject_GetAttrString(p, "charge");	// effective, in electrons
  if (!o) return -1;
  // v = mu k z e / r^2
  // k = 9e9 N m^2/C^2 == 9e9 V m / C
  // e = 1.6-19 C
  // The conversion of k into nm and dT into s cancel.
  c->vCharge = mobility * 9e9 * 1.6e-19 * dT * PyFloat_AsDouble(o);
  // divide this by r^2 to get the impulse distance for the given step.
  Py_DECREF(o);
  if (PyErr_Occurred()) return -1;
#endif

  c->vA = mobility * dT * 1e-9 * potA / c->potExtent;	// < 0
  c->vB = mobility * dT * 1e-9 * (potB-potA) /
                                     (c->vestibuleDepth - c->capHeight);
  c->vC = mobility * dT * 1e-9 * (potC-potB) /
                                     (c->hitPoint - c->vestibuleDepth);
  
  c->ready = 1;
  return 0;
}