This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Two corrects for weakref docs
Type: Stage:
Components: Documentation Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: fdrake, rhettinger, sdeibel
Priority: normal Keywords:

Created on 2002-07-25 16:59 by sdeibel, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
weak.diff rhettinger, 2002-08-07 15:39 Patch to libweakref.tex
Messages (4)
msg11690 - (view) Author: Stephan R.A. Deibel (sdeibel) Date: 2002-07-25 16:59
The Python manual (I'm looking at 2.2.1, but I think
it's true since 2.1) omits one detail for creating weak
references on extension types:

It fails to indicate that the tp_flags field of the
PyTypeObject has to
have Py_TPFLAGS_HAVE_WEAKREFS added into it as well. 
Without this, it doesn't work.

So the second code block would read as follows:

PyTypeObject PyInstance_Type = {
    PyObject_HEAD_INIT(&PyType_Type)
    0,   
    "module.instance",

    /* Lots of stuff omitted for brevity... */

    Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
    NULL, /*doc*/
    0L,0L,0L,
    offsetof(PyInstanceObject, in_weakreflist) /*
tp_weaklistoffset */
  
    /* Possibly more stuff here... */
};
  
----------------------
 
You may also want to emphasize that the in_weakreflist
field that is added should be initialized in the object
constructor.  Since you show the code in
instance_dealloc(), it might make sense to show the
allocation function too, with the code that sets the
in_weakreflist field to NULL.

Yea, I know this should be obvious and it is mentioned
in the first
paragraph, but somehow I got confused into thinking it
would be initialize for me because there wasn't a
seperate code example.

Here is another code block that could be shown before
the instance_dealloc block, to make this clear for
dummies like me:

static PyObject *
instance_new() {

  /* Code removed for brevity */

  self = (PyInstance_Object
*)PyObject_NEW(PyInstance_Object,
                                          
&PyInstance_Type);
  if (self == NULL)
    return NULL;
  
  /* More code removed for brevity */
  
  self->in_weakreflist = NULL;

  return (PyObject *) self;
}

Hope that helps...

- Stephan

------------------------------------------------------------------------
 
Wing IDE for Python                         
Archaeopteryx Software, Inc
www.wingide.com                              Take Flight!

msg11691 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-08-07 15:39
Logged In: YES 
user_id=80475

Documentation patch attached for Fred's approval for 
both 2.2 and 2.3.
msg11692 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2002-08-07 15:52
Logged In: YES 
user_id=3066

Only one comment:  Py_TPFLAGS_HAVE_WEAKREFS should be marked
as \constant{Py_TPFLAGS_HAVE_WEAKREFS}.  Thanks!
msg11693 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-08-07 16:22
Logged In: YES 
user_id=80475

Added \constant{}.
Committed as libweakref.tex versions 1.18 and 1.17.6.1. 
Marking as fixed and closing bug.
History
Date User Action Args
2022-04-10 16:05:31adminsetgithub: 36927
2002-07-25 16:59:20sdeibelcreate