Bug 12559 - source3/lib/tldap.c", line 2539: non-constant initializer: op "NAME"
source3/lib/tldap.c", line 2539: non-constant initializer: op "NAME"
Status: RESOLVED FIXED
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services
4.5.5
Sparc Solaris
: P5 normal
: ---
Assigned To: Karolin Seeger
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2017-02-03 19:14 UTC by Tom Schulz
Modified: 2017-03-27 09:31 UTC (History)
2 users (show)

See Also:


Attachments
Patch in git format (938 bytes, patch)
2017-03-15 17:50 UTC, Tom Schulz
no flags Details
git-am fix for 4.6.next, 4.5.next. (1.17 KB, patch)
2017-03-17 20:04 UTC, Jeremy Allison
martins: review+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Schulz 2017-02-03 19:14:12 UTC
Trying to build Samba 4.5.5 on a Solaris 10 sparc box using the cc: Sun C 5.13 SunOS_sparc 2014/10/20 compiler.The build fails with the following errors:


"../source3/lib/tldap.c", line 2539: non-constant initializer: op "NAME"
"../source3/lib/tldap.c", line 2541: non-constant initializer: op "NAME"
"../source3/lib/tldap.c", line 2543: non-constant initializer: op "NAME"
"../source3/lib/tldap.c", line 2545: non-constant initializer: op "NAME"
"../source3/lib/tldap.c", line 2547: non-constant initializer: op "NAME"
"../source3/lib/tldap.c", line 2549: non-constant initializer: op "NAME"

Only showing the first 6, the rest are the same.

The code generating the errors (only the first part) is:

static const struct { TLDAPRC rc; const char *string; } tldaprc_errmap[] =
{
        { TLDAP_SUCCESS,
          "TLDAP_SUCCESS" },
        { TLDAP_OPERATIONS_ERROR,
          "TLDAP_OPERATIONS_ERROR" },
        { TLDAP_PROTOCOL_ERROR,
          "TLDAP_PROTOCOL_ERROR" },
        { TLDAP_TIMELIMIT_EXCEEDED,
          "TLDAP_TIMELIMIT_EXCEEDED" },
        { TLDAP_SIZELIMIT_EXCEEDED,
          "TLDAP_SIZELIMIT_EXCEEDED" },
        { TLDAP_COMPARE_FALSE,
          "TLDAP_COMPARE_FALSE" },

It certainly looks like the initializers are constants.
The same code compiles on a Solaris 10 i386 box using the gnu compiler.
Comment 1 Tom Schulz 2017-02-17 16:22:31 UTC
I have been looking at this code and I find that I can not understand how it is supposed to work. I asked another person here who is a programmer to look at it and he also does not understand it. We are thinking that this is using some features that are only available in newer C compilers or perhaps only in gcc and our knowledge of C is not quite current. Here is the first part of the revelevent section of source/include/tldap.h.


typedef struct { uint8_t rc; } TLDAPRC;
#define TLDAP_RC(x) ((TLDAPRC){.rc = x})
#define TLDAP_RC_V(x) ((x).rc)

#define TLDAP_RC_EQUAL(x,y) (TLDAP_RC_V(x)==TLDAP_RC_V(y))
#define TLDAP_RC_IS_SUCCESS(x) TLDAP_RC_EQUAL(x,TLDAP_SUCCESS)

#define TLDAP_SUCCESS TLDAP_RC(0x00)
#define TLDAP_OPERATIONS_ERROR TLDAP_RC(0x01)
#define TLDAP_PROTOCOL_ERROR TLDAP_RC(0x02)
#define TLDAP_TIMELIMIT_EXCEEDED TLDAP_RC(0x03)
#define TLDAP_SIZELIMIT_EXCEEDED TLDAP_RC(0x04)
#define TLDAP_COMPARE_FALSE TLDAP_RC(0x05)
#define TLDAP_COMPARE_TRUE TLDAP_RC(0x06)
Comment 2 Jeremy Allison 2017-02-17 22:50:19 UTC
Try adding extra {} braces around the non-string initializers.

eg. Change:

static const struct { TLDAPRC rc; const char *string; } tldaprc_errmap[] =
{
        { TLDAP_SUCCESS,
          "TLDAP_SUCCESS" },
...

To:

static const struct { TLDAPRC rc; const char *string; } tldaprc_errmap[] =
{
        { {TLDAP_SUCCESS},
          "TLDAP_SUCCESS" },

I have a theory about the sun compiler here..
Comment 3 Tom Schulz 2017-02-18 04:50:47 UTC
I just tried those changes (57 lines) and I got the same set of error messages.
Comment 4 Stefan Metzmacher 2017-02-20 08:08:44 UTC
(In reply to Jeremy Allison from comment #2)

For NTSTATUS we have this:

#if defined(HAVE_IMMEDIATE_STRUCTURES)
typedef struct {uint32_t v;} NTSTATUS;
#define NT_STATUS(x) ((NTSTATUS) { x })
#define NT_STATUS_V(x) ((x).v)
#else
typedef uint32_t NTSTATUS;
#define NT_STATUS(x) (x)
#define NT_STATUS_V(x) (x)
#endif

I guess we need something similar for TLDAPRC
Comment 5 Tom Schulz 2017-03-10 20:00:18 UTC
I patched tldap as follows and it now compiles.

--- a/source3/include/tldap.h   Thu Aug 11 03:51:04 2016
+++ b/source3/include/tldap.h   Fri Mar 10 14:00:04 2017
@@ -47,9 +47,15 @@
        DATA_BLOB *values;
 };
 
+#if defined(HAVE_IMMEDIATE_STRUCTURES)
 typedef struct { uint8_t rc; } TLDAPRC;
 #define TLDAP_RC(x) ((TLDAPRC){.rc = x})
 #define TLDAP_RC_V(x) ((x).rc)
+#else
+typedef uint8_t TLDAPRC;
+#define TLDAP_RC(x) (x)
+#define TLDAP_RC_V(x) (x)
+#endif
 
 #define TLDAP_RC_EQUAL(x,y) (TLDAP_RC_V(x)==TLDAP_RC_V(y))
 #define TLDAP_RC_IS_SUCCESS(x) TLDAP_RC_EQUAL(x,TLDAP_SUCCESS)


I have not yet tried it to see if it runs correctly. What function would I exercise to see if the code is working as expected?
Comment 6 Volker Lendecke 2017-03-14 15:09:23 UTC
(In reply to Tom Schulz from comment #5)
> I patched tldap as follows and it now compiles.

Can you send this patch in git-format-patch style to samba-technical@lists.samba.org?

Thanks
Comment 7 Tom Schulz 2017-03-15 17:50:49 UTC
Created attachment 13064 [details]
Patch in git format

Here is the patch in git format. I will also post this to technical.
Comment 8 Tom Schulz 2017-03-17 17:06:08 UTC
The patch should be in master now. This is needed for both 4.5.next and 4.6.next.
Comment 9 Jeremy Allison 2017-03-17 20:04:55 UTC
Created attachment 13082 [details]
git-am fix for 4.6.next, 4.5.next.

Cherry-picked from master.
Comment 10 Martin Schwenke 2017-03-18 09:19:51 UTC
Hi Karolin,

This is ready for 4.5 and 4.6.

Thanks...
Comment 11 Karolin Seeger 2017-03-23 11:53:52 UTC
(In reply to Martin Schwenke from comment #10)
Pushed to autobuild-v4-{5,6}-test.
Comment 12 Karolin Seeger 2017-03-27 09:31:32 UTC
(In reply to Karolin Seeger from comment #11)
Pushed to both branches.
Closing out bug report.

Thanks!