Skip to content

Better 32bit support #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 21, 2018
Merged

Better 32bit support #63

merged 5 commits into from
Nov 21, 2018

Conversation

bpintea
Copy link
Collaborator

@bpintea bpintea commented Nov 20, 2018

This PR prepares the project for an x86 build:

  • reduces the stack consumption in certain cases;
  • fixes the signed/unsigned compilation warnings;
  • fixes a bug occurring when setting the length of the request body in libcurl;
  • ensures that all platform-dependent shared libraries bare 32 suffix in their naming.

- add 32bit indicative to binding library name, now called
esdsnbnd32.dll for x86 builds.
- all local SQLWCHAR buffers of ESODBC_MAX_IDENTIFIER_LEN count or
larger are now allocated, due to the relatively large value of the
define (SHRT_MAX).
- libcurl expects a 64bit value with _LARGE attribute, which is not
supplied in x86 builds.
- on signed/unsigned comparisons.
@bpintea bpintea mentioned this pull request Nov 20, 2018
Closed
driver/connect.c Outdated
@@ -492,9 +492,21 @@ static BOOL dbc_curl_prepare(esodbc_dbc_st *dbc, SQLULEN tout,
}
}

/* curl will always expect a 64bit value (curl_off_t), while size_t
* remains a 32bit type of 32bit platforms (where a long is needed). */
#if defined(_WIN64) || defined (WIN64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this change was necessary. If size_t is 32 bit unsigned and curl_off_t is 64 bit signed then why didn't the original line work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CURLOPT_POSTFIELDSIZE_LARGE attribute will expect a curl_off_t type, which is always 64 bits (on a x86 as well), while CURLOPT_POSTFIELDSIZE will expect a long.

curl_easy_setopt() is a varadic function and will interpret the passed value depending on the attribute. The compiler won't do a type conversion here. (And this is probably what's missing from the comment to make it clearer.)

Which means that on x86, before the fix, the call would pass 4 bytes (a size_t), but curl read 8 (a curl_off_t).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the need for the #if section be avoided with a local variable? That makes the size correct when the variadic function is called. But the compiler can optimize it in the case where sizeof(size_t) == sizeof(curl_off_t).

    curl_off_t curl_len = u8body->cnt;
    dbc->curl_err = curl_easy_setopt(dbc->curl, CURLOPT_POSTFIELDSIZE_LARGE,
     			curl_len);

This is one extra line rather than many, and will work on Linux without any further changes.

Copy link
Collaborator Author

@bpintea bpintea Nov 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right!
I initially wanted to avoid the curl_off_t usage on 32 bits, mostly due to libcurl's recommendation to use it if need to go over the 32bit long limit, but I think there are no measurable down-sides if using it.
Anyways, thanks, that's a better solution.

SQLRETURN ret;
/* b/c declaring an array with a const doesn't work with MSVC's compiler */
enum wbuf_len { wbuf_len = sizeof(SQL_TABLES)
SQLRETURN ret = SQL_ERROR;;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove the extra ;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, addressed.

- also remove a superfluous ';'.
Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bpintea bpintea merged commit 91aadb5 into elastic:master Nov 21, 2018
@bpintea bpintea deleted the feature/better_32bit_support branch November 21, 2018 19:05
@codebrain codebrain mentioned this pull request Nov 21, 2018
18 tasks
bpintea added a commit that referenced this pull request Dec 13, 2018
* append 32 suffix to DSN binding library

- add 32bit indicative to binding library name, now called
esdsnbnd32.dll for x86 builds.

* allocate large objects in catalog funcs on heap

- all local SQLWCHAR buffers of ESODBC_MAX_IDENTIFIER_LEN count or
larger are now allocated, due to the relatively large value of the
define (SHRT_MAX).

* b/f: only use _LARGE body size option on x64

- libcurl expects a 64bit value with _LARGE attribute, which is not
supplied in x86 builds.

* fix: 32 bit compilation warnings

- on signed/unsigned comparisons.

* fix: simpler post size setting for libcurl

- also remove a superfluous ';'.

(cherry picked from commit 91aadb5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants