Bug #20530 qsort redefinition violates the standard
Submitted: 19 Jun 2006 10:15 Modified: 20 Dec 2007 0:51
Reporter: Christopher Yeleighton (Candidate Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.23-BK, 5.0.12 OS:Microsoft Windows (Microsoft Windows XP Professiona)
Assigned to: Alexey Kopytov CPU Architecture:Any
Tags: qc
Triage: D3 (Medium)

[19 Jun 2006 10:15] Christopher Yeleighton
Description:
You are not allowed to override qsort to suit your own needs.  It can conflict with other functions of the run-time library in unpredictable ways (yes, I know what weak symbols are for, but they are nonstandard and unportable).  If you need 'standard' quicksort with the whatever extensions you need, you should give it some other name.  As an alternative, you can ask the compiler vendor to make the improvement for you.  Microsoft already did — it is called qsort_s.

How to repeat:
Compile file mysys\mf_qsort.c
mysys\mf_qsort.c(100) : warning C4273: 'qsort' : inconsistent dll linkage

Offending line:
qsort_t qsort(void *base_ptr, size_t count, size_t size, qsort_cmp cmp)

Suggested fix:
qsort_t xqsort(void *base_ptr, size_t count, size_t size, qsort_cmp cmp)
[19 Jun 2006 10:39] Valeriy Kravchuk
Thank you for a problem report. I am not sure about standard violation (let developers decide), but even in today's 5.0.23-BK sources we still do declare qsort:

/****************************************************************************
** 'standard' quicksort with the following extensions:
**
** Can be compiled with the qsort2_cmp compare function
** Store ranges on stack to avoid recursion
** Use insert sort on small ranges
** Optimize for sorting of pointers (used often by MySQL)
** Use median comparison to find partition element
*****************************************************************************/

#ifdef QSORT_EXTRA_CMP_ARGUMENT
qsort_t qsort2(void *base_ptr, size_t count, size_t size, qsort2_cmp cmp,
               void *cmp_argument)
#else
qsort_t qsort(void *base_ptr, size_t count, size_t size, qsort_cmp cmp)
#endif
[23 Jun 2006 15:04] Elliot Murphy
The naming causes conflicts on OS X build too. This should be fixed.
[23 Oct 2007 5:10] Alexey Kopytov
This bug was fixed by the changesets for bug #31207.
[7 Dec 2007 23:07] Bugs System
Pushed into 6.0.5-alpha
[7 Dec 2007 23:09] Bugs System
Pushed into 5.1.23-rc
[7 Dec 2007 23:10] Bugs System
Pushed into 5.0.54
[20 Dec 2007 0:51] Paul Dubois
Noted in 5.0.54, 5.1.23, 6.0.5 changelogs.

The mysys library had a qsort() function, causing conflicts between
its use and the qsort() in glibc. Resolved by renaming the mysys
version to my_qsort().