After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 559001 - Allow setting pytype wrapper class
Allow setting pytype wrapper class
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
Git master
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks: 559006
 
 
Reported: 2008-11-02 22:43 UTC by John Ehresman
Modified: 2009-03-24 20:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (1.18 KB, patch)
2008-11-02 22:44 UTC, John Ehresman
none Details | Review
updated patch (3.24 KB, patch)
2009-03-22 21:27 UTC, Mark Lee
none Details | Review

Description John Ehresman 2008-11-02 22:43:04 UTC
Patch allows setting the pytype wrapper for a gtype.  Implemented via setattr on  GType.pytype, but could be moved to another function.  Needed for the pybank prototype.
Comment 1 John Ehresman 2008-11-02 22:44:32 UTC
Created attachment 121834 [details] [review]
Patch
Comment 2 Mark Lee 2009-03-19 00:41:55 UTC
> --- gobject/pygtype.c	(revision 974)
> +++ gobject/pygtype.c	(working copy)
> @@ -83,6 +83,23 @@
>      return py_type;
>  }
>  
> +int
> +_wrap_g_type_wrapper__set_pytype(PyGTypeWrapper *self, PyObject* value, void *closure)
> +{

Shouldn't that be a static function?

I'd really like to see this get into pygobject.
Comment 3 Johan (not receiving bugmail) Dahlin 2009-03-20 22:08:48 UTC
We have a getter already, so it make sense to add a setter as well.
Comment 4 Mark Lee 2009-03-22 21:27:49 UTC
Created attachment 131142 [details] [review]
updated patch

Here's an updated version of John's patch with the following changes:

* ChangeLog entry
* consistent formatting
* made the setter a static function
* setter typechecks for None/type objects (throws a TypeError if invalid)
* added two testcases and associated helper methods
Comment 5 Johan (not receiving bugmail) Dahlin 2009-03-22 21:47:56 UTC
Comment on attachment 131142 [details] [review]
updated patch

I *think* that the reference counting is wrong here, if value is non NULL it should be Py_INCREF:ed and g_type_set_qdata_full's destroy notifier should Py_DECREF it.
Shouldn't matter too much in practice though, since the GTypes are likely to survive anyway.
Comment 6 Mark Lee 2009-03-22 22:38:25 UTC
Committed in revision 1030.