Skip to content

#define of OS breaks #pragma argument in subsequent header file includes #15455

Description

@jonrumsey

I did this

Whilst developing some code to call the platform APIs on OS/400 to seed a PRNG;
https://www.ibm.com/docs/en/i/7.5?topic=ssw_ibm_i_75/apis/qc3addprngseed.html
These calls fail at runtime with MCH3601 exceptions, this only occurs when first including curl header files.

I expected the following

To be able to include curl headers before or after unrelated header files.

Many OS/400 system header files use pragmas to control how pointers are passed to APIs
https://www.ibm.com/docs/en/i/7.5?topic=descriptions-argument

Unfortunately the platform specific headers in curl (e.g. lib/config-os400.h) define "OS";

/* Define cpu-machine-OS */
#ifndef OS
#define OS "OS/400"
#endif

This gets expanded by the preprocessor and breaks any pragma that uses OS;

    63       |    #pragma argument (Qc3AddPRNGSeed,OS,nowiden)                                                  |  37415   158
    63       +    #pragma argument (Qc3AddPRNGSeed,"OS/400",nowiden)                                            +  37415   158
 ===========> .....................................a............................................................              
 *=WARNING=========> a - CZM0224  Incorrect pragma ignored.                                                                   
    64       |    void Qc3AddPRNGSeed                                                                           |  37416   158
    65       |                    (char *        , /* Seed data                  */                             |  37417   158
    66       |                     unsigned int  , /* Seed length                */                             |  37418   158
    67       |                     void *       ); /* Error Code                 */                             |  37419   158

This impacts any OS/400 headers that are included after curl header files, this can be worked around by including curl headers last or by undefining "OS" before including other headers. A better fix would be to apply a 'CURL_' prefix to the define i.e. 'CURL_OS' so that a string literal is not expanded incorrectly in place of OS.

curl/libcurl version

curl 8.10.1

operating system

OS/400 V7R4M0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions