EMBEDDERS--REQUEST FOR COMMENTS:

Michael Hudson mwh21 at cam.ac.uk
Wed May 24 03:56:23 EDT 2000


Courageous <jkraska1 at san.rr.com> writes:

> My presumption is that, in this instance, I don't increase the
> reference count on the valuem because I've ascertained that it's a
> primitive (string, int, et al).
> 
> However, if this were a real object, I'd be doing an INCREF() on it,
> and furthermore, would have to take care to do a DECREF() on what I
> was assigning over.
> 
> Do I have this right?

No.  In this case, PyString_AsString returns a pointer to the internal
buffer of the string object.  Look here:

/*const*/ char *
PyString_AsString(op)
	register PyObject *op;
{
	if (!PyString_Check(op)) {
		PyErr_BadInternalCall();
		return NULL;
	}
	return ((PyStringObject *)op) -> ob_sval;
}

You need to make a copy somehow... strdup, or somesuch presumably.

Cheers,
M.

-- 
  Two things I learned for sure during a particularly intense acid
  trip in my own lost youth: (1) everything is a trivial special case
  of something else; and, (2) death is a bunch of blue spheres.
                                             -- Tim Peters, 1 May 1998



More information about the Python-list mailing list