<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
Jim Fulton wrote:
<blockquote cite="mid:FCC9D291-6F66-4CE4-8FF9-10F9EC82D699@zope.com"
 type="cite">The only type-safety mechanism for a CObject is it's
identity.&nbsp; If you want to make sure you're using the foomodule api,
make sure the address of the CObject is the same as the address of the
api object exported by the module.</blockquote>
That doesn't help.&nbsp; Here's a program that crashes the interpreter,
something I shouldn't be able to do from pure Python:<br>
<blockquote>import _socket<br>
import cStringIO<br>
cStringIO.cStringIO_CAPI = _socket.CAPI<br>
  <br>
import cPickle<br>
s = cPickle.dumps([1, 2, 3])<br>
</blockquote>
How can cPickle determine that cStringIO.cStringIO_CAPI is legitimate?<br>
<br>
<blockquote cite="mid:FCC9D291-6F66-4CE4-8FF9-10F9EC82D699@zope.com"
 type="cite">That would break backward compatibility. Are you proposing
this for Python 3?<br>
</blockquote>
<br>
I'm proposing this for Python 3.1.&nbsp; My understanding is that breaking
backwards compatibility is still on the table, which is why I wrote the
patch the way I did.&nbsp; If we have to preserve the existing API, I still
think we should add new APIs and deprecate the old ones.<br>
<br>
It's worth noting that there's been demand for this for a long time.&nbsp;
Check out this comment from Include/datetime.h:<br>
<blockquote>#define PyDateTime_IMPORT \<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import("datetime",
\<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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IC)<br>
*/<br>
</blockquote>
That was checked in by Tim Peters on 2004-06-20, r36214.&nbsp; (At least, in
the py3k/trunk branch; I'd hope it would be the same revision number in
other branches.)<br>
<br>
<br>
/larry/
</body>
</html>