Skip to content

Commit

Permalink
- Fix problems with double definitions
Browse files Browse the repository at this point in the history
- Clean up a bit a type mess - 4 types less. No need to have aliases
  for the same thing (unification is the name).
- New macro for Johannes mysqlnd_stmt_ro_result_metadata
  • Loading branch information
faizshukri committed Jan 2, 2008
1 parent fc74136 commit fdf20a8
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 148 deletions.
8 changes: 4 additions & 4 deletions ext/mysqlnd/mysqlnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ MYSQLND_METHOD(mysqlnd_conn, field_count)(const MYSQLND * const conn)


/* {{{ mysqlnd_conn::insert_id */
static mynd_ulonglong
static uint64
MYSQLND_METHOD(mysqlnd_conn, insert_id)(const MYSQLND * const conn)
{
return conn->upsert_status.last_insert_id;
Expand All @@ -1292,7 +1292,7 @@ MYSQLND_METHOD(mysqlnd_conn, insert_id)(const MYSQLND * const conn)


/* {{{ mysqlnd_conn::affected_rows */
static mynd_ulonglong
static uint64
MYSQLND_METHOD(mysqlnd_conn, affected_rows)(const MYSQLND * const conn)
{
return conn->upsert_status.affected_rows;
Expand Down Expand Up @@ -1371,7 +1371,7 @@ MYSQLND_METHOD(mysqlnd_conn, charset_name)(const MYSQLND * const conn)


/* {{{ mysqlnd_conn::thread_id */
static mynd_ulonglong
static uint64
MYSQLND_METHOD(mysqlnd_conn, thread_id)(const MYSQLND * const conn)
{
return conn->thread_id;
Expand Down Expand Up @@ -1425,7 +1425,7 @@ MYSQLND_METHOD(mysqlnd_conn, next_result)(MYSQLND * const conn TSRMLS_DC)
}

SET_EMPTY_ERROR(conn->error_info);
conn->upsert_status.affected_rows= ~(mynd_ulonglong) 0;
SET_ERROR_AFF_ROWS(conn);
/*
We are sure that there is a result set, since conn->state is set accordingly
in mysqlnd_store_result() or mysqlnd_fetch_row_unbuffered()
Expand Down
1 change: 1 addition & 0 deletions ext/mysqlnd/mysqlnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, int
#define mysqlnd_stmt_bind_result(stmt,bind) (stmt)->m->bind_result((stmt), (bind) TSRMLS_CC)
#define mysqlnd_stmt_param_metadata(stmt) (stmt)->m->get_parameter_metadata((stmt))
#define mysqlnd_stmt_result_metadata(stmt) (stmt)->m->get_result_metadata((stmt) TSRMLS_CC)
#define mysqlnd_stmt_ronly_result_metadata(stmt) ((stmt)->result)

#define mysqlnd_stmt_free_result(stmt) (stmt)->m->free_result((stmt) TSRMLS_CC)
#define mysqlnd_stmt_close(stmt, implicit) (stmt)->m->dtor((stmt), (implicit) TSRMLS_CC)
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqlnd/mysqlnd_libmysql_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define MYSQL_ROW MYSQLND_ROW
#define MYSQL MYSQLND
#define my_bool zend_bool
#define my_ulonglong mynd_ulonglong
#define my_ulonglong uint64

#define MYSQL_VERSION_ID MYSQLND_VERSION_ID
#define MYSQL_SERVER_VERSION MYSQLND_VERSION
Expand Down
136 changes: 61 additions & 75 deletions ext/mysqlnd/mysqlnd_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef int8_t int8; /* Signed integer >= 8 bits */
#endif
#endif


#ifndef HAVE_UINT8
#ifndef HAVE_UINT8_T
typedef unsigned char uint8; /* Unsigned integer >= 8 bits */
Expand Down Expand Up @@ -97,47 +98,83 @@ typedef uint16_t uint16; /* Signed integer >= 16 bits */
typedef unsigned char uchar; /* Short for unsigned char */
#endif


#if defined(HAVE_INT32_T) && defined(HAVE_UINT32_T)
#ifndef HAVE_INT32
#ifdef HAVE_INT32_T
typedef int32_t int32;
typedef uint32_t uint32;

#elif SIZEOF_INT == 4

#ifndef HAVE_INT32
typedef signed int int32;
#endif
#ifndef HAVE_UINT32
typedef unsigned int uint32;
#endif

#elif SIZEOF_LONG == 4

#ifndef HAVE_INT32
typedef signed long int32;
#else
error "Neither int nor long is of 4 bytes width"
#endif
#endif /* HAVE_INT32 */


#ifndef HAVE_UINT32
#ifdef HAVE_UINT32_T
typedef uint32_t uint32;
#elif SIZEOF_INT == 4
typedef unsigned int uint32;
#elif SIZEOF_LONG == 4
typedef unsigned long uint32;
#else
#error "Neither int nor long is of 4 bytes width"
#endif

#endif /* HAVE_UINT32 */


#ifndef HAVE_INT64
#ifdef HAVE_INT64_T
typedef int64_t int64;
#elif SIZEOF_INT == 8
typedef signed int int64;
#elif SIZEOF_LONG == 8
typedef signed long int64;
#elif SIZEOF_LONG_LONG == 8
typedef signed long long int64;
#else
error "Neither int or long is of 4 bytes width"
#error "Neither int nor long nor long long is of 8 bytes width"
#endif
#endif /* HAVE_INT64 */


#ifndef HAVE_UINT64
#ifdef HAVE_UINT64_T
typedef uint64_t uint64;
#elif SIZEOF_INT == 8
typedef unsigned int uint64;
#elif SIZEOF_LONG == 8
typedef unsigned long uint64;
#elif SIZEOF_LONG_LONG == 8
typedef unsigned long long uint64;
#else
#error "Neither int nor long nor long long is of 8 bytes width"
#endif
#endif /* HAVE_INT64 */

#if !defined(HAVE_ULONG) && !defined(__USE_MISC) && !defined(ulong)
typedef unsigned long ulong; /* Short for unsigned long */

#ifdef PHP_WIN32
#define MYSQLND_LLU_SPEC "%I64u"
#define MYSQLND_LL_SPEC "%I64d"
#ifndef L64
#define L64(x) x##i64
#endif
#ifndef longlong_defined
#if defined(HAVE_LONG_LONG) && SIZEOF_LONG != 8
typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
typedef long long int longlong;
typedef __int64 int64;
typedef unsigned __int64 uint64;
#else
typedef unsigned long ulonglong; /* ulong or unsigned long long */
typedef long longlong;
#define MYSQLND_LLU_SPEC "%llu"
#define MYSQLND_LL_SPEC "%lld"
#ifndef L64
#define L64(x) x##LL
#endif
#endif


typedef int64 longlong;
typedef uint64 ulonglong;


#define int1store(T,A) do { *((zend_uchar*) (T)) = (A); } while(0)
#define uint1korr(A) (*(((uint8*)(A))))

Expand Down Expand Up @@ -280,29 +317,9 @@ typedef union {
(((uint32) ((uchar) (A)[1])) << 8) +\
(((uint32) ((uchar) (A)[2])) << 16) +\
(((uint32) ((uchar) (A)[3])) << 24))
#define bit_uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
(((uint32) ((uchar) (A)[1])) << 8) +\
(((uint32) ((uchar) (A)[2])) << 16) +\
(((uint32) ((uchar) (A)[3])) << 24)) +\
(((ulonglong) ((uchar) (A)[4])) << 32))
/* From Andrey Hristov, based on uint5korr */
#define bit_uint6korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[5])) +\
(((uint32) (((uchar*) (A))[4])) << 8) +\
(((uint32) (((uchar*) (A))[3])) << 16) +\
(((uint32) (((uchar*) (A))[2])) << 24)) +\
(((ulonglong) (((uint32) (((uchar*) (A))[1])) +\
(((uint32) (((uchar*) (A))[0]) << 8)))) << 32))

