Discussion:
[omniORB] IDL to Python language mapping update?
Brian Neal
2011-03-16 21:29:13 UTC
Permalink
Hello -

Is anyone interested in collaborating on updating the IDL to Python
language mapping? As you all probably know, the mapping is very old,
and Python has changed a lot over the years since the original mapping
was released. My company is going to be working with CORBA for the
foreseeable future, and I'd sure like to do that work in Python 3.x if
possible.

I'm not a member of the OMG, and I have no idea what it takes to get a
new spec approved, but I reason this group has the best chance of
making that happen (if it indeed can happen). I'd be willing to help
write, review, and work the document through the process. I'm by no
means an expert on all aspects of CORBA and Python, but I have solid
experience in both.

Your thoughts?

Thanks,
Brian Neal
Bruce Visscher
2011-03-16 22:31:02 UTC
Permalink
Post by Brian Neal
I'm not a member of the OMG, and I have no idea what it takes to get a
new spec approved, but I reason this group has the best chance of
making that happen (if it indeed can happen). I'd be willing to help
write, review, and work the document through the process. I'm by no
means an expert on all aspects of CORBA and Python, but I have solid
experience in both.
Unfortunately, my impression is that it takes quite a lot.to get a new
spec approved. Case in point is the C++ mapping. Unfortunately, the
ISO C++ language standard was still pending when the CORBA C++ mapping
standard was designed. The result in my opinion is that it never
really was a good fit with the way the language typically would be
used. I believe there was at least one attempt at a new language
mapping that was not approved. The excuse given that I recall was
that there was too much legacy code to change it. (Does not make
sense to me at all...) In any case, the current situation is that we
are still using the old pre-ISO standard CORBA C++ language mapping
standard. When you consider that the C++ language was standardized in
1998 this is a pretty bad state of affairs. (Again, my opinion. It
is my understanding that there currently is a proposal for a new C++
mapping now. I am not a member either so I don't know the details.)

Perhaps a Python language mapping would go better. You might want to
ask in comp.object.corba newsgroup as well.
Luke Deller
2011-03-17 04:41:34 UTC
Permalink
Hi Brian,

I am going to need omniORBpy working with Python 3.x at some point in the future, so I am certainly interested in helping to make that happen (indeed I have started some experiments modifying omniORBpy source code to work with Python 3.1).

This will involve at least some minimal adjustments to the Python language mapping relating to strings and bytes. It would also be nice to utilize types which have been added to Python since the current spec was written, such as bool and decimal.Decimal. Were you thinking of more serious changes than this to make CORBA feel more Pythonic?

Regards,
Luke.

-----Original Message-----
From: omniorb-list-***@omniorb-support.com [mailto:omniorb-list-***@omniorb-support.com] On Behalf Of Brian Neal
Sent: Thursday, 17 March 2011 3:28 AM
To: omniorb-***@omniorb-support.com
Subject: [omniORB] IDL to Python language mapping update?

Hello -

Is anyone interested in collaborating on updating the IDL to Python language mapping? As you all probably know, the mapping is very old, and Python has changed a lot over the years since the original mapping was released. My company is going to be working with CORBA for the foreseeable future, and I'd sure like to do that work in Python 3.x if possible.

I'm not a member of the OMG, and I have no idea what it takes to get a new spec approved, but I reason this group has the best chance of making that happen (if it indeed can happen). I'd be willing to help write, review, and work the document through the process. I'm by no means an expert on all aspects of CORBA and Python, but I have solid experience in both.

Your thoughts?

Thanks,
Brian Neal

_______________________________________________
omniORB-list mailing list
omniORB-***@omniorb-support.com
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
**********************************************************************************************
Important Note
This email (including any attachments) contains information which is confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, distribute or copy this email. If you have received this email in error please notify the
sender immediately and delete this email. Any views expressed in this email are not necessarily the views of IRESS Market Technology Limited.

It is the duty of the recipient to virus scan and otherwise test the information provided before loading onto any computer system.
IRESS Market Technology Limited does not warrant that the information is free of a virus or any other defect or error.
**********************************************************************************************
Brian Neal
2011-03-17 04:52:16 UTC
Permalink
Hello Luke,
Post by Luke Deller
Hi Brian,
I am going to need omniORBpy working with Python 3.x at some point in the future, so I am certainly interested in helping to make that happen (indeed I have started some experiments modifying omniORBpy source code to work with Python 3.1).
This will involve at least some minimal adjustments to the Python language mapping relating to strings and bytes. ?It would also be nice to utilize types which have been added to Python since the current spec was written, such as bool and decimal.Decimal. ?Were you thinking of more serious changes than this to make CORBA feel more Pythonic?
Regards,
Luke.
I have a short list of things off the top of my head:

* clarify use of unicode and bytes as the existing spec was written
before Python had unicode
* use Python bool
* I had not thought of decimal; you have a good idea there.
* Along those lines, perhaps use named tuples for IDL structs?
* Use of Python property attributes to map IDL properties to

I'm eager to see Duncan's list.

I'd have to review the existing spec to look for more opportunities.

If enough people are interested perhaps we can talk about how to best
collaborate on this project.

Best,
BN
Brian Neal
2011-03-17 17:53:55 UTC
Permalink
Replying to myself here.
Post by Brian Neal
* Along those lines, perhaps use named tuples for IDL structs?
Wow, that won't work. Scratch that one.
Post by Brian Neal
I'm eager to see Duncan's list.
Any thoughts on this effort Duncan?
Post by Brian Neal
I'd have to review the existing spec to look for more opportunities.
I was thinking about the best way to approach rev. 2 of the spec. Do
we start with the existing spec and just rework sections, or is a
brand new document needed? I've always thought the original spec is
fairly good from a user point of view; I don't know about from a CORBA
ORB implementer perspective. Is the original spec author still
involved in CORBA and Python? If we don't envision massive changes
perhaps we just rework the original spec.

Who else should be approached about this effort? Someone suggested
posting in comp.object.corba. Are the GNOME folks still using PyOrbit
or is that project dead?

Thanks,
BN
Duncan Grisby
2011-04-26 23:50:05 UTC
Permalink
Sorry for taking ages to reply to this. A lot of these things are
actually already done, or under way.
Post by Brian Neal
* clarify use of unicode and bytes as the existing spec was written
before Python had unicode
Unicode is already used for wstring and whcar, of course. A Python 3
version should use unicode for string and char too. bytes should be used
for sequence<octet>. I think that will be the biggest change for Python
3 support.
Post by Brian Neal
* use Python bool
omniORBpy already does. It still accepts int and long when bool is
expected, but it always uses bool itself.

On a related note, another Python 3 change is the removal of the int
type, but that's relatively minor since omniORBpy accepts long
everywhere int is expected already.
Post by Brian Neal
* I had not thought of decimal; you have a good idea there.
IDL fixed should indeed map to decimal.Decimal. Although does anyone
actually use IDL fixed? I wouldn't be sure it's worth the effort.
Post by Brian Neal
* Along those lines, perhaps use named tuples for IDL structs?
I don't think that would be good -- structs should be mutable.
Post by Brian Neal
* Use of Python property attributes to map IDL properties to
omniORBpy on trunk in svn does that, in a way that's backwards
compatible with the standard _get_attr / _set_attr naming. Clients can
use property syntax; servers can either implement the attributes with
the standard names or with properties.


I think the biggest challenge with Python 3 support is how to structure
the source. The changes will be sufficiently pervasive that I don't
think it will be sensible to have a single source for both Python 2 and
Python 3 support, which will lead to the risk of divergence between the
implementations. I'm open to suggestions if anyone's looked into it.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Brian Neal
2011-04-27 06:10:19 UTC
Permalink
Hi Duncan,

I'm glad you chimed in here.
Post by Duncan Grisby
Sorry for taking ages to reply to this. A lot of these things are
actually already done, or under way.
Does this mean you are working on an implementation or a draft spec of
the language mapping?

Again, if you need help with the spec, whether it is reviewers or
writers, I'd be willing to help.
Post by Duncan Grisby
I think the biggest challenge with Python 3 support is how to structure
the source. The changes will be sufficiently pervasive that I don't
think it will be sensible to have a single source for both Python 2 and
Python 3 support, which will lead to the risk of divergence between the
implementations. I'm open to suggestions if anyone's looked into it.
I haven't looked at the source, but are you talking about the Python
code, or the C++ or both? I've seen many recommendations these days to
make all new development in Python 3, and then use the 3to2 tool to
automatically create a Python 2.x code-base.

Thanks Duncan,
BN
Luke Deller
2011-04-27 08:33:21 UTC
Permalink
Post by Duncan Grisby
I think the biggest challenge with Python 3 support is how to
structure the source. The changes will be sufficiently pervasive that
I don't think it will be sensible to have a single source for both
Python 2 and Python 3 support, which will lead to the risk of
divergence between the implementations. I'm open to suggestions if
anyone's looked into it.
I haven't looked at the source, but are you talking about the Python
code, or the C++ or both? I've seen many recommendations these days to
make all new development in Python 3, and then use the 3to2 tool to
automatically create a Python 2.x code-base.
I looked into this question with the C++ codebase a few months ago. It
appears to be quite possible to share the same codebase for Python 2.6+ and
Python 3. I got as far as having the same tree compile with 2.6.5 and
3.1.2, though not working right as I didn't work through the str issue
properly yet.

(Perhaps Python 2.4 and 2.5 could be supported too if we added a few
forward-compatibility macros which are included with Python 2.6+, but I'm
not sure how valuable this would be).

Required changes that I encountered were:

- PyInt_* are gone in Python 3. There were actually some macros defined in
3.0 mapping these to PyLong_*, but these were removed in 3.1. These are
not really appropriate for many cases in omniORBpy anyway.

Most omniORBpy code that I came across accepts both int objects and
long objects, handled as two separate cases, so all we need here is
to #ifdef out the int handling code for Python 3.

- PyString_* functions are renamed to PyBytes_* in Python 3 (and both work
in Python 2.6+ where PyBytes_* are defined as macros for PyString_* for
forwards compatibility).

My first attempt was to change all PyString_* calls to PyBytes_*, but
this is not appropriate for text where we actually want to use a str
object in Python 2 but a unicode object in Python 3. What is really
needed here is to sort through every use of PyString_ in the code,
categorising them into three cases:
1) Binary data: rename PyString_* to PyBytes_*
2) Text: use PyString_*, and add macros for Python 3 to map these to
PyUnicode_*. This works in many but not all cases as the PyUnicode_*
interface is a little different from the PyString_* interface.
3) Text where the macro approach does not suffice: need to use #ifdef
with separate code for Python 2 and Python 3.

This is the highest-impact change in Python 3, and may be what makes
a fork for Python 3 become more attractive.

- Module initialisation is different in Python 3, notably Py_InitModule is
gone. The pattern suggested in the porting HOWTO for supporting both
Python 2 and 3 works great:

http://docs.python.org/py3k/howto/cporting.html#module-initialization-and-state

- PyObject_HEAD_INIT() is gone in Python 3; use PyVarObject_HEAD_INIT
instead for both Python 2 and 3.

- tp_compare in the PyTypeObject struct is no longer used in Python 3; use
tp_richcompare instead for both Python 2 and 3 (requires rewriting
comparison function)

- ob_type in PyObject has moved in Python 3; use Py_TYPE() macro instead,
which works in both Python 2 and Python 3.

- Old style classes (PyInstance_*) are gone. There are a few instances in
the omniORBpy code where it grabs the instance dictionary directly out
of the PyInstanceObject struct, purportedly for performance reasons.
This needs to be changed to use the generic object interface such as
PyObject_GetAttrString. This works for both Python 2 and 3, though
perhaps with a performance degradation.

Some places actually fall back to using generic code if PyInstance_Check
fails (eg validateTypeStruct in modules/pyMarshal.cc). In those cases
we could potentially leave the PyInstance optimization in for Python 2
only, protected with an #ifdef.

