Bug 63961 - Examples in Developing Modules guide don't compile with clang 4.x+
Summary: Examples in Developing Modules guide don't compile with clang 4.x+
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Documentation (show other bugs)
Version: 2.5-HEAD
Hardware: PC FreeBSD
: P2 normal (vote)
Target Milestone: ---
Assignee: HTTP Server Documentation List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-25 23:40 UTC by Enji Cooper
Modified: 2019-11-25 23:40 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Enji Cooper 2019-11-25 23:40:46 UTC
While trying to address build warnings with a custom Apache module, I was looking at the Developing Modules guide to see whether or not I could glean information on how to fix the warnings with the module.

Turns out, there are some errors that needed to be addressed with the documentation.

In particular, this section's (https://httpd.apache.org/docs/2.4/developer/modguide.html#basics ) information is incorrect/misleading, in the following ways:

module AP_MODULE_DECLARE_DATA   example_module =
{ 
    STANDARD20_MODULE_STUFF,
    create_dir_conf, /* Per-directory configuration handler */
    merge_dir_conf,  /* Merge handler for per-directory configurations */
    create_svr_conf, /* Per-server configuration handler */
    merge_svr_conf,  /* Merge handler for per-server configurations */
    directives,      /* Any directives we may have for httpd */
    register_hooks   /* Our hook registering function */
};

I discovered that there's an additional field needs to be defined in the `AP_MODULE_DECLARE_DATA` struct:

module AP_MODULE_DECLARE_DATA   example_module =
{ 
    STANDARD20_MODULE_STUFF,
    create_dir_conf, /* Per-directory configuration handler */
    merge_dir_conf,  /* Merge handler for per-directory configurations */
    create_svr_conf, /* Per-server configuration handler */
    merge_svr_conf,  /* Merge handler for per-server configurations */
    directives,      /* Any directives we may have for httpd */
    register_hooks,  /* Our hook registering function */
    AP_MODULE_FLAG_NONE /* <-- HERE */
};

Another thing that didn't work with clang 4.0 is discussed in https://httpd.apache.org/docs/2.4/developer/modguide.html#register_directive :

static const command_rec        example_directives[] =
{
    AP_INIT_TAKE1("exampleEnabled", example_set_enabled, NULL, RSRC_CONF, "Enable or disable mod_example"),
    AP_INIT_TAKE1("examplePath", example_set_path, NULL, RSRC_CONF, "The path to whatever"),
    AP_INIT_TAKE2("exampleAction", example_set_action, NULL, RSRC_CONF, "Special action value!"),
    { NULL }
};

In particular, the sentinel at the end needs to instead be an nul set with clang 4.0, since `command_rec` is not composed of a single element:

static const command_rec        example_directives[] =
{
    AP_INIT_TAKE1("exampleEnabled", example_set_enabled, NULL, RSRC_CONF, "Enable or disable mod_example"),
    AP_INIT_TAKE1("examplePath", example_set_path, NULL, RSRC_CONF, "The path to whatever"),
    AP_INIT_TAKE2("exampleAction", example_set_action, NULL, RSRC_CONF, "Special action value!"),
    { } /* <-- HERE */
};

These fixes might not be 100% portable with other compliers, so additional steps might need to be taken, depending on how conformant compilers are or aren't when it comes to C99, etc.