#define bit_uint7korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[6])) +\
(((uint32) (((uchar*) (A))[5])) << 8) +\
(((uint32) (((uchar*) (A))[4])) << 16) +\
(((uint32) (((uchar*) (A))[3])) << 24)) +\
(((ulonglong) (((uint32) (((uchar*) (A))[2])) +\
(((uint32) (((uchar*) (A))[1])) << 8) +\
(((uint32) (((uchar*) (A))[0])) << 16))) << 32))


#define bit_uint8korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[7])) +\
#define uint8korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[7])) +\
(((uint32) (((uchar*) (A))[6])) << 8) +\
(((uint32) (((uchar*) (A))[5])) << 16) +\
(((uint32) (((uchar*) (A))[4])) << 24)) +\
Expand Down Expand Up @@ -473,37 +490,6 @@ typedef union {
#endif /* WORDS_BIGENDIAN */


#ifdef PHP_WIN32
#define MYSQLND_LLU_SPEC "%I64u"
#define MYSQLND_LL_SPEC "%I64d"
#ifndef L64
#define L64(x) x##i64
#endif
typedef unsigned __int64 my_uint64;
typedef __int64 my_int64;
typedef unsigned __int64 mynd_ulonglong;
typedef __int64 mynd_longlong;
#else
#define MYSQLND_LLU_SPEC "%llu"
#define MYSQLND_LL_SPEC "%lld"
#ifndef L64
#define L64(x) x##LL
#endif
#ifndef HAVE_UINT64_T
typedef unsigned long long my_uint64;
typedef unsigned long long mynd_ulonglong;
#else
typedef uint64_t my_uint64;
typedef uint64_t mynd_ulonglong;
#endif
#ifndef HAVE_INT64_T
typedef long long my_int64;
typedef long long mynd_longlong;
#else
typedef int64_t my_int64;
typedef int64_t mynd_longlong;
#endif
#endif

/*
* Local variables:
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqlnd/mysqlnd_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
#define MAX_CHARSET_LEN 32


#define SET_ERROR_AFF_ROWS(s) (s)->upsert_status.affected_rows = (mynd_ulonglong) ~0
#define SET_ERROR_AFF_ROWS(s) (s)->upsert_status.affected_rows = (uint64) ~0

/* Error handling */
#define SET_NEW_MESSAGE(buf, buf_len, message, len, persistent) \
Expand Down
8 changes: 4 additions & 4 deletions ext/mysqlnd/mysqlnd_ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ MYSQLND_METHOD(mysqlnd_stmt, bind_result)(MYSQLND_STMT * const stmt,


/* {{{ mysqlnd_stmt::insert_id */
static mynd_ulonglong
static uint64
MYSQLND_METHOD(mysqlnd_stmt, insert_id)(const MYSQLND_STMT * const stmt)
{
return stmt->upsert_status.last_insert_id;
Expand All @@ -1224,7 +1224,7 @@ MYSQLND_METHOD(mysqlnd_stmt, insert_id)(const MYSQLND_STMT * const stmt)


/* {{{ mysqlnd_stmt::affected_rows */
static mynd_ulonglong
static uint64
MYSQLND_METHOD(mysqlnd_stmt, affected_rows)(const MYSQLND_STMT * const stmt)
{
return stmt->upsert_status.affected_rows;
Expand All @@ -1233,7 +1233,7 @@ MYSQLND_METHOD(mysqlnd_stmt, affected_rows)(const MYSQLND_STMT * const stmt)


/* {{{ mysqlnd_stmt::num_rows */
static mynd_ulonglong
static uint64
MYSQLND_METHOD(mysqlnd_stmt, num_rows)(const MYSQLND_STMT * const stmt)
{
return stmt->result? mysqlnd_num_rows(stmt->result):0;
Expand Down Expand Up @@ -1297,7 +1297,7 @@ MYSQLND_METHOD(mysqlnd_stmt, sqlstate)(const MYSQLND_STMT * const stmt)

/* {{{ mysqlnd_stmt::data_seek */
static enum_func_status
MYSQLND_METHOD(mysqlnd_stmt, data_seek)(const MYSQLND_STMT * const stmt, mynd_ulonglong row TSRMLS_DC)
MYSQLND_METHOD(mysqlnd_stmt, data_seek)(const MYSQLND_STMT * const stmt, uint64 row TSRMLS_DC)
{
return stmt->result? stmt->result->m.seek_data(stmt->result, row TSRMLS_CC) : FAIL;
}
Expand Down
32 changes: 16 additions & 16 deletions ext/mysqlnd/mysqlnd_ps_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ void ps_fetch_from_1_to_8_bytes(zval *zv, const MYSQLND_FIELD * const field,
size_t tmp_len = 0;
zend_bool is_bit = field->type == MYSQL_TYPE_BIT;
if (field->flags & UNSIGNED_FLAG) {
my_uint64 uval = 0;
uint64 uval = 0;

switch (byte_count) {
case 8:uval = is_bit? (my_uint64) bit_uint8korr(*row):(my_uint64) uint8korr(*row);break;
case 8:uval = is_bit? (uint64) bit_uint8korr(*row):(uint64) uint8korr(*row);break;
case 7:uval = bit_uint7korr(*row);break;
case 6:uval = bit_uint6korr(*row);break;
case 5:uval = bit_uint5korr(*row);break;
case 4:uval = is_bit? (my_uint64) bit_uint4korr(*row):(my_uint64) uint4korr(*row);break;
case 3:uval = is_bit? (my_uint64) bit_uint3korr(*row):(my_uint64) uint3korr(*row);break;
case 2:uval = is_bit? (my_uint64) bit_uint2korr(*row):(my_uint64) uint2korr(*row);break;
case 1:uval = (my_uint64) uint1korr(*row);break;
case 4:uval = is_bit? (uint64) bit_uint4korr(*row):(uint64) uint4korr(*row);break;
case 3:uval = is_bit? (uint64) bit_uint3korr(*row):(uint64) uint3korr(*row);break;
case 2:uval = is_bit? (uint64) bit_uint2korr(*row):(uint64) uint2korr(*row);break;
case 1:uval = (uint64) uint1korr(*row);break;
}

#if SIZEOF_LONG==4
Expand All @@ -100,21 +100,21 @@ void ps_fetch_from_1_to_8_bytes(zval *zv, const MYSQLND_FIELD * const field,
}
} else {
/* SIGNED */
my_int64 lval = 0;
int64 lval = 0;
switch (byte_count) {
case 8:lval = (my_int64) sint8korr(*row);break;
case 8:lval = (int64) sint8korr(*row);break;
/*
7, 6 and 5 are not possible.
BIT is only unsigned, thus only uint5|6|7 macroses exist
*/
case 4:lval = (my_int64) sint4korr(*row);break;
case 3:lval = (my_int64) sint3korr(*row);break;
case 2:lval = (my_int64) sint2korr(*row);break;
case 1:lval = (my_int64) *(my_int8*)*row;break;
case 4:lval = (int64) sint4korr(*row);break;
case 3:lval = (int64) sint3korr(*row);break;
case 2:lval = (int64) sint2korr(*row);break;
case 1:lval = (int64) *(my_int8*)*row;break;
}

#if SIZEOF_LONG==4
if ((L64(2147483647) < (my_int64) lval) || (L64(-2147483648) > (my_int64) lval)) {
if ((L64(2147483647) < (int64) lval) || (L64(-2147483648) > (int64) lval)) {
tmp_len = sprintf((char *)&tmp, MYSQLND_LL_SPEC, lval);
} else
#endif /* SIZEOF */
Expand Down Expand Up @@ -245,15 +245,15 @@ void ps_fetch_int64(zval *zv, const MYSQLND_FIELD * const field,
ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, 8 TSRMLS_CC);
#if 0

my_uint64 llval = (my_uint64) sint8korr(*row);
uint64 llval = (uint64) sint8korr(*row);
zend_bool uns = field->flags & UNSIGNED_FLAG? TRUE:FALSE;

#if SIZEOF_LONG==8
if (uns == TRUE && llval > 9223372036854775807L) {
#elif SIZEOF_LONG==4
if ((uns == TRUE && llval > L64(2147483647)) ||
(uns == FALSE && ((L64( 2147483647) < (my_int64) llval) ||
(L64(-2147483648) > (my_int64) llval))))
(uns == FALSE && ((L64( 2147483647) < (int64) llval) ||
(L64(-2147483648) > (int64) llval))))
{
#endif
char tmp[22];
Expand Down
6 changes: 3 additions & 3 deletions ext/mysqlnd/mysqlnd_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ mysqlnd_store_result_fetch_data(MYSQLND * const conn, MYSQLND_RES *result,
zval **current_row;

if (!free_rows) {
mynd_ulonglong total_rows = free_rows = next_extend = next_extend * 5 / 3; /* extend with 33% */
uint64 total_rows = free_rows = next_extend = next_extend * 5 / 3; /* extend with 33% */
total_rows += set->row_count;
set->data = mnd_perealloc(set->data, total_rows * sizeof(zval **), set->persistent);

Expand Down Expand Up @@ -937,7 +937,7 @@ MYSQLND_METHOD(mysqlnd_res, free_result)(MYSQLND_RES *result, zend_bool implicit

/* {{{ mysqlnd_res::data_seek */
static enum_func_status
MYSQLND_METHOD(mysqlnd_res, data_seek)(MYSQLND_RES *result, mynd_ulonglong row TSRMLS_DC)
MYSQLND_METHOD(mysqlnd_res, data_seek)(MYSQLND_RES *result, uint64 row TSRMLS_DC)
{
DBG_ENTER("mysqlnd_res::data_seek");
DBG_INF_FMT("row=%lu", row);
Expand All @@ -959,7 +959,7 @@ MYSQLND_METHOD(mysqlnd_res, data_seek)(MYSQLND_RES *result, mynd_ulonglong row T


/* {{{ mysqlnd_res::num_fields */
mynd_ulonglong
uint64
MYSQLND_METHOD(mysqlnd_res, num_rows)(const MYSQLND_RES * const res)
{
/* Be compatible with libmysql. We count row_count, but will return 0 */
Expand Down
Loading

0 comments on commit fdf20a8

Please sign in to comment.