- PyArg_NoArgs is gone in Python 3; use METH_NOARGS instead which works
in both Python 2 and Python 3.

- The PyNumberMethods struct has changed in Python 3, eg nb_divide has gone.
This requires some #ifdef's in pyFixed.cc (though ultimately this code
should be removed in favour of using decimal.Decimal)

- the DL_IMPORT macro was deprecated in Python 2.3 and removed in Python 3.0
so we need to declare it ourselves for use in modules/pyFixed.h

- print is now a function; the Makefiles actually invoke python with a print
statement on the command line, so they need to be adjusted to put
parenthesis around the print arguments

The .py files need changes too. I actually changed them to work with both
Python 2 and 3, though I'm not sure if this is the best idea. Changes were:
- print is a function in Python 3; add parentheses around arguments
- replace use of types.TupleType/types.BooleanType/etc with tuple/bool/etc
- "except" syntax for accessing the exception object is conflicting, so use
sys.exc_info() to access it instead
- dict.has_key method is gone; use "in" operator instead
- exceptions module is gone; all the exception types are built-in anyway
in Python 3 and recent Python 2.x

Hopefully this gives an initial idea of things needed to port omniORBpy to
Python 3, and what may be required to support both Python 3 and more recent
Python 2.x versions in the same codebase.

Regards,
Luke.
**********************************************************************************************
Important Note
This email (including any attachments) contains information which is confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, distribute or copy this email. If you have received this email in error please notify the
sender immediately and delete this email. Any views expressed in this email are not necessarily the views of IRESS Market Technology Limited.

It is the duty of the recipient to virus scan and otherwise test the information provided before loading onto any computer system.
IRESS Market Technology Limited does not warrant that the information is free of a virus or any other defect or error.
**********************************************************************************************
Luke Deller
2011-04-27 09:31:30 UTC
Permalink
Post by Luke Deller
- Module initialisation is different in Python 3, notably Py_InitModule is
gone. The pattern suggested in the porting HOWTO for supporting both
http://docs.python.org/py3k/howto/cporting.html#module-initialization-and-state
One aspect of module initialisation dealt with by this HOWTO and the
corresponding PEP 3121 involves moving module state from global variables
into a structure, so that the same module can imported separately by multiple
interpreter instances within the same process. This looks quite hard to do
for omniORBpy and I did not attempt it at all. Ignoring this just means that
omniORBpy doesn't work with multiple interpreters, which is not too bad.

The relevant pattern that I was referring to in the HOWTO was that part
of the example which was exclusive of module state handling: to define a
PyModuleDef structure, call the PyModule_Create function, and return a
module pointer from the module init function, all for Python 3 only
(protected by #if directives).

Regards,
Luke.
**********************************************************************************************
Important Note
This email (including any attachments) contains information which is confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, distribute or copy this email. If you have received this email in error please notify the
sender immediately and delete this email. Any views expressed in this email are not necessarily the views of IRESS Market Technology Limited.

It is the duty of the recipient to virus scan and otherwise test the information provided before loading onto any computer system.
IRESS Market Technology Limited does not warrant that the information is free of a virus or any other defect or error.
**********************************************************************************************
Loading...