From: Barry S. <ba...@ba...> - 2015-09-24 09:45:14
|
This is proving harder to change then I expected. This is because Py::Object( NULL ) most work and be assignable etc. I came across a case where I needed the ability to return a NULL as Py:Object() which is why the Python 3 has that API. Until there are more use cases to consider I want to leave the code as it is. Barry On Friday 18 September 2015 09:47:05 Barry Scott wrote: > Thanks for the feedback. I hope to have something to test next week. > > Barry > > > On 12 Sep 2015, at 20:59, Vivian De Smedt <vd...@gm...> wrote: > > > > Hi Barry, > > > > I understand and share your concerns, backward compatibility is important. > > > > Personally I prefer you second solution based on Py::ObjectAllowNull. > > I think construct object that could accept NULL should be rare and easily > > identifiable in a code. > > > > Best regards, > > Vivian. > > > > > > > > > > Le mar. 1 sept. 2015 à 18:13, Vivian De Smedt <vd...@gm... > > <mailto:vd...@gm...>> a écrit : Hi Barry, > > > > Thanks for your detailed analysis. I'm currently in Holidays in Scotland. > > I'll read your mail carefully next week. > > > > Best regards, > > Vivian > > > > > > On Tuesday, September 1, 2015, Barry Scott <ba...@ba... > > <mailto:ba...@ba...>> wrote: Vivian, > > > > I think I have 2 patches to work on from you. > > > > * Add the ability to react to PySequence_DelItem() > > * Make py2 and py3 handling of Py::Object( NULL ) consistent > > > > I was worried that someone might be relying on being able to use > > detect the NULL value in sequence_ass_item(). Given that Py2 cannot > > call the sequence_ass_item() because of the NULL check. I will take > > your patch to all sequence_ass_del(). It is a nice API. > > > > My feeling that it should be possible to create Py::Object from NULL. > > But there are clearly cases when its not a reasonable thing to do. > > > > I wondering what the API should look like. > > > > Adding another bool to the c’tor is possible. > > > > Py::Object( PyObject *, bool owner, bool accept_null ); > > Then have validate() change behaviour on accept_null. > > > > Or use two classes: > > > > * a Py::Object which Allows Null > > * a Py::Object which Disallows Null > > > > Take the current Py::Object and rename to Py::ObjectAllowNull. > > > > class Py::ObjectAllowNull; > > with validate() { return true; } > > add new predicate hasObject() { return p != NULL; } > > > > Then derive Py::Object from Py::ObjectAllowNull. > > > > class Py::Object(Py::ObjectALllowNull); > > with validate() { return p!=NULL; } > > > > All the existing classes like Py::Int, Py::List derive from Py::Object > > that rejects Null. > > > > With the accept_null c’tor it would be possible to have a Py::Int that > > accepts NULL. > > > > Any thoughts? > > > > Barry |