[Paraview-developers] addrofthis to give Python the address of a vtkObject
Cory Quammen
cory.quammen at kitware.com
Thu Aug 18 14:50:37 EDT 2016
Axel,
I modified the Python Annotation filter so that it does not cut off
the leading "0x", and it worked fine, so I think you can do either. If
you couldn't leave the leading "0x", I would expect consistent and
spectacular crashes when you do so.
HTH,
Cory
On Thu, Aug 18, 2016 at 12:11 PM, Gerstenberger, Axel
<Axel.Gerstenberger at rolls-royce.com> wrote:
> Hi Cory,
>
> Just to confirm: We use both variants at various places (maybe copied from different sources) and also for us either version seems to work.
> But I have some parallel crashes in our python code that I try to understand and I stumbled of this address issue and wanted to make sure that this is not the reason for that.
>
> A statement from a wrapper expert (or a static method that encodes the advice) would make us more confident that we use the right version.
>
> Regards,
> Axel
>
> -----Original Message-----
> From: Cory Quammen [mailto:cory.quammen at kitware.com]
> Sent: Thursday, August 18, 2016 5:59 PM
> To: Gerstenberger, Axel
> Cc: ParaView Developers
> Subject: Re: [Paraview-developers] addrofthis to give Python the address of a vtkObject
>
> HI Axel,
>
>> When looking through the source code of Paraview (from which we learn all the time for our own code), I found that to get the address of a vtkObject for Python interaction you use code like this:
>>
>> // Set self to point to this
>> char addrofthis[1024];
>> sprintf(addrofthis, "%p", somepointer);
>> char *aplus = addrofthis;
>> if ((addrofthis[0] == '0') && ((addrofthis[1] == 'x') || addrofthis[1] == 'X'))
>> {
>> aplus += 2; //skip over "0x"
>> }
>> return std::string(aplus);
>>
>> However, sometimes you use aplus for referencing the address (e.g. in vtkPythonAnnotationFilter), but sometimes you use directly addrofthis, but still execute the part to compute aplus. This happens for example in vtkPythonView.cxx, line 142 ff.
>>
>> Since the first version is used a lot, is the second version in vtkPythonView.cxx a bug or does it serve a different purpose?
>
> Hmm, you are right, that is different from other examples where the
> object address is passed to Python, and is not intended. It seems to
> work, though, or at least it did when I wrote the code.
>
> My hunch is that the Python wrapping handles either case of passing
> "0xffffffff" or "ffffffff" to the constructor to create a Python
> object from an existing VTK object, but I don't know the Python
> wrapping facilities well enough to verify that. Perhaps Python
> wrapping guru David Gobbi can answer affirmatively.
>
>> Also, this code snippet appears to be copied to quite a few places, but it is crucial for vtk Python interaction. Maybe a little static method in VTK could be created for that?
>
> If the wrappers in fact do not handle both address formats, then yes
> it would make sense to have a static member function that would do
> this, probably in vtkPythonUtils.
>
> Thanks,
> Cory
>
>> Thanks,
>> Axel
>>
>>
>> --
>> Dr. Axel Gerstenberger
>> Aero Methods and Design Systems Engineering (ET-DSE)
>>
>> Rolls-Royce Deutschland Ltd & Co KG
>> Eschenweg 11, Dahlewitz, 15827 Blankenfelde-Mahlow, Germany
>>
>> Tel: +49(0)33708-6-3101
>> E-Mail: axel.gerstenberger at rolls-royce.com
>>
>> Absence pending: 14.06.2016
>>
>> Rolls-Royce Deutschland Ltd & Co KG Sitz/Registered Office: Blankenfelde-Mahlow, Deutschland, Registergericht/Court of Register: Amtsgericht Potsdam, HRA 2731 P, Persönlich haftende Gesellschafterin/General Partner: Rolls-Royce General Partner Limited, Sitz/Registered Office: Derby, United Kingdom, Register: Registry of Companies Wales and England, 4066556, Directors/Geschäftsführer: Paul O’Neil, Alastair McIntosh, Nicole Fehr, Dr. Holger Cartsburg Confidentiality Notice: This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person.
>> The data contained in, or attached to, this e-mail, may contain confidential information. If you have received it in error you should notify the sender immediately by reply e-mail, delete the message from your system and contact +44 (0) 3301235850 (Security Operations Centre) if you need assistance. Please do not copy it for any purpose, or disclose its contents to any other person.
>>
>> An e-mail response to this address may be subject to interception or monitoring for operational reasons or for lawful business practices.
>>
>> (c) 2016 Rolls-Royce plc
>>
>> Registered office: 62 Buckingham Gate, London SW1E 6AT Company number: 1003142. Registered in England.
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Search the list archives at: http://markmail.org/search/?q=Paraview-developers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/paraview-developers
>
>
>
> --
> Cory Quammen
> R&D Engineer
> Kitware, Inc.
> Rolls-Royce Deutschland Ltd & Co KG Sitz/Registered Office: Blankenfelde-Mahlow, Deutschland, Registergericht/Court of Register: Amtsgericht Potsdam, HRA 2731 P, Persönlich haftende Gesellschafterin/General Partner: Rolls-Royce General Partner Limited, Sitz/Registered Office: Derby, United Kingdom, Register: Registry of Companies Wales and England, 4066556, Directors/Geschäftsführer: Paul O’Neil, Alastair McIntosh, Nicole Fehr, Dr. Holger Cartsburg Confidentiality Notice: This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person.
> The data contained in, or attached to, this e-mail, may contain confidential information. If you have received it in error you should notify the sender immediately by reply e-mail, delete the message from your system and contact +44 (0) 3301235850 (Security Operations Centre) if you need assistance. Please do not copy it for any purpose, or disclose its contents to any other person.
>
> An e-mail response to this address may be subject to interception or monitoring for operational reasons or for lawful business practices.
>
> (c) 2016 Rolls-Royce plc
>
> Registered office: 62 Buckingham Gate, London SW1E 6AT Company number: 1003142. Registered in England.
--
Cory Quammen
R&D Engineer
Kitware, Inc.
More information about the Paraview-developers
mailing list