Compiling the Python sources with a C++ compiler (aCC)

Discussion in 'Python' started by Paul Sheer, Jun 20, 2004.

  1. Paul Sheer

    Paul Sheer Guest

    I have managed to build Python 2.3.3 with the aCC HP-UX C++
    compiler by making a number of one-line changes. (For reasons
    beyond my control, I am forced to use this compiler and it has
    no C mode at all.)

    Typically to get the Python source code to compile under
    aCC one has to make a number of trivial changes of the form,

    struct whatzit *p;
    - p = malloc (sizeof (struct whatzit));
    + p = (struct whatzit *) malloc (sizeof (struct whatzit));

    since aCC has stricter casting rules than ANSI C and does
    not automatically cast void * .

    Another change is where a forward declaration is
    needed for the module type. The aCC compiler complines
    about a duplicate definition. I change these from "static"
    to "extern" which gives a warning, but otherwise works.
    For example,

    + #define staticforward ... /* in my case 'extern' */

    - static PyTypeObject Comptype;
    + staticforward PyTypeObject Comptype;

    (There is/was a staticforward macro which is not used
    consistently.)

    A third change are the Python module initializers
    (PyMODINIT_FUNC xxx(void) {...): they need to obviously
    be declared 'extern "C"' (for dl importing) which can
    happen in the PyMODINIT_FUNC macro. However the macro
    is not used consistently throughout the Python sources.

    Finally, of course there are numerous uses of "new",
    "class" and other C++ keywords. I wrote a short flex
    script to search and replace through the entire sources
    for instances of these.

    To summarize the changes needed:

    1. explicit casting of void *
    2. consistant use of a "staticforward" type
    for PyTypeObject forward declarations.
    3. consinstant use of PyMODINIT_FUNC.
    4. use of PyMODINIT_FUNC even in prototypes
    (like config.c.in)
    5. renaming of C++ reserved words.

    (There are other changes specific to the HP-UX
    architecture - too numerous to mention.)

    My question is: are the Python maintainers interested
    in such compatibility?

    Although Python will always be strict ANSI C, are such
    changes not of general interest for the purposes of
    consistency of the source code?

    Can someone forward this email to the appropriate
    developers list (or tell me which one)?

    Shall I prepare a proper patch against 2.3.4?

    What would the consensus be on replacements for
    'new', 'class', 'template', 'operator', etc.?
    Perhaps __new, zew, or new2; klass, __class, or
    cla55 etc.?

    Has this issue come up before? URLs?

    Many thanks, best wishes

    -paul
    Paul Sheer, Jun 20, 2004
    #1
    1. Advertising

  2. Paul Sheer wrote:
    > I have managed to build Python 2.3.3 with the aCC HP-UX C++
    > compiler by making a number of one-line changes. (For reasons
    > beyond my control, I am forced to use this compiler and it has
    > no C mode at all.)


    Nice work! It seems like a good idea to me for Python to be compilable in
    either C or C++ mode (not to mention it being a necessity in your case).

    > struct whatzit *p;
    > - p = malloc (sizeof (struct whatzit));
    > + p = (struct whatzit *) malloc (sizeof (struct whatzit));


    If that pattern is used a lot, it would be cleaner to use a macro and avoid
    the duplication.

    Untested, but ought to work:

    #define malloc_struct( s ) ( (struct s*)malloc( sizeof(struct s) ) )

    struct whatzit* p;
    p = malloc_struct( whatzit );

    -Mike
    Michael Geary, Jun 20, 2004
    #2
    1. Advertising

  3. Paul Sheer wrote:
    > I have managed to build Python 2.3.3 with the aCC HP-UX C++
    > compiler by making a number of one-line changes. (For reasons
    > beyond my control, I am forced to use this compiler and it has
    > no C mode at all.)


    Did you try to invoke c89(1)?

    Regards,
    Martin
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=, Jun 20, 2004
    #3
  4. Paul Sheer

    Paul Sheer Guest

    >
    > If that pattern is used a lot, it would be cleaner to use a macro and avoid
    > the duplication.
    >


    there are many other pointer casts that are missing. malloc is only one.

    -paul
    Paul Sheer, Jun 21, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Lemaire
    Replies:
    3
    Views:
    524
    Ivan Vecerina
    Oct 10, 2003
  2. rpmohan
    Replies:
    4
    Views:
    1,658
    Dennis Handly
    Oct 24, 2003
  3. wenmang
    Replies:
    8
    Views:
    571
    wenmang
    Oct 28, 2003
  4. Replies:
    0
    Views:
    494
  5. Bermejo, Rodrigo (GEAE, Foreign National)

    syck compiling error on HPUX - aCC

    Bermejo, Rodrigo (GEAE, Foreign National), Aug 16, 2003, in forum: Ruby
    Replies:
    1
    Views:
    104
    Bermejo, Rodrigo
    Aug 18, 2003
Loading...

Share This Page