Issue1098985
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.
Created on 2005-01-09 16:28 by greg_ball, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Files | ||||
---|---|---|---|---|
File name | Uploaded | Description | Edit | |
marshal.patch | greg_ball, 2005-01-11 18:12 | context diff of new marshal.c against 2.4 version |
Messages (9) | |||
---|---|---|---|
msg23895 - (view) | Author: Gregory H. Ball (greg_ball) | Date: 2005-01-09 16:28 | |
It would be nice if set objects could be marshalled. This would require extra code in marshal.c very similar to that for dictionaries. Since sets can be pickled I guess this is not critical. |
|||
msg23896 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2005-01-11 00:17 | |
Logged In: YES user_id=80475 Guido, what to you think about the OP's request? The need does not arise for pyc files and pickling takes care of general persistance needs. Is there something to be gained? |
|||
msg23897 - (view) | Author: Guido van Rossum (gvanrossum) * | Date: 2005-01-11 00:25 | |
Logged In: YES user_id=6380 As the OP says, it would be nice. Let's see if he or someone else wants it bad enough to submit a patch. |
|||
msg23898 - (view) | Author: Tim Peters (tim.peters) * | Date: 2005-01-11 01:51 | |
Logged In: YES user_id=31435 Just noting that some people prefer to use marshal instead of pickle because unmarshaling can't end up executing arbitrary user-defined code (but unpickling can, via arbitrary module importing and arbitrary construction of objects of user- defined classes). That's really not one of marshal's goals, though, so "would be nice" is as strong as it gets. |
|||
msg23899 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2005-01-11 03:03 | |
Logged In: YES user_id=80475 Then let things be nice for all. See Python marshal.c 1.81. |
|||
msg23900 - (view) | Author: Gregory H. Ball (greg_ball) | Date: 2005-01-11 18:12 | |
Logged In: YES user_id=11365 Thanks for the quick work Raymond! I see you have added a test case too. I am attaching a patch which implements this change in a different style, based on setobject.h publicly advertising that v->data is a dictionary for any set object v. It passes the new test code (and the rest of the test suite). |
|||
msg23901 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2005-01-11 20:39 | |
Logged In: YES user_id=80475 I prefer the existing code though it is slightly inefficient (creating an intermediate tuple whose size is known in advance and whose elements are known to be unique). IMO, this beats breaking the encapsulation of the set object structure (knowledge of the v->data field and knowledge that the dict values are set to True). I want to preserve the option for sets to be possibly re-implemented without an underlying dictionary. Someday, I'll craft a C API for sets. It will include an ability to build-up the values element by element. P.S. The code in the attachment needs error checking for the call to PyDict_SetItem(). |
|||
msg23902 - (view) | Author: Gregory H. Ball (greg_ball) | Date: 2005-01-13 13:34 | |
Logged In: YES user_id=11365 Thanks for the review Raymond. Since the code has only one known user, going for efficiency over encapsulation would certainly be premature optimisation. Regarding the P.S.; I modelled the loop building up the dictionary on the case TYPE_DICT code above. PyErr_Occurred() below the loop should catch anything that goes wrong, albeit not immediately - or can you see some way to break this? If so, that's a bug in the dictionary code, surely. |
|||
msg23903 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2005-01-13 21:14 | |
Logged In: YES user_id=80475 The code in TYPE_DICT is not a good coding practice. I don't think it should be changed, but the style should not get propagated elsewhere. BTW, if sets gets a C API for Py2.5, go ahead and resubmit your patch. At that point, saving a few bytes may become worth it. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:09 | admin | set | github: 41414 |
2005-01-09 16:28:13 | greg_ball | create |