-- cgit v1.2.1 From 5883c6905b5345be55f3c1a1efbd741bb697b115 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 21 Apr 2018 17:37:24 +0200 Subject: 5.6.40 --- storage/innobase/handler/ha_innodb.cc | 3 +- storage/innobase/handler/handler0alter.cc | 51 ++++++++++++++++++++----------- storage/innobase/row/row0import.cc | 12 +++----- storage/innobase/row/row0log.cc | 12 ++++++-- storage/innobase/row/row0mysql.cc | 8 ++--- 5 files changed, 54 insertions(+), 32 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 2b41c3db344..eb7fdaaddf4 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2000, 2017, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2000, 2018, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, 2009 Google Inc. Copyright (c) 2009, Percona Inc. Copyright (c) 2012, Facebook Inc. @@ -12225,6 +12225,7 @@ ha_innobase::start_stmt( case SQLCOM_INSERT: case SQLCOM_UPDATE: case SQLCOM_DELETE: + case SQLCOM_REPLACE: init_table_handle_for_HANDLER(); prebuilt->select_lock_type = LOCK_X; prebuilt->stored_select_lock_type = LOCK_X; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 437d38e29de..f945f40fc40 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2005, 2017, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2005, 2018, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -4604,13 +4604,15 @@ processed_field: } /** Get the auto-increment value of the table on commit. -@param ha_alter_info Data used during in-place alter -@param ctx In-place ALTER TABLE context -@param altered_table MySQL table that is being altered -@param old_table MySQL table as it is before the ALTER operation -@return the next auto-increment value (0 if not present) */ +@param[in] ha_alter_info Data used during in-place alter +@param[in,out] ctx In-place ALTER TABLE context + return autoinc value in ctx->max_autoinc +@param altered_table[in] MySQL table that is being altered +@param old_table[in] MySQL table as it is before the ALTER operation +retval true Failure +@retval false Success*/ static MY_ATTRIBUTE((nonnull, warn_unused_result)) -ulonglong +bool commit_get_autoinc( /*===============*/ Alter_inplace_info* ha_alter_info, @@ -4618,23 +4620,28 @@ commit_get_autoinc( const TABLE* altered_table, const TABLE* old_table) { - ulonglong max_autoinc; DBUG_ENTER("commit_get_autoinc"); if (!altered_table->found_next_number_field) { /* There is no AUTO_INCREMENT column in the table after the ALTER operation. */ - max_autoinc = 0; + ctx->max_autoinc = 0; } else if (ctx->add_autoinc != ULINT_UNDEFINED) { /* An AUTO_INCREMENT column was added. Get the last value from the sequence, which may be based on a supplied AUTO_INCREMENT value. */ - max_autoinc = ctx->sequence.last(); + ctx->max_autoinc = ctx->sequence.last(); } else if ((ha_alter_info->handler_flags & Alter_inplace_info::CHANGE_CREATE_OPTION) && (ha_alter_info->create_info->used_fields & HA_CREATE_USED_AUTO)) { + + /* Check if the table is discarded */ + if(dict_table_is_discarded(ctx->old_table)) { + DBUG_RETURN(true); + } + /* An AUTO_INCREMENT value was supplied, but the table was not rebuilt. Get the user-supplied value or the last value from the sequence. */ @@ -4647,7 +4654,8 @@ commit_get_autoinc( dict_index_t* index = dict_table_get_index_on_first_col( ctx->old_table, autoinc_field->field_index); - max_autoinc = ha_alter_info->create_info->auto_increment_value; + ctx->max_autoinc = + ha_alter_info->create_info->auto_increment_value; dict_table_autoinc_lock(ctx->old_table); @@ -4656,8 +4664,8 @@ commit_get_autoinc( if (err != DB_SUCCESS) { ut_ad(0); - max_autoinc = 0; - } else if (max_autoinc <= max_value_table) { + ctx->max_autoinc = 0; + } else if (ctx->max_autoinc <= max_value_table) { ulonglong col_max_value; ulonglong offset; @@ -4665,7 +4673,7 @@ commit_get_autoinc( old_table->found_next_number_field); offset = ctx->prebuilt->autoinc_offset; - max_autoinc = innobase_next_autoinc( + ctx->max_autoinc = innobase_next_autoinc( max_value_table, 1, 1, offset, col_max_value); } @@ -4675,11 +4683,11 @@ commit_get_autoinc( Read the old counter value from the table. */ ut_ad(old_table->found_next_number_field); dict_table_autoinc_lock(ctx->old_table); - max_autoinc = ctx->old_table->autoinc; + ctx->max_autoinc = ctx->old_table->autoinc; dict_table_autoinc_unlock(ctx->old_table); } - DBUG_RETURN(max_autoinc); + DBUG_RETURN(false); } /** Add or drop foreign key constraints to the data dictionary tables, @@ -5660,8 +5668,13 @@ ha_innobase::commit_inplace_alter_table( DBUG_ASSERT(new_clustered == ctx->need_rebuild()); - ctx->max_autoinc = commit_get_autoinc( - ha_alter_info, ctx, altered_table, table); + if (commit_get_autoinc(ha_alter_info, ctx, altered_table, + table)) { + fail = true; + my_error(ER_TABLESPACE_DISCARDED, MYF(0), + table->s->table_name.str); + goto rollback_trx; + } if (ctx->need_rebuild()) { ctx->tmp_name = dict_mem_create_temporary_tablename( @@ -5693,6 +5706,8 @@ ha_innobase::commit_inplace_alter_table( #endif } +rollback_trx: + /* Commit or roll back the changes to the data dictionary. */ if (fail) { diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index eda89951c3f..cd3f88c240e 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2012, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2012, 2018, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1827,12 +1827,6 @@ PageConverter::update_records( rec_t* rec = m_rec_iter.current(); - /* FIXME: Move out of the loop */ - - if (rec_get_status(rec) == REC_STATUS_NODE_PTR) { - break; - } - ibool deleted = rec_get_deleted_flag(rec, comp); /* For the clustered index we have to adjust the BLOB @@ -1934,6 +1928,10 @@ PageConverter::update_index_page( return(DB_SUCCESS); } + if (!page_is_leaf(block->frame)) { + return (DB_SUCCESS); + } + return(update_records(block)); } diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc index 4596e2fb951..7320fe3ac85 100644 --- a/storage/innobase/row/row0log.cc +++ b/storage/innobase/row/row0log.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2011, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2011, 2018, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -2720,7 +2720,15 @@ all_done: while (!trx_is_interrupted(trx)) { mrec = next_mrec; - ut_ad(mrec < mrec_end); + ut_ad(mrec <= mrec_end); + + if (mrec == mrec_end) { + /* We are at the end of the log. + Mark the replay all_done. */ + if (has_index_lock) { + goto all_done; + } + } if (!has_index_lock) { /* We are applying operations from a different diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 8d2d9e1c76b..cfd640ed4d5 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2000, 2017, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2000, 2018, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1426,8 +1426,7 @@ error_exit: doc_ids difference should not exceed FTS_DOC_ID_MAX_STEP value. */ - if (next_doc_id > 1 - && doc_id - next_doc_id >= FTS_DOC_ID_MAX_STEP) { + if (doc_id - next_doc_id >= FTS_DOC_ID_MAX_STEP) { fprintf(stderr, "InnoDB: Doc ID " UINT64PF " is too" " big. Its difference with largest" @@ -5086,7 +5085,8 @@ row_rename_table_for_mysql( } } - if (dict_table_has_fts_index(table) + if ((dict_table_has_fts_index(table) + || DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_HAS_DOC_ID)) && !dict_tables_have_same_db(old_name, new_name)) { err = fts_rename_aux_tables(table, new_name, trx); if (err != DB_TABLE_NOT_FOUND) { -- cgit v1.2.1 -- cgit v1.2.1 From 7f6561225a469b6968683fe9099868a87dab8f31 Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Mon, 23 Apr 2018 12:25:03 -0400 Subject: bump the VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 44f719ca097..23e938e60e1 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=5 MYSQL_VERSION_MINOR=5 -MYSQL_VERSION_PATCH=60 +MYSQL_VERSION_PATCH=61 MYSQL_VERSION_EXTRA= -- cgit v1.2.1 From 6b84fdb2f32e52299809c0bb771dfeefdb17be03 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 24 Apr 2018 16:17:43 +0200 Subject: 5.6.39-83.1 --- storage/xtradb/CMakeLists.txt | 4 ++- storage/xtradb/dict/dict0dict.cc | 66 ++++++++++++++++++++----------------- storage/xtradb/dict/dict0mem.cc | 13 ++++++-- storage/xtradb/fts/fts0fts.cc | 14 ++++++-- storage/xtradb/fts/fts0que.cc | 17 +++++++--- storage/xtradb/handler/ha_innodb.cc | 8 +++++ storage/xtradb/include/univ.i | 2 +- storage/xtradb/include/ut0ut.h | 11 ++++++- storage/xtradb/row/row0sel.cc | 2 +- storage/xtradb/trx/trx0purge.cc | 15 ++++++--- storage/xtradb/ut/ut0ut.cc | 30 +++++++++++++++-- 11 files changed, 131 insertions(+), 51 deletions(-) diff --git a/storage/xtradb/CMakeLists.txt b/storage/xtradb/CMakeLists.txt index 927d060d6c3..4284c3a0753 100644 --- a/storage/xtradb/CMakeLists.txt +++ b/storage/xtradb/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -452,3 +452,5 @@ MYSQL_ADD_PLUGIN(innobase ${INNOBASE_SOURCES} STORAGE_ENGINE DEFAULT MODULE_OUTPUT_NAME ha_innodb LINK_LIBRARIES ${ZLIB_LIBRARY}) + +ADD_DEPENDENCIES(innobase GenError) diff --git a/storage/xtradb/dict/dict0dict.cc b/storage/xtradb/dict/dict0dict.cc index eec681c4005..816c6f913a4 100644 --- a/storage/xtradb/dict/dict0dict.cc +++ b/storage/xtradb/dict/dict0dict.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2012, Facebook Inc. This program is free software; you can redistribute it and/or modify it under @@ -556,6 +556,8 @@ dict_table_close( indexes after an aborted online index creation */ { + + ibool drop_aborted; if (!dict_locked) { mutex_enter(&dict_sys->mutex); } @@ -563,6 +565,11 @@ dict_table_close( ut_ad(mutex_own(&dict_sys->mutex)); ut_a(table->n_ref_count > 0); + drop_aborted = try_drop + && table->drop_aborted + && table->n_ref_count == 1 + && dict_table_get_first_index(table); + --table->n_ref_count; /* Force persistent stats re-read upon next open of the table @@ -591,12 +598,6 @@ dict_table_close( if (!dict_locked) { table_id_t table_id = table->id; - ibool drop_aborted; - - drop_aborted = try_drop - && table->drop_aborted - && table->n_ref_count == 1 - && dict_table_get_first_index(table); mutex_exit(&dict_sys->mutex); @@ -2063,6 +2064,33 @@ dict_table_remove_from_cache_low( foreign->referenced_index = NULL; } + /* The check for dropped index should happen before we release + all the indexes */ + + if (lru_evict && table->drop_aborted) { + /* Do as dict_table_try_drop_aborted() does. */ + + trx_t* trx = trx_allocate_for_background(); + + ut_ad(mutex_own(&dict_sys->mutex)); +#ifdef UNIV_SYNC_DEBUG + ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX)); +#endif /* UNIV_SYNC_DEBUG */ + /* Mimic row_mysql_lock_data_dictionary(). */ + trx->dict_operation_lock_mode = RW_X_LATCH; + + trx_set_dict_operation(trx, TRX_DICT_OP_INDEX); + + /* Silence a debug assertion in row_merge_drop_indexes(). */ + ut_d(table->n_ref_count++); + row_merge_drop_indexes(trx, table, TRUE); + ut_d(table->n_ref_count--); + ut_ad(table->n_ref_count == 0); + trx_commit_for_mysql(trx); + trx->dict_operation_lock_mode = 0; + trx_free_for_background(trx); + } + /* Remove the indexes from the cache */ for (index = UT_LIST_GET_LAST(table->indexes); @@ -2095,30 +2123,6 @@ dict_table_remove_from_cache_low( dict_table_autoinc_store(table); } - if (lru_evict && table->drop_aborted) { - /* Do as dict_table_try_drop_aborted() does. */ - - trx_t* trx = trx_allocate_for_background(); - - ut_ad(mutex_own(&dict_sys->mutex)); -#ifdef UNIV_SYNC_DEBUG - ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX)); -#endif /* UNIV_SYNC_DEBUG */ - /* Mimic row_mysql_lock_data_dictionary(). */ - trx->dict_operation_lock_mode = RW_X_LATCH; - - trx_set_dict_operation(trx, TRX_DICT_OP_INDEX); - - /* Silence a debug assertion in row_merge_drop_indexes(). */ - ut_d(table->n_ref_count++); - row_merge_drop_indexes(trx, table, TRUE); - ut_d(table->n_ref_count--); - ut_ad(table->n_ref_count == 0); - trx_commit_for_mysql(trx); - trx->dict_operation_lock_mode = 0; - trx_free_for_background(trx); - } - size = mem_heap_get_size(table->heap) + strlen(table->name) + 1; ut_ad(dict_sys->size >= size); diff --git a/storage/xtradb/dict/dict0mem.cc b/storage/xtradb/dict/dict0mem.cc index 24a9e00412a..79d493ed65b 100644 --- a/storage/xtradb/dict/dict0mem.cc +++ b/storage/xtradb/dict/dict0mem.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2012, Facebook Inc. This program is free software; you can redistribute it and/or modify it under @@ -303,11 +303,20 @@ dict_mem_table_col_rename_low( char* col_names; if (to_len > from_len) { + ulint table_size_before_rename_col + = mem_heap_get_size(table->heap); col_names = static_cast( mem_heap_alloc( table->heap, full_len + to_len - from_len)); - + ulint table_size_after_rename_col + = mem_heap_get_size(table->heap); + if (table_size_before_rename_col + != table_size_after_rename_col) { + dict_sys->size += + table_size_after_rename_col + - table_size_before_rename_col; + } memcpy(col_names, table->col_names, prefix_len); } else { col_names = const_cast(table->col_names); diff --git a/storage/xtradb/fts/fts0fts.cc b/storage/xtradb/fts/fts0fts.cc index a29e046eb84..f3fa6e52d0d 100644 --- a/storage/xtradb/fts/fts0fts.cc +++ b/storage/xtradb/fts/fts0fts.cc @@ -4804,9 +4804,17 @@ fts_process_token( t_str.f_str = static_cast( mem_heap_alloc(heap, t_str.f_len)); - newlen = innobase_fts_casedn_str( - doc->charset, (char*) str.f_str, str.f_len, - (char*) t_str.f_str, t_str.f_len); + /* For binary collations, a case sensitive search is + performed. Hence don't convert to lower case. */ + if (my_binary_compare(result_doc->charset)) { + memcpy(t_str.f_str, str.f_str, str.f_len); + t_str.f_str[str.f_len]= 0; + newlen= str.f_len; + } else { + newlen = innobase_fts_casedn_str( + doc->charset, (char*) str.f_str, str.f_len, + (char*) t_str.f_str, t_str.f_len); + } t_str.f_len = newlen; t_str.f_str[newlen] = 0; diff --git a/storage/xtradb/fts/fts0que.cc b/storage/xtradb/fts/fts0que.cc index 84f616b7800..18cf41d4a48 100644 --- a/storage/xtradb/fts/fts0que.cc +++ b/storage/xtradb/fts/fts0que.cc @@ -3784,10 +3784,19 @@ fts_query_str_preprocess( str_len = query_len * charset->casedn_multiply + 1; str_ptr = static_cast(ut_malloc(str_len)); - *result_len = innobase_fts_casedn_str( - charset, const_cast(reinterpret_cast( - query_str)), query_len, - reinterpret_cast(str_ptr), str_len); + /* For binary collations, a case sensitive search is + performed. Hence don't convert to lower case. */ + if (my_binary_compare(charset)) { + memcpy(str_ptr, query_str, query_len); + str_ptr[query_len]= 0; + *result_len= query_len; + } else { + *result_len = innobase_fts_casedn_str( + charset, const_cast + (reinterpret_cast( query_str)), + query_len, + reinterpret_cast(str_ptr), str_len); + } ut_ad(*result_len < str_len); diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index 7b695fd4c5a..7b6d4243ba8 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -4071,6 +4071,14 @@ innobase_change_buffering_inited_ok: /* Turn on monitor counters that are default on */ srv_mon_default_on(); +#ifndef UNIV_HOTBACKUP +#ifdef _WIN32 + if (ut_win_init_time()) { + goto mem_free_and_error; + } +#endif /* _WIN32 */ +#endif /* !UNIV_HOTBACKUP */ + DBUG_RETURN(FALSE); error: DBUG_RETURN(TRUE); diff --git a/storage/xtradb/include/univ.i b/storage/xtradb/include/univ.i index ce2de004dd4..8eb3e6ef9bc 100644 --- a/storage/xtradb/include/univ.i +++ b/storage/xtradb/include/univ.i @@ -47,7 +47,7 @@ Created 1/20/1994 Heikki Tuuri #define INNODB_VERSION_BUGFIX MYSQL_VERSION_PATCH #ifndef PERCONA_INNODB_VERSION -#define PERCONA_INNODB_VERSION 83.0 +#define PERCONA_INNODB_VERSION 83.1 #endif /* Enable UNIV_LOG_ARCHIVE in XtraDB */ diff --git a/storage/xtradb/include/ut0ut.h b/storage/xtradb/include/ut0ut.h index ef887ed5e58..7c28081dd70 100644 --- a/storage/xtradb/include/ut0ut.h +++ b/storage/xtradb/include/ut0ut.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1994, 2017, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -266,6 +266,15 @@ UNIV_INTERN ulint ut_time_ms(void); /*============*/ +#ifdef _WIN32 +/**********************************************************//** +Initialise highest available time resolution API on Windows +@return 0 if all OK else -1 */ +int +ut_win_init_time(); + +#endif /* _WIN32 */ + #endif /* !UNIV_HOTBACKUP */ /**********************************************************//** diff --git a/storage/xtradb/row/row0sel.cc b/storage/xtradb/row/row0sel.cc index 060c12e7e2e..3e79d00b07c 100644 --- a/storage/xtradb/row/row0sel.cc +++ b/storage/xtradb/row/row0sel.cc @@ -2821,7 +2821,7 @@ row_sel_store_mysql_field_func( { const byte* data; ulint len; - ulint clust_field_no; + ulint clust_field_no = 0; bool clust_templ_for_sec = (sec_field_no != ULINT_UNDEFINED); ut_ad(prebuilt->default_rec); diff --git a/storage/xtradb/trx/trx0purge.cc b/storage/xtradb/trx/trx0purge.cc index d0d7ef2432e..9073bb02d4c 100644 --- a/storage/xtradb/trx/trx0purge.cc +++ b/storage/xtradb/trx/trx0purge.cc @@ -583,6 +583,7 @@ trx_purge_rseg_get_next_history_log( mutex_exit(&(rseg->mutex)); mtr_commit(&mtr); +#ifdef UNIV_DEBUG mutex_enter(&trx_sys->mutex); /* Add debug code to track history list corruption reported @@ -599,15 +600,19 @@ trx_purge_rseg_get_next_history_log( " InnoDB: Warning: purge reached the" " head of the history list,\n" "InnoDB: but its length is still" - " reported as %lu! Make a detailed bug\n" - "InnoDB: report, and submit it" - " to http://bugs.mysql.com\n", + " reported as %lu!.\n" + "This can happen for multiple reasons\n" + "1. A long running transaction is" + " withholding purging of undo logs or a read" + " view is open. Please try to commit the long" + " running transaction.\n" + "2. Try increasing the number of purge" + " threads to expedite purging of undo logs.", (ulong) trx_sys->rseg_history_len); - ut_ad(0); } mutex_exit(&trx_sys->mutex); - +#endif return; } diff --git a/storage/xtradb/ut/ut0ut.cc b/storage/xtradb/ut/ut0ut.cc index 597cbdf42c6..f9f39cb1269 100644 --- a/storage/xtradb/ut/ut0ut.cc +++ b/storage/xtradb/ut/ut0ut.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2014, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1994, 2017, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -49,6 +49,10 @@ Created 5/11/1994 Heikki Tuuri UNIV_INTERN ibool ut_always_false = FALSE; #ifdef __WIN__ +#include /* For sql_print_error */ +typedef VOID(WINAPI *time_fn)(LPFILETIME); +static time_fn ut_get_system_time_as_file_time = GetSystemTimeAsFileTime; + /*****************************************************************//** NOTE: The Windows epoch starts from 1601/01/01 whereas the Unix epoch starts from 1970/1/1. For selection of constant see: @@ -56,6 +60,28 @@ http://support.microsoft.com/kb/167296/ */ #define WIN_TO_UNIX_DELTA_USEC ((ib_int64_t) 11644473600000000ULL) +/** +Initialise highest available time resolution API on Windows +@return 0 if all OK else -1 */ +int +ut_win_init_time() +{ + HMODULE h = LoadLibrary("kernel32.dll"); + if (h != NULL) + { + time_fn pfn = (time_fn)GetProcAddress(h, "GetSystemTimePreciseAsFileTime"); + if (pfn != NULL) + { + ut_get_system_time_as_file_time = pfn; + } + return false; + } + DWORD error = GetLastError(); + sql_print_error( + "LoadLibrary(\"kernel32.dll\") failed: GetLastError returns %lu", error); + return(-1); +} + /*****************************************************************//** This is the Windows version of gettimeofday(2). @return 0 if all OK else -1 */ @@ -74,7 +100,7 @@ ut_gettimeofday( return(-1); } - GetSystemTimeAsFileTime(&ft); + ut_get_system_time_as_file_time(&ft); tm = (ib_int64_t) ft.dwHighDateTime << 32; tm |= ft.dwLowDateTime; -- cgit v1.2.1 From 3cd4da3257b84e35b82fa6f5542fc78bc80dfdb9 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 24 Apr 2018 16:25:16 +0200 Subject: 5.6.39-83.1 --- storage/tokudb/CMakeLists.txt | 2 +- storage/tokudb/PerconaFT/.clang-format | 36 +++++++++ storage/tokudb/PerconaFT/CMakeLists.txt | 6 ++ storage/tokudb/PerconaFT/README.md | 29 +++---- storage/tokudb/PerconaFT/ft/ft-ops.cc | 91 +++++++++++++++++++++- storage/tokudb/PerconaFT/ft/tests/ft-clock-test.cc | 4 +- storage/tokudb/PerconaFT/ft/tests/log-test4.cc | 2 +- .../PerconaFT/portability/tests/test-max-data.cc | 2 +- .../PerconaFT/portability/toku_instrumentation.h | 2 + .../PerconaFT/portability/toku_portability.h | 2 +- .../tokudb/PerconaFT/portability/toku_pthread.h | 6 +- storage/tokudb/PerconaFT/portability/toku_time.h | 5 ++ .../PerconaFT/src/tests/checkpoint_stress.cc | 2 +- .../tokudb/PerconaFT/src/tests/directory_lock.cc | 2 +- .../PerconaFT/src/tests/loader-cleanup-test.cc | 18 ++--- .../src/tests/recover-del-multiple-abort.cc | 6 +- .../recover-del-multiple-srcdb-fdelete-all.cc | 6 +- .../PerconaFT/src/tests/recover-del-multiple.cc | 6 +- .../src/tests/recover-put-multiple-abort.cc | 6 +- .../PerconaFT/src/tests/recovery_fileops_unit.cc | 4 +- .../tokudb/PerconaFT/src/tests/test-prepare3.cc | 1 + storage/tokudb/hatoku_hton.cc | 20 ++++- 22 files changed, 200 insertions(+), 58 deletions(-) create mode 100644 storage/tokudb/PerconaFT/.clang-format diff --git a/storage/tokudb/CMakeLists.txt b/storage/tokudb/CMakeLists.txt index 87c49deb91d..4580973cb80 100644 --- a/storage/tokudb/CMakeLists.txt +++ b/storage/tokudb/CMakeLists.txt @@ -1,4 +1,4 @@ -SET(TOKUDB_VERSION 5.6.38-83.0) +SET(TOKUDB_VERSION 5.6.39-83.1) # PerconaFT only supports x86-64 and cmake-2.8.9+ IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT CMAKE_VERSION VERSION_LESS "2.8.9") diff --git a/storage/tokudb/PerconaFT/.clang-format b/storage/tokudb/PerconaFT/.clang-format new file mode 100644 index 00000000000..0888185848d --- /dev/null +++ b/storage/tokudb/PerconaFT/.clang-format @@ -0,0 +1,36 @@ +Language: Cpp +BasedOnStyle: Google + +# The following parameters are default for Google style, +# but as they are important for our project they +# are set explicitly here +AlignAfterOpenBracket: Align +BreakBeforeBinaryOperators: None +ColumnLimit: 80 +PointerAlignment: Left +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +UseTab: Never + +# Non-default parametes +NamespaceIndentation: All +IndentWidth: 4 +TabWidth: 4 +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +BinPackParameters: false +BinPackArguments: false +ExperimentalAutoDetectBinPacking: false +AllowAllParametersOfDeclarationOnNextLine: false +#AlignConsecutiveAssignments: yes +#AlignConsecutiveDeclarations: yes +BreakStringLiterals: false +ReflowComments: true diff --git a/storage/tokudb/PerconaFT/CMakeLists.txt b/storage/tokudb/PerconaFT/CMakeLists.txt index 487ba8b734a..50db3068daa 100644 --- a/storage/tokudb/PerconaFT/CMakeLists.txt +++ b/storage/tokudb/PerconaFT/CMakeLists.txt @@ -9,6 +9,12 @@ project(TokuDB) set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") +# See: https://jira.percona.com/browse/TDB-93 +IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-address-of-packed-member") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-address-of-packed-member") +ENDIF() + # detect when we are being built as a subproject if (DEFINED MYSQL_PROJECT_NAME_DOCSTRING) add_definitions( -DMYSQL_TOKUDB_ENGINE=1) diff --git a/storage/tokudb/PerconaFT/README.md b/storage/tokudb/PerconaFT/README.md index d53caf00190..ffb646b67af 100644 --- a/storage/tokudb/PerconaFT/README.md +++ b/storage/tokudb/PerconaFT/README.md @@ -9,20 +9,18 @@ PerconaFT is provided as a shared library with an interface similar to Berkeley DB. To build the full MySQL product, see the instructions for -[Percona/tokudb-engine][tokudb-engine]. To build TokuMX, see the instructions -for [Percona/percona-server-mongodb][mongo]. This document covers PerconaFT only. +[Percona/percona-server][percona-server]. This document covers PerconaFT only. -[tokudb-engine]: https://github.com/Percona/tokudb-engine -[mongo]: https://github.com/Percona/percona-server-mongodb +[percona-server]: https://github.com/Percona/percona-server Building -------- PerconaFT is built using CMake >= 2.8.9. Out-of-source builds are -recommended. You need a C++11 compiler, though only GCC >= 4.7 and -Apple's Clang are tested. You also need zlib development packages -(`yum install zlib-devel` or `apt-get install zlib1g-dev`). +recommended. You need a C++11 compiler, though only some versions +of GCC >= 4.7 and Clang are tested. You also need zlib development +packages (`yum install zlib-devel` or `apt-get install zlib1g-dev`). You will also need the source code for jemalloc, checked out in `third_party/`. @@ -42,16 +40,16 @@ CC=gcc47 CXX=g++47 cmake \ cmake --build . --target install ``` -This will build `libtokudb.so` and `libtokuportability.so` and install it, +This will build `libft.so` and `libtokuportability.so` and install it, some header files, and some examples to `percona-ft/prefix/`. It will also build jemalloc and install it alongside these libraries, you should link to that if you are planning to run benchmarks or in production. ### Platforms -PerconaFT is supported on 64-bit Centos, should work on other 64-bit linux -distributions, and may work on OSX 10.8 and FreeBSD. PerconaFT is not -supported on 32-bit systems. +PerconaFT is supported on 64-bit Centos, Debian, and Ubuntu and should work +on other 64-bit linux distributions, and may work on OSX 10.8 and FreeBSD. +PerconaFT is not supported on 32-bit systems. [Transparent hugepages][transparent-hugepages] is a feature in newer linux kernel versions that causes problems for the memory usage tracking @@ -97,16 +95,9 @@ We have two publicly accessible mailing lists for TokuDB: - tokudb-dev@googlegroups.com is for discussion of the development of TokuDB. -and two for TokuMX: - - - tokumx-user@googlegroups.com is for general and support related - questions about the use of TokuMX. - - tokumx-dev@googlegroups.com is for discussion of the development of - TokuMX. - All source code and test contributions must be provided under a [BSD 2-Clause][bsd-2] license. For any small change set, the license text may be contained within the commit comment and the pull request. For larger contributions, the license must be presented in a COPYING. file in the root of the PerconaFT project. Please see the [BSD 2-Clause license template][bsd-2] for the content of the license text. -[jira]: https://tokutek.atlassian.net/browse/FT/ +[jira]: https://jira.percona.com/projects/TDB [bsd-2]: http://opensource.org/licenses/BSD-2-Clause/ diff --git a/storage/tokudb/PerconaFT/ft/ft-ops.cc b/storage/tokudb/PerconaFT/ft/ft-ops.cc index 60885ed9f33..d036366dd63 100644 --- a/storage/tokudb/PerconaFT/ft/ft-ops.cc +++ b/storage/tokudb/PerconaFT/ft/ft-ops.cc @@ -4880,6 +4880,94 @@ static void toku_pfs_keys_init(const char *toku_instr_group_name) { toku_instr_probe_1 = new toku_instr_probe(*fti_probe_1_key); } +static void toku_pfs_keys_destroy(void) { + delete kibbutz_mutex_key; + delete minicron_p_mutex_key; + delete queue_result_mutex_key; + delete tpool_lock_mutex_key; + delete workset_lock_mutex_key; + delete bjm_jobs_lock_mutex_key; + delete log_internal_lock_mutex_key; + delete cachetable_ev_thread_lock_mutex_key; + delete cachetable_disk_nb_mutex_key; + delete safe_file_size_lock_mutex_key; + delete cachetable_m_mutex_key; + delete checkpoint_safe_mutex_key; + delete ft_ref_lock_mutex_key; + delete ft_open_close_lock_mutex_key; + delete loader_error_mutex_key; + delete bfs_mutex_key; + delete loader_bl_mutex_key; + delete loader_fi_lock_mutex_key; + delete loader_out_mutex_key; + delete result_output_condition_lock_mutex_key; + delete block_table_mutex_key; + delete rollback_log_node_cache_mutex_key; + delete txn_lock_mutex_key; + delete txn_state_lock_mutex_key; + delete txn_child_manager_mutex_key; + delete txn_manager_lock_mutex_key; + delete treenode_mutex_key; + delete locktree_request_info_mutex_key; + delete locktree_request_info_retry_mutex_key; + delete manager_mutex_key; + delete manager_escalation_mutex_key; + delete db_txn_struct_i_txn_mutex_key; + delete manager_escalator_mutex_key; + delete indexer_i_indexer_lock_mutex_key; + delete indexer_i_indexer_estimate_lock_mutex_key; + + delete tokudb_file_data_key; + delete tokudb_file_load_key; + delete tokudb_file_tmp_key; + delete tokudb_file_log_key; + + delete fti_probe_1_key; + + delete extractor_thread_key; + delete fractal_thread_key; + delete io_thread_key; + delete eviction_thread_key; + delete kibbutz_thread_key; + delete minicron_thread_key; + delete tp_internal_thread_key; + + delete result_state_cond_key; + delete bjm_jobs_wait_key; + delete cachetable_p_refcount_wait_key; + delete cachetable_m_flow_control_cond_key; + delete cachetable_m_ev_thread_cond_key; + delete bfs_cond_key; + delete result_output_condition_key; + delete manager_m_escalator_done_key; + delete lock_request_m_wait_cond_key; + delete queue_result_cond_key; + delete ws_worker_wait_key; + delete rwlock_wait_read_key; + delete rwlock_wait_write_key; + delete rwlock_cond_key; + delete tp_thread_wait_key; + delete tp_pool_wait_free_key; + delete frwlock_m_wait_read_key; + delete kibbutz_k_cond_key; + delete minicron_p_condvar_key; + delete locktree_request_info_retry_cv_key; + + delete multi_operation_lock_key; + delete low_priority_multi_operation_lock_key; + delete cachetable_m_list_lock_key; + delete cachetable_m_pending_lock_expensive_key; + delete cachetable_m_pending_lock_cheap_key; + delete cachetable_m_lock_key; + delete result_i_open_dbs_rwlock_key; + delete checkpoint_safe_rwlock_key; + delete cachetable_value_key; + delete safe_file_size_lock_rwlock_key; + + delete cachetable_disk_nb_rwlock_key; + delete toku_instr_probe_1; +} + int toku_ft_layer_init(void) { int r = 0; @@ -4916,8 +5004,7 @@ void toku_ft_layer_destroy(void) { toku_status_destroy(); partitioned_counters_destroy(); toku_scoped_malloc_destroy(); - - delete toku_instr_probe_1; + toku_pfs_keys_destroy(); // Portability must be cleaned up last toku_portability_destroy(); diff --git a/storage/tokudb/PerconaFT/ft/tests/ft-clock-test.cc b/storage/tokudb/PerconaFT/ft/tests/ft-clock-test.cc index 26a3dae673c..00ff8cf204b 100644 --- a/storage/tokudb/PerconaFT/ft/tests/ft-clock-test.cc +++ b/storage/tokudb/PerconaFT/ft/tests/ft-clock-test.cc @@ -184,11 +184,11 @@ static void test2(int fd, FT ft_h, FTNODE *dn) { PAIR_ATTR attr; memset(&attr, 0, sizeof(attr)); toku_ftnode_pe_callback(*dn, attr, ft_h, def_pe_finalize_impl, nullptr); - invariant(BP_STATE(*dn, 0) == (is_leaf) ? PT_ON_DISK : PT_COMPRESSED); + invariant(BP_STATE(*dn, 0) == ((is_leaf) ? PT_ON_DISK : PT_COMPRESSED)); invariant(BP_STATE(*dn, 1) == PT_AVAIL); invariant(BP_SHOULD_EVICT(*dn, 1)); toku_ftnode_pe_callback(*dn, attr, ft_h, def_pe_finalize_impl, nullptr); - invariant(BP_STATE(*dn, 1) == (is_leaf) ? PT_ON_DISK : PT_COMPRESSED); + invariant(BP_STATE(*dn, 1) == ((is_leaf) ? PT_ON_DISK : PT_COMPRESSED)); bool req = toku_ftnode_pf_req_callback(*dn, &bfe_subset); invariant(req); diff --git a/storage/tokudb/PerconaFT/ft/tests/log-test4.cc b/storage/tokudb/PerconaFT/ft/tests/log-test4.cc index e0bbedb95bf..019852bb729 100644 --- a/storage/tokudb/PerconaFT/ft/tests/log-test4.cc +++ b/storage/tokudb/PerconaFT/ft/tests/log-test4.cc @@ -54,7 +54,7 @@ test_main (int argc __attribute__((__unused__)), { ml_lock(&logger->input_lock); toku_logger_make_space_in_inbuf(logger, 5); - snprintf(logger->inbuf.buf+logger->inbuf.n_in_buf, 5, "a1234"); + memcpy(logger->inbuf.buf+logger->inbuf.n_in_buf, "a1234", 5); logger->inbuf.n_in_buf+=5; logger->lsn.lsn++; logger->inbuf.max_lsn_in_buf = logger->lsn; diff --git a/storage/tokudb/PerconaFT/portability/tests/test-max-data.cc b/storage/tokudb/PerconaFT/portability/tests/test-max-data.cc index dbbea974a49..fb5fc37111a 100644 --- a/storage/tokudb/PerconaFT/portability/tests/test-max-data.cc +++ b/storage/tokudb/PerconaFT/portability/tests/test-max-data.cc @@ -64,7 +64,7 @@ int main(int argc, char *const argv[]) { if (verbose) printf("maxdata=%" PRIu64 " 0x%" PRIx64 "\n", maxdata, maxdata); // check the data size -#if defined(__x86_64__) || defined(__aarch64__) +#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) assert(maxdata > (1ULL << 32)); #elif __i386__ assert(maxdata < (1ULL << 32)); diff --git a/storage/tokudb/PerconaFT/portability/toku_instrumentation.h b/storage/tokudb/PerconaFT/portability/toku_instrumentation.h index 8c9390edc0a..c300f9275b8 100644 --- a/storage/tokudb/PerconaFT/portability/toku_instrumentation.h +++ b/storage/tokudb/PerconaFT/portability/toku_instrumentation.h @@ -52,6 +52,8 @@ class toku_instr_key { UU(const char *name)) {} explicit toku_instr_key(UU(pfs_key_t key_id)) {} + + ~toku_instr_key() {} }; typedef toku_instr_probe_empty toku_instr_probe; diff --git a/storage/tokudb/PerconaFT/portability/toku_portability.h b/storage/tokudb/PerconaFT/portability/toku_portability.h index 1096467a35d..8a3dcf5afc4 100644 --- a/storage/tokudb/PerconaFT/portability/toku_portability.h +++ b/storage/tokudb/PerconaFT/portability/toku_portability.h @@ -157,7 +157,7 @@ extern "C" { #endif // Deprecated functions. -#if !defined(TOKU_ALLOW_DEPRECATED) +#if !defined(TOKU_ALLOW_DEPRECATED) && !defined(__clang__) int creat(const char *pathname, mode_t mode) __attribute__((__deprecated__)); int fstat(int fd, struct stat *buf) __attribute__((__deprecated__)); int stat(const char *path, struct stat *buf) __attribute__((__deprecated__)); diff --git a/storage/tokudb/PerconaFT/portability/toku_pthread.h b/storage/tokudb/PerconaFT/portability/toku_pthread.h index 44de01244d2..e3bd3bce598 100644 --- a/storage/tokudb/PerconaFT/portability/toku_pthread.h +++ b/storage/tokudb/PerconaFT/portability/toku_pthread.h @@ -168,11 +168,7 @@ typedef struct toku_mutex_aligned { } #else // __linux__, at least #define ZERO_COND_INITIALIZER \ - { \ - { \ - { 0 } \ - } \ - } + {} #endif static inline void toku_mutexattr_init(toku_pthread_mutexattr_t *attr) { diff --git a/storage/tokudb/PerconaFT/portability/toku_time.h b/storage/tokudb/PerconaFT/portability/toku_time.h index a1278ef0337..c4c45b8e8c7 100644 --- a/storage/tokudb/PerconaFT/portability/toku_time.h +++ b/storage/tokudb/PerconaFT/portability/toku_time.h @@ -43,6 +43,9 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. #include #include #include +#if defined(__powerpc__) +# include +#endif static inline float toku_tdiff (struct timeval *a, struct timeval *b) { return (float)((a->tv_sec - b->tv_sec) + 1e-6 * (a->tv_usec - b->tv_usec)); @@ -106,6 +109,8 @@ static inline tokutime_t toku_time_now(void) { uint64_t result; __asm __volatile__ ("mrs %[rt], cntvct_el0" : [rt] "=r" (result)); return result; +#elif defined(__powerpc__) + return __ppc_get_timebase(); #else #error No timer implementation for this platform #endif diff --git a/storage/tokudb/PerconaFT/src/tests/checkpoint_stress.cc b/storage/tokudb/PerconaFT/src/tests/checkpoint_stress.cc index 135a9843ce4..d3e5ddd5031 100644 --- a/storage/tokudb/PerconaFT/src/tests/checkpoint_stress.cc +++ b/storage/tokudb/PerconaFT/src/tests/checkpoint_stress.cc @@ -351,7 +351,7 @@ test_main (int argc, char * const argv[]) { // arg that suppresses valgrind on this child process break; } - // otherwise, fall through to an error + /* fall through */ // otherwise, fall through to an error case 'h': case '?': usage(argv[0]); diff --git a/storage/tokudb/PerconaFT/src/tests/directory_lock.cc b/storage/tokudb/PerconaFT/src/tests/directory_lock.cc index f040e680903..b28a71704cf 100644 --- a/storage/tokudb/PerconaFT/src/tests/directory_lock.cc +++ b/storage/tokudb/PerconaFT/src/tests/directory_lock.cc @@ -69,7 +69,7 @@ static void verify_shared_ops_fail(DB_ENV* env, DB* db) { uint32_t flags = 0; DBT key,val; DBT in_key,in_val; - uint32_t in_key_data, in_val_data = 0; + uint32_t in_key_data = 0, in_val_data = 0; memset(&in_key, 0, sizeof(in_key)); memset(&in_val, 0, sizeof(in_val)); in_key.size = sizeof(in_key_data); diff --git a/storage/tokudb/PerconaFT/src/tests/loader-cleanup-test.cc b/storage/tokudb/PerconaFT/src/tests/loader-cleanup-test.cc index ea894683c23..a229cb5b565 100644 --- a/storage/tokudb/PerconaFT/src/tests/loader-cleanup-test.cc +++ b/storage/tokudb/PerconaFT/src/tests/loader-cleanup-test.cc @@ -172,12 +172,12 @@ err_type_str (enum test_type t) { case einval_o: return "open"; case enospc_fc: return "fclose"; case abort_via_poll: return "abort_via_poll"; - case commit: assert(0); - case abort_txn: assert(0); - case abort_loader: assert(0); + case commit: abort(); + case abort_txn: abort(); + case abort_loader: abort(); } // I know that Barry prefers the single-return case, but writing the code this way means that the compiler will complain if I forget something in the enum. -Bradley - assert(0); + abort(); return NULL; } @@ -193,12 +193,12 @@ err_msg_type_str (enum test_type t) { case einval_o: return "EINVAL"; case enospc_fc: return "ENOSPC"; case abort_via_poll: return "non-zero"; - case commit: assert(0); - case abort_txn: assert(0); - case abort_loader: assert(0); + case commit: abort(); + case abort_txn: abort(); + case abort_loader: abort(); } // I know that Barry prefers the single-return case, but writing the code this way means that the compiler will complain if I forget something in the enum. -Bradley - assert(0); + abort(); return NULL; } @@ -873,7 +873,7 @@ static void run_test(enum test_type t, int trigger) case abort_via_poll: poll_count_trigger = trigger; break; default: - assert(0); + abort(); } diff --git a/storage/tokudb/PerconaFT/src/tests/recover-del-multiple-abort.cc b/storage/tokudb/PerconaFT/src/tests/recover-del-multiple-abort.cc index a8455c0f406..425c12e1a90 100644 --- a/storage/tokudb/PerconaFT/src/tests/recover-del-multiple-abort.cc +++ b/storage/tokudb/PerconaFT/src/tests/recover-del-multiple-abort.cc @@ -81,7 +81,7 @@ put_callback(DB *dest_db, DB *src_db, DBT_ARRAY *dest_keys, DBT_ARRAY *dest_vals memcpy(dest_key->data, &pri_data[dbnum], dest_key->size); break; default: - assert(0); + abort(); } if (dest_val) { @@ -95,9 +95,9 @@ put_callback(DB *dest_db, DB *src_db, DBT_ARRAY *dest_keys, DBT_ARRAY *dest_vals } break; case DB_DBT_REALLOC: - assert(0); + abort(); default: - assert(0); + abort(); } } diff --git a/storage/tokudb/PerconaFT/src/tests/recover-del-multiple-srcdb-fdelete-all.cc b/storage/tokudb/PerconaFT/src/tests/recover-del-multiple-srcdb-fdelete-all.cc index e823a74627d..75479cb69c4 100644 --- a/storage/tokudb/PerconaFT/src/tests/recover-del-multiple-srcdb-fdelete-all.cc +++ b/storage/tokudb/PerconaFT/src/tests/recover-del-multiple-srcdb-fdelete-all.cc @@ -85,7 +85,7 @@ put_callback(DB *dest_db, DB *src_db, DBT_ARRAY *dest_keys, DBT_ARRAY *dest_vals memcpy(dest_key->data, &pri_data[dbnum], dest_key->size); break; default: - assert(0); + abort(); } if (dest_val) { @@ -99,9 +99,9 @@ put_callback(DB *dest_db, DB *src_db, DBT_ARRAY *dest_keys, DBT_ARRAY *dest_vals } break; case DB_DBT_REALLOC: - assert(0); + abort(); default: - assert(0); + abort(); } } diff --git a/storage/tokudb/PerconaFT/src/tests/recover-del-multiple.cc b/storage/tokudb/PerconaFT/src/tests/recover-del-multiple.cc index c2ee80c438f..9f4b1cd9cb8 100644 --- a/storage/tokudb/PerconaFT/src/tests/recover-del-multiple.cc +++ b/storage/tokudb/PerconaFT/src/tests/recover-del-multiple.cc @@ -84,7 +84,7 @@ put_callback(DB *dest_db, DB *src_db, DBT_ARRAY *dest_keys, DBT_ARRAY *dest_vals memcpy(dest_key->data, &pri_data[dbnum], dest_key->size); break; default: - assert(0); + abort(); } if (dest_val) { @@ -98,9 +98,9 @@ put_callback(DB *dest_db, DB *src_db, DBT_ARRAY *dest_keys, DBT_ARRAY *dest_vals } break; case DB_DBT_REALLOC: - assert(0); + abort(); default: - assert(0); + abort(); } } diff --git a/storage/tokudb/PerconaFT/src/tests/recover-put-multiple-abort.cc b/storage/tokudb/PerconaFT/src/tests/recover-put-multiple-abort.cc index d045800960c..da40a61f24b 100644 --- a/storage/tokudb/PerconaFT/src/tests/recover-put-multiple-abort.cc +++ b/storage/tokudb/PerconaFT/src/tests/recover-put-multiple-abort.cc @@ -81,7 +81,7 @@ put_callback(DB *dest_db, DB *src_db, DBT_ARRAY *dest_keys, DBT_ARRAY *dest_vals memcpy(dest_key->data, &pri_data[dbnum], dest_key->size); break; default: - assert(0); + abort(); } if (dest_val) { @@ -95,9 +95,9 @@ put_callback(DB *dest_db, DB *src_db, DBT_ARRAY *dest_keys, DBT_ARRAY *dest_vals } break; case DB_DBT_REALLOC: - assert(0); + abort(); default: - assert(0); + abort(); } } diff --git a/storage/tokudb/PerconaFT/src/tests/recovery_fileops_unit.cc b/storage/tokudb/PerconaFT/src/tests/recovery_fileops_unit.cc index cc99ab560d8..45f0b465db4 100644 --- a/storage/tokudb/PerconaFT/src/tests/recovery_fileops_unit.cc +++ b/storage/tokudb/PerconaFT/src/tests/recovery_fileops_unit.cc @@ -158,7 +158,7 @@ do_args(int argc, char * const argv[]) { choices[i] = -1; } - char c; + signed char c; while ((c = getopt(argc, argv, "vqhcrO:A:B:C:D:E:F:G:H:I:J:X:")) != -1) { switch (c) { case 'v': @@ -217,7 +217,7 @@ do_args(int argc, char * const argv[]) { // arg that suppresses valgrind on this child process break; } - // otherwise, fall through to an error + /* fall through */ // otherwise, fall through to an error default: usage(); break; diff --git a/storage/tokudb/PerconaFT/src/tests/test-prepare3.cc b/storage/tokudb/PerconaFT/src/tests/test-prepare3.cc index 5cb3796a26b..f57fc963529 100644 --- a/storage/tokudb/PerconaFT/src/tests/test-prepare3.cc +++ b/storage/tokudb/PerconaFT/src/tests/test-prepare3.cc @@ -128,6 +128,7 @@ static void check_prepared_list (enum prepared_state ps[NTXNS], long count, DB_P goto next; case PREPARED: count_prepared++; + /* fall through */ case MAYBE_COMMITTED: case MAYBE_ABORTED: count_maybe_prepared++; diff --git a/storage/tokudb/hatoku_hton.cc b/storage/tokudb/hatoku_hton.cc index 1cfe4e0a8bc..114376f3541 100644 --- a/storage/tokudb/hatoku_hton.cc +++ b/storage/tokudb/hatoku_hton.cc @@ -983,7 +983,7 @@ static bool tokudb_sync_on_prepare(void) { } static int tokudb_xa_prepare(handlerton* hton, THD* thd, bool all) { - TOKUDB_DBUG_ENTER(""); + TOKUDB_DBUG_ENTER("%u", all); TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_XA, "enter"); int r = 0; @@ -1011,6 +1011,22 @@ static int tokudb_xa_prepare(handlerton* hton, THD* thd, bool all) { r = txn->xa_prepare(txn, &thd_xid, syncflag); // test hook to induce a crash on a debug build DBUG_EXECUTE_IF("tokudb_crash_prepare_after", DBUG_SUICIDE();); + + // XA log entries can be interleaved in the binlog since XA prepare on the master + // flushes to the binlog. There can be log entries from different clients pushed + // into the binlog before XA commit is executed on the master. Therefore, the slave + // thread must be able to juggle multiple XA transactions. Tokudb does this by + // zapping the client transaction context on the slave when executing the XA prepare + // and expecting to process XA commit with commit_by_xid (which supplies the XID so + // that the transaction can be looked up and committed). + if (r == 0 && all && thd->slave_thread) { + TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_XA, "zap txn context %u", thd_sql_command(thd)); + if (thd_sql_command(thd) == SQLCOM_XA_PREPARE) { + trx->all = NULL; + trx->sub_sp_level = NULL; + trx->sp_level = NULL; + } + } } else { TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_XA, "nothing to prepare %d", all); } @@ -1041,6 +1057,7 @@ static int tokudb_xa_recover(handlerton* hton, XID* xid_list, uint len) { static int tokudb_commit_by_xid(handlerton* hton, XID* xid) { TOKUDB_DBUG_ENTER(""); TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_XA, "enter"); + TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_XA, "xid %p", xid); int r = 0; DB_TXN* txn = NULL; TOKU_XA_XID* toku_xid = (TOKU_XA_XID*)xid; @@ -1060,6 +1077,7 @@ cleanup: static int tokudb_rollback_by_xid(handlerton* hton, XID* xid) { TOKUDB_DBUG_ENTER(""); TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_XA, "enter"); + TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_XA, "xid %p", xid); int r = 0; DB_TXN* txn = NULL; TOKU_XA_XID* toku_xid = (TOKU_XA_XID*)xid; -- cgit v1.2.1 From cf242aded51f1e1fb53b75911ab7e4da3af37eb4 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 24 Apr 2018 19:08:50 +0200 Subject: 8.42 --- pcre/AUTHORS | 6 +- pcre/ChangeLog | 53 ++ pcre/INSTALL | 320 ++++++----- pcre/LICENCE | 6 +- pcre/Makefile.in | 58 +- pcre/NEWS | 6 + pcre/NON-AUTOTOOLS-BUILD | 15 +- pcre/aclocal.m4 | 46 +- pcre/ar-lib | 2 +- pcre/compile | 9 +- pcre/config.guess | 188 ++++--- pcre/config.h.generic | 6 +- pcre/config.sub | 73 ++- pcre/configure | 145 +++-- pcre/configure.ac | 26 +- pcre/depcomp | 6 +- pcre/doc/html/NON-AUTOTOOLS-BUILD.txt | 15 +- pcre/install-sh | 4 +- pcre/ltmain.sh | 764 +++++++++++++++++--------- pcre/m4/libtool.m4 | 69 ++- pcre/m4/ltoptions.m4 | 2 +- pcre/m4/ltsugar.m4 | 2 +- pcre/m4/ltversion.m4 | 12 +- pcre/m4/lt~obsolete.m4 | 2 +- pcre/missing | 6 +- pcre/pcre.h.generic | 12 +- pcre/pcre.h.in | 8 +- pcre/pcre_compile.c | 2 +- pcre/pcre_dfa_exec.c | 4 +- pcre/pcre_exec.c | 8 +- pcre/pcre_jit_compile.c | 407 ++++++++++---- pcre/pcregrep.c | 55 +- pcre/pcreposix.c | 6 +- pcre/sljit/sljitConfig.h | 6 +- pcre/sljit/sljitConfigInternal.h | 70 ++- pcre/sljit/sljitLir.c | 711 ++++++++++++++++++------ pcre/sljit/sljitLir.h | 435 +++++++++------ pcre/sljit/sljitNativeARM_32.c | 750 ++++++++++++++++++------- pcre/sljit/sljitNativeARM_64.c | 994 +++++++++++++++------------------- pcre/sljit/sljitNativeARM_T2_32.c | 647 ++++++++++++++++------ pcre/sljit/sljitNativeMIPS_32.c | 229 ++++++++ pcre/sljit/sljitNativeMIPS_64.c | 129 +++++ pcre/sljit/sljitNativeMIPS_common.c | 315 +++++------ pcre/sljit/sljitNativePPC_64.c | 55 ++ pcre/sljit/sljitNativePPC_common.c | 964 ++++++++++++++------------------- pcre/sljit/sljitNativeSPARC_32.c | 119 ++++ pcre/sljit/sljitNativeSPARC_common.c | 221 ++++---- pcre/sljit/sljitNativeX86_32.c | 488 +++++++++++++---- pcre/sljit/sljitNativeX86_64.c | 364 ++++++++----- pcre/sljit/sljitNativeX86_common.c | 214 +++----- pcre/sljit/sljitUtils.c | 103 ++-- pcre/test-driver | 6 +- pcre/testdata/testinput2 | 8 + pcre/testdata/testinput5 | 6 + pcre/testdata/testoutput2 | 16 + pcre/testdata/testoutput5 | 8 + 56 files changed, 5804 insertions(+), 3397 deletions(-) diff --git a/pcre/AUTHORS b/pcre/AUTHORS index 291657caef1..eb9b1a44b34 100644 --- a/pcre/AUTHORS +++ b/pcre/AUTHORS @@ -8,7 +8,7 @@ Email domain: cam.ac.uk University of Cambridge Computing Service, Cambridge, England. -Copyright (c) 1997-2017 University of Cambridge +Copyright (c) 1997-2018 University of Cambridge All rights reserved @@ -19,7 +19,7 @@ Written by: Zoltan Herczeg Email local part: hzmester Emain domain: freemail.hu -Copyright(c) 2010-2017 Zoltan Herczeg +Copyright(c) 2010-2018 Zoltan Herczeg All rights reserved. @@ -30,7 +30,7 @@ Written by: Zoltan Herczeg Email local part: hzmester Emain domain: freemail.hu -Copyright(c) 2009-2017 Zoltan Herczeg +Copyright(c) 2009-2018 Zoltan Herczeg All rights reserved. diff --git a/pcre/ChangeLog b/pcre/ChangeLog index 590a7542885..7b53195f6a6 100644 --- a/pcre/ChangeLog +++ b/pcre/ChangeLog @@ -4,6 +4,59 @@ ChangeLog for PCRE Note that the PCRE 8.xx series (PCRE1) is now in a bugfix-only state. All development is happening in the PCRE2 10.xx series. + +Version 8.42 20-March-2018 +-------------------------- + +1. Fixed a MIPS issue in the JIT compiler reported by Joshua Kinard. + +2. Fixed outdated real_pcre definitions in pcre.h.in (patch by Evgeny Kotkov). + +3. pcregrep was truncating components of file names to 128 characters when +processing files with the -r option, and also (some very odd code) truncating +path names to 512 characters. There is now a check on the absolute length of +full path file names, which may be up to 2047 characters long. + +4. Using pcre_dfa_exec(), in UTF mode when UCP support was not defined, there +was the possibility of a false positive match when caselessly matching a "not +this character" item such as [^\x{1234}] (with a code point greater than 127) +because the "other case" variable was not being initialized. + +5. Although pcre_jit_exec checks whether the pattern is compiled +in a given mode, it was also expected that at least one mode is available. +This is fixed and pcre_jit_exec returns with PCRE_ERROR_JIT_BADOPTION +when the pattern is not optimized by JIT at all. + +6. The line number and related variables such as match counts in pcregrep +were all int variables, causing overflow when files with more than 2147483647 +lines were processed (assuming 32-bit ints). They have all been changed to +unsigned long ints. + +7. If a backreference with a minimum repeat count of zero was first in a +pattern, apart from assertions, an incorrect first matching character could be +recorded. For example, for the pattern /(?=(a))\1?b/, "b" was incorrectly set +as the first character of a match. + +8. Fix out-of-bounds read for partial matching of /./ against an empty string +when the newline type is CRLF. + +9. When matching using the the REG_STARTEND feature of the POSIX API with a +non-zero starting offset, unset capturing groups with lower numbers than a +group that did capture something were not being correctly returned as "unset" +(that is, with offset values of -1). + +10. Matching the pattern /(*UTF)\C[^\v]+\x80/ against an 8-bit string +containing multi-code-unit characters caused bad behaviour and possibly a +crash. This issue was fixed for other kinds of repeat in release 8.37 by change +38, but repeating character classes were overlooked. + +11. A small fix to pcregrep to avoid compiler warnings for -Wformat-overflow=2. + +12. Added --enable-jit=auto support to configure.ac. + +13. Fix misleading error message in configure.ac. + + Version 8.41 05-July-2017 ------------------------- diff --git a/pcre/INSTALL b/pcre/INSTALL index 2099840756e..8865734f81b 100644 --- a/pcre/INSTALL +++ b/pcre/INSTALL @@ -1,8 +1,8 @@ Installation Instructions ************************* -Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation, -Inc. + Copyright (C) 1994-1996, 1999-2002, 2004-2016 Free Software +Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright @@ -12,97 +12,96 @@ without warranty of any kind. Basic Installation ================== - Briefly, the shell command `./configure && make && make install' + Briefly, the shell command './configure && make && make install' should configure, build, and install this package. The following -more-detailed instructions are generic; see the `README' file for +more-detailed instructions are generic; see the 'README' file for instructions specific to this package. Some packages provide this -`INSTALL' file but do not implement all of the features documented +'INSTALL' file but do not implement all of the features documented below. The lack of an optional feature in a given package is not necessarily a bug. More recommendations for GNU packages can be found in *note Makefile Conventions: (standards)Makefile Conventions. - The `configure' shell script attempts to guess correct values for + The 'configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that +those values to create a 'Makefile' in each directory of the package. +It may also create one or more '.h' files containing system-dependent +definitions. Finally, it creates a shell script 'config.status' that you can run in the future to recreate the current configuration, and a -file `config.log' containing compiler output (useful mainly for -debugging `configure'). +file 'config.log' containing compiler output (useful mainly for +debugging 'configure'). - It can also use an optional file (typically called `config.cache' -and enabled with `--cache-file=config.cache' or simply `-C') that saves -the results of its tests to speed up reconfiguring. Caching is -disabled by default to prevent problems with accidental use of stale -cache files. + It can also use an optional file (typically called 'config.cache' and +enabled with '--cache-file=config.cache' or simply '-C') that saves the +results of its tests to speed up reconfiguring. Caching is disabled by +default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can +to figure out how 'configure' could check whether to do them, and mail +diffs or instructions to the address given in the 'README' so they can be considered for the next release. If you are using the cache, and at -some point `config.cache' contains results you don't want to keep, you +some point 'config.cache' contains results you don't want to keep, you may remove or edit it. - The file `configure.ac' (or `configure.in') is used to create -`configure' by a program called `autoconf'. You need `configure.ac' if -you want to change it or regenerate `configure' using a newer version -of `autoconf'. + The file 'configure.ac' (or 'configure.in') is used to create +'configure' by a program called 'autoconf'. You need 'configure.ac' if +you want to change it or regenerate 'configure' using a newer version of +'autoconf'. The simplest way to compile this package is: - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. + 1. 'cd' to the directory containing the package's source code and type + './configure' to configure the package for your system. - Running `configure' might take a while. While running, it prints + Running 'configure' might take a while. While running, it prints some messages telling which features it is checking for. - 2. Type `make' to compile the package. + 2. Type 'make' to compile the package. - 3. Optionally, type `make check' to run any self-tests that come with + 3. Optionally, type 'make check' to run any self-tests that come with the package, generally using the just-built uninstalled binaries. - 4. Type `make install' to install the programs and any data files and + 4. Type 'make install' to install the programs and any data files and documentation. When installing into a prefix owned by root, it is recommended that the package be configured and built as a regular - user, and only the `make install' phase executed with root + user, and only the 'make install' phase executed with root privileges. - 5. Optionally, type `make installcheck' to repeat any self-tests, but + 5. Optionally, type 'make installcheck' to repeat any self-tests, but this time using the binaries in their final installed location. This target does not install anything. Running this target as a - regular user, particularly if the prior `make install' required + regular user, particularly if the prior 'make install' required root privileges, verifies that the installation completed correctly. 6. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly + source code directory by typing 'make clean'. To also remove the + files that 'configure' created (so you can compile the package for + a different kind of computer), type 'make distclean'. There is + also a 'make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. - 7. Often, you can also type `make uninstall' to remove the installed + 7. Often, you can also type 'make uninstall' to remove the installed files again. In practice, not all packages have tested that uninstallation works correctly, even though it is required by the GNU Coding Standards. - 8. Some packages, particularly those that use Automake, provide `make + 8. Some packages, particularly those that use Automake, provide 'make distcheck', which can by used by developers to test that all other - targets like `make install' and `make uninstall' work correctly. + targets like 'make install' and 'make uninstall' work correctly. This target is generally not run by end users. Compilers and Options ===================== Some systems require unusual options for compilation or linking that -the `configure' script does not know about. Run `./configure --help' +the 'configure' script does not know about. Run './configure --help' for details on some of the pertinent environment variables. - You can give `configure' initial values for configuration parameters -by setting variables in the command line or in the environment. Here -is an example: + You can give 'configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here is +an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix @@ -113,21 +112,21 @@ Compiling For Multiple Architectures You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their -own directory. To do this, you can use GNU `make'. `cd' to the +own directory. To do this, you can use GNU 'make'. 'cd' to the directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. This -is known as a "VPATH" build. +the 'configure' script. 'configure' automatically checks for the source +code in the directory that 'configure' is in and in '..'. This is known +as a "VPATH" build. - With a non-GNU `make', it is safer to compile the package for one + With a non-GNU 'make', it is safer to compile the package for one architecture at a time in the source code directory. After you have -installed the package for one architecture, use `make distclean' before +installed the package for one architecture, use 'make distclean' before reconfiguring for another architecture. On MacOS X 10.5 and later systems, you can create libraries and executables that work on multiple system types--known as "fat" or -"universal" binaries--by specifying multiple `-arch' options to the -compiler but only a single `-arch' option to the preprocessor. Like +"universal" binaries--by specifying multiple '-arch' options to the +compiler but only a single '-arch' option to the preprocessor. Like this: ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ @@ -136,105 +135,104 @@ this: This is not guaranteed to produce working output in all cases, you may have to build one architecture at a time and combine the results -using the `lipo' tool if you have problems. +using the 'lipo' tool if you have problems. Installation Names ================== - By default, `make install' installs the package's commands under -`/usr/local/bin', include files under `/usr/local/include', etc. You -can specify an installation prefix other than `/usr/local' by giving -`configure' the option `--prefix=PREFIX', where PREFIX must be an + By default, 'make install' installs the package's commands under +'/usr/local/bin', include files under '/usr/local/include', etc. You +can specify an installation prefix other than '/usr/local' by giving +'configure' the option '--prefix=PREFIX', where PREFIX must be an absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you -pass the option `--exec-prefix=PREFIX' to `configure', the package uses +pass the option '--exec-prefix=PREFIX' to 'configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give -options like `--bindir=DIR' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. In general, the -default for these options is expressed in terms of `${prefix}', so that -specifying just `--prefix' will affect all of the other directory +options like '--bindir=DIR' to specify different values for particular +kinds of files. Run 'configure --help' for a list of the directories +you can set and what kinds of files go in them. In general, the default +for these options is expressed in terms of '${prefix}', so that +specifying just '--prefix' will affect all of the other directory specifications that were not explicitly provided. The most portable way to affect installation locations is to pass the -correct locations to `configure'; however, many packages provide one or +correct locations to 'configure'; however, many packages provide one or both of the following shortcuts of passing variable assignments to the -`make install' command line to change installation locations without +'make install' command line to change installation locations without having to reconfigure or recompile. The first method involves providing an override variable for each -affected directory. For example, `make install +affected directory. For example, 'make install prefix=/alternate/directory' will choose an alternate location for all directory configuration variables that were expressed in terms of -`${prefix}'. Any directories that were specified during `configure', -but not in terms of `${prefix}', must each be overridden at install -time for the entire installation to be relocated. The approach of -makefile variable overrides for each directory variable is required by -the GNU Coding Standards, and ideally causes no recompilation. -However, some platforms have known limitations with the semantics of -shared libraries that end up requiring recompilation when using this -method, particularly noticeable in packages that use GNU Libtool. - - The second method involves providing the `DESTDIR' variable. For -example, `make install DESTDIR=/alternate/directory' will prepend -`/alternate/directory' before all installation names. The approach of -`DESTDIR' overrides is not required by the GNU Coding Standards, and +'${prefix}'. Any directories that were specified during 'configure', +but not in terms of '${prefix}', must each be overridden at install time +for the entire installation to be relocated. The approach of makefile +variable overrides for each directory variable is required by the GNU +Coding Standards, and ideally causes no recompilation. However, some +platforms have known limitations with the semantics of shared libraries +that end up requiring recompilation when using this method, particularly +noticeable in packages that use GNU Libtool. + + The second method involves providing the 'DESTDIR' variable. For +example, 'make install DESTDIR=/alternate/directory' will prepend +'/alternate/directory' before all installation names. The approach of +'DESTDIR' overrides is not required by the GNU Coding Standards, and does not work on platforms that have drive letters. On the other hand, it does better at avoiding recompilation issues, and works well even -when some directory options were not specified in terms of `${prefix}' -at `configure' time. +when some directory options were not specified in terms of '${prefix}' +at 'configure' time. Optional Features ================= If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the +with an extra prefix or suffix on their names by giving 'configure' the +option '--program-prefix=PREFIX' or '--program-suffix=SUFFIX'. + + Some packages pay attention to '--enable-FEATURE' options to +'configure', where FEATURE indicates an optional part of the package. +They may also pay attention to '--with-PACKAGE' options, where PACKAGE +is something like 'gnu-as' or 'x' (for the X Window System). The +'README' should mention any '--enable-' and '--with-' options that the package recognizes. - For packages that use the X Window System, `configure' can usually + For packages that use the X Window System, 'configure' can usually find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. +you can use the 'configure' options '--x-includes=DIR' and +'--x-libraries=DIR' to specify their locations. Some packages offer the ability to configure how verbose the -execution of `make' will be. For these packages, running `./configure +execution of 'make' will be. For these packages, running './configure --enable-silent-rules' sets the default to minimal output, which can be -overridden with `make V=1'; while running `./configure +overridden with 'make V=1'; while running './configure --disable-silent-rules' sets the default to verbose, which can be -overridden with `make V=0'. +overridden with 'make V=0'. Particular systems ================== - On HP-UX, the default C compiler is not ANSI C compatible. If GNU -CC is not installed, it is recommended to use the following options in + On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC +is not installed, it is recommended to use the following options in order to use an ANSI C compiler: ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. - HP-UX `make' updates targets which have the same time stamps as -their prerequisites, which makes it generally unusable when shipped -generated files such as `configure' are involved. Use GNU `make' -instead. + HP-UX 'make' updates targets which have the same time stamps as their +prerequisites, which makes it generally unusable when shipped generated +files such as 'configure' are involved. Use GNU 'make' instead. On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot -parse its `' header file. The option `-nodtk' can be used as -a workaround. If GNU CC is not installed, it is therefore recommended -to try +parse its '' header file. The option '-nodtk' can be used as a +workaround. If GNU CC is not installed, it is therefore recommended to +try ./configure CC="cc" @@ -242,26 +240,26 @@ and if that doesn't work, try ./configure CC="cc -nodtk" - On Solaris, don't put `/usr/ucb' early in your `PATH'. This + On Solaris, don't put '/usr/ucb' early in your 'PATH'. This directory contains several dysfunctional programs; working variants of -these programs are available in `/usr/bin'. So, if you need `/usr/ucb' -in your `PATH', put it _after_ `/usr/bin'. +these programs are available in '/usr/bin'. So, if you need '/usr/ucb' +in your 'PATH', put it _after_ '/usr/bin'. - On Haiku, software installed for all users goes in `/boot/common', -not `/usr/local'. It is recommended to use the following options: + On Haiku, software installed for all users goes in '/boot/common', +not '/usr/local'. It is recommended to use the following options: ./configure --prefix=/boot/common Specifying the System Type ========================== - There may be some features `configure' cannot figure out + There may be some features 'configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the -_same_ architectures, `configure' can figure that out, but if it prints +_same_ architectures, 'configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the -`--build=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name which has the form: +'--build=TYPE' option. TYPE can either be a short name for the system +type, such as 'sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM @@ -270,101 +268,101 @@ where SYSTEM can have one of these forms: OS KERNEL-OS - See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't + See the file 'config.sub' for the possible values of each field. If +'config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should -use the option `--target=TYPE' to select the type of system they will +use the option '--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will -eventually be run) with `--host=TYPE'. +eventually be run) with '--host=TYPE'. Sharing Defaults ================ - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. + If you want to set default values for 'configure' scripts to share, +you can create a site shell script called 'config.site' that gives +default values for variables like 'CC', 'cache_file', and 'prefix'. +'configure' looks for 'PREFIX/share/config.site' if it exists, then +'PREFIX/etc/config.site' if it exists. Or, you can set the +'CONFIG_SITE' environment variable to the location of the site script. +A warning: not all 'configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the -environment passed to `configure'. However, some packages may run +environment passed to 'configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set -them in the `configure' command line, using `VAR=value'. For example: +them in the 'configure' command line, using 'VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc -causes the specified `gcc' to be used as the C compiler (unless it is +causes the specified 'gcc' to be used as the C compiler (unless it is overridden in the site shell script). -Unfortunately, this technique does not work for `CONFIG_SHELL' due to -an Autoconf limitation. Until the limitation is lifted, you can use -this workaround: +Unfortunately, this technique does not work for 'CONFIG_SHELL' due to an +Autoconf limitation. Until the limitation is lifted, you can use this +workaround: CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash -`configure' Invocation +'configure' Invocation ====================== - `configure' recognizes the following options to control how it + 'configure' recognizes the following options to control how it operates. -`--help' -`-h' - Print a summary of all of the options to `configure', and exit. +'--help' +'-h' + Print a summary of all of the options to 'configure', and exit. -`--help=short' -`--help=recursive' +'--help=short' +'--help=recursive' Print a summary of the options unique to this package's - `configure', and exit. The `short' variant lists options used - only in the top level, while the `recursive' variant lists options - also present in any nested packages. + 'configure', and exit. The 'short' variant lists options used only + in the top level, while the 'recursive' variant lists options also + present in any nested packages. -`--version' -`-V' - Print the version of Autoconf used to generate the `configure' +'--version' +'-V' + Print the version of Autoconf used to generate the 'configure' script, and exit. -`--cache-file=FILE' +'--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, - traditionally `config.cache'. FILE defaults to `/dev/null' to + traditionally 'config.cache'. FILE defaults to '/dev/null' to disable caching. -`--config-cache' -`-C' - Alias for `--cache-file=config.cache'. +'--config-cache' +'-C' + Alias for '--cache-file=config.cache'. -`--quiet' -`--silent' -`-q' +'--quiet' +'--silent' +'-q' Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error + suppress all normal output, redirect it to '/dev/null' (any error messages will still be shown). -`--srcdir=DIR' +'--srcdir=DIR' Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. + 'configure' can determine that directory automatically. -`--prefix=DIR' - Use DIR as the installation prefix. *note Installation Names:: - for more details, including other options available for fine-tuning - the installation locations. +'--prefix=DIR' + Use DIR as the installation prefix. *note Installation Names:: for + more details, including other options available for fine-tuning the + installation locations. -`--no-create' -`-n' +'--no-create' +'-n' Run the configure checks, but stop before creating any output files. -`configure' also accepts some other, not widely useful, options. Run -`configure --help' for more details. +'configure' also accepts some other, not widely useful, options. Run +'configure --help' for more details. diff --git a/pcre/LICENCE b/pcre/LICENCE index dd9071a8dd8..f6ef7fd7664 100644 --- a/pcre/LICENCE +++ b/pcre/LICENCE @@ -25,7 +25,7 @@ Email domain: cam.ac.uk University of Cambridge Computing Service, Cambridge, England. -Copyright (c) 1997-2017 University of Cambridge +Copyright (c) 1997-2018 University of Cambridge All rights reserved. @@ -36,7 +36,7 @@ Written by: Zoltan Herczeg Email local part: hzmester Emain domain: freemail.hu -Copyright(c) 2010-2017 Zoltan Herczeg +Copyright(c) 2010-2018 Zoltan Herczeg All rights reserved. @@ -47,7 +47,7 @@ Written by: Zoltan Herczeg Email local part: hzmester Emain domain: freemail.hu -Copyright(c) 2009-2017 Zoltan Herczeg +Copyright(c) 2009-2018 Zoltan Herczeg All rights reserved. diff --git a/pcre/Makefile.in b/pcre/Makefile.in index 9c8ccecbd87..156cb77fe47 100644 --- a/pcre/Makefile.in +++ b/pcre/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2014 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -251,7 +251,7 @@ libpcre_la_OBJECTS = $(am_libpcre_la_OBJECTS) \ AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent -am__v_lt_1 = +am__v_lt_1 = libpcre_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libpcre_la_CFLAGS) \ $(CFLAGS) $(libpcre_la_LDFLAGS) $(LDFLAGS) -o $@ @@ -449,11 +449,11 @@ am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; -am__v_GEN_1 = +am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ -am__v_at_1 = +am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -467,7 +467,7 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ AM_V_CC = $(am__v_CC_@AM_V@) am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) am__v_CC_0 = @echo " CC " $@; -am__v_CC_1 = +am__v_CC_1 = CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ @@ -475,7 +475,7 @@ LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; -am__v_CCLD_1 = +am__v_CCLD_1 = CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ @@ -485,7 +485,7 @@ LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ AM_V_CXX = $(am__v_CXX_@AM_V@) am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@) am__v_CXX_0 = @echo " CXX " $@; -am__v_CXX_1 = +am__v_CXX_1 = CXXLD = $(CXX) CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ @@ -493,7 +493,7 @@ CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ AM_V_CXXLD = $(am__v_CXXLD_@AM_V@) am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) am__v_CXXLD_0 = @echo " CXXLD " $@; -am__v_CXXLD_1 = +am__v_CXXLD_1 = SOURCES = $(libpcre_la_SOURCES) $(nodist_libpcre_la_SOURCES) \ $(libpcre16_la_SOURCES) $(nodist_libpcre16_la_SOURCES) \ $(libpcre32_la_SOURCES) $(nodist_libpcre32_la_SOURCES) \ @@ -988,7 +988,7 @@ dist_noinst_DATA = $(pcrecpp_html) # The Libtool libraries to install. We'll add to this later. lib_LTLIBRARIES = $(am__append_4) $(am__append_5) $(am__append_6) \ $(am__append_20) $(am__append_22) -check_SCRIPTS = +check_SCRIPTS = dist_noinst_SCRIPTS = RunTest $(am__append_39) # Additional files to delete on 'make clean' and 'make maintainer-clean'. @@ -1110,7 +1110,7 @@ BUILT_SOURCES = pcre_chartables.c @WITH_PCRE8_TRUE@libpcre_la_CFLAGS = $(VISIBILITY_CFLAGS) $(AM_CFLAGS) \ @WITH_PCRE8_TRUE@ $(am__append_7) $(am__append_10) -@WITH_PCRE8_TRUE@libpcre_la_LIBADD = +@WITH_PCRE8_TRUE@libpcre_la_LIBADD = @WITH_PCRE8_TRUE@nodist_libpcre_la_SOURCES = \ @WITH_PCRE8_TRUE@ pcre_chartables.c @@ -1141,7 +1141,7 @@ BUILT_SOURCES = pcre_chartables.c @WITH_PCRE16_TRUE@libpcre16_la_CFLAGS = $(VISIBILITY_CFLAGS) \ @WITH_PCRE16_TRUE@ $(AM_CFLAGS) $(am__append_8) \ @WITH_PCRE16_TRUE@ $(am__append_11) -@WITH_PCRE16_TRUE@libpcre16_la_LIBADD = +@WITH_PCRE16_TRUE@libpcre16_la_LIBADD = @WITH_PCRE16_TRUE@nodist_libpcre16_la_SOURCES = \ @WITH_PCRE16_TRUE@ pcre_chartables.c @@ -1172,7 +1172,7 @@ BUILT_SOURCES = pcre_chartables.c @WITH_PCRE32_TRUE@libpcre32_la_CFLAGS = $(VISIBILITY_CFLAGS) \ @WITH_PCRE32_TRUE@ $(AM_CFLAGS) $(am__append_9) \ @WITH_PCRE32_TRUE@ $(am__append_12) -@WITH_PCRE32_TRUE@libpcre32_la_LIBADD = +@WITH_PCRE32_TRUE@libpcre32_la_LIBADD = @WITH_PCRE32_TRUE@nodist_libpcre32_la_SOURCES = \ @WITH_PCRE32_TRUE@ pcre_chartables.c @@ -1313,8 +1313,8 @@ pcrecpp_man = doc/pcrecpp.3 @WITH_GCOV_TRUE@COVERAGE_NAME = $(PACKAGE)-$(VERSION) @WITH_GCOV_TRUE@COVERAGE_OUTPUT_FILE = $(COVERAGE_NAME)-coverage.info @WITH_GCOV_TRUE@COVERAGE_OUTPUT_DIR = $(COVERAGE_NAME)-coverage -@WITH_GCOV_TRUE@COVERAGE_LCOV_EXTRA_FLAGS = -@WITH_GCOV_TRUE@COVERAGE_GENHTML_EXTRA_FLAGS = +@WITH_GCOV_TRUE@COVERAGE_LCOV_EXTRA_FLAGS = +@WITH_GCOV_TRUE@COVERAGE_GENHTML_EXTRA_FLAGS = @WITH_GCOV_TRUE@coverage_quiet = $(coverage_quiet_$(V)) @WITH_GCOV_TRUE@coverage_quiet_ = $(coverage_quiet_$(AM_DEFAULT_VERBOSITY)) @WITH_GCOV_TRUE@coverage_quiet_0 = --quiet @@ -1364,7 +1364,7 @@ config.h: stamp-h1 stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status @rm -f stamp-h1 cd $(top_builddir) && $(SHELL) ./config.status config.h -$(srcdir)/config.h.in: $(am__configure_deps) +$(srcdir)/config.h.in: $(am__configure_deps) ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) rm -f stamp-h1 touch $@ @@ -1425,19 +1425,19 @@ clean-libLTLIBRARIES: rm -f $${locs}; \ } -libpcre.la: $(libpcre_la_OBJECTS) $(libpcre_la_DEPENDENCIES) $(EXTRA_libpcre_la_DEPENDENCIES) +libpcre.la: $(libpcre_la_OBJECTS) $(libpcre_la_DEPENDENCIES) $(EXTRA_libpcre_la_DEPENDENCIES) $(AM_V_CCLD)$(libpcre_la_LINK) $(am_libpcre_la_rpath) $(libpcre_la_OBJECTS) $(libpcre_la_LIBADD) $(LIBS) -libpcre16.la: $(libpcre16_la_OBJECTS) $(libpcre16_la_DEPENDENCIES) $(EXTRA_libpcre16_la_DEPENDENCIES) +libpcre16.la: $(libpcre16_la_OBJECTS) $(libpcre16_la_DEPENDENCIES) $(EXTRA_libpcre16_la_DEPENDENCIES) $(AM_V_CCLD)$(libpcre16_la_LINK) $(am_libpcre16_la_rpath) $(libpcre16_la_OBJECTS) $(libpcre16_la_LIBADD) $(LIBS) -libpcre32.la: $(libpcre32_la_OBJECTS) $(libpcre32_la_DEPENDENCIES) $(EXTRA_libpcre32_la_DEPENDENCIES) +libpcre32.la: $(libpcre32_la_OBJECTS) $(libpcre32_la_DEPENDENCIES) $(EXTRA_libpcre32_la_DEPENDENCIES) $(AM_V_CCLD)$(libpcre32_la_LINK) $(am_libpcre32_la_rpath) $(libpcre32_la_OBJECTS) $(libpcre32_la_LIBADD) $(LIBS) -libpcrecpp.la: $(libpcrecpp_la_OBJECTS) $(libpcrecpp_la_DEPENDENCIES) $(EXTRA_libpcrecpp_la_DEPENDENCIES) +libpcrecpp.la: $(libpcrecpp_la_OBJECTS) $(libpcrecpp_la_DEPENDENCIES) $(EXTRA_libpcrecpp_la_DEPENDENCIES) $(AM_V_CXXLD)$(libpcrecpp_la_LINK) $(am_libpcrecpp_la_rpath) $(libpcrecpp_la_OBJECTS) $(libpcrecpp_la_LIBADD) $(LIBS) -libpcreposix.la: $(libpcreposix_la_OBJECTS) $(libpcreposix_la_DEPENDENCIES) $(EXTRA_libpcreposix_la_DEPENDENCIES) +libpcreposix.la: $(libpcreposix_la_OBJECTS) $(libpcreposix_la_DEPENDENCIES) $(EXTRA_libpcreposix_la_DEPENDENCIES) $(AM_V_CCLD)$(libpcreposix_la_LINK) $(am_libpcreposix_la_rpath) $(libpcreposix_la_OBJECTS) $(libpcreposix_la_LIBADD) $(LIBS) install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) @@ -1498,31 +1498,31 @@ clean-noinstPROGRAMS: echo " rm -f" $$list; \ rm -f $$list -dftables$(EXEEXT): $(dftables_OBJECTS) $(dftables_DEPENDENCIES) $(EXTRA_dftables_DEPENDENCIES) +dftables$(EXEEXT): $(dftables_OBJECTS) $(dftables_DEPENDENCIES) $(EXTRA_dftables_DEPENDENCIES) @rm -f dftables$(EXEEXT) $(AM_V_CCLD)$(LINK) $(dftables_OBJECTS) $(dftables_LDADD) $(LIBS) -pcre_jit_test$(EXEEXT): $(pcre_jit_test_OBJECTS) $(pcre_jit_test_DEPENDENCIES) $(EXTRA_pcre_jit_test_DEPENDENCIES) +pcre_jit_test$(EXEEXT): $(pcre_jit_test_OBJECTS) $(pcre_jit_test_DEPENDENCIES) $(EXTRA_pcre_jit_test_DEPENDENCIES) @rm -f pcre_jit_test$(EXEEXT) $(AM_V_CCLD)$(pcre_jit_test_LINK) $(pcre_jit_test_OBJECTS) $(pcre_jit_test_LDADD) $(LIBS) -pcre_scanner_unittest$(EXEEXT): $(pcre_scanner_unittest_OBJECTS) $(pcre_scanner_unittest_DEPENDENCIES) $(EXTRA_pcre_scanner_unittest_DEPENDENCIES) +pcre_scanner_unittest$(EXEEXT): $(pcre_scanner_unittest_OBJECTS) $(pcre_scanner_unittest_DEPENDENCIES) $(EXTRA_pcre_scanner_unittest_DEPENDENCIES) @rm -f pcre_scanner_unittest$(EXEEXT) $(AM_V_CXXLD)$(pcre_scanner_unittest_LINK) $(pcre_scanner_unittest_OBJECTS) $(pcre_scanner_unittest_LDADD) $(LIBS) -pcre_stringpiece_unittest$(EXEEXT): $(pcre_stringpiece_unittest_OBJECTS) $(pcre_stringpiece_unittest_DEPENDENCIES) $(EXTRA_pcre_stringpiece_unittest_DEPENDENCIES) +pcre_stringpiece_unittest$(EXEEXT): $(pcre_stringpiece_unittest_OBJECTS) $(pcre_stringpiece_unittest_DEPENDENCIES) $(EXTRA_pcre_stringpiece_unittest_DEPENDENCIES) @rm -f pcre_stringpiece_unittest$(EXEEXT) $(AM_V_CXXLD)$(pcre_stringpiece_unittest_LINK) $(pcre_stringpiece_unittest_OBJECTS) $(pcre_stringpiece_unittest_LDADD) $(LIBS) -pcrecpp_unittest$(EXEEXT): $(pcrecpp_unittest_OBJECTS) $(pcrecpp_unittest_DEPENDENCIES) $(EXTRA_pcrecpp_unittest_DEPENDENCIES) +pcrecpp_unittest$(EXEEXT): $(pcrecpp_unittest_OBJECTS) $(pcrecpp_unittest_DEPENDENCIES) $(EXTRA_pcrecpp_unittest_DEPENDENCIES) @rm -f pcrecpp_unittest$(EXEEXT) $(AM_V_CXXLD)$(pcrecpp_unittest_LINK) $(pcrecpp_unittest_OBJECTS) $(pcrecpp_unittest_LDADD) $(LIBS) -pcregrep$(EXEEXT): $(pcregrep_OBJECTS) $(pcregrep_DEPENDENCIES) $(EXTRA_pcregrep_DEPENDENCIES) +pcregrep$(EXEEXT): $(pcregrep_OBJECTS) $(pcregrep_DEPENDENCIES) $(EXTRA_pcregrep_DEPENDENCIES) @rm -f pcregrep$(EXEEXT) $(AM_V_CCLD)$(pcregrep_LINK) $(pcregrep_OBJECTS) $(pcregrep_LDADD) $(LIBS) -pcretest$(EXEEXT): $(pcretest_OBJECTS) $(pcretest_DEPENDENCIES) $(EXTRA_pcretest_DEPENDENCIES) +pcretest$(EXEEXT): $(pcretest_OBJECTS) $(pcretest_DEPENDENCIES) $(EXTRA_pcretest_DEPENDENCIES) @rm -f pcretest$(EXEEXT) $(AM_V_CCLD)$(pcretest_LINK) $(pcretest_OBJECTS) $(pcretest_LDADD) $(LIBS) install-binSCRIPTS: $(bin_SCRIPTS) @@ -3003,8 +3003,8 @@ maintainer-clean-generic: @echo "it deletes files that may require special tools to rebuild." -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) -@WITH_GCOV_FALSE@distclean-local: @WITH_GCOV_FALSE@clean-local: +@WITH_GCOV_FALSE@distclean-local: clean: clean-am clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \ diff --git a/pcre/NEWS b/pcre/NEWS index 36be07cb880..09b4ad36003 100644 --- a/pcre/NEWS +++ b/pcre/NEWS @@ -1,6 +1,12 @@ News about PCRE releases ------------------------ +Release 8.42 20-March-2018 +-------------------------- + +This is a bug-fix release. + + Release 8.41 13-June-2017 ------------------------- diff --git a/pcre/NON-AUTOTOOLS-BUILD b/pcre/NON-AUTOTOOLS-BUILD index 3910059106b..37f6164475b 100644 --- a/pcre/NON-AUTOTOOLS-BUILD +++ b/pcre/NON-AUTOTOOLS-BUILD @@ -760,13 +760,14 @@ The character code used is EBCDIC, not ASCII or Unicode. In z/OS, UNIX APIs and applications can be supported through UNIX System Services, and in such an environment PCRE can be built in the same way as in other systems. However, in native z/OS (without UNIX System Services) and in z/VM, special ports are -required. For details, please see this web site: +required. PCRE1 version 8.39 is available in file 882 on this site: - http://www.zaconsultants.net + http://www.cbttape.org -You may download PCRE from WWW.CBTTAPE.ORG, file 882.  Everything, source and -executable, is in EBCDIC and native z/OS file formats and this is the -recommended download site. +Everything, source and executable, is in EBCDIC and native z/OS file formats. +However, this software is not maintained and will not be upgraded. If you are +new to PCRE you should be looking at PCRE2 (version 10.30 or later). -========================== -Last Updated: 25 June 2015 +=============================== +Last Updated: 13 September 2017 +=============================== diff --git a/pcre/aclocal.m4 b/pcre/aclocal.m4 index c2b46211930..71bd63e6c80 100644 --- a/pcre/aclocal.m4 +++ b/pcre/aclocal.m4 @@ -1,6 +1,6 @@ -# generated automatically by aclocal 1.15 -*- Autoconf -*- +# generated automatically by aclocal 1.15.1 -*- Autoconf -*- -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -296,7 +296,7 @@ AS_VAR_COPY([$1], [pkg_cv_][$1]) AS_VAR_IF([$1], [""], [$5], [$4])dnl ])dnl PKG_CHECK_VAR -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -311,7 +311,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.15' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.15], [], +m4_if([$1], [1.15.1], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -327,12 +327,12 @@ m4_define([_AM_AUTOCONF_VERSION], []) # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.15])dnl +[AM_AUTOMAKE_VERSION([1.15.1])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -394,7 +394,7 @@ AC_SUBST([AR])dnl # AM_AUX_DIR_EXPAND -*- Autoconf -*- -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -446,7 +446,7 @@ am_aux_dir=`cd "$ac_aux_dir" && pwd` # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -477,7 +477,7 @@ AC_CONFIG_COMMANDS_PRE( Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -668,7 +668,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -744,7 +744,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -941,7 +941,7 @@ for _am_header in $config_headers :; do done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -962,7 +962,7 @@ if test x"${install_sh+set}" != xset; then fi AC_SUBST([install_sh])]) -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -983,7 +983,7 @@ AC_SUBST([am__leading_dot])]) # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1033,7 +1033,7 @@ rm -f confinc confmf # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1072,7 +1072,7 @@ fi # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1101,7 +1101,7 @@ AC_DEFUN([_AM_SET_OPTIONS], AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1148,7 +1148,7 @@ AC_LANG_POP([C])]) # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1167,7 +1167,7 @@ AC_DEFUN([AM_RUN_LOG], # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1248,7 +1248,7 @@ AC_CONFIG_COMMANDS_PRE( rm -f conftest.file ]) -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1308,7 +1308,7 @@ AC_SUBST([AM_BACKSLASH])dnl _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1336,7 +1336,7 @@ fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1355,7 +1355,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, diff --git a/pcre/ar-lib b/pcre/ar-lib index 463b9ec0206..05094d34c69 100755 --- a/pcre/ar-lib +++ b/pcre/ar-lib @@ -4,7 +4,7 @@ me=ar-lib scriptversion=2012-03-01.08; # UTC -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2017 Free Software Foundation, Inc. # Written by Peter Rosin . # # This program is free software; you can redistribute it and/or modify diff --git a/pcre/compile b/pcre/compile index a85b723c7e6..2ab71e4ea13 100755 --- a/pcre/compile +++ b/pcre/compile @@ -1,9 +1,9 @@ #! /bin/sh # Wrapper for compilers which do not understand '-c -o'. -scriptversion=2012-10-14.11; # UTC +scriptversion=2016-01-11.22; # UTC -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # Written by Tom Tromey . # # This program is free software; you can redistribute it and/or modify @@ -255,7 +255,8 @@ EOF echo "compile $scriptversion" exit $? ;; - cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) + cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ + icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) func_cl_wrapper "$@" # Doesn't return... ;; esac @@ -342,6 +343,6 @@ exit $ret # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-time-zone: "UTC" +# time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: diff --git a/pcre/config.guess b/pcre/config.guess index 6c32c8645c8..2193702b12a 100755 --- a/pcre/config.guess +++ b/pcre/config.guess @@ -1,8 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright 1992-2014 Free Software Foundation, Inc. +# Copyright 1992-2017 Free Software Foundation, Inc. -timestamp='2014-11-04' +timestamp='2017-05-27' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ timestamp='2014-11-04' # Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # # You can get the latest version of this script from: -# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess # # Please send patches to . @@ -50,7 +50,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright 1992-2014 Free Software Foundation, Inc. +Copyright 1992-2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -168,19 +168,29 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ + /sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || \ + echo unknown)` case "${UNAME_MACHINE_ARCH}" in armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; + earmv*) + arch=`echo ${UNAME_MACHINE_ARCH} | sed -e 's,^e\(armv[0-9]\).*$,\1,'` + endian=`echo ${UNAME_MACHINE_ARCH} | sed -ne 's,^.*\(eb\)$,\1,p'` + machine=${arch}${endian}-unknown + ;; *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched - # to ELF recently, or will in the future. + # to ELF recently (or will in the future) and ABI. case "${UNAME_MACHINE_ARCH}" in + earm*) + os=netbsdelf + ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) eval $set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ @@ -197,6 +207,13 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in os=netbsd ;; esac + # Determine ABI tags. + case "${UNAME_MACHINE_ARCH}" in + earm*) + expr='s/^earmv[0-9]/-eabi/;s/eb$//' + abi=`echo ${UNAME_MACHINE_ARCH} | sed -e "$expr"` + ;; + esac # The OS release # Debian GNU/NetBSD machines have a different userland, and # thus, need a distinct triplet. However, they do not need @@ -207,13 +224,13 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in release='-gnu' ;; *) - release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + release=`echo ${UNAME_RELEASE} | sed -e 's/[-_].*//' | cut -d. -f1,2` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}" + echo "${machine}-${os}${release}${abi}" exit ;; *:Bitrig:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` @@ -223,6 +240,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} exit ;; + *:LibertyBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-libertybsd${UNAME_RELEASE} + exit ;; *:ekkoBSD:*:*) echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} exit ;; @@ -235,6 +256,9 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in *:MirBSD:*:*) echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} exit ;; + *:Sortix:*:*) + echo ${UNAME_MACHINE}-unknown-sortix + exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in *4.0) @@ -251,42 +275,42 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` case "$ALPHA_CPU_TYPE" in "EV4 (21064)") - UNAME_MACHINE="alpha" ;; + UNAME_MACHINE=alpha ;; "EV4.5 (21064)") - UNAME_MACHINE="alpha" ;; + UNAME_MACHINE=alpha ;; "LCA4 (21066/21068)") - UNAME_MACHINE="alpha" ;; + UNAME_MACHINE=alpha ;; "EV5 (21164)") - UNAME_MACHINE="alphaev5" ;; + UNAME_MACHINE=alphaev5 ;; "EV5.6 (21164A)") - UNAME_MACHINE="alphaev56" ;; + UNAME_MACHINE=alphaev56 ;; "EV5.6 (21164PC)") - UNAME_MACHINE="alphapca56" ;; + UNAME_MACHINE=alphapca56 ;; "EV5.7 (21164PC)") - UNAME_MACHINE="alphapca57" ;; + UNAME_MACHINE=alphapca57 ;; "EV6 (21264)") - UNAME_MACHINE="alphaev6" ;; + UNAME_MACHINE=alphaev6 ;; "EV6.7 (21264A)") - UNAME_MACHINE="alphaev67" ;; + UNAME_MACHINE=alphaev67 ;; "EV6.8CB (21264C)") - UNAME_MACHINE="alphaev68" ;; + UNAME_MACHINE=alphaev68 ;; "EV6.8AL (21264B)") - UNAME_MACHINE="alphaev68" ;; + UNAME_MACHINE=alphaev68 ;; "EV6.8CX (21264D)") - UNAME_MACHINE="alphaev68" ;; + UNAME_MACHINE=alphaev68 ;; "EV6.9A (21264/EV69A)") - UNAME_MACHINE="alphaev69" ;; + UNAME_MACHINE=alphaev69 ;; "EV7 (21364)") - UNAME_MACHINE="alphaev7" ;; + UNAME_MACHINE=alphaev7 ;; "EV7.9 (21364A)") - UNAME_MACHINE="alphaev79" ;; + UNAME_MACHINE=alphaev79 ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` # Reset EXIT trap before exiting to avoid spurious non-zero exit code. exitcode=$? trap '' 0 @@ -359,16 +383,16 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) eval $set_cc_for_build - SUN_ARCH="i386" + SUN_ARCH=i386 # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if [ "$CC_FOR_BUILD" != no_compiler_found ]; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then - SUN_ARCH="x86_64" + SUN_ARCH=x86_64 fi fi echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` @@ -393,7 +417,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in exit ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + test "x${UNAME_RELEASE}" = x && UNAME_RELEASE=3 case "`/bin/arch`" in sun3) echo m68k-sun-sunos${UNAME_RELEASE} @@ -618,13 +642,13 @@ EOF sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` case "${sc_cpu_version}" in - 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 - 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 + 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 case "${sc_kernel_bits}" in - 32) HP_ARCH="hppa2.0n" ;; - 64) HP_ARCH="hppa2.0w" ;; - '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + 32) HP_ARCH=hppa2.0n ;; + 64) HP_ARCH=hppa2.0w ;; + '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 esac ;; esac fi @@ -663,11 +687,11 @@ EOF exit (0); } EOF - (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + (CCOPTS="" $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac - if [ ${HP_ARCH} = "hppa2.0w" ] + if [ ${HP_ARCH} = hppa2.0w ] then eval $set_cc_for_build @@ -680,12 +704,12 @@ EOF # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess # => hppa64-hp-hpux11.23 - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | grep -q __LP64__ then - HP_ARCH="hppa2.0w" + HP_ARCH=hppa2.0w else - HP_ARCH="hppa64" + HP_ARCH=hppa64 fi fi echo ${HP_ARCH}-hp-hpux${HPUX_REV} @@ -790,14 +814,14 @@ EOF echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) @@ -813,10 +837,11 @@ EOF UNAME_PROCESSOR=`/usr/bin/uname -p` case ${UNAME_PROCESSOR} in amd64) - echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - *) - echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + UNAME_PROCESSOR=x86_64 ;; + i386) + UNAME_PROCESSOR=i586 ;; esac + echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin @@ -879,7 +904,7 @@ EOF exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} exit ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix @@ -902,7 +927,7 @@ EOF EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep -q ld.so.1 - if test "$?" = 0 ; then LIBC="gnulibc1" ; fi + if test "$?" = 0 ; then LIBC=gnulibc1 ; fi echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; arc:Linux:*:* | arceb:Linux:*:*) @@ -933,6 +958,9 @@ EOF crisv32:Linux:*:*) echo ${UNAME_MACHINE}-axis-linux-${LIBC} exit ;; + e2k:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; frv:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; @@ -945,6 +973,9 @@ EOF ia64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; + k1om:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; m32r*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; @@ -970,6 +1001,9 @@ EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } ;; + mips64el:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; openrisc*:Linux:*:*) echo or1k-unknown-linux-${LIBC} exit ;; @@ -1002,6 +1036,9 @@ EOF ppcle:Linux:*:*) echo powerpcle-unknown-linux-${LIBC} exit ;; + riscv32:Linux:*:* | riscv64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; s390:Linux:*:* | s390x:Linux:*:*) echo ${UNAME_MACHINE}-ibm-linux-${LIBC} exit ;; @@ -1021,7 +1058,7 @@ EOF echo ${UNAME_MACHINE}-dec-linux-${LIBC} exit ;; x86_64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + echo ${UNAME_MACHINE}-pc-linux-${LIBC} exit ;; xtensa*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} @@ -1100,7 +1137,7 @@ EOF # uname -m prints for DJGPP always 'pc', but it prints nothing about # the processor, so we play safe by assuming i586. # Note: whatever this is, it MUST be the same as what config.sub - # prints for the "djgpp" host, or else GDB configury will decide that + # prints for the "djgpp" host, or else GDB configure will decide that # this is a cross-build. echo i586-pc-msdosdjgpp exit ;; @@ -1249,6 +1286,9 @@ EOF SX-8R:SUPER-UX:*:*) echo sx8r-nec-superux${UNAME_RELEASE} exit ;; + SX-ACE:SUPER-UX:*:*) + echo sxace-nec-superux${UNAME_RELEASE} + exit ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody${UNAME_RELEASE} exit ;; @@ -1262,16 +1302,23 @@ EOF UNAME_PROCESSOR=powerpc fi if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if [ "$CC_FOR_BUILD" != no_compiler_found ]; then if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null then case $UNAME_PROCESSOR in i386) UNAME_PROCESSOR=x86_64 ;; powerpc) UNAME_PROCESSOR=powerpc64 ;; esac fi + # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc + if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_PPC >/dev/null + then + UNAME_PROCESSOR=powerpc + fi fi elif test "$UNAME_PROCESSOR" = i386 ; then # Avoid executing cc on OS X 10.9, as it ships with a stub @@ -1286,7 +1333,7 @@ EOF exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = "x86"; then + if test "$UNAME_PROCESSOR" = x86; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi @@ -1295,15 +1342,18 @@ EOF *:QNX:*:4*) echo i386-pc-qnx exit ;; - NEO-?:NONSTOP_KERNEL:*:*) + NEO-*:NONSTOP_KERNEL:*:*) echo neo-tandem-nsk${UNAME_RELEASE} exit ;; NSE-*:NONSTOP_KERNEL:*:*) echo nse-tandem-nsk${UNAME_RELEASE} exit ;; - NSR-?:NONSTOP_KERNEL:*:*) + NSR-*:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk${UNAME_RELEASE} exit ;; + NSX-*:NONSTOP_KERNEL:*:*) + echo nsx-tandem-nsk${UNAME_RELEASE} + exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux exit ;; @@ -1317,7 +1367,7 @@ EOF # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. - if test "$cputype" = "386"; then + if test "$cputype" = 386; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" @@ -1359,7 +1409,7 @@ EOF echo i386-pc-xenix exit ;; i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE} | sed -e 's/ .*$//'` exit ;; i*86:rdos:*:*) echo ${UNAME_MACHINE}-pc-rdos @@ -1370,23 +1420,25 @@ EOF x86_64:VMkernel:*:*) echo ${UNAME_MACHINE}-unknown-esx exit ;; + amd64:Isilon\ OneFS:*:*) + echo x86_64-unknown-onefs + exit ;; esac cat >&2 < in order to provide the needed -information to handle your system. +If $0 has already been updated, send the following data and any +information you think might be pertinent to config-patches@gnu.org to +provide the necessary information to handle your system. config.guess timestamp = $timestamp diff --git a/pcre/config.h.generic b/pcre/config.h.generic index 3ad45741272..b7473c205c7 100644 --- a/pcre/config.h.generic +++ b/pcre/config.h.generic @@ -235,7 +235,7 @@ sure both macros are undefined; an emulation function will then be used. */ #define PACKAGE_NAME "PCRE" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "PCRE 8.41" +#define PACKAGE_STRING "PCRE 8.42" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "pcre" @@ -244,7 +244,7 @@ sure both macros are undefined; an emulation function will then be used. */ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "8.41" +#define PACKAGE_VERSION "8.42" /* The value of PARENS_NEST_LIMIT specifies the maximum depth of nested parentheses (of any kind) in a pattern. This limits the amount of system @@ -336,7 +336,7 @@ sure both macros are undefined; an emulation function will then be used. */ /* #undef SUPPORT_VALGRIND */ /* Version number of package */ -#define VERSION "8.41" +#define VERSION "8.42" /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ diff --git a/pcre/config.sub b/pcre/config.sub index 7ffe3737842..40ea5dfe115 100755 --- a/pcre/config.sub +++ b/pcre/config.sub @@ -1,8 +1,8 @@ #! /bin/sh # Configuration validation subroutine script. -# Copyright 1992-2014 Free Software Foundation, Inc. +# Copyright 1992-2017 Free Software Foundation, Inc. -timestamp='2014-12-03' +timestamp='2017-04-02' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ timestamp='2014-12-03' # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: -# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases @@ -53,8 +53,7 @@ timestamp='2014-12-03' me=`echo "$0" | sed -e 's,.*/,,'` usage="\ -Usage: $0 [OPTION] CPU-MFR-OPSYS - $0 [OPTION] ALIAS +Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. @@ -68,7 +67,7 @@ Report bugs and patches to ." version="\ GNU config.sub ($timestamp) -Copyright 1992-2014 Free Software Foundation, Inc. +Copyright 1992-2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -117,8 +116,8 @@ maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \ linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ - knetbsd*-gnu* | netbsd*-gnu* | \ - kopensolaris*-gnu* | \ + knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \ + kopensolaris*-gnu* | cloudabi*-eabi* | \ storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` @@ -255,15 +254,16 @@ case $basic_machine in | arc | arceb \ | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \ | avr | avr32 \ + | ba \ | be32 | be64 \ | bfin \ | c4x | c8051 | clipper \ | d10v | d30v | dlx | dsp16xx \ - | epiphany \ - | fido | fr30 | frv \ + | e2k | epiphany \ + | fido | fr30 | frv | ft32 \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | hexagon \ - | i370 | i860 | i960 | ia64 \ + | i370 | i860 | i960 | ia16 | ia64 \ | ip2k | iq2000 \ | k1om \ | le32 | le64 \ @@ -301,11 +301,12 @@ case $basic_machine in | open8 | or1k | or1knd | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle \ + | pru \ | pyramid \ | riscv32 | riscv64 \ | rl78 | rx \ | score \ - | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ @@ -314,6 +315,7 @@ case $basic_machine in | ubicom32 \ | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \ | visium \ + | wasm32 \ | we32k \ | x86 | xc16x | xstormy16 | xtensa \ | z8k | z80) @@ -376,17 +378,18 @@ case $basic_machine in | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* | avr32-* \ + | ba-* \ | be32-* | be64-* \ | bfin-* | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* \ | c8051-* | clipper-* | craynv-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ - | elxsi-* \ + | e2k-* | elxsi-* \ | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | hexagon-* \ - | i*86-* | i860-* | i960-* | ia64-* \ + | i*86-* | i860-* | i960-* | ia16-* | ia64-* \ | ip2k-* | iq2000-* \ | k1om-* \ | le32-* | le64-* \ @@ -427,13 +430,15 @@ case $basic_machine in | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \ + | pru-* \ | pyramid-* \ + | riscv32-* | riscv64-* \ | rl78-* | romp-* | rs6000-* | rx-* \ | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \ | tahoe-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tile*-* \ @@ -442,6 +447,7 @@ case $basic_machine in | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \ | vax-* \ | visium-* \ + | wasm32-* \ | we32k-* \ | x86-* | x86_64-* | xc16x-* | xps100-* \ | xstormy16-* | xtensa*-* \ @@ -518,6 +524,9 @@ case $basic_machine in basic_machine=i386-pc os=-aros ;; + asmjs) + basic_machine=asmjs-unknown + ;; aux) basic_machine=m68k-apple os=-aux @@ -638,6 +647,14 @@ case $basic_machine in basic_machine=m68k-bull os=-sysv3 ;; + e500v[12]) + basic_machine=powerpc-unknown + os=$os"spe" + ;; + e500v[12]-*) + basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + os=$os"spe" + ;; ebmon29k) basic_machine=a29k-amd os=-ebmon @@ -933,6 +950,9 @@ case $basic_machine in nsr-tandem) basic_machine=nsr-tandem ;; + nsx-tandem) + basic_machine=nsx-tandem + ;; op50n-* | op60c-*) basic_machine=hppa1.1-oki os=-proelf @@ -1017,7 +1037,7 @@ case $basic_machine in ppc-* | ppcbe-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` ;; - ppcle | powerpclittle | ppc-le | powerpc-little) + ppcle | powerpclittle) basic_machine=powerpcle-unknown ;; ppcle-* | powerpclittle-*) @@ -1027,7 +1047,7 @@ case $basic_machine in ;; ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` ;; - ppc64le | powerpc64little | ppc64-le | powerpc64-little) + ppc64le | powerpc64little) basic_machine=powerpc64le-unknown ;; ppc64le-* | powerpc64little-*) @@ -1228,6 +1248,9 @@ case $basic_machine in basic_machine=a29k-wrs os=-vxworks ;; + wasm32) + basic_machine=wasm32-unknown + ;; w65*) basic_machine=w65-wdc os=-none @@ -1373,18 +1396,18 @@ case $os in | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \ | -sym* | -kopensolaris* | -plan9* \ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ - | -aos* | -aros* \ + | -aos* | -aros* | -cloudabi* | -sortix* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -bitrig* | -openbsd* | -solidbsd* \ + | -bitrig* | -openbsd* | -solidbsd* | -libertybsd* \ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ - | -chorusos* | -chorusrdb* | -cegcc* \ + | -chorusos* | -chorusrdb* | -cegcc* | -glidix* \ | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ + | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ | -linux-newlib* | -linux-musl* | -linux-uclibc* \ | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ @@ -1393,7 +1416,8 @@ case $os in | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*) + | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \ + | -onefs* | -tirtos* | -phoenix* | -fuchsia* | -redox*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) @@ -1525,6 +1549,8 @@ case $os in ;; -nacl*) ;; + -ios) + ;; -none) ;; *) @@ -1620,6 +1646,9 @@ case $basic_machine in sparc-* | *-sun) os=-sunos4.1.1 ;; + pru-*) + os=-elf + ;; *-be) os=-beos ;; diff --git a/pcre/configure b/pcre/configure index 6fe8854a94e..0d05374f1f6 100755 --- a/pcre/configure +++ b/pcre/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for PCRE 8.41. +# Generated by GNU Autoconf 2.69 for PCRE 8.42. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -587,8 +587,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='PCRE' PACKAGE_TARNAME='pcre' -PACKAGE_VERSION='8.41' -PACKAGE_STRING='PCRE 8.41' +PACKAGE_VERSION='8.42' +PACKAGE_STRING='PCRE 8.42' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1418,7 +1418,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures PCRE 8.41 to adapt to many kinds of systems. +\`configure' configures PCRE 8.42 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1488,7 +1488,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of PCRE 8.41:";; + short | recursive ) echo "Configuration of PCRE 8.42:";; esac cat <<\_ACEOF @@ -1662,7 +1662,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -PCRE configure 8.41 +PCRE configure 8.42 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2419,7 +2419,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by PCRE $as_me 8.41, which was +It was created by PCRE $as_me 8.42, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3283,7 +3283,7 @@ fi # Define the identity of the package. PACKAGE='pcre' - VERSION='8.41' + VERSION='8.42' cat >>confdefs.h <<_ACEOF @@ -6608,8 +6608,8 @@ esac -macro_version='2.4.6' -macro_revision='2.4.6' +macro_version='2.4.6.40-6ca5-dirty' +macro_revision='2.4.6.40' @@ -8064,13 +8064,29 @@ esac fi : ${AR=ar} -: ${AR_FLAGS=cru} +# Use ARFLAGS variable as AR's operation code to sync the variable naming with +# Automake. If both AR_FLAGS and ARFLAGS are specified, AR_FLAGS should have +# higher priority because thats what people were doing historically (setting +# ARFLAGS for automake and AR_FLAGS for libtool). FIXME: Make the AR_FLAGS +# variable obsoleted/removed. + +test ${AR_FLAGS+y} || AR_FLAGS=${ARFLAGS-cr} +lt_ar_flags=$AR_FLAGS + + + + + + +# Make AR_FLAGS overridable by 'make ARFLAGS='. Don't try to run-time override +# by AR_FLAGS because that was never working and AR_FLAGS is about to die. + @@ -9788,8 +9804,8 @@ int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5 $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5 - echo "$AR cru libconftest.a conftest.o" >&5 - $AR cru libconftest.a conftest.o 2>&5 + echo "$AR $AR_FLAGS libconftest.a conftest.o" >&5 + $AR $AR_FLAGS libconftest.a conftest.o 2>&5 echo "$RANLIB libconftest.a" >&5 $RANLIB libconftest.a 2>&5 cat > conftest.c << _LT_EOF @@ -11293,6 +11309,7 @@ _LT_EOF emximp -o $lib $output_objdir/$libname.def' old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' enable_shared_with_static_runtimes=yes + file_list_spec='@' ;; interix[3-9]*) @@ -11510,7 +11527,7 @@ _LT_EOF if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' else - export_symbols_cmds='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + export_symbols_cmds='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' fi aix_use_runtimelinking=no @@ -12147,6 +12164,7 @@ $as_echo "$lt_cv_irix_exported_symbol" >&6; } emximp -o $lib $output_objdir/$libname.def' old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' enable_shared_with_static_runtimes=yes + file_list_spec='@' ;; osf3*) @@ -14090,30 +14108,41 @@ striplib= old_striplib= { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 $as_echo_n "checking whether stripping libraries is possible... " >&6; } -if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then - test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" - test -z "$striplib" && striplib="$STRIP --strip-unneeded" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } +if test -z "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } else -# FIXME - insert some real tests, host_os isn't really good enough - case $host_os in - darwin*) - if test -n "$STRIP"; then + if $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + old_striplib="$STRIP --strip-debug" + striplib="$STRIP --strip-unneeded" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + else + case $host_os in + darwin*) + # FIXME - insert some real tests, host_os isn't really good enough striplib="$STRIP -x" old_striplib="$STRIP -S" { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } - else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 + ;; + freebsd*) + if $STRIP -V 2>&1 | $GREP "elftoolchain" >/dev/null; then + old_striplib="$STRIP --strip-debug" + striplib="$STRIP --strip-unneeded" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - fi - ;; - *) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 + fi + ;; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - ;; - esac + ;; + esac + fi fi @@ -15012,6 +15041,7 @@ fi emximp -o $lib $output_objdir/$libname.def' old_archive_From_new_cmds_CXX='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' enable_shared_with_static_runtimes_CXX=yes + file_list_spec_CXX='@' ;; dgux*) @@ -16447,7 +16477,7 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then export_symbols_cmds_CXX='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' else - export_symbols_cmds_CXX='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + export_symbols_cmds_CXX='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' fi ;; pw32*) @@ -17634,9 +17664,9 @@ _ACEOF # Versioning PCRE_MAJOR="8" -PCRE_MINOR="41" +PCRE_MINOR="42" PCRE_PRERELEASE="" -PCRE_DATE="2017-07-05" +PCRE_DATE="2018-03-20" if test "$PCRE_MINOR" = "08" -o "$PCRE_MINOR" = "09" then @@ -17708,6 +17738,32 @@ else fi +# This code enables JIT if the hardware supports it. + +if test "$enable_jit" = "auto"; then + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #define SLJIT_CONFIG_AUTO 1 + #include "sljit/sljitConfigInternal.h" + #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) + #error unsupported + #endif +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + enable_jit=yes +else + enable_jit=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + # Handle --disable-pcregrep-jit (enabled by default) # Check whether --enable-pcregrep-jit was given. if test "${enable_pcregrep_jit+set}" = set; then : @@ -18204,7 +18260,7 @@ pcre_have_type_traits="0" pcre_have_bits_type_traits="0" if test "x$enable_cpp" = "xyes" -a -z "$CXX"; then - as_fn_error $? "You need a C++ compiler for C++ support." "$LINENO" 5 + as_fn_error $? "Invalid C++ compiler or C++ compiler flags" "$LINENO" 5 fi if test "x$enable_cpp" = "xyes" -a -n "$CXX" @@ -19658,16 +19714,16 @@ esac # (Note: The libpcre*_version bits are m4 variables, assigned above) EXTRA_LIBPCRE_LDFLAGS="$EXTRA_LIBPCRE_LDFLAGS \ - $NO_UNDEFINED -version-info 3:9:2" + $NO_UNDEFINED -version-info 3:10:2" EXTRA_LIBPCRE16_LDFLAGS="$EXTRA_LIBPCRE16_LDFLAGS \ - $NO_UNDEFINED -version-info 2:9:2" + $NO_UNDEFINED -version-info 2:10:2" EXTRA_LIBPCRE32_LDFLAGS="$EXTRA_LIBPCRE32_LDFLAGS \ - $NO_UNDEFINED -version-info 0:9:0" + $NO_UNDEFINED -version-info 0:10:0" EXTRA_LIBPCREPOSIX_LDFLAGS="$EXTRA_LIBPCREPOSIX_LDFLAGS \ - $NO_UNDEFINED -version-info 0:5:0" + $NO_UNDEFINED -version-info 0:6:0" EXTRA_LIBPCRECPP_LDFLAGS="$EXTRA_LIBPCRECPP_LDFLAGS \ $NO_UNDEFINED -version-info 0:1:0 \ @@ -20719,7 +20775,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by PCRE $as_me 8.41, which was +This file was extended by PCRE $as_me 8.42, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -20785,7 +20841,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -PCRE config.status 8.41 +PCRE config.status 8.42 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -20957,6 +21013,7 @@ file_magic_glob='`$ECHO "$file_magic_glob" | $SED "$delay_single_quote_subst"`' want_nocaseglob='`$ECHO "$want_nocaseglob" | $SED "$delay_single_quote_subst"`' sharedlib_from_linklib_cmd='`$ECHO "$sharedlib_from_linklib_cmd" | $SED "$delay_single_quote_subst"`' AR='`$ECHO "$AR" | $SED "$delay_single_quote_subst"`' +lt_ar_flags='`$ECHO "$lt_ar_flags" | $SED "$delay_single_quote_subst"`' AR_FLAGS='`$ECHO "$AR_FLAGS" | $SED "$delay_single_quote_subst"`' archiver_list_spec='`$ECHO "$archiver_list_spec" | $SED "$delay_single_quote_subst"`' STRIP='`$ECHO "$STRIP" | $SED "$delay_single_quote_subst"`' @@ -21140,7 +21197,6 @@ file_magic_glob \ want_nocaseglob \ sharedlib_from_linklib_cmd \ AR \ -AR_FLAGS \ archiver_list_spec \ STRIP \ RANLIB \ @@ -22162,8 +22218,11 @@ sharedlib_from_linklib_cmd=$lt_sharedlib_from_linklib_cmd # The archiver. AR=$lt_AR +# Flags to create an archive (by configure). +lt_ar_flags=$lt_ar_flags + # Flags to create an archive. -AR_FLAGS=$lt_AR_FLAGS +AR_FLAGS=\${ARFLAGS-"\$lt_ar_flags"} # How to feed a file listing to the archiver. archiver_list_spec=$lt_archiver_list_spec diff --git a/pcre/configure.ac b/pcre/configure.ac index 718a18508c9..dcdef6a9427 100644 --- a/pcre/configure.ac +++ b/pcre/configure.ac @@ -9,18 +9,18 @@ dnl The PCRE_PRERELEASE feature is for identifying release candidates. It might dnl be defined as -RC2, for example. For real releases, it should be empty. m4_define(pcre_major, [8]) -m4_define(pcre_minor, [41]) +m4_define(pcre_minor, [42]) m4_define(pcre_prerelease, []) -m4_define(pcre_date, [2017-07-05]) +m4_define(pcre_date, [2018-03-20]) # NOTE: The CMakeLists.txt file searches for the above variables in the first # 50 lines of this file. Please update that if the variables above are moved. # Libtool shared library interface versions (current:revision:age) -m4_define(libpcre_version, [3:9:2]) -m4_define(libpcre16_version, [2:9:2]) -m4_define(libpcre32_version, [0:9:0]) -m4_define(libpcreposix_version, [0:5:0]) +m4_define(libpcre_version, [3:10:2]) +m4_define(libpcre16_version, [2:10:2]) +m4_define(libpcre32_version, [0:10:0]) +m4_define(libpcreposix_version, [0:6:0]) m4_define(libpcrecpp_version, [0:1:0]) AC_PREREQ(2.57) @@ -155,6 +155,18 @@ AC_ARG_ENABLE(jit, [enable Just-In-Time compiling support]), , enable_jit=no) +# This code enables JIT if the hardware supports it. + +if test "$enable_jit" = "auto"; then + AC_LANG(C) + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ + #define SLJIT_CONFIG_AUTO 1 + #include "sljit/sljitConfigInternal.h" + #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) + #error unsupported + #endif]])], enable_jit=yes, enable_jit=no) +fi + # Handle --disable-pcregrep-jit (enabled by default) AC_ARG_ENABLE(pcregrep-jit, AS_HELP_STRING([--disable-pcregrep-jit], @@ -469,7 +481,7 @@ pcre_have_type_traits="0" pcre_have_bits_type_traits="0" if test "x$enable_cpp" = "xyes" -a -z "$CXX"; then - AC_MSG_ERROR([You need a C++ compiler for C++ support.]) + AC_MSG_ERROR([Invalid C++ compiler or C++ compiler flags]) fi if test "x$enable_cpp" = "xyes" -a -n "$CXX" diff --git a/pcre/depcomp b/pcre/depcomp index fc98710e2a1..b39f98f9ae9 100755 --- a/pcre/depcomp +++ b/pcre/depcomp @@ -1,9 +1,9 @@ #! /bin/sh # depcomp - compile a program generating dependencies as side-effects -scriptversion=2013-05-30.07; # UTC +scriptversion=2016-01-11.22; # UTC -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -786,6 +786,6 @@ exit 0 # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-time-zone: "UTC" +# time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: diff --git a/pcre/doc/html/NON-AUTOTOOLS-BUILD.txt b/pcre/doc/html/NON-AUTOTOOLS-BUILD.txt index 3910059106b..37f6164475b 100644 --- a/pcre/doc/html/NON-AUTOTOOLS-BUILD.txt +++ b/pcre/doc/html/NON-AUTOTOOLS-BUILD.txt @@ -760,13 +760,14 @@ The character code used is EBCDIC, not ASCII or Unicode. In z/OS, UNIX APIs and applications can be supported through UNIX System Services, and in such an environment PCRE can be built in the same way as in other systems. However, in native z/OS (without UNIX System Services) and in z/VM, special ports are -required. For details, please see this web site: +required. PCRE1 version 8.39 is available in file 882 on this site: - http://www.zaconsultants.net + http://www.cbttape.org -You may download PCRE from WWW.CBTTAPE.ORG, file 882.  Everything, source and -executable, is in EBCDIC and native z/OS file formats and this is the -recommended download site. +Everything, source and executable, is in EBCDIC and native z/OS file formats. +However, this software is not maintained and will not be upgraded. If you are +new to PCRE you should be looking at PCRE2 (version 10.30 or later). -========================== -Last Updated: 25 June 2015 +=============================== +Last Updated: 13 September 2017 +=============================== diff --git a/pcre/install-sh b/pcre/install-sh index 0b0fdcbba69..0360b79e7d0 100755 --- a/pcre/install-sh +++ b/pcre/install-sh @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2013-12-25.23; # UTC +scriptversion=2016-01-11.22; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -496,6 +496,6 @@ done # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-time-zone: "UTC" +# time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: diff --git a/pcre/ltmain.sh b/pcre/ltmain.sh index 0f0a2da3f9d..857338fef37 100644 --- a/pcre/ltmain.sh +++ b/pcre/ltmain.sh @@ -1,12 +1,12 @@ #! /bin/sh ## DO NOT EDIT - This file generated from ./build-aux/ltmain.in -## by inline-source v2014-01-03.01 +## by inline-source v2016-02-21.11 -# libtool (GNU libtool) 2.4.6 +# libtool (GNU libtool) 2.4.6.40-6ca5-dirty # Provide generalized library-building support services. # Written by Gordon Matzigkeit , 1996 -# Copyright (C) 1996-2015 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -31,8 +31,8 @@ PROGRAM=libtool PACKAGE=libtool -VERSION=2.4.6 -package_revision=2.4.6 +VERSION=2.4.6.40-6ca5-dirty +package_revision=2.4.6.40 ## ------ ## @@ -64,34 +64,25 @@ package_revision=2.4.6 # libraries, which are installed to $pkgauxdir. # Set a version string for this script. -scriptversion=2015-01-20.17; # UTC +scriptversion=2017-04-19.12; # UTC # General shell script boiler plate, and helper functions. # Written by Gary V. Vaughan, 2004 -# Copyright (C) 2004-2015 Free Software Foundation, Inc. -# This is free software; see the source for copying conditions. There is NO -# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. - -# As a special exception to the GNU General Public License, if you distribute -# this file as part of a program or library that is built using GNU Libtool, -# you may include this file under the same distribution terms that you use -# for the rest of that program. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# This is free software. There is NO warranty; not even for +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# Copyright (C) 2004-2017 Bootstrap Authors +# +# This file is dual licensed under the terms of the MIT license +# , and GPL version 3 or later +# . You must apply one of +# these licenses when using or redistributing this software or any of +# the files within it. See the URLs above, or the file `LICENSE` +# included in the Bootstrap distribution for the full license texts. -# Please report bugs or propose patches to gary@gnu.org. +# Please report bugs or propose patches to: +# ## ------ ## @@ -140,9 +131,6 @@ do fi" done -# CDPATH. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH - # Make sure IFS has a sensible default sp=' ' nl=' @@ -159,6 +147,26 @@ if test "${PATH_SEPARATOR+set}" != set; then fi +# func_unset VAR +# -------------- +# Portably unset VAR. +# In some shells, an 'unset VAR' statement leaves a non-zero return +# status if VAR is already unset, which might be problematic if the +# statement is used at the end of a function (thus poisoning its return +# value) or when 'set -e' is active (causing even a spurious abort of +# the script in this case). +func_unset () +{ + { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; } +} + + +# Make sure CDPATH doesn't cause `cd` commands to output the target dir. +func_unset CDPATH + +# Make sure ${,E,F}GREP behave sanely. +func_unset GREP_OPTIONS + ## ------------------------- ## ## Locate command utilities. ## @@ -259,7 +267,7 @@ test -z "$SED" && { rm -f conftest.in conftest.tmp conftest.nl conftest.out } - func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin + func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin" rm -f conftest.sed SED=$func_path_progs_result } @@ -295,7 +303,7 @@ test -z "$GREP" && { rm -f conftest.in conftest.tmp conftest.nl conftest.out } - func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin + func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin" GREP=$func_path_progs_result } @@ -580,16 +588,16 @@ if test yes = "$_G_HAVE_PLUSEQ_OP"; then { $debug_cmd - func_quote_for_eval "$2" - eval "$1+=\\ \$func_quote_for_eval_result" + func_quote_arg pretty "$2" + eval "$1+=\\ \$func_quote_arg_result" }' else func_append_quoted () { $debug_cmd - func_quote_for_eval "$2" - eval "$1=\$$1\\ \$func_quote_for_eval_result" + func_quote_arg pretty "$2" + eval "$1=\$$1\\ \$func_quote_arg_result" } fi @@ -1091,85 +1099,199 @@ func_relative_path () } -# func_quote_for_eval ARG... -# -------------------------- -# Aesthetically quote ARGs to be evaled later. -# This function returns two values: -# i) func_quote_for_eval_result -# double-quoted, suitable for a subsequent eval -# ii) func_quote_for_eval_unquoted_result -# has all characters that are still active within double -# quotes backslashified. -func_quote_for_eval () +# func_quote_portable EVAL ARG +# ---------------------------- +# Internal function to portably implement func_quote_arg. Note that we still +# keep attention to performance here so we as much as possible try to avoid +# calling sed binary (so far O(N) complexity as long as func_append is O(1)). +func_quote_portable () { $debug_cmd - func_quote_for_eval_unquoted_result= - func_quote_for_eval_result= - while test 0 -lt $#; do - case $1 in - *[\\\`\"\$]*) - _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;; - *) - _G_unquoted_arg=$1 ;; - esac - if test -n "$func_quote_for_eval_unquoted_result"; then - func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg" - else - func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg" + func_quote_portable_result=$2 + + # one-time-loop (easy break) + while true + do + if $1; then + func_quote_portable_result=`$ECHO "$2" | $SED \ + -e "$sed_double_quote_subst" -e "$sed_double_backslash"` + break fi - case $_G_unquoted_arg in - # Double-quote args containing shell metacharacters to delay - # word splitting, command substitution and variable expansion - # for a subsequent eval. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, so we specify it separately. - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - _G_quoted_arg=\"$_G_unquoted_arg\" + # Quote for eval. + case $func_quote_portable_result in + *[\\\`\"\$]*) + case $func_quote_portable_result in + *[\[\*\?]*) + func_quote_portable_result=`$ECHO "$func_quote_portable_result" \ + | $SED "$sed_quote_subst"` + break + ;; + esac + + func_quote_portable_old_IFS=$IFS + for _G_char in '\' '`' '"' '$' + do + # STATE($1) PREV($2) SEPARATOR($3) + set start "" "" + func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy + IFS=$_G_char + for _G_part in $func_quote_portable_result + do + case $1 in + quote) + func_append func_quote_portable_result "$3$2" + set quote "$_G_part" "\\$_G_char" + ;; + start) + set first "" "" + func_quote_portable_result= + ;; + first) + set quote "$_G_part" "" + ;; + esac + done + done + IFS=$func_quote_portable_old_IFS ;; - *) - _G_quoted_arg=$_G_unquoted_arg - ;; + *) ;; esac - - if test -n "$func_quote_for_eval_result"; then - func_append func_quote_for_eval_result " $_G_quoted_arg" - else - func_append func_quote_for_eval_result "$_G_quoted_arg" - fi - shift + break done + + func_quote_portable_unquoted_result=$func_quote_portable_result + case $func_quote_portable_result in + # double-quote args containing shell metacharacters to delay + # word splitting, command substitution and variable expansion + # for a subsequent eval. + # many bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + func_quote_portable_result=\"$func_quote_portable_result\" + ;; + esac } -# func_quote_for_expand ARG -# ------------------------- -# Aesthetically quote ARG to be evaled later; same as above, -# but do not quote variable references. -func_quote_for_expand () -{ - $debug_cmd +# func_quotefast_eval ARG +# ----------------------- +# Quote one ARG (internal). This is equivalent to 'func_quote_arg eval ARG', +# but optimized for speed. Result is stored in $func_quotefast_eval. +if test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then + printf -v _GL_test_printf_tilde %q '~' + if test '\~' = "$_GL_test_printf_tilde"; then + func_quotefast_eval () + { + printf -v func_quotefast_eval_result %q "$1" + } + else + # Broken older Bash implementations. Make those faster too if possible. + func_quotefast_eval () + { + case $1 in + '~'*) + func_quote_portable false "$1" + func_quotefast_eval_result=$func_quote_portable_result + ;; + *) + printf -v func_quotefast_eval_result %q "$1" + ;; + esac + } + fi +else + func_quotefast_eval () + { + func_quote_portable false "$1" + func_quotefast_eval_result=$func_quote_portable_result + } +fi - case $1 in - *[\\\`\"]*) - _G_arg=`$ECHO "$1" | $SED \ - -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;; - *) - _G_arg=$1 ;; + +# func_quote_arg MODEs ARG +# ------------------------ +# Quote one ARG to be evaled later. MODEs argument may contain zero or more +# specifiers listed below separated by ',' character. This function returns two +# values: +# i) func_quote_arg_result +# double-quoted (when needed), suitable for a subsequent eval +# ii) func_quote_arg_unquoted_result +# has all characters that are still active within double +# quotes backslashified. Available only if 'unquoted' is specified. +# +# Available modes: +# ---------------- +# 'eval' (default) +# - escape shell special characters +# 'expand' +# - the same as 'eval'; but do not quote variable references +# 'pretty' +# - request aesthetic output, i.e. '"a b"' instead of 'a\ b'. This might +# be used later in func_quote to get output like: 'echo "a b"' instead +# of 'echo a\ b'. This is slower than default on some shells. +# 'unquoted' +# - produce also $func_quote_arg_unquoted_result which does not contain +# wrapping double-quotes. +# +# Examples for 'func_quote_arg pretty,unquoted string': +# +# string | *_result | *_unquoted_result +# ------------+-----------------------+------------------- +# " | \" | \" +# a b | "a b" | a b +# "a b" | "\"a b\"" | \"a b\" +# * | "*" | * +# z="${x-$y}" | "z=\"\${x-\$y}\"" | z=\"\${x-\$y}\" +# +# Examples for 'func_quote_arg pretty,unquoted,expand string': +# +# string | *_result | *_unquoted_result +# --------------+---------------------+-------------------- +# z="${x-$y}" | "z=\"${x-$y}\"" | z=\"${x-$y}\" +func_quote_arg () +{ + _G_quote_expand=false + case ,$1, in + *,expand,*) + _G_quote_expand=: + ;; esac - case $_G_arg in - # Double-quote args containing shell metacharacters to delay - # word splitting and command substitution for a subsequent eval. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, so we specify it separately. - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - _G_arg=\"$_G_arg\" + case ,$1, in + *,pretty,*|*,expand,*|*,unquoted,*) + func_quote_portable $_G_quote_expand "$2" + func_quote_arg_result=$func_quote_portable_result + func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result + ;; + *) + # Faster quote-for-eval for some shells. + func_quotefast_eval "$2" + func_quote_arg_result=$func_quotefast_eval_result ;; esac +} + - func_quote_for_expand_result=$_G_arg +# func_quote MODEs ARGs... +# ------------------------ +# Quote all ARGs to be evaled later and join them into single command. See +# func_quote_arg's description for more info. +func_quote () +{ + $debug_cmd + _G_func_quote_mode=$1 ; shift + func_quote_result= + while test 0 -lt $#; do + func_quote_arg "$_G_func_quote_mode" "$1" + if test -n "$func_quote_result"; then + func_append func_quote_result " $func_quote_arg_result" + else + func_append func_quote_result "$func_quote_arg_result" + fi + shift + done } @@ -1215,8 +1337,8 @@ func_show_eval () _G_cmd=$1 _G_fail_exp=${2-':'} - func_quote_for_expand "$_G_cmd" - eval "func_notquiet $func_quote_for_expand_result" + func_quote_arg pretty,expand "$_G_cmd" + eval "func_notquiet $func_quote_arg_result" $opt_dry_run || { eval "$_G_cmd" @@ -1241,8 +1363,8 @@ func_show_eval_locale () _G_fail_exp=${2-':'} $opt_quiet || { - func_quote_for_expand "$_G_cmd" - eval "func_echo $func_quote_for_expand_result" + func_quote_arg expand,pretty "$_G_cmd" + eval "func_echo $func_quote_arg_result" } $opt_dry_run || { @@ -1369,30 +1491,26 @@ func_lt_ver () # End: #! /bin/sh -# Set a version string for this script. -scriptversion=2014-01-07.03; # UTC - # A portable, pluggable option parser for Bourne shell. # Written by Gary V. Vaughan, 2010 -# Copyright (C) 2010-2015 Free Software Foundation, Inc. -# This is free software; see the source for copying conditions. There is NO -# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This is free software. There is NO warranty; not even for +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# Copyright (C) 2010-2017 Bootstrap Authors +# +# This file is dual licensed under the terms of the MIT license +# , and GPL version 3 or later +# . You must apply one of +# these licenses when using or redistributing this software or any of +# the files within it. See the URLs above, or the file `LICENSE` +# included in the Bootstrap distribution for the full license texts. -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Please report bugs or propose patches to: +# -# Please report bugs or propose patches to gary@gnu.org. +# Set a version string for this script. +scriptversion=2016-03-06.01; # UTC ## ------ ## @@ -1415,7 +1533,7 @@ scriptversion=2014-01-07.03; # UTC # # In order for the '--version' option to work, you will need to have a # suitably formatted comment like the one at the top of this file -# starting with '# Written by ' and ending with '# warranty; '. +# starting with '# Written by ' and ending with '# Copyright'. # # For '-h' and '--help' to work, you will also need a one line # description of your script's purpose in a comment directly above the @@ -1427,7 +1545,7 @@ scriptversion=2014-01-07.03; # UTC # to display verbose messages only when your user has specified # '--verbose'. # -# After sourcing this file, you can plug processing for additional +# After sourcing this file, you can plug in processing for additional # options by amending the variables from the 'Configuration' section # below, and following the instructions in the 'Option parsing' # section further down. @@ -1476,8 +1594,8 @@ fatal_help="Try '\$progname --help' for more information." ## ------------------------- ## # This section contains functions for adding, removing, and running hooks -# to the main code. A hook is just a named list of of function, that can -# be run in order later on. +# in the main code. A hook is just a list of function names that can be +# run in order later on. # func_hookable FUNC_NAME # ----------------------- @@ -1510,7 +1628,8 @@ func_add_hook () # func_remove_hook FUNC_NAME HOOK_FUNC # ------------------------------------ -# Remove HOOK_FUNC from the list of functions called by FUNC_NAME. +# Remove HOOK_FUNC from the list of hook functions to be called by +# FUNC_NAME. func_remove_hook () { $debug_cmd @@ -1519,10 +1638,28 @@ func_remove_hook () } +# func_propagate_result FUNC_NAME_A FUNC_NAME_B +# --------------------------------------------- +# If the *_result variable of FUNC_NAME_A _is set_, assign its value to +# *_result variable of FUNC_NAME_B. +func_propagate_result () +{ + $debug_cmd + + func_propagate_result_result=: + if eval "test \"\${${1}_result+set}\" = set" + then + eval "${2}_result=\$${1}_result" + else + func_propagate_result_result=false + fi +} + + # func_run_hooks FUNC_NAME [ARG]... # --------------------------------- # Run all hook functions registered to FUNC_NAME. -# It is assumed that the list of hook functions contains nothing more +# It's assumed that the list of hook functions contains nothing more # than a whitespace-delimited list of legal shell function names, and # no effort is wasted trying to catch shell meta-characters or preserve # whitespace. @@ -1532,22 +1669,19 @@ func_run_hooks () case " $hookable_fns " in *" $1 "*) ;; - *) func_fatal_error "'$1' does not support hook funcions.n" ;; + *) func_fatal_error "'$1' does not support hook functions." ;; esac eval _G_hook_fns=\$$1_hooks; shift for _G_hook in $_G_hook_fns; do - eval $_G_hook '"$@"' - - # store returned options list back into positional - # parameters for next 'cmd' execution. - eval _G_hook_result=\$${_G_hook}_result - eval set dummy "$_G_hook_result"; shift + func_unset "${_G_hook}_result" + eval $_G_hook '${1+"$@"}' + func_propagate_result $_G_hook func_run_hooks + if $func_propagate_result_result; then + eval set dummy "$func_run_hooks_result"; shift + fi done - - func_quote_for_eval ${1+"$@"} - func_run_hooks_result=$func_quote_for_eval_result } @@ -1557,10 +1691,18 @@ func_run_hooks () ## --------------- ## # In order to add your own option parsing hooks, you must accept the -# full positional parameter list in your hook function, remove any -# options that you action, and then pass back the remaining unprocessed -# options in '_result', escaped suitably for -# 'eval'. Like this: +# full positional parameter list from your hook function. You may remove +# or edit any options that you action, and then pass back the remaining +# unprocessed options in '_result', escaped +# suitably for 'eval'. +# +# The '_result' variable is automatically unset +# before your hook gets called; for best performance, only set the +# *_result variable when necessary (i.e. don't call the 'func_quote' +# function unnecessarily because it can be an expensive operation on some +# machines). +# +# Like this: # # my_options_prep () # { @@ -1570,9 +1712,8 @@ func_run_hooks () # usage_message=$usage_message' # -s, --silent don'\''t print informational messages # ' -# -# func_quote_for_eval ${1+"$@"} -# my_options_prep_result=$func_quote_for_eval_result +# # No change in '$@' (ignored completely by this hook). Leave +# # my_options_prep_result variable intact. # } # func_add_hook func_options_prep my_options_prep # @@ -1581,25 +1722,36 @@ func_run_hooks () # { # $debug_cmd # -# # Note that for efficiency, we parse as many options as we can +# args_changed=false +# +# # Note that, for efficiency, we parse as many options as we can # # recognise in a loop before passing the remainder back to the # # caller on the first unrecognised argument we encounter. # while test $# -gt 0; do # opt=$1; shift # case $opt in -# --silent|-s) opt_silent=: ;; +# --silent|-s) opt_silent=: +# args_changed=: +# ;; # # Separate non-argument short options: # -s*) func_split_short_opt "$_G_opt" # set dummy "$func_split_short_opt_name" \ # "-$func_split_short_opt_arg" ${1+"$@"} # shift +# args_changed=: # ;; -# *) set dummy "$_G_opt" "$*"; shift; break ;; +# *) # Make sure the first unrecognised option "$_G_opt" +# # is added back to "$@" in case we need it later, +# # if $args_changed was set to 'true'. +# set dummy "$_G_opt" ${1+"$@"}; shift; break ;; # esac # done # -# func_quote_for_eval ${1+"$@"} -# my_silent_option_result=$func_quote_for_eval_result +# # Only call 'func_quote' here if we processed at least one argument. +# if $args_changed; then +# func_quote eval ${1+"$@"} +# my_silent_option_result=$func_quote_result +# fi # } # func_add_hook func_parse_options my_silent_option # @@ -1610,17 +1762,26 @@ func_run_hooks () # # $opt_silent && $opt_verbose && func_fatal_help "\ # '--silent' and '--verbose' options are mutually exclusive." -# -# func_quote_for_eval ${1+"$@"} -# my_option_validation_result=$func_quote_for_eval_result # } # func_add_hook func_validate_options my_option_validation # -# You'll alse need to manually amend $usage_message to reflect the extra +# You'll also need to manually amend $usage_message to reflect the extra # options you parse. It's preferable to append if you can, so that # multiple option parsing hooks can be added safely. +# func_options_finish [ARG]... +# ---------------------------- +# Finishing the option parse loop (call 'func_options' hooks ATM). +func_options_finish () +{ + $debug_cmd + + func_run_hooks func_options ${1+"$@"} + func_propagate_result func_run_hooks func_options_finish +} + + # func_options [ARG]... # --------------------- # All the functions called inside func_options are hookable. See the @@ -1630,17 +1791,27 @@ func_options () { $debug_cmd - func_options_prep ${1+"$@"} - eval func_parse_options \ - ${func_options_prep_result+"$func_options_prep_result"} - eval func_validate_options \ - ${func_parse_options_result+"$func_parse_options_result"} + _G_options_quoted=false - eval func_run_hooks func_options \ - ${func_validate_options_result+"$func_validate_options_result"} + for my_func in options_prep parse_options validate_options options_finish + do + func_unset func_${my_func}_result + func_unset func_run_hooks_result + eval func_$my_func '${1+"$@"}' + func_propagate_result func_$my_func func_options + if $func_propagate_result_result; then + eval set dummy "$func_options_result"; shift + _G_options_quoted=: + fi + done - # save modified positional parameters for caller - func_options_result=$func_run_hooks_result + $_G_options_quoted || { + # As we (func_options) are top-level options-parser function and + # nobody quoted "$@" for us yet, we need to do it explicitly for + # caller. + func_quote eval ${1+"$@"} + func_options_result=$func_quote_result + } } @@ -1649,9 +1820,8 @@ func_options () # All initialisations required before starting the option parse loop. # Note that when calling hook functions, we pass through the list of # positional parameters. If a hook function modifies that list, and -# needs to propogate that back to rest of this script, then the complete -# modified list must be put in 'func_run_hooks_result' before -# returning. +# needs to propagate that back to rest of this script, then the complete +# modified list must be put in 'func_run_hooks_result' before returning. func_hookable func_options_prep func_options_prep () { @@ -1662,9 +1832,7 @@ func_options_prep () opt_warning_types= func_run_hooks func_options_prep ${1+"$@"} - - # save modified positional parameters for caller - func_options_prep_result=$func_run_hooks_result + func_propagate_result func_run_hooks func_options_prep } @@ -1676,25 +1844,32 @@ func_parse_options () { $debug_cmd - func_parse_options_result= - + _G_parse_options_requote=false # this just eases exit handling while test $# -gt 0; do # Defer to hook functions for initial option parsing, so they # get priority in the event of reusing an option name. func_run_hooks func_parse_options ${1+"$@"} - - # Adjust func_parse_options positional parameters to match - eval set dummy "$func_run_hooks_result"; shift + func_propagate_result func_run_hooks func_parse_options + if $func_propagate_result_result; then + eval set dummy "$func_parse_options_result"; shift + # Even though we may have changed "$@", we passed the "$@" array + # down into the hook and it quoted it for us (because we are in + # this if-branch). No need to quote it again. + _G_parse_options_requote=false + fi # Break out of the loop if we already parsed every option. test $# -gt 0 || break + # We expect that one of the options parsed in this function matches + # and thus we remove _G_opt from "$@" and need to re-quote. + _G_match_parse_options=: _G_opt=$1 shift case $_G_opt in --debug|-x) debug_cmd='set -x' - func_echo "enabling shell trace mode" + func_echo "enabling shell trace mode" >&2 $debug_cmd ;; @@ -1704,7 +1879,10 @@ func_parse_options () ;; --warnings|--warning|-W) - test $# = 0 && func_missing_arg $_G_opt && break + if test $# = 0 && func_missing_arg $_G_opt; then + _G_parse_options_requote=: + break + fi case " $warning_categories $1" in *" $1 "*) # trailing space prevents matching last $1 above @@ -1757,15 +1935,24 @@ func_parse_options () shift ;; - --) break ;; + --) _G_parse_options_requote=: ; break ;; -*) func_fatal_help "unrecognised option: '$_G_opt'" ;; - *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; + *) set dummy "$_G_opt" ${1+"$@"}; shift + _G_match_parse_options=false + break + ;; esac + + if $_G_match_parse_options; then + _G_parse_options_requote=: + fi done - # save modified positional parameters for caller - func_quote_for_eval ${1+"$@"} - func_parse_options_result=$func_quote_for_eval_result + if $_G_parse_options_requote; then + # save modified positional parameters for caller + func_quote eval ${1+"$@"} + func_parse_options_result=$func_quote_result + fi } @@ -1782,12 +1969,10 @@ func_validate_options () test -n "$opt_warning_types" || opt_warning_types=" $warning_categories" func_run_hooks func_validate_options ${1+"$@"} + func_propagate_result func_run_hooks func_validate_options # Bail if the options were screwed! $exit_cmd $EXIT_FAILURE - - # save modified positional parameters for caller - func_validate_options_result=$func_run_hooks_result } @@ -1843,8 +2028,8 @@ func_missing_arg () # func_split_equals STRING # ------------------------ -# Set func_split_equals_lhs and func_split_equals_rhs shell variables after -# splitting STRING at the '=' sign. +# Set func_split_equals_lhs and func_split_equals_rhs shell variables +# after splitting STRING at the '=' sign. test -z "$_G_HAVE_XSI_OPS" \ && (eval 'x=a/b/c; test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \ @@ -1859,8 +2044,9 @@ then func_split_equals_lhs=${1%%=*} func_split_equals_rhs=${1#*=} - test "x$func_split_equals_lhs" = "x$1" \ - && func_split_equals_rhs= + if test "x$func_split_equals_lhs" = "x$1"; then + func_split_equals_rhs= + fi }' else # ...otherwise fall back to using expr, which is often a shell builtin. @@ -1938,31 +2124,44 @@ func_usage_message () # func_version # ------------ # Echo version message to standard output and exit. +# The version message is extracted from the calling file's header +# comments, with leading '# ' stripped: +# 1. First display the progname and version +# 2. Followed by the header comment line matching /^# Written by / +# 3. Then a blank line followed by the first following line matching +# /^# Copyright / +# 4. Immediately followed by any lines between the previous matches, +# except lines preceding the intervening completely blank line. +# For example, see the header comments of this file. func_version () { $debug_cmd printf '%s\n' "$progname $scriptversion" $SED -n ' - /(C)/!b go - :more - /\./!{ - N - s|\n# | | - b more - } - :go - /^# Written by /,/# warranty; / { - s|^# || - s|^# *$|| - s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2| - p + /^# Written by /!b + s|^# ||; p; n + + :fwd2blnk + /./ { + n + b fwd2blnk } - /^# Written by / { - s|^# || - p + p; n + + :holdwrnt + s|^# || + s|^# *$|| + /^Copyright /!{ + /./H + n + b holdwrnt } - /^warranty; /q' < "$progpath" + + s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2| + G + s|\(\n\)\n*|\1|g + p; q' < "$progpath" exit $? } @@ -1977,7 +2176,7 @@ func_version () # End: # Set a version string. -scriptversion='(GNU libtool) 2.4.6' +scriptversion='(GNU libtool) 2.4.6.40-6ca5-dirty' # func_echo ARG... @@ -2068,12 +2267,12 @@ include the following information: compiler: $LTCC compiler flags: $LTCFLAGS linker: $LD (gnu? $with_gnu_ld) - version: $progname (GNU libtool) 2.4.6 + version: $progname (GNU libtool) 2.4.6.40-6ca5-dirty automake: `($AUTOMAKE --version) 2>/dev/null |$SED 1q` autoconf: `($AUTOCONF --version) 2>/dev/null |$SED 1q` Report bugs to . -GNU libtool home page: . +GNU libtool home page: . General help using GNU software: ." exit 0 } @@ -2124,7 +2323,7 @@ fi # a configuration failure hint, and exit. func_fatal_configuration () { - func__fatal_error ${1+"$@"} \ + func_fatal_error ${1+"$@"} \ "See the $PACKAGE documentation for more information." \ "Fatal configuration error." } @@ -2270,6 +2469,8 @@ libtool_options_prep () nonopt= preserve_args= + _G_rc_lt_options_prep=: + # Shorthand for --mode=foo, only valid as the first argument case $1 in clean|clea|cle|cl) @@ -2293,11 +2494,16 @@ libtool_options_prep () uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) shift; set dummy --mode uninstall ${1+"$@"}; shift ;; + *) + _G_rc_lt_options_prep=false + ;; esac - # Pass back the list of options. - func_quote_for_eval ${1+"$@"} - libtool_options_prep_result=$func_quote_for_eval_result + if $_G_rc_lt_options_prep; then + # Pass back the list of options. + func_quote eval ${1+"$@"} + libtool_options_prep_result=$func_quote_result + fi } func_add_hook func_options_prep libtool_options_prep @@ -2309,9 +2515,12 @@ libtool_parse_options () { $debug_cmd + _G_rc_lt_parse_options=false + # Perform our own loop to consume as many options as possible in # each iteration. while test $# -gt 0; do + _G_match_lt_parse_options=: _G_opt=$1 shift case $_G_opt in @@ -2386,15 +2595,20 @@ libtool_parse_options () func_append preserve_args " $_G_opt" ;; - # An option not handled by this hook function: - *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; + # An option not handled by this hook function: + *) set dummy "$_G_opt" ${1+"$@"} ; shift + _G_match_lt_parse_options=false + break + ;; esac + $_G_match_lt_parse_options && _G_rc_lt_parse_options=: done - - # save modified positional parameters for caller - func_quote_for_eval ${1+"$@"} - libtool_parse_options_result=$func_quote_for_eval_result + if $_G_rc_lt_parse_options; then + # save modified positional parameters for caller + func_quote eval ${1+"$@"} + libtool_parse_options_result=$func_quote_result + fi } func_add_hook func_parse_options libtool_parse_options @@ -2451,8 +2665,8 @@ libtool_validate_options () } # Pass back the unparsed argument list - func_quote_for_eval ${1+"$@"} - libtool_validate_options_result=$func_quote_for_eval_result + func_quote eval ${1+"$@"} + libtool_validate_options_result=$func_quote_result } func_add_hook func_validate_options libtool_validate_options @@ -3418,8 +3632,8 @@ func_mode_compile () esac done - func_quote_for_eval "$libobj" - test "X$libobj" != "X$func_quote_for_eval_result" \ + func_quote_arg pretty "$libobj" + test "X$libobj" != "X$func_quote_arg_result" \ && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"' &()|`$[]' \ && func_warning "libobj name '$libobj' may not contain shell special characters." func_dirname_and_basename "$obj" "/" "" @@ -3492,8 +3706,8 @@ compiler." func_to_tool_file "$srcfile" func_convert_file_msys_to_w32 srcfile=$func_to_tool_file_result - func_quote_for_eval "$srcfile" - qsrcfile=$func_quote_for_eval_result + func_quote_arg pretty "$srcfile" + qsrcfile=$func_quote_arg_result # Only build a PIC object if we are building libtool libraries. if test yes = "$build_libtool_libs"; then @@ -4096,8 +4310,8 @@ func_mode_install () case $nonopt in *shtool*) :;; *) false;; esac then # Aesthetically quote it. - func_quote_for_eval "$nonopt" - install_prog="$func_quote_for_eval_result " + func_quote_arg pretty "$nonopt" + install_prog="$func_quote_arg_result " arg=$1 shift else @@ -4107,8 +4321,8 @@ func_mode_install () # The real first argument should be the name of the installation program. # Aesthetically quote it. - func_quote_for_eval "$arg" - func_append install_prog "$func_quote_for_eval_result" + func_quote_arg pretty "$arg" + func_append install_prog "$func_quote_arg_result" install_shared_prog=$install_prog case " $install_prog " in *[\\\ /]cp\ *) install_cp=: ;; @@ -4165,12 +4379,12 @@ func_mode_install () esac # Aesthetically quote the argument. - func_quote_for_eval "$arg" - func_append install_prog " $func_quote_for_eval_result" + func_quote_arg pretty "$arg" + func_append install_prog " $func_quote_arg_result" if test -n "$arg2"; then - func_quote_for_eval "$arg2" + func_quote_arg pretty "$arg2" fi - func_append install_shared_prog " $func_quote_for_eval_result" + func_append install_shared_prog " $func_quote_arg_result" done test -z "$install_prog" && \ @@ -4181,8 +4395,8 @@ func_mode_install () if test -n "$install_override_mode" && $no_mode; then if $install_cp; then :; else - func_quote_for_eval "$install_override_mode" - func_append install_shared_prog " -m $func_quote_for_eval_result" + func_quote_arg pretty "$install_override_mode" + func_append install_shared_prog " -m $func_quote_arg_result" fi fi @@ -4478,8 +4692,8 @@ func_mode_install () relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'` $opt_quiet || { - func_quote_for_expand "$relink_command" - eval "func_echo $func_quote_for_expand_result" + func_quote_arg expand,pretty "$relink_command" + eval "func_echo $func_quote_arg_result" } if eval "$relink_command"; then : else @@ -5258,7 +5472,8 @@ else if test \"\$libtool_execute_magic\" != \"$magic\"; then file=\"\$0\"" - qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"` + func_quote_arg pretty "$ECHO" + qECHO=$func_quote_arg_result $ECHO "\ # A function that is used when there is no print builtin or printf. @@ -5268,7 +5483,7 @@ func_fallback_echo () \$1 _LTECHO_EOF' } - ECHO=\"$qECHO\" + ECHO=$qECHO fi # Very basic option parsing. These options are (a) specific to @@ -6611,9 +6826,9 @@ func_mode_link () while test "$#" -gt 0; do arg=$1 shift - func_quote_for_eval "$arg" - qarg=$func_quote_for_eval_unquoted_result - func_append libtool_args " $func_quote_for_eval_result" + func_quote_arg pretty,unquoted "$arg" + qarg=$func_quote_arg_unquoted_result + func_append libtool_args " $func_quote_arg_result" # If the previous option needs an argument, assign it. if test -n "$prev"; then @@ -7211,9 +7426,9 @@ func_mode_link () save_ifs=$IFS; IFS=, for flag in $args; do IFS=$save_ifs - func_quote_for_eval "$flag" - func_append arg " $func_quote_for_eval_result" - func_append compiler_flags " $func_quote_for_eval_result" + func_quote_arg pretty "$flag" + func_append arg " $func_quote_arg_result" + func_append compiler_flags " $func_quote_arg_result" done IFS=$save_ifs func_stripname ' ' '' "$arg" @@ -7227,10 +7442,10 @@ func_mode_link () save_ifs=$IFS; IFS=, for flag in $args; do IFS=$save_ifs - func_quote_for_eval "$flag" - func_append arg " $wl$func_quote_for_eval_result" - func_append compiler_flags " $wl$func_quote_for_eval_result" - func_append linker_flags " $func_quote_for_eval_result" + func_quote_arg pretty "$flag" + func_append arg " $wl$func_quote_arg_result" + func_append compiler_flags " $wl$func_quote_arg_result" + func_append linker_flags " $func_quote_arg_result" done IFS=$save_ifs func_stripname ' ' '' "$arg" @@ -7254,8 +7469,8 @@ func_mode_link () # -msg_* for osf cc -msg_*) - func_quote_for_eval "$arg" - arg=$func_quote_for_eval_result + func_quote_arg pretty "$arg" + arg=$func_quote_arg_result ;; # Flags to be passed through unchanged, with rationale: @@ -7272,12 +7487,16 @@ func_mode_link () # -tp=* Portland pgcc target processor selection # --sysroot=* for sysroot support # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization + # -specs=* GCC specs files # -stdlib=* select c++ std lib with clang + # -fsanitize=* Clang/GCC memory and address sanitizer + # -fuse-ld=* Linker select flags for GCC -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ - -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*) - func_quote_for_eval "$arg" - arg=$func_quote_for_eval_result + -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \ + -specs=*|-fsanitize=*|-fuse-ld=*) + func_quote_arg pretty "$arg" + arg=$func_quote_arg_result func_append compile_command " $arg" func_append finalize_command " $arg" func_append compiler_flags " $arg" @@ -7298,15 +7517,15 @@ func_mode_link () continue else # Otherwise treat like 'Some other compiler flag' below - func_quote_for_eval "$arg" - arg=$func_quote_for_eval_result + func_quote_arg pretty "$arg" + arg=$func_quote_arg_result fi ;; # Some other compiler flag. -* | +*) - func_quote_for_eval "$arg" - arg=$func_quote_for_eval_result + func_quote_arg pretty "$arg" + arg=$func_quote_arg_result ;; *.$objext) @@ -7426,8 +7645,8 @@ func_mode_link () *) # Unknown arguments in both finalize_command and compile_command need # to be aesthetically quoted because they are evaled later. - func_quote_for_eval "$arg" - arg=$func_quote_for_eval_result + func_quote_arg pretty "$arg" + arg=$func_quote_arg_result ;; esac # arg @@ -9933,8 +10152,8 @@ EOF for cmd in $concat_cmds; do IFS=$save_ifs $opt_quiet || { - func_quote_for_expand "$cmd" - eval "func_echo $func_quote_for_expand_result" + func_quote_arg expand,pretty "$cmd" + eval "func_echo $func_quote_arg_result" } $opt_dry_run || eval "$cmd" || { lt_exit=$? @@ -10027,8 +10246,8 @@ EOF eval cmd=\"$cmd\" IFS=$save_ifs $opt_quiet || { - func_quote_for_expand "$cmd" - eval "func_echo $func_quote_for_expand_result" + func_quote_arg expand,pretty "$cmd" + eval "func_echo $func_quote_arg_result" } $opt_dry_run || eval "$cmd" || { lt_exit=$? @@ -10502,12 +10721,13 @@ EOF elif eval var_value=\$$var; test -z "$var_value"; then relink_command="$var=; export $var; $relink_command" else - func_quote_for_eval "$var_value" - relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + func_quote_arg pretty "$var_value" + relink_command="$var=$func_quote_arg_result; export $var; $relink_command" fi done - relink_command="(cd `pwd`; $relink_command)" - relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"` + func_quote eval cd "`pwd`" + func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)" + relink_command=$func_quote_arg_unquoted_result fi # Only actually do things if not in dry run mode. @@ -10747,13 +10967,15 @@ EOF elif eval var_value=\$$var; test -z "$var_value"; then relink_command="$var=; export $var; $relink_command" else - func_quote_for_eval "$var_value" - relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + func_quote_arg pretty,unquoted "$var_value" + relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command" fi done # Quote the link command for shipping. - relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" - relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"` + func_quote eval cd "`pwd`" + relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" + func_quote_arg pretty,unquoted "$relink_command" + relink_command=$func_quote_arg_unquoted_result if test yes = "$hardcode_automatic"; then relink_command= fi diff --git a/pcre/m4/libtool.m4 b/pcre/m4/libtool.m4 index a3bc337b79a..597c6042bd1 100644 --- a/pcre/m4/libtool.m4 +++ b/pcre/m4/libtool.m4 @@ -1,6 +1,6 @@ # libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- # -# Copyright (C) 1996-2001, 2003-2015 Free Software Foundation, Inc. +# Copyright (C) 1996-2001, 2003-2017 Free Software Foundation, Inc. # Written by Gordon Matzigkeit, 1996 # # This file is free software; the Free Software Foundation gives @@ -1042,8 +1042,8 @@ int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD - echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD - $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD + echo "$AR $AR_FLAGS libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD + $AR $AR_FLAGS libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD cat > conftest.c << _LT_EOF @@ -1493,9 +1493,22 @@ need_locks=$enable_libtool_lock m4_defun([_LT_PROG_AR], [AC_CHECK_TOOLS(AR, [ar], false) : ${AR=ar} -: ${AR_FLAGS=cru} _LT_DECL([], [AR], [1], [The archiver]) -_LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive]) + +# Use ARFLAGS variable as AR's operation code to sync the variable naming with +# Automake. If both AR_FLAGS and ARFLAGS are specified, AR_FLAGS should have +# higher priority because thats what people were doing historically (setting +# ARFLAGS for automake and AR_FLAGS for libtool). FIXME: Make the AR_FLAGS +# variable obsoleted/removed. + +test ${AR_FLAGS+y} || AR_FLAGS=${ARFLAGS-cr} +lt_ar_flags=$AR_FLAGS +_LT_DECL([], [lt_ar_flags], [0], [Flags to create an archive (by configure)]) + +# Make AR_FLAGS overridable by 'make ARFLAGS='. Don't try to run-time override +# by AR_FLAGS because that was never working and AR_FLAGS is about to die. +_LT_DECL([], [AR_FLAGS], [\@S|@{ARFLAGS-"\@S|@lt_ar_flags"}], + [Flags to create an archive]) AC_CACHE_CHECK([for archiver @FILE support], [lt_cv_ar_at_file], [lt_cv_ar_at_file=no @@ -2207,26 +2220,35 @@ m4_defun([_LT_CMD_STRIPLIB], striplib= old_striplib= AC_MSG_CHECKING([whether stripping libraries is possible]) -if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then - test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" - test -z "$striplib" && striplib="$STRIP --strip-unneeded" - AC_MSG_RESULT([yes]) +if test -z "$STRIP"; then + AC_MSG_RESULT([no]) else -# FIXME - insert some real tests, host_os isn't really good enough - case $host_os in - darwin*) - if test -n "$STRIP"; then + if $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + old_striplib="$STRIP --strip-debug" + striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) + else + case $host_os in + darwin*) + # FIXME - insert some real tests, host_os isn't really good enough striplib="$STRIP -x" old_striplib="$STRIP -S" AC_MSG_RESULT([yes]) - else + ;; + freebsd*) + if $STRIP -V 2>&1 | $GREP "elftoolchain" >/dev/null; then + old_striplib="$STRIP --strip-debug" + striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + *) AC_MSG_RESULT([no]) - fi - ;; - *) - AC_MSG_RESULT([no]) - ;; - esac + ;; + esac + fi fi _LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) _LT_DECL([], [striplib], [1]) @@ -4919,7 +4941,7 @@ m4_if([$1], [CXX], [ if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' else - _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' fi ;; pw32*) @@ -5156,6 +5178,7 @@ _LT_EOF emximp -o $lib $output_objdir/$libname.def' _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' ;; interix[[3-9]]*) @@ -5373,7 +5396,7 @@ _LT_EOF if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' else - _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' fi aix_use_runtimelinking=no @@ -5861,6 +5884,7 @@ _LT_EOF emximp -o $lib $output_objdir/$libname.def' _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' ;; osf3*) @@ -6730,6 +6754,7 @@ if test yes != "$_lt_caught_CXX_error"; then emximp -o $lib $output_objdir/$libname.def' _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' ;; dgux*) diff --git a/pcre/m4/ltoptions.m4 b/pcre/m4/ltoptions.m4 index 94b08297666..621bd18b2f3 100644 --- a/pcre/m4/ltoptions.m4 +++ b/pcre/m4/ltoptions.m4 @@ -1,6 +1,6 @@ # Helper functions for option handling. -*- Autoconf -*- # -# Copyright (C) 2004-2005, 2007-2009, 2011-2015 Free Software +# Copyright (C) 2004-2005, 2007-2009, 2011-2017 Free Software # Foundation, Inc. # Written by Gary V. Vaughan, 2004 # diff --git a/pcre/m4/ltsugar.m4 b/pcre/m4/ltsugar.m4 index 48bc9344a4d..ab69a6b96b0 100644 --- a/pcre/m4/ltsugar.m4 +++ b/pcre/m4/ltsugar.m4 @@ -1,6 +1,6 @@ # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- # -# Copyright (C) 2004-2005, 2007-2008, 2011-2015 Free Software +# Copyright (C) 2004-2005, 2007-2008, 2011-2017 Free Software # Foundation, Inc. # Written by Gary V. Vaughan, 2004 # diff --git a/pcre/m4/ltversion.m4 b/pcre/m4/ltversion.m4 index fa04b52a3bf..8250ea47cf7 100644 --- a/pcre/m4/ltversion.m4 +++ b/pcre/m4/ltversion.m4 @@ -1,6 +1,6 @@ # ltversion.m4 -- version numbers -*- Autoconf -*- # -# Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. +# Copyright (C) 2004, 2011-2017 Free Software Foundation, Inc. # Written by Scott James Remnant, 2004 # # This file is free software; the Free Software Foundation gives @@ -9,15 +9,15 @@ # @configure_input@ -# serial 4179 ltversion.m4 +# serial 4219 ltversion.m4 # This file is part of GNU Libtool -m4_define([LT_PACKAGE_VERSION], [2.4.6]) -m4_define([LT_PACKAGE_REVISION], [2.4.6]) +m4_define([LT_PACKAGE_VERSION], [2.4.6.40-6ca5-dirty]) +m4_define([LT_PACKAGE_REVISION], [2.4.6.40]) AC_DEFUN([LTVERSION_VERSION], -[macro_version='2.4.6' -macro_revision='2.4.6' +[macro_version='2.4.6.40-6ca5-dirty' +macro_revision='2.4.6.40' _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) _LT_DECL(, macro_revision, 0) ]) diff --git a/pcre/m4/lt~obsolete.m4 b/pcre/m4/lt~obsolete.m4 index c6b26f88f6c..9919d4de5e8 100644 --- a/pcre/m4/lt~obsolete.m4 +++ b/pcre/m4/lt~obsolete.m4 @@ -1,6 +1,6 @@ # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- # -# Copyright (C) 2004-2005, 2007, 2009, 2011-2015 Free Software +# Copyright (C) 2004-2005, 2007, 2009, 2011-2017 Free Software # Foundation, Inc. # Written by Scott James Remnant, 2004. # diff --git a/pcre/missing b/pcre/missing index f62bbae306c..c6e379584ba 100755 --- a/pcre/missing +++ b/pcre/missing @@ -1,9 +1,9 @@ #! /bin/sh # Common wrapper for a few potentially missing GNU programs. -scriptversion=2013-10-28.13; # UTC +scriptversion=2016-01-11.22; # UTC -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # Originally written by Fran,cois Pinard , 1996. # This program is free software; you can redistribute it and/or modify @@ -210,6 +210,6 @@ exit $st # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-time-zone: "UTC" +# time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: diff --git a/pcre/pcre.h.generic b/pcre/pcre.h.generic index 442c6bdb5fe..0efad3f9511 100644 --- a/pcre/pcre.h.generic +++ b/pcre/pcre.h.generic @@ -42,9 +42,9 @@ POSSIBILITY OF SUCH DAMAGE. /* The current PCRE version information. */ #define PCRE_MAJOR 8 -#define PCRE_MINOR 41 +#define PCRE_MINOR 42 #define PCRE_PRERELEASE -#define PCRE_DATE 2017-07-05 +#define PCRE_DATE 2018-03-20 /* When an application links to a PCRE DLL in Windows, the symbols that are imported have to be identified as such. When building PCRE, the appropriate @@ -321,11 +321,11 @@ these bits, just add new ones on the end, in order to remain compatible. */ /* Types */ -struct real_pcre; /* declaration; the definition is private */ -typedef struct real_pcre pcre; +struct real_pcre8_or_16; /* declaration; the definition is private */ +typedef struct real_pcre8_or_16 pcre; -struct real_pcre16; /* declaration; the definition is private */ -typedef struct real_pcre16 pcre16; +struct real_pcre8_or_16; /* declaration; the definition is private */ +typedef struct real_pcre8_or_16 pcre16; struct real_pcre32; /* declaration; the definition is private */ typedef struct real_pcre32 pcre32; diff --git a/pcre/pcre.h.in b/pcre/pcre.h.in index 667a45ed575..d4d78926984 100644 --- a/pcre/pcre.h.in +++ b/pcre/pcre.h.in @@ -321,11 +321,11 @@ these bits, just add new ones on the end, in order to remain compatible. */ /* Types */ -struct real_pcre; /* declaration; the definition is private */ -typedef struct real_pcre pcre; +struct real_pcre8_or_16; /* declaration; the definition is private */ +typedef struct real_pcre8_or_16 pcre; -struct real_pcre16; /* declaration; the definition is private */ -typedef struct real_pcre16 pcre16; +struct real_pcre8_or_16; /* declaration; the definition is private */ +typedef struct real_pcre8_or_16 pcre16; struct real_pcre32; /* declaration; the definition is private */ typedef struct real_pcre32 pcre32; diff --git a/pcre/pcre_compile.c b/pcre/pcre_compile.c index 42f204cdfff..6dd88860638 100644 --- a/pcre/pcre_compile.c +++ b/pcre/pcre_compile.c @@ -8060,7 +8060,7 @@ for (;; ptr++) single group (i.e. not to a duplicated name. */ HANDLE_REFERENCE: - if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE; + if (firstcharflags == REQ_UNSET) zerofirstcharflags = firstcharflags = REQ_NONE; previous = code; item_hwm_offset = cd->hwm - cd->start_workspace; *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF; diff --git a/pcre/pcre_dfa_exec.c b/pcre/pcre_dfa_exec.c index bc09ced3a7c..f333381d088 100644 --- a/pcre/pcre_dfa_exec.c +++ b/pcre/pcre_dfa_exec.c @@ -2287,12 +2287,14 @@ for (;;) case OP_NOTI: if (clen > 0) { - unsigned int otherd; + pcre_uint32 otherd; #ifdef SUPPORT_UTF if (utf && d >= 128) { #ifdef SUPPORT_UCP otherd = UCD_OTHERCASE(d); +#else + otherd = d; #endif /* SUPPORT_UCP */ } else diff --git a/pcre/pcre_exec.c b/pcre/pcre_exec.c index 1a9bdd546ee..3fd58cbe31c 100644 --- a/pcre/pcre_exec.c +++ b/pcre/pcre_exec.c @@ -6,7 +6,7 @@ and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2014 University of Cambridge + Copyright (c) 1997-2018 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -2305,7 +2305,7 @@ for (;;) case OP_ANY: if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); if (md->partial != 0 && - eptr + 1 >= md->end_subject && + eptr == md->end_subject - 1 && NLBLOCK->nltype == NLTYPE_FIXED && NLBLOCK->nllen == 2 && UCHAR21TEST(eptr) == NLBLOCK->nl[0]) @@ -3053,7 +3053,7 @@ for (;;) { RMATCH(eptr, ecode, offset_top, md, eptrb, RM18); if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (eptr-- == pp) break; /* Stop if tried at original pos */ + if (eptr-- <= pp) break; /* Stop if tried at original pos */ BACKCHAR(eptr); } } @@ -3210,7 +3210,7 @@ for (;;) { RMATCH(eptr, ecode, offset_top, md, eptrb, RM21); if (rrc != MATCH_NOMATCH) RRETURN(rrc); - if (eptr-- == pp) break; /* Stop if tried at original pos */ + if (eptr-- <= pp) break; /* Stop if tried at original pos */ #ifdef SUPPORT_UTF if (utf) BACKCHAR(eptr); #endif diff --git a/pcre/pcre_jit_compile.c b/pcre/pcre_jit_compile.c index 249edbe8e7f..2bad74b0231 100644 --- a/pcre/pcre_jit_compile.c +++ b/pcre/pcre_jit_compile.c @@ -164,7 +164,6 @@ typedef struct jit_arguments { const pcre_uchar *begin; const pcre_uchar *end; int *offsets; - pcre_uchar *uchar_ptr; pcre_uchar *mark_ptr; void *callout_data; /* Everything else after. */ @@ -214,7 +213,7 @@ enum control_types { type_then_trap = 1 }; -typedef int (SLJIT_CALL *jit_function)(jit_arguments *args); +typedef int (SLJIT_FUNC *jit_function)(jit_arguments *args); /* The following structure is the key data type for the recursive code generator. It is allocated by compile_matchingpath, and contains @@ -489,9 +488,24 @@ typedef struct compare_context { /* Used for accessing the elements of the stack. */ #define STACK(i) ((i) * (int)sizeof(sljit_sw)) +#ifdef SLJIT_PREF_SHIFT_REG +#if SLJIT_PREF_SHIFT_REG == SLJIT_R2 +/* Nothing. */ +#elif SLJIT_PREF_SHIFT_REG == SLJIT_R3 +#define SHIFT_REG_IS_R3 +#else +#error "Unsupported shift register" +#endif +#endif + #define TMP1 SLJIT_R0 +#ifdef SHIFT_REG_IS_R3 +#define TMP2 SLJIT_R3 +#define TMP3 SLJIT_R2 +#else #define TMP2 SLJIT_R2 #define TMP3 SLJIT_R3 +#endif #define STR_PTR SLJIT_S0 #define STR_END SLJIT_S1 #define STACK_TOP SLJIT_R1 @@ -520,13 +534,10 @@ the start pointers when the end of the capturing group has not yet reached. */ #if defined COMPILE_PCRE8 #define MOV_UCHAR SLJIT_MOV_U8 -#define MOVU_UCHAR SLJIT_MOVU_U8 #elif defined COMPILE_PCRE16 #define MOV_UCHAR SLJIT_MOV_U16 -#define MOVU_UCHAR SLJIT_MOVU_U16 #elif defined COMPILE_PCRE32 #define MOV_UCHAR SLJIT_MOV_U32 -#define MOVU_UCHAR SLJIT_MOVU_U32 #else #error Unsupported compiling mode #endif @@ -2383,12 +2394,25 @@ if (length < 8) } else { - GET_LOCAL_BASE(SLJIT_R1, 0, OVECTOR_START); - OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, length - 1); - loop = LABEL(); - OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw), SLJIT_R0, 0); - OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, loop); + if (sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw)) == SLJIT_SUCCESS) + { + GET_LOCAL_BASE(SLJIT_R1, 0, OVECTOR_START); + OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, length - 1); + loop = LABEL(); + sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw)); + OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1); + JUMPTO(SLJIT_NOT_ZERO, loop); + } + else + { + GET_LOCAL_BASE(SLJIT_R1, 0, OVECTOR_START + sizeof(sljit_sw)); + OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, length - 1); + loop = LABEL(); + OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R0, 0); + OP2(SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw)); + OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1); + JUMPTO(SLJIT_NOT_ZERO, loop); + } } } @@ -2421,12 +2445,25 @@ if (length < 8) } else { - GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw)); - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2); - loop = LABEL(); - OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0); - OP2(SLJIT_SUB | SLJIT_SET_Z, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, loop); + if (sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, TMP1, SLJIT_MEM1(TMP2), sizeof(sljit_sw)) == SLJIT_SUCCESS) + { + GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw)); + OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2); + loop = LABEL(); + sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_STORE | SLJIT_MEM_PRE, TMP1, SLJIT_MEM1(TMP2), sizeof(sljit_sw)); + OP2(SLJIT_SUB | SLJIT_SET_Z, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1); + JUMPTO(SLJIT_NOT_ZERO, loop); + } + else + { + GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + 2 * sizeof(sljit_sw)); + OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2); + loop = LABEL(); + OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, TMP1, 0); + OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, sizeof(sljit_sw)); + OP2(SLJIT_SUB | SLJIT_SET_Z, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1); + JUMPTO(SLJIT_NOT_ZERO, loop); + } } OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0); @@ -2436,10 +2473,10 @@ if (common->control_head_ptr != 0) OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0); OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack)); OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr); -OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base)); +OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, end)); } -static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg) +static sljit_sw SLJIT_FUNC do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg) { while (current != NULL) { @@ -2460,7 +2497,7 @@ while (current != NULL) SLJIT_ASSERT(current[0] == 0 || current < (sljit_sw*)current[0]); current = (sljit_sw*)current[0]; } -return -1; +return 0; } static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket) @@ -2468,6 +2505,7 @@ static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket) DEFINE_COMPILER; struct sljit_label *loop; struct sljit_jump *early_quit; +BOOL has_pre; /* At this point we can freely use all registers. */ OP1(SLJIT_MOV, SLJIT_S2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)); @@ -2481,17 +2519,30 @@ if (common->mark_ptr != 0) OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_R2, 0); OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int)); OP1(SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, begin)); -GET_LOCAL_BASE(SLJIT_S0, 0, OVECTOR_START); + +has_pre = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_S1, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw)) == SLJIT_SUCCESS; +GET_LOCAL_BASE(SLJIT_S0, 0, OVECTOR_START - (has_pre ? sizeof(sljit_sw) : 0)); + /* Unlikely, but possible */ early_quit = CMP(SLJIT_EQUAL, SLJIT_R1, 0, SLJIT_IMM, 0); loop = LABEL(); -OP2(SLJIT_SUB, SLJIT_S1, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0); -OP2(SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, sizeof(sljit_sw)); + +if (has_pre) + sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_PRE, SLJIT_S1, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw)); +else + { + OP1(SLJIT_MOV, SLJIT_S1, 0, SLJIT_MEM1(SLJIT_S0), 0); + OP2(SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, sizeof(sljit_sw)); + } + +OP2(SLJIT_ADD, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, sizeof(int)); +OP2(SLJIT_SUB, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_R0, 0); /* Copy the integer value to the output buffer */ #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 OP2(SLJIT_ASHR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, UCHAR_SHIFT); #endif -OP1(SLJIT_MOVU_S32, SLJIT_MEM1(SLJIT_R2), sizeof(int), SLJIT_S1, 0); + +OP1(SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_R2), 0, SLJIT_S1, 0); OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1); JUMPTO(SLJIT_NOT_ZERO, loop); JUMPHERE(early_quit); @@ -2499,14 +2550,29 @@ JUMPHERE(early_quit); /* Calculate the return value, which is the maximum ovector value. */ if (topbracket > 1) { - GET_LOCAL_BASE(SLJIT_R0, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, topbracket + 1); + if (sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R0), -(2 * (sljit_sw)sizeof(sljit_sw))) == SLJIT_SUCCESS) + { + GET_LOCAL_BASE(SLJIT_R0, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw)); + OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, topbracket + 1); - /* OVECTOR(0) is never equal to SLJIT_S2. */ - loop = LABEL(); - OP1(SLJIT_MOVU, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), -(2 * (sljit_sw)sizeof(sljit_sw))); - OP2(SLJIT_SUB, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1); - CMPTO(SLJIT_EQUAL, SLJIT_R2, 0, SLJIT_S2, 0, loop); + /* OVECTOR(0) is never equal to SLJIT_S2. */ + loop = LABEL(); + sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R0), -(2 * (sljit_sw)sizeof(sljit_sw))); + OP2(SLJIT_SUB, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1); + CMPTO(SLJIT_EQUAL, SLJIT_R2, 0, SLJIT_S2, 0, loop); + } + else + { + GET_LOCAL_BASE(SLJIT_R0, 0, OVECTOR_START + (topbracket - 1) * 2 * sizeof(sljit_sw)); + OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, topbracket + 1); + + /* OVECTOR(0) is never equal to SLJIT_S2. */ + loop = LABEL(); + OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), 0); + OP2(SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 2 * (sljit_sw)sizeof(sljit_sw)); + OP2(SLJIT_SUB, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1); + CMPTO(SLJIT_EQUAL, SLJIT_R2, 0, SLJIT_S2, 0, loop); + } OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_R1, 0); } else @@ -5167,93 +5233,190 @@ OP_FLAGS(SLJIT_OR | SLJIT_SET_Z, TMP2, 0, SLJIT_EQUAL); sljit_emit_fast_return(compiler, RETURN_ADDR, 0); } -#define CHAR1 STR_END -#define CHAR2 STACK_TOP - static void do_casefulcmp(compiler_common *common) { DEFINE_COMPILER; struct sljit_jump *jump; struct sljit_label *label; +int char1_reg; +int char2_reg; -sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); +if (sljit_get_register_index(TMP3) < 0) + { + char1_reg = STR_END; + char2_reg = STACK_TOP; + } +else + { + char1_reg = TMP3; + char2_reg = RETURN_ADDR; + } + +sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0); OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); -OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, CHAR2, 0); -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -label = LABEL(); -OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1)); -OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); -jump = CMP(SLJIT_NOT_EQUAL, CHAR1, 0, CHAR2, 0); -OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); -JUMPTO(SLJIT_NOT_ZERO, label); +if (char1_reg == STR_END) + { + OP1(SLJIT_MOV, TMP3, 0, char1_reg, 0); + OP1(SLJIT_MOV, RETURN_ADDR, 0, char2_reg, 0); + } -JUMPHERE(jump); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -OP1(SLJIT_MOV, CHAR1, 0, TMP3, 0); -OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0); -sljit_emit_fast_return(compiler, RETURN_ADDR, 0); -} +if (sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_SUPP | SLJIT_MEM_POST, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)) == SLJIT_SUCCESS) + { + label = LABEL(); + sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_POST, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)); + sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_POST, char2_reg, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); + jump = CMP(SLJIT_NOT_EQUAL, char1_reg, 0, char2_reg, 0); + OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); + JUMPTO(SLJIT_NOT_ZERO, label); + + JUMPHERE(jump); + OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0); + } +else if (sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)) == SLJIT_SUCCESS) + { + OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); + OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); + + label = LABEL(); + sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_PRE, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)); + sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_PRE, char2_reg, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); + jump = CMP(SLJIT_NOT_EQUAL, char1_reg, 0, char2_reg, 0); + OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); + JUMPTO(SLJIT_NOT_ZERO, label); -#define LCC_TABLE STACK_LIMIT + JUMPHERE(jump); + OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0); + OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); + } +else + { + label = LABEL(); + OP1(MOV_UCHAR, char1_reg, 0, SLJIT_MEM1(TMP1), 0); + OP1(MOV_UCHAR, char2_reg, 0, SLJIT_MEM1(STR_PTR), 0); + OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); + OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); + jump = CMP(SLJIT_NOT_EQUAL, char1_reg, 0, char2_reg, 0); + OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); + JUMPTO(SLJIT_NOT_ZERO, label); + + JUMPHERE(jump); + OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0); + } + +if (char1_reg == STR_END) + { + OP1(SLJIT_MOV, char1_reg, 0, TMP3, 0); + OP1(SLJIT_MOV, char2_reg, 0, RETURN_ADDR, 0); + } + +sljit_emit_fast_return(compiler, TMP1, 0); +} static void do_caselesscmp(compiler_common *common) { DEFINE_COMPILER; struct sljit_jump *jump; struct sljit_label *label; +int char1_reg = STR_END; +int char2_reg; +int lcc_table; +int opt_type = 0; -sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); +if (sljit_get_register_index(TMP3) < 0) + { + char2_reg = STACK_TOP; + lcc_table = STACK_LIMIT; + } +else + { + char2_reg = RETURN_ADDR; + lcc_table = TMP3; + } + +if (sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_SUPP | SLJIT_MEM_POST, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)) == SLJIT_SUCCESS) + opt_type = 1; +else if (sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)) == SLJIT_SUCCESS) + opt_type = 2; + +sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0); OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); -OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, CHAR1, 0); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, CHAR2, 0); -OP1(SLJIT_MOV, LCC_TABLE, 0, SLJIT_IMM, common->lcc); -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); +OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, char1_reg, 0); + +if (char2_reg == STACK_TOP) + { + OP1(SLJIT_MOV, TMP3, 0, char2_reg, 0); + OP1(SLJIT_MOV, RETURN_ADDR, 0, lcc_table, 0); + } + +OP1(SLJIT_MOV, lcc_table, 0, SLJIT_IMM, common->lcc); + +if (opt_type == 1) + { + label = LABEL(); + sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_POST, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)); + sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_POST, char2_reg, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); + } +else if (opt_type == 2) + { + OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); + OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); + + label = LABEL(); + sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_PRE, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)); + sljit_emit_mem(compiler, MOV_UCHAR | SLJIT_MEM_PRE, char2_reg, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); + } +else + { + label = LABEL(); + OP1(MOV_UCHAR, char1_reg, 0, SLJIT_MEM1(TMP1), 0); + OP1(MOV_UCHAR, char2_reg, 0, SLJIT_MEM1(STR_PTR), 0); + OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); + } -label = LABEL(); -OP1(MOVU_UCHAR, CHAR1, 0, SLJIT_MEM1(TMP1), IN_UCHARS(1)); -OP1(MOVU_UCHAR, CHAR2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); #ifndef COMPILE_PCRE8 -jump = CMP(SLJIT_GREATER, CHAR1, 0, SLJIT_IMM, 255); +jump = CMP(SLJIT_GREATER, char1_reg, 0, SLJIT_IMM, 255); #endif -OP1(SLJIT_MOV_U8, CHAR1, 0, SLJIT_MEM2(LCC_TABLE, CHAR1), 0); +OP1(SLJIT_MOV_U8, char1_reg, 0, SLJIT_MEM2(lcc_table, char1_reg), 0); #ifndef COMPILE_PCRE8 JUMPHERE(jump); -jump = CMP(SLJIT_GREATER, CHAR2, 0, SLJIT_IMM, 255); +jump = CMP(SLJIT_GREATER, char2_reg, 0, SLJIT_IMM, 255); #endif -OP1(SLJIT_MOV_U8, CHAR2, 0, SLJIT_MEM2(LCC_TABLE, CHAR2), 0); +OP1(SLJIT_MOV_U8, char2_reg, 0, SLJIT_MEM2(lcc_table, char2_reg), 0); #ifndef COMPILE_PCRE8 JUMPHERE(jump); #endif -jump = CMP(SLJIT_NOT_EQUAL, CHAR1, 0, CHAR2, 0); + +if (opt_type == 0) + OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); + +jump = CMP(SLJIT_NOT_EQUAL, char1_reg, 0, char2_reg, 0); OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); JUMPTO(SLJIT_NOT_ZERO, label); JUMPHERE(jump); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -OP1(SLJIT_MOV, LCC_TABLE, 0, TMP3, 0); -OP1(SLJIT_MOV, CHAR1, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0); -OP1(SLJIT_MOV, CHAR2, 0, SLJIT_MEM1(SLJIT_SP), LOCALS1); -sljit_emit_fast_return(compiler, RETURN_ADDR, 0); -} +OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0); + +if (opt_type == 2) + OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -#undef LCC_TABLE -#undef CHAR1 -#undef CHAR2 +if (char2_reg == STACK_TOP) + { + OP1(SLJIT_MOV, char2_reg, 0, TMP3, 0); + OP1(SLJIT_MOV, lcc_table, 0, RETURN_ADDR, 0); + } + +OP1(SLJIT_MOV, char1_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCALS1); +sljit_emit_fast_return(compiler, TMP1, 0); +} #if defined SUPPORT_UTF && defined SUPPORT_UCP -static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1) +static const pcre_uchar * SLJIT_FUNC do_utf_caselesscmp(pcre_uchar *src1, pcre_uchar *src2, pcre_uchar *end1, pcre_uchar *end2) { /* This function would be ineffective to do in JIT level. */ sljit_u32 c1, c2; -const pcre_uchar *src2 = args->uchar_ptr; -const pcre_uchar *end2 = args->end; const ucd_record *ur; const sljit_u32 *pp; @@ -6776,32 +6939,37 @@ else #if defined SUPPORT_UTF && defined SUPPORT_UCP if (common->utf && *cc == OP_REFI) { - SLJIT_ASSERT(TMP1 == SLJIT_R0 && STACK_TOP == SLJIT_R1 && TMP2 == SLJIT_R2); + SLJIT_ASSERT(TMP1 == SLJIT_R0 && STACK_TOP == SLJIT_R1); if (ref) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); + OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); else - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw)); + OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw)); if (withchecks) - jump = CMP(SLJIT_EQUAL, TMP1, 0, TMP2, 0); + jump = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_R2, 0); - /* Needed to save important temporary registers. */ + /* No free saved registers so save data on stack. */ OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, STACK_TOP, 0); - OP1(SLJIT_MOV, SLJIT_R1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, uchar_ptr), STR_PTR, 0); - sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp)); + OP1(SLJIT_MOV, SLJIT_R1, 0, STR_PTR, 0); + OP1(SLJIT_MOV, SLJIT_R3, 0, STR_END, 0); + sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW) | SLJIT_ARG4(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp)); OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0); + OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0); + if (common->mode == JIT_COMPILE) add_jump(compiler, backtracks, CMP(SLJIT_LESS_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1)); else { - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0)); - nopartial = CMP(SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1); + OP2(SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1); + + add_jump(compiler, backtracks, JUMP(SLJIT_LESS)); + + nopartial = JUMP(SLJIT_NOT_EQUAL); + OP1(SLJIT_MOV, STR_PTR, 0, STR_END, 0); check_partial(common, FALSE); add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); JUMPHERE(nopartial); } - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0); } else #endif /* SUPPORT_UTF && SUPPORT_UCP */ @@ -7125,7 +7293,7 @@ add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IM return cc + 1 + LINK_SIZE; } -static int SLJIT_CALL do_callout(struct jit_arguments *arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector) +static sljit_s32 SLJIT_FUNC do_callout(struct jit_arguments *arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector) { const pcre_uchar *begin = arguments->begin; int *offset_vector = arguments->offsets; @@ -7207,18 +7375,17 @@ OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, STACK_TOP, 0); /* SLJIT_R0 = arguments */ OP1(SLJIT_MOV, SLJIT_R1, 0, STACK_TOP, 0); GET_LOCAL_BASE(SLJIT_R2, 0, OVECTOR_START); -sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout)); -OP1(SLJIT_MOV_S32, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0); +sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(S32) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout)); OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0); free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw)); /* Check return value. */ -OP2(SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0); -add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_SIG_GREATER)); +OP2(SLJIT_SUB32 | SLJIT_SET_Z | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0); +add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_SIG_GREATER32)); if (common->forced_quit_label == NULL) - add_jump(compiler, &common->forced_quit, JUMP(SLJIT_NOT_EQUAL) /* SIG_LESS */); + add_jump(compiler, &common->forced_quit, JUMP(SLJIT_NOT_EQUAL32) /* SIG_LESS */); else - JUMPTO(SLJIT_NOT_EQUAL /* SIG_LESS */, common->forced_quit_label); + JUMPTO(SLJIT_NOT_EQUAL32 /* SIG_LESS */, common->forced_quit_label); return cc + 2 + 2 * LINK_SIZE; } @@ -10439,11 +10606,11 @@ if (opcode == OP_SKIP_ARG) OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, STACK_TOP, 0); OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, (sljit_sw)(current->cc + 2)); - sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_search_mark)); + sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(do_search_mark)); OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0); OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0); - add_jump(compiler, &common->reset_match, CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1)); + add_jump(compiler, &common->reset_match, CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0)); return; } @@ -11031,7 +11198,7 @@ if (!compiler) common->compiler = compiler; /* Main pcre_jit_exec entry. */ -sljit_emit_enter(compiler, 0, 1, 5, 5, 0, 0, private_data_size); +sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, private_data_size); /* Register init. */ reset_ovector(common, (re->top_bracket + 1) * 2); @@ -11044,8 +11211,8 @@ OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str)) OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end)); OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack)); OP1(SLJIT_MOV_U32, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, limit_match)); -OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base)); -OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit)); +OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, end)); +OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, start)); OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LIMIT_MATCH, TMP1, 0); @@ -11251,20 +11418,22 @@ common->quit_label = quit_label; set_jumps(common->stackalloc, LABEL()); /* RETURN_ADDR is not a saved register. */ sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP2, 0); -OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack)); -OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(struct sljit_stack, top), STACK_TOP, 0); -OP2(SLJIT_SUB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(struct sljit_stack, limit), SLJIT_IMM, STACK_GROWTH_RATE); -sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize)); -jump = CMP(SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0); -OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack)); -OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(struct sljit_stack, top)); -OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(struct sljit_stack, limit)); -OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), LOCALS1); -sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0); +SLJIT_ASSERT(TMP1 == SLJIT_R0 && STACK_TOP == SLJIT_R1); + +OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, STACK_TOP, 0); +OP1(SLJIT_MOV, SLJIT_R0, 0, ARGUMENTS, 0); +OP2(SLJIT_SUB, SLJIT_R1, 0, STACK_LIMIT, 0, SLJIT_IMM, STACK_GROWTH_RATE); +OP1(SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, stack)); +OP1(SLJIT_MOV, STACK_LIMIT, 0, TMP2, 0); + +sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize)); +jump = CMP(SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0); +OP1(SLJIT_MOV, TMP2, 0, STACK_LIMIT, 0); +OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_RETURN_REG, 0); +OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCALS0); +OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), LOCALS1); +sljit_emit_fast_return(compiler, TMP1, 0); /* Allocation failed. */ JUMPHERE(jump); @@ -11409,9 +11578,9 @@ union { sljit_u8 local_space[MACHINE_STACK_SIZE]; struct sljit_stack local_stack; -local_stack.max_limit = local_space; -local_stack.limit = local_space; -local_stack.base = local_space + MACHINE_STACK_SIZE; +local_stack.min_start = local_space; +local_stack.start = local_space; +local_stack.end = local_space + MACHINE_STACK_SIZE; local_stack.top = local_space + MACHINE_STACK_SIZE; arguments->stack = &local_stack; convert_executable_func.executable_func = executable_func; @@ -11529,7 +11698,7 @@ if ((options & PCRE_PARTIAL_HARD) != 0) else if ((options & PCRE_PARTIAL_SOFT) != 0) mode = JIT_PARTIAL_SOFT_COMPILE; -if (functions->executable_funcs[mode] == NULL) +if (functions == NULL || functions->executable_funcs[mode] == NULL) return PCRE_ERROR_JIT_BADOPTION; /* Sanity checks should be handled by pcre_exec. */ diff --git a/pcre/pcregrep.c b/pcre/pcregrep.c index 317f7454e13..a406be962d7 100644 --- a/pcre/pcregrep.c +++ b/pcre/pcregrep.c @@ -1387,8 +1387,8 @@ Returns: nothing */ static void -do_after_lines(int lastmatchnumber, char *lastmatchrestart, char *endptr, - char *printname) +do_after_lines(unsigned long int lastmatchnumber, char *lastmatchrestart, + char *endptr, char *printname) { if (after_context > 0 && lastmatchnumber > 0) { @@ -1398,7 +1398,7 @@ if (after_context > 0 && lastmatchnumber > 0) int ellength; char *pp = lastmatchrestart; if (printname != NULL) fprintf(stdout, "%s-", printname); - if (number) fprintf(stdout, "%d-", lastmatchnumber++); + if (number) fprintf(stdout, "%lu-", lastmatchnumber++); pp = end_of_line(pp, endptr, &ellength); FWRITE(lastmatchrestart, 1, pp - lastmatchrestart, stdout); lastmatchrestart = pp; @@ -1502,11 +1502,11 @@ static int pcregrep(void *handle, int frtype, char *filename, char *printname) { int rc = 1; -int linenumber = 1; -int lastmatchnumber = 0; -int count = 0; int filepos = 0; int offsets[OFFSET_SIZE]; +unsigned long int linenumber = 1; +unsigned long int lastmatchnumber = 0; +unsigned long int count = 0; char *lastmatchrestart = NULL; char *ptr = main_buffer; char *endptr; @@ -1609,7 +1609,7 @@ while (ptr < endptr) if (endlinelength == 0 && t == main_buffer + bufsize) { - fprintf(stderr, "pcregrep: line %d%s%s is too long for the internal buffer\n" + fprintf(stderr, "pcregrep: line %lu%s%s is too long for the internal buffer\n" "pcregrep: check the --buffer-size option\n", linenumber, (filename == NULL)? "" : " of file ", @@ -1747,7 +1747,7 @@ while (ptr < endptr) prevoffsets[1] = offsets[1]; if (printname != NULL) fprintf(stdout, "%s:", printname); - if (number) fprintf(stdout, "%d:", linenumber); + if (number) fprintf(stdout, "%lu:", linenumber); /* Handle --line-offsets */ @@ -1862,7 +1862,7 @@ while (ptr < endptr) { char *pp = lastmatchrestart; if (printname != NULL) fprintf(stdout, "%s-", printname); - if (number) fprintf(stdout, "%d-", lastmatchnumber++); + if (number) fprintf(stdout, "%lu-", lastmatchnumber++); pp = end_of_line(pp, endptr, &ellength); FWRITE(lastmatchrestart, 1, pp - lastmatchrestart, stdout); lastmatchrestart = pp; @@ -1902,7 +1902,7 @@ while (ptr < endptr) int ellength; char *pp = p; if (printname != NULL) fprintf(stdout, "%s-", printname); - if (number) fprintf(stdout, "%d-", linenumber - linecount--); + if (number) fprintf(stdout, "%lu-", linenumber - linecount--); pp = end_of_line(pp, endptr, &ellength); FWRITE(p, 1, pp - p, stdout); p = pp; @@ -1916,7 +1916,7 @@ while (ptr < endptr) endhyphenpending = TRUE; if (printname != NULL) fprintf(stdout, "%s:", printname); - if (number) fprintf(stdout, "%d:", linenumber); + if (number) fprintf(stdout, "%lu:", linenumber); /* In multiline mode, we want to print to the end of the line in which the end of the matched string is found, so we adjust linelength and the @@ -2112,7 +2112,7 @@ if (count_only && !quiet) { if (printname != NULL && filenames != FN_NONE) fprintf(stdout, "%s:", printname); - fprintf(stdout, "%d\n", count); + fprintf(stdout, "%lu\n", count); } } @@ -2234,7 +2234,7 @@ if (isdirectory(pathname)) if (dee_action == dee_RECURSE) { - char buffer[1024]; + char buffer[2048]; char *nextfile; directory_type *dir = opendirectory(pathname); @@ -2249,7 +2249,14 @@ if (isdirectory(pathname)) while ((nextfile = readdirectory(dir)) != NULL) { int frc; - sprintf(buffer, "%.512s%c%.128s", pathname, FILESEP, nextfile); + int fnlength = strlen(pathname) + strlen(nextfile) + 2; + if (fnlength > 2048) + { + fprintf(stderr, "pcre2grep: recursive filename is too long\n"); + rc = 2; + break; + } + sprintf(buffer, "%s%c%s", pathname, FILESEP, nextfile); frc = grep_or_recurse(buffer, dir_recurse, FALSE); if (frc > 1) rc = frc; else if (frc == 0 && rc == 1) rc = 0; @@ -2520,7 +2527,14 @@ if ((popts & PO_FIXED_STRINGS) != 0) } } -sprintf(buffer, "%s%.*s%s", prefix[popts], patlen, ps, suffix[popts]); +if (snprintf(buffer, PATBUFSIZE, "%s%.*s%s", prefix[popts], patlen, ps, + suffix[popts]) > PATBUFSIZE) + { + fprintf(stderr, "pcregrep: Buffer overflow while compiling \"%s\"\n", + ps); + return FALSE; + } + p->compiled = pcre_compile(buffer, options, &error, &errptr, pcretables); if (p->compiled != NULL) return TRUE; @@ -2756,8 +2770,15 @@ for (i = 1; i < argc; i++) int arglen = (argequals == NULL || equals == NULL)? (int)strlen(arg) : (int)(argequals - arg); - sprintf(buff1, "%.*s", baselen, op->long_name); - sprintf(buff2, "%s%.*s", buff1, fulllen - baselen - 2, opbra + 1); + if (snprintf(buff1, sizeof(buff1), "%.*s", baselen, op->long_name) > + (int)sizeof(buff1) || + snprintf(buff2, sizeof(buff2), "%s%.*s", buff1, + fulllen - baselen - 2, opbra + 1) > (int)sizeof(buff2)) + { + fprintf(stderr, "pcregrep: Buffer overflow when parsing %s option\n", + op->long_name); + pcregrep_exit(2); + } if (strncmp(arg, buff1, arglen) == 0 || strncmp(arg, buff2, arglen) == 0) diff --git a/pcre/pcreposix.c b/pcre/pcreposix.c index 7b404a71100..a76d6bfca45 100644 --- a/pcre/pcreposix.c +++ b/pcre/pcreposix.c @@ -6,7 +6,7 @@ and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2017 University of Cambridge + Copyright (c) 1997-2018 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -389,8 +389,8 @@ if (rc >= 0) { for (i = 0; i < (size_t)rc; i++) { - pmatch[i].rm_so = ovector[i*2] + so; - pmatch[i].rm_eo = ovector[i*2+1] + so; + pmatch[i].rm_so = (ovector[i*2] < 0)? -1 : ovector[i*2] + so; + pmatch[i].rm_eo = (ovector[i*2+1] < 0)? -1: ovector[i*2+1] + so; } if (allocated_ovector) free(ovector); for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1; diff --git a/pcre/sljit/sljitConfig.h b/pcre/sljit/sljitConfig.h index b65584a4afd..d54b5e6f544 100644 --- a/pcre/sljit/sljitConfig.h +++ b/pcre/sljit/sljitConfig.h @@ -108,8 +108,10 @@ /* Force cdecl calling convention even if a better calling convention (e.g. fastcall) is supported by the C compiler. - If this option is enabled, C functions without - SLJIT_CALL can also be called from JIT code. */ + If this option is disabled (this is the default), functions + called from JIT should be defined with SLJIT_FUNC attribute. + Standard C functions can still be called by using the + SLJIT_CALL_CDECL jump type. */ #ifndef SLJIT_USE_CDECL_CALLING_CONVENTION /* Disabled by default */ #define SLJIT_USE_CDECL_CALLING_CONVENTION 0 diff --git a/pcre/sljit/sljitConfigInternal.h b/pcre/sljit/sljitConfigInternal.h index cc0810fbd7a..00525de854f 100644 --- a/pcre/sljit/sljitConfigInternal.h +++ b/pcre/sljit/sljitConfigInternal.h @@ -60,11 +60,13 @@ a single precision floating point array by index SLJIT_F64_SHIFT : the shift required to apply when accessing a double precision floating point array by index + SLJIT_PREF_SHIFT_REG : x86 systems prefers ecx for shifting by register + the scratch register index of ecx is stored in this variable SLJIT_LOCALS_OFFSET : local space starting offset (SLJIT_SP + SLJIT_LOCALS_OFFSET) SLJIT_RETURN_ADDRESS_OFFSET : a return instruction always adds this offset to the return address Other macros: - SLJIT_CALL : C calling convention define for both calling JIT form C and C callbacks for JIT + SLJIT_FUNC : calling convention attribute for both calling JIT form C and C calling back from JIT SLJIT_W(number) : defining 64 bit constants on 64 bit architectures (compiler independent helper) */ @@ -145,17 +147,23 @@ #define SLJIT_CONFIG_UNSUPPORTED 1 #endif -#else /* !_WIN32 */ +#else /* _WIN32 */ #if defined(_M_X64) || defined(__x86_64__) #define SLJIT_CONFIG_X86_64 1 +#elif (defined(_M_ARM) && _M_ARM >= 7 && defined(_M_ARMT)) || defined(__thumb2__) +#define SLJIT_CONFIG_ARM_THUMB2 1 +#elif (defined(_M_ARM) && _M_ARM >= 7) +#define SLJIT_CONFIG_ARM_V7 1 #elif defined(_ARM_) #define SLJIT_CONFIG_ARM_V5 1 +#elif defined(_M_ARM64) || defined(__aarch64__) +#define SLJIT_CONFIG_ARM_64 1 #else #define SLJIT_CONFIG_X86_32 1 #endif -#endif /* !WIN32 */ +#endif /* !_WIN32 */ #endif /* SLJIT_CONFIG_AUTO */ #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) @@ -322,6 +330,11 @@ sparc_cache_flush((from), (to)) #define SLJIT_CACHE_FLUSH_OWN_IMPL 1 +#elif defined _WIN32 + +#define SLJIT_CACHE_FLUSH(from, to) \ + FlushInstructionCache(GetCurrentProcess(), (char*)(from), (char*)(to) - (char*)(from)) + #else /* Calls __ARM_NR_cacheflush on ARM-Linux. */ @@ -369,12 +382,18 @@ typedef int sljit_sw; #define SLJIT_64BIT_ARCHITECTURE 1 #define SLJIT_WORD_SHIFT 3 #ifdef _WIN32 +#ifdef __GNUC__ +/* These types do not require windows.h */ +typedef unsigned long long sljit_uw; +typedef long long sljit_sw; +#else typedef unsigned __int64 sljit_uw; typedef __int64 sljit_sw; -#else +#endif +#else /* !_WIN32 */ typedef unsigned long int sljit_uw; typedef long int sljit_sw; -#endif +#endif /* _WIN32 */ #endif typedef sljit_uw sljit_p; @@ -471,44 +490,44 @@ typedef double sljit_f64; /* Calling convention of functions generated by SLJIT or called from the generated code. */ /*****************************************************************************************/ -#ifndef SLJIT_CALL +#ifndef SLJIT_FUNC #if (defined SLJIT_USE_CDECL_CALLING_CONVENTION && SLJIT_USE_CDECL_CALLING_CONVENTION) /* Force cdecl. */ -#define SLJIT_CALL +#define SLJIT_FUNC #elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) #if defined(__GNUC__) && !defined(__APPLE__) -#define SLJIT_CALL __attribute__ ((fastcall)) +#define SLJIT_FUNC __attribute__ ((fastcall)) #define SLJIT_X86_32_FASTCALL 1 #elif defined(_MSC_VER) -#define SLJIT_CALL __fastcall +#define SLJIT_FUNC __fastcall #define SLJIT_X86_32_FASTCALL 1 #elif defined(__BORLANDC__) -#define SLJIT_CALL __msfastcall +#define SLJIT_FUNC __msfastcall #define SLJIT_X86_32_FASTCALL 1 #else /* Unknown compiler. */ /* The cdecl attribute is the default. */ -#define SLJIT_CALL +#define SLJIT_FUNC #endif #else /* Non x86-32 architectures. */ -#define SLJIT_CALL +#define SLJIT_FUNC #endif /* SLJIT_CONFIG_X86_32 */ -#endif /* !SLJIT_CALL */ +#endif /* !SLJIT_FUNC */ #ifndef SLJIT_INDIRECT_CALL #if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)) \ @@ -557,24 +576,20 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void* ptr); #define SLJIT_NUMBER_OF_REGISTERS 12 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 9 -#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) #define SLJIT_LOCALS_OFFSET_BASE (compiler->locals_offset) -#else -/* Maximum 3 arguments are passed on the stack, +1 for double alignment. */ -#define SLJIT_LOCALS_OFFSET_BASE (compiler->locals_offset) -#endif /* SLJIT_X86_32_FASTCALL */ +#define SLJIT_PREF_SHIFT_REG SLJIT_R2 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) -#ifndef _WIN64 #define SLJIT_NUMBER_OF_REGISTERS 13 +#ifndef _WIN64 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 6 #define SLJIT_LOCALS_OFFSET_BASE 0 -#else -#define SLJIT_NUMBER_OF_REGISTERS 13 +#else /* _WIN64 */ #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8 #define SLJIT_LOCALS_OFFSET_BASE (compiler->locals_offset) -#endif /* _WIN64 */ +#endif /* !_WIN64 */ +#define SLJIT_PREF_SHIFT_REG SLJIT_R3 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) @@ -590,13 +605,13 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void* ptr); #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) -#define SLJIT_NUMBER_OF_REGISTERS 25 +#define SLJIT_NUMBER_OF_REGISTERS 26 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 10 -#define SLJIT_LOCALS_OFFSET_BASE (2 * sizeof(sljit_sw)) +#define SLJIT_LOCALS_OFFSET_BASE 0 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) -#define SLJIT_NUMBER_OF_REGISTERS 22 +#define SLJIT_NUMBER_OF_REGISTERS 23 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 17 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) || (defined _AIX) #define SLJIT_LOCALS_OFFSET_BASE ((6 + 8) * sizeof(sljit_sw)) @@ -622,8 +637,9 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void* ptr); #define SLJIT_NUMBER_OF_REGISTERS 18 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 14 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) -/* Add +1 for double alignment. */ -#define SLJIT_LOCALS_OFFSET_BASE ((23 + 1) * sizeof(sljit_sw)) +/* saved registers (16), return struct pointer (1), space for 6 argument words (1), + 4th double arg (2), double alignment (1). */ +#define SLJIT_LOCALS_OFFSET_BASE ((16 + 1 + 6 + 2 + 1) * sizeof(sljit_sw)) #endif #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) diff --git a/pcre/sljit/sljitLir.c b/pcre/sljit/sljitLir.c index 66cdda3db42..5bdddc10cff 100644 --- a/pcre/sljit/sljitLir.c +++ b/pcre/sljit/sljitLir.c @@ -26,6 +26,13 @@ #include "sljitLir.h" +#ifdef _WIN32 + +/* For SLJIT_CACHE_FLUSH, which can expand to FlushInstructionCache. */ +#include + +#endif /* _WIN32 */ + #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED) /* These libraries are needed for the macros below. */ @@ -97,8 +104,13 @@ #define GET_ALL_FLAGS(op) \ ((op) & (SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK)) +#if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) #define TYPE_CAST_NEEDED(op) \ - (((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S16) || ((op) >= SLJIT_MOVU_U8 && (op) <= SLJIT_MOVU_S16)) + ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S32) +#else +#define TYPE_CAST_NEEDED(op) \ + ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S16) +#endif #define BUF_SIZE 4096 @@ -118,16 +130,19 @@ /* When reg can be unused. */ #define SLOW_IS_REG(reg) ((reg) > 0 && (reg) <= REG_MASK) +/* Mask for argument types. */ +#define SLJIT_DEF_MASK ((1 << SLJIT_DEF_SHIFT) - 1) + /* Jump flags. */ #define JUMP_LABEL 0x1 #define JUMP_ADDR 0x2 /* SLJIT_REWRITABLE_JUMP is 0x1000. */ #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) -# define PATCH_MB 0x4 -# define PATCH_MW 0x8 +# define PATCH_MB 0x4 +# define PATCH_MW 0x8 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) -# define PATCH_MD 0x10 +# define PATCH_MD 0x10 #endif #endif @@ -591,6 +606,19 @@ static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler) compiler->buf = prev; } +static SLJIT_INLINE sljit_s32 get_arg_count(sljit_s32 arg_types) +{ + sljit_s32 arg_count = 0; + + arg_types >>= SLJIT_DEF_SHIFT; + while (arg_types) { + arg_count++; + arg_types >>= SLJIT_DEF_SHIFT; + } + + return arg_count; +} + static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler, sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) @@ -664,80 +692,106 @@ static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_comp #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) #define FUNCTION_CHECK_IS_REG(r) \ - (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) || \ - ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0)) + (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) \ + || ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0)) -#define FUNCTION_CHECK_IS_REG_OR_UNUSED(r) \ - ((r) == SLJIT_UNUSED || \ - ((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) || \ - ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0)) +#define FUNCTION_CHECK_IS_FREG(fr) \ + (((fr) >= SLJIT_FR0 && (fr) < (SLJIT_FR0 + compiler->fscratches)) \ + || ((fr) > (SLJIT_FS0 - compiler->fsaveds) && (fr) <= SLJIT_FS0)) #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) -#define CHECK_NOT_VIRTUAL_REGISTER(p) \ - CHECK_ARGUMENT((p) < SLJIT_R3 || (p) > SLJIT_R6); +#define CHECK_IF_VIRTUAL_REGISTER(p) ((p) <= SLJIT_S3 && (p) >= SLJIT_S8) #else -#define CHECK_NOT_VIRTUAL_REGISTER(p) +#define CHECK_IF_VIRTUAL_REGISTER(p) 0 #endif -#define FUNCTION_CHECK_SRC(p, i) \ - CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); \ - if (FUNCTION_CHECK_IS_REG(p)) \ - CHECK_ARGUMENT((i) == 0); \ - else if ((p) == SLJIT_IMM) \ - ; \ - else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \ - CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \ - else { \ - CHECK_ARGUMENT((p) & SLJIT_MEM); \ - CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \ - CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \ - if ((p) & OFFS_REG_MASK) { \ - CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \ - CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \ - CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \ - CHECK_ARGUMENT(!((i) & ~0x3)); \ - } \ - CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK))); \ +static sljit_s32 function_check_src_mem(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) +{ + if (compiler->scratches == -1 || compiler->saveds == -1) + return 0; + + if (!(p & SLJIT_MEM)) + return 0; + + if (!((p & REG_MASK) == SLJIT_UNUSED || FUNCTION_CHECK_IS_REG(p & REG_MASK))) + return 0; + + if (CHECK_IF_VIRTUAL_REGISTER(p & REG_MASK)) + return 0; + + if (p & OFFS_REG_MASK) { + if ((p & REG_MASK) == SLJIT_UNUSED) + return 0; + + if (!(FUNCTION_CHECK_IS_REG(OFFS_REG(p)))) + return 0; + + if (CHECK_IF_VIRTUAL_REGISTER(OFFS_REG(p))) + return 0; + + if ((i & ~0x3) != 0) + return 0; } + return (p & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK)) == 0; +} + +#define FUNCTION_CHECK_SRC_MEM(p, i) \ + CHECK_ARGUMENT(function_check_src_mem(compiler, p, i)); + +static sljit_s32 function_check_src(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) +{ + if (compiler->scratches == -1 || compiler->saveds == -1) + return 0; + + if (FUNCTION_CHECK_IS_REG(p)) + return (i == 0); + + if (p == SLJIT_IMM) + return 1; + + if (p == SLJIT_MEM1(SLJIT_SP)) + return (i >= 0 && i < compiler->logical_local_size); + + return function_check_src_mem(compiler, p, i); +} + +#define FUNCTION_CHECK_SRC(p, i) \ + CHECK_ARGUMENT(function_check_src(compiler, p, i)); + +static sljit_s32 function_check_dst(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i, sljit_s32 unused) +{ + if (compiler->scratches == -1 || compiler->saveds == -1) + return 0; + + if (FUNCTION_CHECK_IS_REG(p) || ((unused) && (p) == SLJIT_UNUSED)) + return (i == 0); + + if (p == SLJIT_MEM1(SLJIT_SP)) + return (i >= 0 && i < compiler->logical_local_size); + + return function_check_src_mem(compiler, p, i); +} + #define FUNCTION_CHECK_DST(p, i, unused) \ - CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); \ - if (FUNCTION_CHECK_IS_REG(p) || ((unused) && (p) == SLJIT_UNUSED)) \ - CHECK_ARGUMENT((i) == 0); \ - else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \ - CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \ - else { \ - CHECK_ARGUMENT((p) & SLJIT_MEM); \ - CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \ - CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \ - if ((p) & OFFS_REG_MASK) { \ - CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \ - CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \ - CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \ - CHECK_ARGUMENT(!((i) & ~0x3)); \ - } \ - CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK))); \ - } + CHECK_ARGUMENT(function_check_dst(compiler, p, i, unused)); + +static sljit_s32 function_fcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) +{ + if (compiler->scratches == -1 || compiler->saveds == -1) + return 0; + + if (FUNCTION_CHECK_IS_FREG(p)) + return (i == 0); + + if (p == SLJIT_MEM1(SLJIT_SP)) + return (i >= 0 && i < compiler->logical_local_size); + + return function_check_src_mem(compiler, p, i); +} #define FUNCTION_FCHECK(p, i) \ - CHECK_ARGUMENT(compiler->fscratches != -1 && compiler->fsaveds != -1); \ - if (((p) >= SLJIT_FR0 && (p) < (SLJIT_FR0 + compiler->fscratches)) || \ - ((p) > (SLJIT_FS0 - compiler->fsaveds) && (p) <= SLJIT_FS0)) \ - CHECK_ARGUMENT(i == 0); \ - else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \ - CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \ - else { \ - CHECK_ARGUMENT((p) & SLJIT_MEM); \ - CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \ - CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \ - if ((p) & OFFS_REG_MASK) { \ - CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \ - CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \ - CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \ - CHECK_ARGUMENT(((p) & OFFS_REG_MASK) != TO_OFFS_REG(SLJIT_SP) && !(i & ~0x3)); \ - } \ - CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK))); \ - } + CHECK_ARGUMENT(function_fcheck(compiler, p, i)); #endif /* SLJIT_ARGUMENT_CHECKS */ @@ -758,64 +812,72 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *comp # define SLJIT_PRINT_D "" #endif -#define sljit_verbose_reg(compiler, r) \ - do { \ - if ((r) < (SLJIT_R0 + compiler->scratches)) \ - fprintf(compiler->verbose, "r%d", (r) - SLJIT_R0); \ - else if ((r) != SLJIT_SP) \ - fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - (r)); \ - else \ - fprintf(compiler->verbose, "sp"); \ - } while (0) +static void sljit_verbose_reg(struct sljit_compiler *compiler, sljit_s32 r) +{ + if (r < (SLJIT_R0 + compiler->scratches)) + fprintf(compiler->verbose, "r%d", r - SLJIT_R0); + else if (r != SLJIT_SP) + fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - r); + else + fprintf(compiler->verbose, "sp"); +} -#define sljit_verbose_param(compiler, p, i) \ - if ((p) & SLJIT_IMM) \ - fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i)); \ - else if ((p) & SLJIT_MEM) { \ - if ((p) & REG_MASK) { \ - fputc('[', compiler->verbose); \ - sljit_verbose_reg(compiler, (p) & REG_MASK); \ - if ((p) & OFFS_REG_MASK) { \ - fprintf(compiler->verbose, " + "); \ - sljit_verbose_reg(compiler, OFFS_REG(p)); \ - if (i) \ - fprintf(compiler->verbose, " * %d", 1 << (i)); \ - } \ - else if (i) \ - fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i)); \ - fputc(']', compiler->verbose); \ - } \ - else \ - fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); \ - } else if (p) \ - sljit_verbose_reg(compiler, p); \ - else \ +static void sljit_verbose_freg(struct sljit_compiler *compiler, sljit_s32 r) +{ + if (r < (SLJIT_FR0 + compiler->fscratches)) + fprintf(compiler->verbose, "fr%d", r - SLJIT_FR0); + else + fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - r); +} + +static void sljit_verbose_param(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) +{ + if ((p) & SLJIT_IMM) + fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i)); + else if ((p) & SLJIT_MEM) { + if ((p) & REG_MASK) { + fputc('[', compiler->verbose); + sljit_verbose_reg(compiler, (p) & REG_MASK); + if ((p) & OFFS_REG_MASK) { + fprintf(compiler->verbose, " + "); + sljit_verbose_reg(compiler, OFFS_REG(p)); + if (i) + fprintf(compiler->verbose, " * %d", 1 << (i)); + } + else if (i) + fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i)); + fputc(']', compiler->verbose); + } + else + fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); + } else if (p) + sljit_verbose_reg(compiler, p); + else fprintf(compiler->verbose, "unused"); +} -#define sljit_verbose_fparam(compiler, p, i) \ - if ((p) & SLJIT_MEM) { \ - if ((p) & REG_MASK) { \ - fputc('[', compiler->verbose); \ - sljit_verbose_reg(compiler, (p) & REG_MASK); \ - if ((p) & OFFS_REG_MASK) { \ - fprintf(compiler->verbose, " + "); \ - sljit_verbose_reg(compiler, OFFS_REG(p)); \ - if (i) \ - fprintf(compiler->verbose, "%d", 1 << (i)); \ - } \ - else if (i) \ - fprintf(compiler->verbose, "%" SLJIT_PRINT_D "d", (i)); \ - fputc(']', compiler->verbose); \ - } \ - else \ - fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); \ - } \ - else { \ - if ((p) < (SLJIT_FR0 + compiler->fscratches)) \ - fprintf(compiler->verbose, "fr%d", (p) - SLJIT_FR0); \ - else \ - fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - (p)); \ +static void sljit_verbose_fparam(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) +{ + if ((p) & SLJIT_MEM) { + if ((p) & REG_MASK) { + fputc('[', compiler->verbose); + sljit_verbose_reg(compiler, (p) & REG_MASK); + if ((p) & OFFS_REG_MASK) { + fprintf(compiler->verbose, " + "); + sljit_verbose_reg(compiler, OFFS_REG(p)); + if (i) + fprintf(compiler->verbose, "%d", 1 << (i)); + } + else if (i) + fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i)); + fputc(']', compiler->verbose); + } + else + fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); } + else + sljit_verbose_freg(compiler, p); +} static const char* op0_names[] = { (char*)"breakpoint", (char*)"nop", (char*)"lmul.uw", (char*)"lmul.sw", @@ -864,7 +926,11 @@ static char* jump_names[] = { (char*)"greater", (char*)"less_equal", (char*)"unordered", (char*)"ordered", (char*)"jump", (char*)"fast_call", - (char*)"call0", (char*)"call1", (char*)"call2", (char*)"call3" + (char*)"call", (char*)"call.cdecl" +}; + +static char* call_arg_names[] = { + (char*)"void", (char*)"sw", (char*)"uw", (char*)"s32", (char*)"u32", (char*)"f32", (char*)"f64" }; #endif /* SLJIT_VERBOSE */ @@ -897,53 +963,104 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_com } static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { +#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + sljit_s32 types, arg_count, curr_type; +#endif + SLJIT_UNUSED_ARG(compiler); #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(!(options & ~SLJIT_F64_ALIGNMENT)); - CHECK_ARGUMENT(args >= 0 && args <= 3); CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS); CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS); CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS); - CHECK_ARGUMENT(args <= saveds); CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS); CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS); CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS); CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE); + CHECK_ARGUMENT((arg_types & SLJIT_DEF_MASK) == 0); + + types = (arg_types >> SLJIT_DEF_SHIFT); + arg_count = 0; + while (types != 0 && arg_count < 3) { + curr_type = (types & SLJIT_DEF_MASK); + CHECK_ARGUMENT(curr_type == SLJIT_ARG_TYPE_SW || curr_type == SLJIT_ARG_TYPE_UW); + arg_count++; + types >>= SLJIT_DEF_SHIFT; + } + CHECK_ARGUMENT(arg_count <= saveds && types == 0); + compiler->last_flags = 0; #endif #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) - if (SLJIT_UNLIKELY(!!compiler->verbose)) - fprintf(compiler->verbose, " enter options:none args:%d scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n", - args, scratches, saveds, fscratches, fsaveds, local_size); + if (SLJIT_UNLIKELY(!!compiler->verbose)) { + fprintf(compiler->verbose, " enter options:%s args[", (options & SLJIT_F64_ALIGNMENT) ? "f64_align" : ""); + + arg_types >>= SLJIT_DEF_SHIFT; + while (arg_types) { + fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]); + arg_types >>= SLJIT_DEF_SHIFT; + if (arg_types) + fprintf(compiler->verbose, ","); + } + + fprintf(compiler->verbose, "] scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n", + scratches, saveds, fscratches, fsaveds, local_size); + } #endif CHECK_RETURN_OK; } static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { +#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + sljit_s32 types, arg_count, curr_type; +#endif + + SLJIT_UNUSED_ARG(compiler); + #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(!(options & ~SLJIT_F64_ALIGNMENT)); - CHECK_ARGUMENT(args >= 0 && args <= 3); CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS); CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS); CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS); - CHECK_ARGUMENT(args <= saveds); CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS); CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS); CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS); CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE); + + types = (arg_types >> SLJIT_DEF_SHIFT); + arg_count = 0; + while (types != 0 && arg_count < 3) { + curr_type = (types & SLJIT_DEF_MASK); + CHECK_ARGUMENT(curr_type == SLJIT_ARG_TYPE_SW || curr_type == SLJIT_ARG_TYPE_UW); + arg_count++; + types >>= SLJIT_DEF_SHIFT; + } + CHECK_ARGUMENT(arg_count <= saveds && types == 0); + compiler->last_flags = 0; #endif #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) - if (SLJIT_UNLIKELY(!!compiler->verbose)) - fprintf(compiler->verbose, " set_context options:none args:%d scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n", - args, scratches, saveds, fscratches, fsaveds, local_size); + if (SLJIT_UNLIKELY(!!compiler->verbose)) { + fprintf(compiler->verbose, " set_context options:%s args[", (options & SLJIT_F64_ALIGNMENT) ? "f64_align" : ""); + + arg_types >>= SLJIT_DEF_SHIFT; + while (arg_types) { + fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]); + arg_types >>= SLJIT_DEF_SHIFT; + if (arg_types) + fprintf(compiler->verbose, ","); + } + + fprintf(compiler->verbose, "] scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n", + scratches, saveds, fscratches, fsaveds, local_size); + } #endif CHECK_RETURN_OK; } @@ -994,6 +1111,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_return(struct sljit_ { #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) FUNCTION_CHECK_SRC(src, srcw); + CHECK_ARGUMENT(src != SLJIT_IMM); compiler->last_flags = 0; #endif #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) @@ -1052,9 +1170,6 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler case SLJIT_MOV: case SLJIT_MOV_U32: case SLJIT_MOV_P: - case SLJIT_MOVU: - case SLJIT_MOVU_U32: - case SLJIT_MOVU_P: /* Nothing allowed */ CHECK_ARGUMENT(!(op & (SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK))); break; @@ -1067,28 +1182,17 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler FUNCTION_CHECK_DST(dst, dstw, 1); FUNCTION_CHECK_SRC(src, srcw); - if (GET_OPCODE(op) >= SLJIT_NOT) + if (GET_OPCODE(op) >= SLJIT_NOT) { + CHECK_ARGUMENT(src != SLJIT_IMM); compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z)); - else if (GET_OPCODE(op) >= SLJIT_MOVU) { - CHECK_ARGUMENT(!(src & SLJIT_MEM) || (src & REG_MASK) != SLJIT_SP); - CHECK_ARGUMENT(!(dst & SLJIT_MEM) || (dst & REG_MASK) != SLJIT_SP); - if ((src & REG_MASK) != SLJIT_UNUSED) { - CHECK_ARGUMENT((src & REG_MASK) != (dst & REG_MASK) && (src & REG_MASK) != OFFS_REG(dst)); - CHECK_ARGUMENT((src & OFFS_REG_MASK) == SLJIT_UNUSED || srcw == 0); - } - if ((dst & REG_MASK) != SLJIT_UNUSED) { - CHECK_ARGUMENT((dst & REG_MASK) != OFFS_REG(src)); - CHECK_ARGUMENT((dst & OFFS_REG_MASK) == SLJIT_UNUSED || dstw == 0); - } - compiler->last_flags = 0; } #endif #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) if (SLJIT_UNLIKELY(!!compiler->verbose)) { - if (GET_OPCODE(op) <= SLJIT_MOVU_P) + if (GET_OPCODE(op) <= SLJIT_MOV_P) { - fprintf(compiler->verbose, " mov%s%s%s ", (GET_OPCODE(op) >= SLJIT_MOVU) ? "u" : "", - !(op & SLJIT_I32_OP) ? "" : "32", (op != SLJIT_MOV32 && op != SLJIT_MOVU32) ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ""); + fprintf(compiler->verbose, " mov%s%s ", !(op & SLJIT_I32_OP) ? "" : "32", + (op != SLJIT_MOV32) ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ""); } else { @@ -1417,9 +1521,8 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compile #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP))); CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1)); - CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_CALL3); + CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_FAST_CALL); CHECK_ARGUMENT((type & 0xff) < SLJIT_JUMP || !(type & SLJIT_I32_OP)); - CHECK_ARGUMENT((type & 0xff) <= SLJIT_CALL0 || ((type & 0xff) - SLJIT_CALL0) <= compiler->scratches); if ((type & 0xff) < SLJIT_JUMP) { if ((type & 0xff) <= SLJIT_NOT_ZERO) @@ -1439,6 +1542,63 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compile CHECK_RETURN_OK; } +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ +#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + sljit_s32 i, types, curr_type, scratches, fscratches; + + CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP))); + CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL || (type & 0xff) == SLJIT_CALL_CDECL); + + types = arg_types; + scratches = 0; + fscratches = 0; + for (i = 0; i < 5; i++) { + curr_type = (types & SLJIT_DEF_MASK); + CHECK_ARGUMENT(curr_type <= SLJIT_ARG_TYPE_F64); + if (i > 0) { + if (curr_type == 0) { + break; + } + if (curr_type >= SLJIT_ARG_TYPE_F32) + fscratches++; + else + scratches++; + } else { + if (curr_type >= SLJIT_ARG_TYPE_F32) { + CHECK_ARGUMENT(compiler->fscratches > 0); + } else if (curr_type >= SLJIT_ARG_TYPE_SW) { + CHECK_ARGUMENT(compiler->scratches > 0); + } + } + types >>= SLJIT_DEF_SHIFT; + } + CHECK_ARGUMENT(compiler->scratches >= scratches); + CHECK_ARGUMENT(compiler->fscratches >= fscratches); + CHECK_ARGUMENT(types == 0); +#endif +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) + if (SLJIT_UNLIKELY(!!compiler->verbose)) { + fprintf(compiler->verbose, " %s%s ret[%s", jump_names[type & 0xff], + !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", call_arg_names[arg_types & SLJIT_DEF_MASK]); + + arg_types >>= SLJIT_DEF_SHIFT; + if (arg_types) { + fprintf(compiler->verbose, "], args["); + do { + fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]); + arg_types >>= SLJIT_DEF_SHIFT; + if (arg_types) + fprintf(compiler->verbose, ","); + } while (arg_types); + } + fprintf(compiler->verbose, "]\n"); + } +#endif + CHECK_RETURN_OK; +} + static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w) @@ -1488,20 +1648,16 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compile CHECK_RETURN_OK; } -static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 src, sljit_sw srcw) { -#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) - compiler->last_flags = 0; -#endif - if (SLJIT_UNLIKELY(compiler->skip_checks)) { compiler->skip_checks = 0; CHECK_RETURN_OK; } #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) - CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_CALL3); - CHECK_ARGUMENT(type <= SLJIT_CALL0 || (type - SLJIT_CALL0) <= compiler->scratches); + CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_FAST_CALL); FUNCTION_CHECK_SRC(src, srcw); #endif #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) @@ -1514,6 +1670,66 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compil CHECK_RETURN_OK; } +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ +#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + sljit_s32 i, types, curr_type, scratches, fscratches; + + CHECK_ARGUMENT(type == SLJIT_CALL || type == SLJIT_CALL_CDECL); + FUNCTION_CHECK_SRC(src, srcw); + + types = arg_types; + scratches = 0; + fscratches = 0; + for (i = 0; i < 5; i++) { + curr_type = (types & SLJIT_DEF_MASK); + CHECK_ARGUMENT(curr_type <= SLJIT_ARG_TYPE_F64); + if (i > 0) { + if (curr_type == 0) { + break; + } + if (curr_type >= SLJIT_ARG_TYPE_F32) + fscratches++; + else + scratches++; + } else { + if (curr_type >= SLJIT_ARG_TYPE_F32) { + CHECK_ARGUMENT(compiler->fscratches > 0); + } else if (curr_type >= SLJIT_ARG_TYPE_SW) { + CHECK_ARGUMENT(compiler->scratches > 0); + } + } + types >>= SLJIT_DEF_SHIFT; + } + CHECK_ARGUMENT(compiler->scratches >= scratches); + CHECK_ARGUMENT(compiler->fscratches >= fscratches); + CHECK_ARGUMENT(types == 0); +#endif +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) + if (SLJIT_UNLIKELY(!!compiler->verbose)) { + fprintf(compiler->verbose, " i%s%s ret[%s", jump_names[type & 0xff], + !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", call_arg_names[arg_types & SLJIT_DEF_MASK]); + + arg_types >>= SLJIT_DEF_SHIFT; + if (arg_types) { + fprintf(compiler->verbose, "], args["); + do { + fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]); + arg_types >>= SLJIT_DEF_SHIFT; + if (arg_types) + fprintf(compiler->verbose, ","); + } while (arg_types); + } + fprintf(compiler->verbose, "], "); + sljit_verbose_param(compiler, src, srcw); + fprintf(compiler->verbose, "\n"); + } +#endif + CHECK_RETURN_OK; +} + static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 dst, sljit_sw dstw, sljit_s32 type) @@ -1558,9 +1774,12 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compile #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_I32_OP))); CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_ORDERED_F64); + + CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg & ~SLJIT_I32_OP)); if (src != SLJIT_IMM) { CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src)); + CHECK_ARGUMENT(srcw == 0); } if ((type & 0xff) <= SLJIT_NOT_ZERO) @@ -1573,7 +1792,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compile #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) if (SLJIT_UNLIKELY(!!compiler->verbose)) { fprintf(compiler->verbose, " cmov%s %s%s, ", - !(dst_reg & SLJIT_I32_OP) ? "" : ".i", + !(dst_reg & SLJIT_I32_OP) ? "" : "32", jump_names[type & 0xff], JUMP_POSTFIX(type)); sljit_verbose_reg(compiler, dst_reg & ~SLJIT_I32_OP); fprintf(compiler->verbose, ", "); @@ -1584,8 +1803,75 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compile CHECK_RETURN_OK; } +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 reg, + sljit_s32 mem, sljit_sw memw) +{ +#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P); + CHECK_ARGUMENT(!(type & SLJIT_I32_OP) || ((type & 0xff) != SLJIT_MOV && (type & 0xff) != SLJIT_MOV_U32 && (type & 0xff) != SLJIT_MOV_P)); + CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST)); + CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST)); + CHECK_ARGUMENT((type & ~(0xff | SLJIT_I32_OP | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0); + + FUNCTION_CHECK_SRC_MEM(mem, memw); + CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg)); + + CHECK_ARGUMENT((mem & REG_MASK) != SLJIT_UNUSED && (mem & REG_MASK) != reg); +#endif +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) + if (!(type & SLJIT_MEM_SUPP) && SLJIT_UNLIKELY(!!compiler->verbose)) { + if (sljit_emit_mem(compiler, type | SLJIT_MEM_SUPP, reg, mem, memw) == SLJIT_ERR_UNSUPPORTED) + fprintf(compiler->verbose, " //"); + + fprintf(compiler->verbose, " mem%s.%s%s%s ", + !(type & SLJIT_I32_OP) ? "" : "32", + (type & SLJIT_MEM_STORE) ? "st" : "ld", + op1_names[(type & 0xff) - SLJIT_OP1_BASE], + (type & SLJIT_MEM_PRE) ? ".pre" : ".post"); + sljit_verbose_reg(compiler, reg); + fprintf(compiler->verbose, ", "); + sljit_verbose_param(compiler, mem, memw); + fprintf(compiler->verbose, "\n"); + } +#endif + CHECK_RETURN_OK; +} + +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 freg, + sljit_s32 mem, sljit_sw memw) +{ +#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64); + CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST)); + CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST)); + CHECK_ARGUMENT((type & ~(0xff | SLJIT_I32_OP | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0); + + FUNCTION_CHECK_SRC_MEM(mem, memw); + CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg)); +#endif +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) + if (!(type & SLJIT_MEM_SUPP) && SLJIT_UNLIKELY(!!compiler->verbose)) { + if (sljit_emit_fmem(compiler, type | SLJIT_MEM_SUPP, freg, mem, memw) == SLJIT_ERR_UNSUPPORTED) + fprintf(compiler->verbose, " //"); + + fprintf(compiler->verbose, " fmem.%s%s%s ", + (type & SLJIT_MEM_STORE) ? "st" : "ld", + !(type & SLJIT_I32_OP) ? ".f64" : ".f32", + (type & SLJIT_MEM_PRE) ? ".pre" : ".post"); + sljit_verbose_freg(compiler, freg); + fprintf(compiler->verbose, ", "); + sljit_verbose_param(compiler, mem, memw); + fprintf(compiler->verbose, "\n"); + } +#endif + CHECK_RETURN_OK; +} + static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset) { + /* Any offset is allowed. */ SLJIT_UNUSED_ARG(offset); #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) @@ -1856,7 +2142,51 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compile return sljit_emit_jump(compiler, type); } -#if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) +#if !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \ + && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \ + && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 reg, + sljit_s32 mem, sljit_sw memw) +{ + SLJIT_UNUSED_ARG(compiler); + SLJIT_UNUSED_ARG(type); + SLJIT_UNUSED_ARG(reg); + SLJIT_UNUSED_ARG(mem); + SLJIT_UNUSED_ARG(memw); + + CHECK_ERROR(); + CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw)); + + return SLJIT_ERR_UNSUPPORTED; +} + +#endif + +#if !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \ + && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 freg, + sljit_s32 mem, sljit_sw memw) +{ + SLJIT_UNUSED_ARG(compiler); + SLJIT_UNUSED_ARG(type); + SLJIT_UNUSED_ARG(freg); + SLJIT_UNUSED_ARG(mem); + SLJIT_UNUSED_ARG(memw); + + CHECK_ERROR(); + CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw)); + + return SLJIT_ERR_UNSUPPORTED; +} + +#endif + +#if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \ + && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset) { @@ -1941,12 +2271,12 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code) } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { SLJIT_UNUSED_ARG(compiler); SLJIT_UNUSED_ARG(options); - SLJIT_UNUSED_ARG(args); + SLJIT_UNUSED_ARG(arg_types); SLJIT_UNUSED_ARG(scratches); SLJIT_UNUSED_ARG(saveds); SLJIT_UNUSED_ARG(fscratches); @@ -1957,12 +2287,12 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { SLJIT_UNUSED_ARG(compiler); SLJIT_UNUSED_ARG(options); - SLJIT_UNUSED_ARG(args); + SLJIT_UNUSED_ARG(arg_types); SLJIT_UNUSED_ARG(scratches); SLJIT_UNUSED_ARG(saveds); SLJIT_UNUSED_ARG(fscratches); @@ -2107,6 +2437,16 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile return NULL; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ + SLJIT_UNUSED_ARG(compiler); + SLJIT_UNUSED_ARG(type); + SLJIT_UNUSED_ARG(arg_types); + SLJIT_UNREACHABLE(); + return NULL; +} + SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w) @@ -2159,6 +2499,19 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi return SLJIT_ERR_UNSUPPORTED; } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ + SLJIT_UNUSED_ARG(compiler); + SLJIT_UNUSED_ARG(type); + SLJIT_UNUSED_ARG(arg_types); + SLJIT_UNUSED_ARG(src); + SLJIT_UNUSED_ARG(srcw); + SLJIT_UNREACHABLE(); + return SLJIT_ERR_UNSUPPORTED; +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 dst, sljit_sw dstw, sljit_s32 type) @@ -2185,6 +2538,28 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compil return SLJIT_ERR_UNSUPPORTED; } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 reg, sljit_s32 mem, sljit_sw memw) +{ + SLJIT_UNUSED_ARG(compiler); + SLJIT_UNUSED_ARG(type); + SLJIT_UNUSED_ARG(reg); + SLJIT_UNUSED_ARG(mem); + SLJIT_UNUSED_ARG(memw); + SLJIT_UNREACHABLE(); + return SLJIT_ERR_UNSUPPORTED; +} + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 freg, sljit_s32 mem, sljit_sw memw) +{ + SLJIT_UNUSED_ARG(compiler); + SLJIT_UNUSED_ARG(type); + SLJIT_UNUSED_ARG(freg); + SLJIT_UNUSED_ARG(mem); + SLJIT_UNUSED_ARG(memw); + SLJIT_UNREACHABLE(); + return SLJIT_ERR_UNSUPPORTED; +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset) { SLJIT_UNUSED_ARG(compiler); diff --git a/pcre/sljit/sljitLir.h b/pcre/sljit/sljitLir.h index a58ad6e6387..920f6d4f783 100644 --- a/pcre/sljit/sljitLir.h +++ b/pcre/sljit/sljitLir.h @@ -153,8 +153,8 @@ of sljitConfigInternal.h */ is not available at all. */ -/* When SLJIT_UNUSED is specified as the destination of sljit_emit_op1 and - and sljit_emit_op2 operations the result is discarded. If no status +/* When SLJIT_UNUSED is specified as the destination of sljit_emit_op1 + or sljit_emit_op2 operations the result is discarded. If no status flags are set, no instructions are emitted for these operations. Data prefetch is a special exception, see SLJIT_MOV operation. Other SLJIT operations do not support SLJIT_UNUSED as a destination operand. */ @@ -213,14 +213,6 @@ of sljitConfigInternal.h */ #define SLJIT_RETURN_REG SLJIT_R0 -/* x86 prefers specific registers for special purposes. In case of shift - by register it supports only SLJIT_R2 for shift argument - (which is the src2 argument of sljit_emit_op2). If another register is - used, sljit must exchange data between registers which cause a minor - slowdown. Other architectures has no such limitation. */ - -#define SLJIT_PREF_SHIFT_REG SLJIT_R2 - /* --------------------------------------------------------------------- */ /* Floating point registers */ /* --------------------------------------------------------------------- */ @@ -257,6 +249,79 @@ of sljitConfigInternal.h */ /* Float registers >= SLJIT_FIRST_SAVED_FLOAT_REG are saved registers. */ #define SLJIT_FIRST_SAVED_FLOAT_REG (SLJIT_FS0 - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS + 1) +/* --------------------------------------------------------------------- */ +/* Argument type definitions */ +/* --------------------------------------------------------------------- */ + +/* Argument type definitions. + Used by SLJIT_[DEF_]ARGx and SLJIT_[DEF]_RET macros. */ + +#define SLJIT_ARG_TYPE_VOID 0 +#define SLJIT_ARG_TYPE_SW 1 +#define SLJIT_ARG_TYPE_UW 2 +#define SLJIT_ARG_TYPE_S32 3 +#define SLJIT_ARG_TYPE_U32 4 +#define SLJIT_ARG_TYPE_F32 5 +#define SLJIT_ARG_TYPE_F64 6 + +/* The following argument type definitions are used by sljit_emit_enter, + sljit_set_context, sljit_emit_call, and sljit_emit_icall functions. + The following return type definitions are used by sljit_emit_call + and sljit_emit_icall functions. + + When a function is called, the first integer argument must be placed + in SLJIT_R0, the second in SLJIT_R1, and so on. Similarly the first + floating point argument must be placed in SLJIT_FR0, the second in + SLJIT_FR1, and so on. + + Example function definition: + sljit_f32 SLJIT_FUNC example_c_callback(sljit_sw arg_a, + sljit_f64 arg_b, sljit_u32 arg_c, sljit_f32 arg_d); + + Argument type definition: + SLJIT_DEF_RET(SLJIT_ARG_TYPE_F32) + | SLJIT_DEF_ARG1(SLJIT_ARG_TYPE_SW) | SLJIT_DEF_ARG2(SLJIT_ARG_TYPE_F64) + | SLJIT_DEF_ARG3(SLJIT_ARG_TYPE_U32) | SLJIT_DEF_ARG2(SLJIT_ARG_TYPE_F32) + + Short form of argument type definition: + SLJIT_RET(F32) | SLJIT_ARG1(SW) | SLJIT_ARG2(F64) + | SLJIT_ARG3(S32) | SLJIT_ARG4(F32) + + Argument passing: + arg_a must be placed in SLJIT_R0 + arg_c must be placed in SLJIT_R1 + arg_b must be placed in SLJIT_FR0 + arg_d must be placed in SLJIT_FR1 + +Note: + The SLJIT_ARG_TYPE_VOID type is only supported by + SLJIT_DEF_RET, and SLJIT_ARG_TYPE_VOID is also the + default value when SLJIT_DEF_RET is not specified. */ +#define SLJIT_DEF_SHIFT 4 +#define SLJIT_DEF_RET(type) (type) +#define SLJIT_DEF_ARG1(type) ((type) << SLJIT_DEF_SHIFT) +#define SLJIT_DEF_ARG2(type) ((type) << (2 * SLJIT_DEF_SHIFT)) +#define SLJIT_DEF_ARG3(type) ((type) << (3 * SLJIT_DEF_SHIFT)) +#define SLJIT_DEF_ARG4(type) ((type) << (4 * SLJIT_DEF_SHIFT)) + +/* Short form of the macros above. + + For example the following definition: + SLJIT_DEF_RET(SLJIT_ARG_TYPE_SW) | SLJIT_DEF_ARG1(SLJIT_ARG_TYPE_F32) + + can be shortened to: + SLJIT_RET(SW) | SLJIT_ARG1(F32) + +Note: + The VOID type is only supported by SLJIT_RET, and + VOID is also the default value when SLJIT_RET is + not specified. */ +#define SLJIT_RET(type) SLJIT_DEF_RET(SLJIT_ARG_TYPE_ ## type) +#define SLJIT_ARG1(type) SLJIT_DEF_ARG1(SLJIT_ARG_TYPE_ ## type) +#define SLJIT_ARG2(type) SLJIT_DEF_ARG2(SLJIT_ARG_TYPE_ ## type) +#define SLJIT_ARG3(type) SLJIT_DEF_ARG3(SLJIT_ARG_TYPE_ ## type) +#define SLJIT_ARG4(type) SLJIT_DEF_ARG4(SLJIT_ARG_TYPE_ ## type) + /* --------------------------------------------------------------------- */ /* Main structures and functions */ /* --------------------------------------------------------------------- */ @@ -331,6 +396,7 @@ struct sljit_compiler { sljit_s32 args; sljit_s32 locals_offset; sljit_s32 saveds_offset; + sljit_s32 stack_tmp_size; #endif #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) @@ -356,15 +422,8 @@ struct sljit_compiler { sljit_uw shift_imm; #endif -#if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) - sljit_s32 cache_arg; - sljit_sw cache_argw; -#endif - #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) sljit_sw imm; - sljit_s32 cache_arg; - sljit_sw cache_argw; #endif #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) @@ -499,14 +558,10 @@ static SLJIT_INLINE sljit_uw sljit_get_generated_code_size(struct sljit_compiler #define SLJIT_HAS_FPU 0 /* [Limitation] Some registers are virtual registers. */ #define SLJIT_HAS_VIRTUAL_REGISTERS 1 -/* [Emulated] Some forms of move with pre update is supported. */ -#define SLJIT_HAS_PRE_UPDATE 2 /* [Emulated] Count leading zero is supported. */ -#define SLJIT_HAS_CLZ 3 +#define SLJIT_HAS_CLZ 2 /* [Emulated] Conditional move is supported. */ -#define SLJIT_HAS_CMOV 4 -/* [Limitation] [Emulated] Shifting with register is limited to SLJIT_PREF_SHIFT_REG. */ -#define SLJIT_HAS_PREF_SHIFT_REG 5 +#define SLJIT_HAS_CMOV 3 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) /* [Not emulated] SSE2 support is available on x86. */ @@ -519,27 +574,28 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) error, they return with SLJIT_SUCCESS. */ /* - The executable code is a function call from the viewpoint of the C + The executable code is a function from the viewpoint of the C language. The function calls must obey to the ABI (Application Binary Interface) of the platform, which specify the purpose of - all machine registers and stack handling among other things. The + machine registers and stack handling among other things. The sljit_emit_enter function emits the necessary instructions for setting up a new context for the executable code and moves function arguments to the saved registers. Furthermore the options argument can be used to pass configuration options to the compiler. The available options are listed before sljit_emit_enter. - The number of sljit_sw arguments passed to the generated function - are specified in the "args" parameter. The number of arguments must - be less than or equal to 3. The first argument goes to SLJIT_S0, - the second goes to SLJIT_S1 and so on. The register set used by - the function must be declared as well. The number of scratch and - saved registers used by the function must be passed to sljit_emit_enter. - Only R registers between R0 and "scratches" argument can be used - later. E.g. if "scratches" is set to 2, the register set will be - limited to R0 and R1. The S registers and the floating point + The function argument list is the combination of SLJIT_ARGx + (SLJIT_DEF_ARG1) macros. Currently maximum 3 SW / UW + (SLJIT_ARG_TYPE_SW / LJIT_ARG_TYPE_UW) arguments are supported. + The first argument goes to SLJIT_S0, the second goes to SLJIT_S1 + and so on. The register set used by the function must be declared + as well. The number of scratch and saved registers used by the + function must be passed to sljit_emit_enter. Only R registers + between R0 and "scratches" argument can be used later. E.g. if + "scratches" is set to 2, the scratch register set will be limited + to SLJIT_R0 and SLJIT_R1. The S registers and the floating point registers ("fscratches" and "fsaveds") are specified in a similar - way. The sljit_emit_enter is also capable of allocating a stack + manner. The sljit_emit_enter is also capable of allocating a stack space for local variables. The "local_size" argument contains the size in bytes of this local area and its staring address is stored in SLJIT_SP. The memory area between SLJIT_SP (inclusive) and @@ -566,7 +622,7 @@ offset 0 is aligned to sljit_f64. Otherwise it is aligned to sljit_sw. */ #define SLJIT_MAX_LOCAL_SIZE 65536 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size); /* The machine code has a context (which contains the local stack space size, @@ -580,7 +636,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi the previous context. */ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size); /* Return from machine code. The op argument can be SLJIT_UNUSED which means the @@ -592,26 +648,31 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *comp SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw); -/* Fast calling mechanism for utility functions (see SLJIT_FAST_CALL). All registers and - even the stack frame is passed to the callee. The return address is preserved in - dst/dstw by sljit_emit_fast_enter (the type of the value stored by this function - is sljit_p), and sljit_emit_fast_return can use this as a return value later. */ +/* Generating entry and exit points for fast call functions (see SLJIT_FAST_CALL). + Both sljit_emit_fast_enter and sljit_emit_fast_return functions preserve the + values of all registers and stack frame. The return address is stored in the + dst argument of sljit_emit_fast_enter, and this return address can be passed + to sljit_emit_fast_return to continue the execution after the fast call. -/* Note: only for sljit specific, non ABI compilant calls. Fast, since only a few machine - instructions are needed. Excellent for small uility functions, where saving registers - and setting up a new stack frame would cost too much performance. However, it is still - possible to return to the address of the caller (or anywhere else). */ + Fast calls are cheap operations (usually only a single call instruction is + emitted) but they do not preserve any registers. However the callee function + can freely use / update any registers and stack values which can be + efficiently exploited by various optimizations. Registers can be saved + manually by the callee function if needed. -/* Note: may destroy flags. */ + Although returning to different address by sljit_emit_fast_return is possible, + this address usually cannot be predicted by the return address predictor of + modern CPUs which may reduce performance. Furthermore using sljit_emit_ijump + to return is also inefficient since return address prediction is usually + triggered by a specific form of ijump. -/* Note: although sljit_emit_fast_return could be replaced by an ijump, it is not suggested, - since many architectures do clever branch prediction on call / return instruction pairs. */ + Flags: - (does not modify flags). */ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw); SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw); /* - Source and destination values for arithmetical instructions + Source and destination operands for arithmetical instructions imm - a simple immediate value (cannot be used as a destination) reg - any of the registers (immediate argument must be 0) [imm] - absolute immediate memory address @@ -652,6 +713,9 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler arm-t2: [reg+imm], -255 <= imm <= 4095 [reg+(reg<cpool_diff == CONST_POOL_EMPTY || compiler->size - compiler->cpool_diff < MAX_DIFFERENCE(4092)); - return push_inst(compiler, BLX | RM(TMP_REG2)); + SLJIT_ASSERT(reg_map[TMP_REG1] != 14); + + return push_inst(compiler, BLX | RM(TMP_REG1)); } static sljit_uw patch_pc_relative_loads(sljit_uw *last_pc_patch, sljit_uw *code_ptr, sljit_uw* const_pool, sljit_uw cpool_size) @@ -825,7 +837,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) return 1; #endif - case SLJIT_HAS_PRE_UPDATE: case SLJIT_HAS_CLZ: case SLJIT_HAS_CMOV: return 1; @@ -840,18 +851,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) /* --------------------------------------------------------------------- */ /* Creates an index in data_transfer_insts array. */ -#define WORD_DATA 0x00 -#define BYTE_DATA 0x01 -#define HALF_DATA 0x02 -#define PRELOAD_DATA 0x03 -#define SIGNED_DATA 0x04 +#define WORD_SIZE 0x00 +#define BYTE_SIZE 0x01 +#define HALF_SIZE 0x02 +#define PRELOAD 0x03 +#define SIGNED 0x04 #define LOAD_DATA 0x08 -/* emit_op inp_flags. - WRITE_BACK must be the first, since it is a flag. */ -#define WRITE_BACK 0x10 -#define ALLOW_IMM 0x20 -#define ALLOW_INV_IMM 0x40 +/* Flag bits for emit_op. */ +#define ALLOW_IMM 0x10 +#define ALLOW_INV_IMM 0x20 #define ALLOW_ANY_IMM (ALLOW_IMM | ALLOW_INV_IMM) /* s/l - store/load (1 bit) @@ -872,15 +881,15 @@ static const sljit_uw data_transfer_insts[16] = { /* l u w */ 0xe5100000 /* ldr */, /* l u b */ 0xe5500000 /* ldrb */, /* l u h */ 0xe11000b0 /* ldrh */, -/* l u p */ 0xf5500000 /* preload data */, +/* l u p */ 0xf5500000 /* preload */, /* l s w */ 0xe5100000 /* ldr */, /* l s b */ 0xe11000d0 /* ldrsb */, /* l s h */ 0xe11000f0 /* ldrsh */, /* l s N */ 0x00000000 /* not allowed */, }; -#define EMIT_DATA_TRANSFER(type, add, wb, target_reg, base_reg, arg) \ - (data_transfer_insts[(type) & 0xf] | ((add) << 23) | ((wb) << (21 - 4)) | RD(target_reg) | RN(base_reg) | (arg)) +#define EMIT_DATA_TRANSFER(type, add, target_reg, base_reg, arg) \ + (data_transfer_insts[(type) & 0xf] | ((add) << 23) | RD(target_reg) | RN(base_reg) | (arg)) /* Normal ldr/str instruction. Type2: ldrsb, ldrh, ldrsh */ @@ -889,25 +898,21 @@ static const sljit_uw data_transfer_insts[16] = { #define TYPE2_TRANSFER_IMM(imm) \ (((imm) & 0xf) | (((imm) & 0xf0) << 4) | (1 << 22)) -/* Condition: AL. */ -#define EMIT_DATA_PROCESS_INS(opcode, set_flags, dst, src1, src2) \ - (0xe0000000 | ((opcode) << 21) | (set_flags) | RD(dst) | RN(src1) | (src2)) - static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 inp_flags, sljit_s32 dst, sljit_sw dstw, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w); SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { - sljit_s32 size, i, tmp; + sljit_s32 args, size, i, tmp; sljit_uw push; CHECK_ERROR(); - CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); /* Push saved registers, temporary registers stmdb sp!, {..., lr} */ @@ -929,25 +934,27 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi if (local_size > 0) FAIL_IF(emit_op(compiler, SLJIT_SUB, ALLOW_IMM, SLJIT_SP, 0, SLJIT_SP, 0, SLJIT_IMM, local_size)); + args = get_arg_count(arg_types); + if (args >= 1) - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, SLJIT_S0, SLJIT_UNUSED, RM(SLJIT_R0)))); + FAIL_IF(push_inst(compiler, MOV | RD(SLJIT_S0) | RM(SLJIT_R0))); if (args >= 2) - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, SLJIT_S1, SLJIT_UNUSED, RM(SLJIT_R1)))); + FAIL_IF(push_inst(compiler, MOV | RD(SLJIT_S1) | RM(SLJIT_R1))); if (args >= 3) - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, SLJIT_S2, SLJIT_UNUSED, RM(SLJIT_R2)))); + FAIL_IF(push_inst(compiler, MOV | RD(SLJIT_S2) | RM(SLJIT_R2))); return SLJIT_SUCCESS; } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { sljit_s32 size; CHECK_ERROR(); - CHECK(check_sljit_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); size = GET_SAVED_REGISTERS_SIZE(scratches, saveds, 1); compiler->local_size = ((size + local_size + 7) & ~7) - size; @@ -1009,12 +1016,12 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *comp SLJIT_ASSERT(!(flags & ARGS_SWAPPED)); \ \ if (compiler->shift_imm != 0) \ - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, flags & SET_FLAGS, \ - dst, SLJIT_UNUSED, (compiler->shift_imm << 7) | (opcode << 5) | RM(src2))); \ - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, flags & SET_FLAGS, dst, SLJIT_UNUSED, RM(src2))); \ + return push_inst(compiler, MOV | (flags & SET_FLAGS) | \ + RD(dst) | (compiler->shift_imm << 7) | (opcode << 5) | RM(src2)); \ + return push_inst(compiler, MOV | (flags & SET_FLAGS) | RD(dst) | RM(src2)); \ } \ - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, flags & SET_FLAGS, \ - dst, SLJIT_UNUSED, (reg_map[(flags & ARGS_SWAPPED) ? src1 : src2] << 8) | (opcode << 5) | 0x10 | RM((flags & ARGS_SWAPPED) ? src2 : src1))); + return push_inst(compiler, MOV | (flags & SET_FLAGS) | RD(dst) | \ + (reg_map[(flags & ARGS_SWAPPED) ? src1 : src2] << 8) | (opcode << 5) | 0x10 | RM((flags & ARGS_SWAPPED) ? src2 : src1)); static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 flags, sljit_s32 dst, sljit_s32 src1, sljit_s32 src2) @@ -1024,10 +1031,9 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl SLJIT_ASSERT(src1 == TMP_REG1 && !(flags & ARGS_SWAPPED)); if (dst != src2) { if (src2 & SRC2_IMM) { - return push_inst(compiler, EMIT_DATA_PROCESS_INS((flags & INV_IMM) ? MVN_DP : MOV_DP, 0, - dst, SLJIT_UNUSED, src2)); + return push_inst(compiler, ((flags & INV_IMM) ? MVN : MOV) | RD(dst) | src2); } - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, dst, SLJIT_UNUSED, RM(src2))); + return push_inst(compiler, MOV | RD(dst) | RM(src2)); } return SLJIT_SUCCESS; @@ -1037,17 +1043,16 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl if (flags & MOVE_REG_CONV) { #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) if (op == SLJIT_MOV_U8) - return push_inst(compiler, EMIT_DATA_PROCESS_INS(AND_DP, 0, dst, src2, SRC2_IMM | 0xff)); - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, dst, SLJIT_UNUSED, (24 << 7) | RM(src2)))); - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, dst, SLJIT_UNUSED, (24 << 7) | (op == SLJIT_MOV_U8 ? 0x20 : 0x40) | RM(dst))); + return push_inst(compiler, AND | RD(dst) | RN(src2) | SRC2_IMM | 0xff); + FAIL_IF(push_inst(compiler, MOV | RD(dst) | (24 << 7) | RM(src2))); + return push_inst(compiler, MOV | RD(dst) | (24 << 7) | (op == SLJIT_MOV_U8 ? 0x20 : 0x40) | RM(dst)); #else return push_inst(compiler, (op == SLJIT_MOV_U8 ? UXTB : SXTB) | RD(dst) | RM(src2)); #endif } else if (dst != src2) { SLJIT_ASSERT(src2 & SRC2_IMM); - return push_inst(compiler, EMIT_DATA_PROCESS_INS((flags & INV_IMM) ? MVN_DP : MOV_DP, 0, - dst, SLJIT_UNUSED, src2)); + return push_inst(compiler, ((flags & INV_IMM) ? MVN : MOV) | RD(dst) | src2); } return SLJIT_SUCCESS; @@ -1056,25 +1061,23 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl SLJIT_ASSERT(src1 == TMP_REG1 && !(flags & ARGS_SWAPPED)); if (flags & MOVE_REG_CONV) { #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, dst, SLJIT_UNUSED, (16 << 7) | RM(src2)))); - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, dst, SLJIT_UNUSED, (16 << 7) | (op == SLJIT_MOV_U16 ? 0x20 : 0x40) | RM(dst))); + FAIL_IF(push_inst(compiler, MOV | RD(dst) | (16 << 7) | RM(src2))); + return push_inst(compiler, MOV | RD(dst) | (16 << 7) | (op == SLJIT_MOV_U16 ? 0x20 : 0x40) | RM(dst)); #else return push_inst(compiler, (op == SLJIT_MOV_U16 ? UXTH : SXTH) | RD(dst) | RM(src2)); #endif } else if (dst != src2) { SLJIT_ASSERT(src2 & SRC2_IMM); - return push_inst(compiler, EMIT_DATA_PROCESS_INS((flags & INV_IMM) ? MVN_DP : MOV_DP, 0, - dst, SLJIT_UNUSED, src2)); + return push_inst(compiler, ((flags & INV_IMM) ? MVN : MOV) | RD(dst) | src2); } return SLJIT_SUCCESS; case SLJIT_NOT: if (src2 & SRC2_IMM) { - return push_inst(compiler, EMIT_DATA_PROCESS_INS((flags & INV_IMM) ? MOV_DP : MVN_DP, flags & SET_FLAGS, - dst, SLJIT_UNUSED, src2)); + return push_inst(compiler, ((flags & INV_IMM) ? MOV : MVN) | (flags & SET_FLAGS) | RD(dst) | src2); } - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MVN_DP, flags & SET_FLAGS, dst, SLJIT_UNUSED, RM(src2))); + return push_inst(compiler, MVN | (flags & SET_FLAGS) | RD(dst) | RM(src2)); case SLJIT_CLZ: SLJIT_ASSERT(!(flags & INV_IMM)); @@ -1085,28 +1088,24 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl case SLJIT_ADD: SLJIT_ASSERT(!(flags & INV_IMM)); if ((flags & (UNUSED_RETURN | SET_FLAGS)) == (UNUSED_RETURN | SET_FLAGS) && !(flags & ARGS_SWAPPED)) - return push_inst(compiler, EMIT_DATA_PROCESS_INS(CMN_DP, SET_FLAGS, - SLJIT_UNUSED, src1, (src2 & SRC2_IMM) ? src2 : RM(src2))); - return push_inst(compiler, EMIT_DATA_PROCESS_INS(ADD_DP, flags & SET_FLAGS, - dst, src1, (src2 & SRC2_IMM) ? src2 : RM(src2))); + return push_inst(compiler, CMN | SET_FLAGS | RN(src1) | ((src2 & SRC2_IMM) ? src2 : RM(src2))); + return push_inst(compiler, ADD | (flags & SET_FLAGS) | RD(dst) | RN(src1) | ((src2 & SRC2_IMM) ? src2 : RM(src2))); case SLJIT_ADDC: SLJIT_ASSERT(!(flags & INV_IMM)); - return push_inst(compiler, EMIT_DATA_PROCESS_INS(ADC_DP, flags & SET_FLAGS, - dst, src1, (src2 & SRC2_IMM) ? src2 : RM(src2))); + return push_inst(compiler, ADC | (flags & SET_FLAGS) | RD(dst) | RN(src1) | ((src2 & SRC2_IMM) ? src2 : RM(src2))); case SLJIT_SUB: SLJIT_ASSERT(!(flags & INV_IMM)); if ((flags & (UNUSED_RETURN | SET_FLAGS)) == (UNUSED_RETURN | SET_FLAGS) && !(flags & ARGS_SWAPPED)) - return push_inst(compiler, EMIT_DATA_PROCESS_INS(CMP_DP, SET_FLAGS, - SLJIT_UNUSED, src1, (src2 & SRC2_IMM) ? src2 : RM(src2))); - return push_inst(compiler, EMIT_DATA_PROCESS_INS(!(flags & ARGS_SWAPPED) ? SUB_DP : RSB_DP, flags & SET_FLAGS, - dst, src1, (src2 & SRC2_IMM) ? src2 : RM(src2))); + return push_inst(compiler, CMP | SET_FLAGS | RN(src1) | ((src2 & SRC2_IMM) ? src2 : RM(src2))); + return push_inst(compiler, (!(flags & ARGS_SWAPPED) ? SUB : RSB) | (flags & SET_FLAGS) + | RD(dst) | RN(src1) | ((src2 & SRC2_IMM) ? src2 : RM(src2))); case SLJIT_SUBC: SLJIT_ASSERT(!(flags & INV_IMM)); - return push_inst(compiler, EMIT_DATA_PROCESS_INS(!(flags & ARGS_SWAPPED) ? SBC_DP : RSC_DP, flags & SET_FLAGS, - dst, src1, (src2 & SRC2_IMM) ? src2 : RM(src2))); + return push_inst(compiler, (!(flags & ARGS_SWAPPED) ? SBC : RSC) | (flags & SET_FLAGS) + | RD(dst) | RN(src1) | ((src2 & SRC2_IMM) ? src2 : RM(src2))); case SLJIT_MUL: SLJIT_ASSERT(!(flags & INV_IMM)); @@ -1118,19 +1117,19 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl FAIL_IF(push_inst(compiler, SMULL | (reg_map[TMP_REG1] << 16) | (reg_map[dst] << 12) | (reg_map[src2] << 8) | reg_map[src1])); /* cmp TMP_REG1, dst asr #31. */ - return push_inst(compiler, EMIT_DATA_PROCESS_INS(CMP_DP, SET_FLAGS, SLJIT_UNUSED, TMP_REG1, RM(dst) | 0xfc0)); + return push_inst(compiler, CMP | SET_FLAGS | RN(TMP_REG1) | RM(dst) | 0xfc0); case SLJIT_AND: - return push_inst(compiler, EMIT_DATA_PROCESS_INS(!(flags & INV_IMM) ? AND_DP : BIC_DP, flags & SET_FLAGS, - dst, src1, (src2 & SRC2_IMM) ? src2 : RM(src2))); + return push_inst(compiler, (!(flags & INV_IMM) ? AND : BIC) | (flags & SET_FLAGS) + | RD(dst) | RN(src1) | ((src2 & SRC2_IMM) ? src2 : RM(src2))); case SLJIT_OR: SLJIT_ASSERT(!(flags & INV_IMM)); - return push_inst(compiler, EMIT_DATA_PROCESS_INS(ORR_DP, flags & SET_FLAGS, dst, src1, (src2 & SRC2_IMM) ? src2 : RM(src2))); + return push_inst(compiler, ORR | (flags & SET_FLAGS) | RD(dst) | RN(src1) | ((src2 & SRC2_IMM) ? src2 : RM(src2))); case SLJIT_XOR: SLJIT_ASSERT(!(flags & INV_IMM)); - return push_inst(compiler, EMIT_DATA_PROCESS_INS(EOR_DP, flags & SET_FLAGS, dst, src1, (src2 & SRC2_IMM) ? src2 : RM(src2))); + return push_inst(compiler, EOR | (flags & SET_FLAGS) | RD(dst) | RN(src1) | ((src2 & SRC2_IMM) ? src2 : RM(src2))); case SLJIT_SHL: EMIT_SHIFT_INS_AND_RETURN(0); @@ -1293,8 +1292,8 @@ static sljit_s32 generate_int(struct sljit_compiler *compiler, sljit_s32 reg, sl return 0; } - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(positive ? MOV_DP : MVN_DP, 0, reg, SLJIT_UNUSED, imm1))); - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(positive ? ORR_DP : BIC_DP, 0, reg, reg, imm2))); + FAIL_IF(push_inst(compiler, (positive ? MOV : MVN) | RD(reg) | imm1)); + FAIL_IF(push_inst(compiler, (positive ? ORR : BIC) | RD(reg) | RN(reg) | imm2)); return 1; } #endif @@ -1311,11 +1310,11 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 reg, /* Create imm by 1 inst. */ tmp = get_imm(imm); if (tmp) - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, reg, SLJIT_UNUSED, tmp)); + return push_inst(compiler, MOV | RD(reg) | tmp); tmp = get_imm(~imm); if (tmp) - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MVN_DP, 0, reg, SLJIT_UNUSED, tmp)); + return push_inst(compiler, MVN | RD(reg) | tmp); #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) /* Create imm by 2 inst. */ @@ -1323,7 +1322,7 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 reg, FAIL_IF(generate_int(compiler, reg, ~imm, 0)); /* Load integer. */ - return push_inst_with_literal(compiler, EMIT_DATA_TRANSFER(WORD_DATA | LOAD_DATA, 1, 0, reg, TMP_PC, 0), imm); + return push_inst_with_literal(compiler, EMIT_DATA_TRANSFER(WORD_SIZE | LOAD_DATA, 1, reg, TMP_PC, 0), imm); #else FAIL_IF(push_inst(compiler, MOVW | RD(reg) | ((imm << 4) & 0xf0000) | (imm & 0xfff))); if (imm <= 0xffff) @@ -1335,16 +1334,13 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 reg, static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw, sljit_s32 tmp_reg) { - sljit_uw offset_reg, imm; + sljit_uw imm, offset_reg; sljit_uw is_type1_transfer = IS_TYPE1_TRANSFER(flags); SLJIT_ASSERT (arg & SLJIT_MEM); SLJIT_ASSERT((arg & REG_MASK) != tmp_reg); - SLJIT_COMPILE_ASSERT(WRITE_BACK == 0x10, optimized_for_emit_data_transfer); - if ((arg & REG_MASK) == SLJIT_UNUSED) { - /* Write back is not used. */ if (is_type1_transfer) { FAIL_IF(load_immediate(compiler, tmp_reg, argw & ~0xfff)); argw &= 0xfff; @@ -1354,7 +1350,8 @@ static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit argw &= 0xff; } - return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, 0, reg, tmp_reg, is_type1_transfer ? argw : TYPE2_TRANSFER_IMM(argw))); + return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, reg, tmp_reg, + is_type1_transfer ? argw : TYPE2_TRANSFER_IMM(argw))); } if (arg & OFFS_REG_MASK) { @@ -1363,14 +1360,12 @@ static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit argw &= 0x3; if (argw != 0 && !is_type1_transfer) { - SLJIT_ASSERT(!(flags & WRITE_BACK)); - - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(ADD_DP, 0, tmp_reg, arg, RM(offset_reg) | (argw << 7)))); - return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, 0, reg, tmp_reg, TYPE2_TRANSFER_IMM(0))); + FAIL_IF(push_inst(compiler, ADD | RD(tmp_reg) | RN(arg) | RM(offset_reg) | (argw << 7))); + return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, reg, tmp_reg, TYPE2_TRANSFER_IMM(0))); } /* Bit 25: RM is offset. */ - return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, flags & WRITE_BACK, reg, arg, + return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, reg, arg, RM(offset_reg) | (is_type1_transfer ? (1 << 25) : 0) | (argw << 7))); } @@ -1380,60 +1375,55 @@ static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit if (argw > 0xfff) { imm = get_imm(argw & ~0xfff); if (imm) { - offset_reg = (flags & WRITE_BACK) ? arg : tmp_reg; - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(ADD_DP, 0, offset_reg, arg, imm))); + FAIL_IF(push_inst(compiler, ADD | RD(tmp_reg) | RN(arg) | imm)); argw = argw & 0xfff; - arg = offset_reg; + arg = tmp_reg; } } else if (argw < -0xfff) { imm = get_imm(-argw & ~0xfff); if (imm) { - offset_reg = (flags & WRITE_BACK) ? arg : tmp_reg; - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(SUB_DP, 0, offset_reg, arg, imm))); + FAIL_IF(push_inst(compiler, SUB | RD(tmp_reg) | RN(arg) | imm)); argw = -(-argw & 0xfff); - arg = offset_reg; + arg = tmp_reg; } } - if (argw >= 0 && argw <= 0xfff) { - return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, flags & WRITE_BACK, reg, arg & REG_MASK, argw)); - } - if (argw < 0 && argw >= -0xfff) { - return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 0, flags & WRITE_BACK, reg, arg & REG_MASK, -argw)); - } + if (argw >= 0 && argw <= 0xfff) + return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, reg, arg, argw)); + + if (argw < 0 && argw >= -0xfff) + return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 0, reg, arg, -argw)); } else { if (argw > 0xff) { imm = get_imm(argw & ~0xff); if (imm) { - offset_reg = (flags & WRITE_BACK) ? arg : tmp_reg; - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(ADD_DP, 0, offset_reg, arg, imm))); + FAIL_IF(push_inst(compiler, ADD | RD(tmp_reg) | RN(arg) | imm)); argw = argw & 0xff; - arg = offset_reg; + arg = tmp_reg; } } else if (argw < -0xff) { imm = get_imm(-argw & ~0xff); if (imm) { - offset_reg = (flags & WRITE_BACK) ? arg : tmp_reg; - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(SUB_DP, 0, offset_reg, arg, imm))); + FAIL_IF(push_inst(compiler, SUB | RD(tmp_reg) | RN(arg) | imm)); argw = -(-argw & 0xff); - arg = offset_reg; + arg = tmp_reg; } } - if (argw >= 0 && argw <= 0xff) { - return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, flags & WRITE_BACK, reg, arg, TYPE2_TRANSFER_IMM(argw))); - } + if (argw >= 0 && argw <= 0xff) + return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, reg, arg, TYPE2_TRANSFER_IMM(argw))); + if (argw < 0 && argw >= -0xff) { argw = -argw; - return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 0, flags & WRITE_BACK, reg, arg, TYPE2_TRANSFER_IMM(argw))); + return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 0, reg, arg, TYPE2_TRANSFER_IMM(argw))); } } FAIL_IF(load_immediate(compiler, tmp_reg, argw)); - return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, flags & WRITE_BACK, reg, arg, + return push_inst(compiler, EMIT_DATA_TRANSFER(flags, 1, reg, arg, RM(tmp_reg) | (is_type1_transfer ? (1 << 25) : 0))); } @@ -1536,10 +1526,10 @@ static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s3 /* Destination. */ dst_reg = SLOW_IS_REG(dst) ? dst : TMP_REG2; - if (op <= SLJIT_MOVU_P) { + if (op <= SLJIT_MOV_P) { if (dst & SLJIT_MEM) { - if (inp_flags & BYTE_DATA) - inp_flags &= ~SIGNED_DATA; + if (inp_flags & BYTE_SIZE) + inp_flags &= ~SIGNED; if (FAST_IS_REG(src2)) return emit_op_mem(compiler, inp_flags, src2, dst, dstw, TMP_REG2); @@ -1551,7 +1541,7 @@ static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s3 /* Source 2. */ if (src2_reg == 0) { - src2_reg = (op <= SLJIT_MOVU_P) ? dst_reg : TMP_REG2; + src2_reg = (op <= SLJIT_MOV_P) ? dst_reg : TMP_REG2; if (FAST_IS_REG(src2)) src2_reg = src2; @@ -1672,7 +1662,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile if (dst == SLJIT_UNUSED && !HAS_FLAGS(op)) { #if (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) if (op <= SLJIT_MOV_P && (src & SLJIT_MEM)) - return emit_op_mem(compiler, PRELOAD_DATA | LOAD_DATA, TMP_PC, src, srcw, TMP_REG1); + return emit_op_mem(compiler, PRELOAD | LOAD_DATA, TMP_PC, src, srcw, TMP_REG1); #endif return SLJIT_SUCCESS; } @@ -1685,34 +1675,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile return emit_op(compiler, SLJIT_MOV, ALLOW_ANY_IMM, dst, dstw, TMP_REG1, 0, src, srcw); case SLJIT_MOV_U8: - return emit_op(compiler, SLJIT_MOV_U8, ALLOW_ANY_IMM | BYTE_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u8)srcw : srcw); + return emit_op(compiler, SLJIT_MOV_U8, ALLOW_ANY_IMM | BYTE_SIZE, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u8)srcw : srcw); case SLJIT_MOV_S8: - return emit_op(compiler, SLJIT_MOV_S8, ALLOW_ANY_IMM | SIGNED_DATA | BYTE_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s8)srcw : srcw); + return emit_op(compiler, SLJIT_MOV_S8, ALLOW_ANY_IMM | SIGNED | BYTE_SIZE, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s8)srcw : srcw); case SLJIT_MOV_U16: - return emit_op(compiler, SLJIT_MOV_U16, ALLOW_ANY_IMM | HALF_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u16)srcw : srcw); + return emit_op(compiler, SLJIT_MOV_U16, ALLOW_ANY_IMM | HALF_SIZE, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u16)srcw : srcw); case SLJIT_MOV_S16: - return emit_op(compiler, SLJIT_MOV_S16, ALLOW_ANY_IMM | SIGNED_DATA | HALF_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s16)srcw : srcw); - - case SLJIT_MOVU: - case SLJIT_MOVU_U32: - case SLJIT_MOVU_S32: - case SLJIT_MOVU_P: - return emit_op(compiler, SLJIT_MOV, ALLOW_ANY_IMM | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw); - - case SLJIT_MOVU_U8: - return emit_op(compiler, SLJIT_MOV_U8, ALLOW_ANY_IMM | BYTE_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u8)srcw : srcw); - - case SLJIT_MOVU_S8: - return emit_op(compiler, SLJIT_MOV_S8, ALLOW_ANY_IMM | SIGNED_DATA | BYTE_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s8)srcw : srcw); - - case SLJIT_MOVU_U16: - return emit_op(compiler, SLJIT_MOV_U16, ALLOW_ANY_IMM | HALF_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u16)srcw : srcw); - - case SLJIT_MOVU_S16: - return emit_op(compiler, SLJIT_MOV_S16, ALLOW_ANY_IMM | SIGNED_DATA | HALF_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s16)srcw : srcw); + return emit_op(compiler, SLJIT_MOV_S16, ALLOW_ANY_IMM | SIGNED | HALF_SIZE, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s16)srcw : srcw); case SLJIT_NOT: return emit_op(compiler, op, ALLOW_ANY_IMM, dst, dstw, TMP_REG1, 0, src, srcw); @@ -1785,7 +1757,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg) SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_float_register_index(sljit_s32 reg) { CHECK_REG_INDEX(check_sljit_get_float_register_index(reg)); - return reg << 1; + return (freg_map[reg] << 1); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler, @@ -1804,9 +1776,9 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *c #define FPU_LOAD (1 << 20) #define EMIT_FPU_DATA_TRANSFER(inst, add, base, freg, offs) \ - ((inst) | ((add) << 23) | (reg_map[base] << 16) | (freg << 12) | (offs)) + ((inst) | ((add) << 23) | (reg_map[base] << 16) | (freg_map[freg] << 12) | (offs)) #define EMIT_FPU_OPERATION(opcode, mode, dst, src1, src2) \ - ((opcode) | (mode) | ((dst) << 12) | (src1) | ((src2) << 16)) + ((opcode) | (mode) | (freg_map[dst] << 12) | freg_map[src1] | (freg_map[src2] << 16)) static sljit_s32 emit_fop_mem(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw) { @@ -1817,7 +1789,7 @@ static sljit_s32 emit_fop_mem(struct sljit_compiler *compiler, sljit_s32 flags, arg &= ~SLJIT_MEM; if (SLJIT_UNLIKELY(arg & OFFS_REG_MASK)) { - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(ADD_DP, 0, TMP_REG2, arg & REG_MASK, RM(OFFS_REG(arg)) | ((argw & 0x3) << 7)))); + FAIL_IF(push_inst(compiler, ADD | RD(TMP_REG2) | RN(arg & REG_MASK) | RM(OFFS_REG(arg)) | ((argw & 0x3) << 7))); arg = TMP_REG2; argw = 0; } @@ -1831,20 +1803,20 @@ static sljit_s32 emit_fop_mem(struct sljit_compiler *compiler, sljit_s32 flags, imm = get_imm(argw & ~0x3fc); if (imm) { - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(ADD_DP, 0, TMP_REG2, arg & REG_MASK, imm))); + FAIL_IF(push_inst(compiler, ADD | RD(TMP_REG2) | RN(arg & REG_MASK) | imm)); return push_inst(compiler, EMIT_FPU_DATA_TRANSFER(inst, 1, TMP_REG2, reg, (argw & 0x3fc) >> 2)); } imm = get_imm(-argw & ~0x3fc); if (imm) { argw = -argw; - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(SUB_DP, 0, TMP_REG2, arg & REG_MASK, imm))); + FAIL_IF(push_inst(compiler, SUB | RD(TMP_REG2) | RN(arg & REG_MASK) | imm)); return push_inst(compiler, EMIT_FPU_DATA_TRANSFER(inst, 0, TMP_REG2, reg, (argw & 0x3fc) >> 2)); } } if (arg) { FAIL_IF(load_immediate(compiler, TMP_REG2, argw)); - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(ADD_DP, 0, TMP_REG2, arg & REG_MASK, RM(TMP_REG2)))); + FAIL_IF(push_inst(compiler, ADD | RD(TMP_REG2) | RN(arg & REG_MASK) | RM(TMP_REG2))); } else FAIL_IF(load_immediate(compiler, TMP_REG2, argw)); @@ -1866,7 +1838,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_comp FAIL_IF(push_inst(compiler, EMIT_FPU_OPERATION(VCVT_S32_F32, op & SLJIT_F32_OP, TMP_FREG1, src, 0))); if (FAST_IS_REG(dst)) - return push_inst(compiler, VMOV | (1 << 20) | RD(dst) | (TMP_FREG1 << 16)); + return push_inst(compiler, VMOV | (1 << 20) | RD(dst) | (freg_map[TMP_FREG1] << 16)); /* Store the integer value from a VFP register. */ return emit_fop_mem(compiler, 0, TMP_FREG1, dst, dstw); @@ -1881,14 +1853,14 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_comp op ^= SLJIT_F32_OP; if (FAST_IS_REG(src)) - FAIL_IF(push_inst(compiler, VMOV | RD(src) | (TMP_FREG1 << 16))); + FAIL_IF(push_inst(compiler, VMOV | RD(src) | (freg_map[TMP_FREG1] << 16))); else if (src & SLJIT_MEM) { /* Load the integer value into a VFP register. */ FAIL_IF(emit_fop_mem(compiler, FPU_LOAD, TMP_FREG1, src, srcw)); } else { FAIL_IF(load_immediate(compiler, TMP_REG1, srcw)); - FAIL_IF(push_inst(compiler, VMOV | RD(TMP_REG1) | (TMP_FREG1 << 16))); + FAIL_IF(push_inst(compiler, VMOV | RD(TMP_REG1) | (freg_map[TMP_FREG1] << 16))); } FAIL_IF(push_inst(compiler, EMIT_FPU_OPERATION(VCVT_F32_S32, op & SLJIT_F32_OP, dst_r, TMP_FREG1, 0))); @@ -2018,7 +1990,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil #undef FPU_LOAD #undef EMIT_FPU_DATA_TRANSFER -#undef EMIT_FPU_OPERATION /* --------------------------------------------------------------------- */ /* Other instructions */ @@ -2030,13 +2001,13 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler * CHECK(check_sljit_emit_fast_enter(compiler, dst, dstw)); ADJUST_LOCAL_OFFSET(dst, dstw); - SLJIT_ASSERT(reg_map[TMP_REG1] == 14); + SLJIT_ASSERT(reg_map[TMP_REG2] == 14); if (FAST_IS_REG(dst)) - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, dst, SLJIT_UNUSED, RM(TMP_REG1))); + return push_inst(compiler, MOV | RD(dst) | RM(TMP_REG2)); /* Memory. */ - return emit_op_mem(compiler, WORD_DATA, TMP_REG1, dst, dstw, TMP_REG2); + return emit_op_mem(compiler, WORD_SIZE, TMP_REG2, dst, dstw, TMP_REG1); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw) @@ -2045,16 +2016,14 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler CHECK(check_sljit_emit_fast_return(compiler, src, srcw)); ADJUST_LOCAL_OFFSET(src, srcw); - SLJIT_ASSERT(reg_map[TMP_REG1] == 14); + SLJIT_ASSERT(reg_map[TMP_REG2] == 14); if (FAST_IS_REG(src)) - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, TMP_REG1, 0, RM(src)))); - else if (src & SLJIT_MEM) - FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_REG1, src, srcw, TMP_REG2)); - else if (src & SLJIT_IMM) - FAIL_IF(load_immediate(compiler, TMP_REG1, srcw)); + FAIL_IF(push_inst(compiler, MOV | RD(TMP_REG2) | RM(src))); + else + FAIL_IF(emit_op_mem(compiler, WORD_SIZE | LOAD_DATA, TMP_REG2, src, srcw, TMP_REG1)); - return push_inst(compiler, BX | RM(TMP_REG1)); + return push_inst(compiler, BX | RM(TMP_REG2)); } /* --------------------------------------------------------------------- */ @@ -2111,7 +2080,7 @@ static sljit_uw get_cc(sljit_s32 type) return 0x70000000; default: - SLJIT_ASSERT(type >= SLJIT_JUMP && type <= SLJIT_CALL3); + SLJIT_ASSERT(type >= SLJIT_JUMP && type <= SLJIT_CALL_CDECL); return 0xe0000000; } } @@ -2144,12 +2113,13 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP); type &= 0xff; - /* In ARM, we don't need to touch the arguments. */ + SLJIT_ASSERT(reg_map[TMP_REG1] != 14); + #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) if (type >= SLJIT_FAST_CALL) PTR_FAIL_IF(prepare_blx(compiler)); - PTR_FAIL_IF(push_inst_with_unique_literal(compiler, ((EMIT_DATA_TRANSFER(WORD_DATA | LOAD_DATA, 1, 0, - type <= SLJIT_JUMP ? TMP_PC : TMP_REG2, TMP_PC, 0)) & ~COND_MASK) | get_cc(type), 0)); + PTR_FAIL_IF(push_inst_with_unique_literal(compiler, ((EMIT_DATA_TRANSFER(WORD_SIZE | LOAD_DATA, 1, + type <= SLJIT_JUMP ? TMP_PC : TMP_REG1, TMP_PC, 0)) & ~COND_MASK) | get_cc(type), 0)); if (jump->flags & SLJIT_REWRITABLE_JUMP) { jump->addr = compiler->size; @@ -2166,13 +2136,248 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile #else if (type >= SLJIT_FAST_CALL) jump->flags |= IS_BL; - PTR_FAIL_IF(emit_imm(compiler, TMP_REG2, 0)); - PTR_FAIL_IF(push_inst(compiler, (((type <= SLJIT_JUMP ? BX : BLX) | RM(TMP_REG2)) & ~COND_MASK) | get_cc(type))); + PTR_FAIL_IF(emit_imm(compiler, TMP_REG1, 0)); + PTR_FAIL_IF(push_inst(compiler, (((type <= SLJIT_JUMP ? BX : BLX) | RM(TMP_REG1)) & ~COND_MASK) | get_cc(type))); jump->addr = compiler->size; #endif return jump; } +#ifdef __SOFTFP__ + +static sljit_s32 softfloat_call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_s32 *src) +{ + sljit_s32 stack_offset = 0; + sljit_s32 arg_count = 0; + sljit_s32 word_arg_offset = 0; + sljit_s32 float_arg_count = 0; + sljit_s32 types = 0; + sljit_s32 src_offset = 4 * sizeof(sljit_sw); + sljit_u8 offsets[4]; + + if (src && FAST_IS_REG(*src)) + src_offset = reg_map[*src] * sizeof(sljit_sw); + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + types = (types << SLJIT_DEF_SHIFT) | (arg_types & SLJIT_DEF_MASK); + + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + offsets[arg_count] = (sljit_u8)stack_offset; + stack_offset += sizeof(sljit_f32); + arg_count++; + float_arg_count++; + break; + case SLJIT_ARG_TYPE_F64: + if (stack_offset & 0x7) + stack_offset += sizeof(sljit_sw); + offsets[arg_count] = (sljit_u8)stack_offset; + stack_offset += sizeof(sljit_f64); + arg_count++; + float_arg_count++; + break; + default: + offsets[arg_count] = (sljit_u8)stack_offset; + stack_offset += sizeof(sljit_sw); + arg_count++; + word_arg_offset += sizeof(sljit_sw); + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + if (stack_offset > 16) + FAIL_IF(push_inst(compiler, SUB | RD(SLJIT_SP) | RN(SLJIT_SP) | SRC2_IMM | (((stack_offset - 16) + 0x7) & ~0x7))); + + /* Process arguments in reversed direction. */ + while (types) { + switch (types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + arg_count--; + float_arg_count--; + stack_offset = offsets[arg_count]; + + if (stack_offset < 16) { + if (src_offset == stack_offset) { + FAIL_IF(push_inst(compiler, MOV | RD(TMP_REG1) | (src_offset >> 2))); + *src = TMP_REG1; + } + FAIL_IF(push_inst(compiler, VMOV | 0x100000 | (float_arg_count << 16) | (stack_offset << 10))); + } else + FAIL_IF(push_inst(compiler, VSTR_F32 | 0x800000 | RN(SLJIT_SP) | (float_arg_count << 12) | ((stack_offset - 16) >> 2))); + break; + case SLJIT_ARG_TYPE_F64: + arg_count--; + float_arg_count--; + stack_offset = offsets[arg_count]; + + SLJIT_ASSERT((stack_offset & 0x7) == 0); + + if (stack_offset < 16) { + if (src_offset == stack_offset || src_offset == stack_offset + sizeof(sljit_sw)) { + FAIL_IF(push_inst(compiler, MOV | RD(TMP_REG1) | (src_offset >> 2))); + *src = TMP_REG1; + } + FAIL_IF(push_inst(compiler, VMOV2 | 0x100000 | (stack_offset << 10) | ((stack_offset + sizeof(sljit_sw)) << 14) | float_arg_count)); + } else + FAIL_IF(push_inst(compiler, VSTR_F32 | 0x800100 | RN(SLJIT_SP) | (float_arg_count << 12) | ((stack_offset - 16) >> 2))); + break; + default: + arg_count--; + word_arg_offset -= sizeof(sljit_sw); + stack_offset = offsets[arg_count]; + + SLJIT_ASSERT(stack_offset >= word_arg_offset); + + if (stack_offset != word_arg_offset) { + if (stack_offset < 16) { + if (src_offset == stack_offset) { + FAIL_IF(push_inst(compiler, MOV | RD(TMP_REG1) | (src_offset >> 2))); + *src = TMP_REG1; + } + else if (src_offset == word_arg_offset) { + *src = 1 + (stack_offset >> 2); + src_offset = stack_offset; + } + FAIL_IF(push_inst(compiler, MOV | (stack_offset << 10) | (word_arg_offset >> 2))); + } else + FAIL_IF(push_inst(compiler, data_transfer_insts[WORD_SIZE] | 0x800000 | RN(SLJIT_SP) | (word_arg_offset << 10) | (stack_offset - 16))); + } + break; + } + + types >>= SLJIT_DEF_SHIFT; + } + + return SLJIT_SUCCESS; +} + +static sljit_s32 softfloat_post_call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types) +{ + sljit_s32 stack_size = 0; + + if ((arg_types & SLJIT_DEF_MASK) == SLJIT_ARG_TYPE_F32) + FAIL_IF(push_inst(compiler, VMOV | (0 << 16) | (0 << 12))); + if ((arg_types & SLJIT_DEF_MASK) == SLJIT_ARG_TYPE_F64) + FAIL_IF(push_inst(compiler, VMOV2 | (1 << 16) | (0 << 12) | 0)); + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + stack_size += sizeof(sljit_f32); + break; + case SLJIT_ARG_TYPE_F64: + if (stack_size & 0x7) + stack_size += sizeof(sljit_sw); + stack_size += sizeof(sljit_f64); + break; + default: + stack_size += sizeof(sljit_sw); + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + if (stack_size <= 16) + return SLJIT_SUCCESS; + + return push_inst(compiler, ADD | RD(SLJIT_SP) | RN(SLJIT_SP) | SRC2_IMM | (((stack_size - 16) + 0x7) & ~0x7)); +} + +#else /* !__SOFTFP__ */ + +static sljit_s32 hardfloat_call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types) +{ + sljit_u32 remap = 0; + sljit_u32 offset = 0; + sljit_u32 new_offset, mask; + + /* Remove return value. */ + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + if ((arg_types & SLJIT_DEF_MASK) == SLJIT_ARG_TYPE_F32) { + new_offset = 0; + mask = 1; + + while (remap & mask) { + new_offset++; + mask <<= 1; + } + remap |= mask; + + if (offset != new_offset) + FAIL_IF(push_inst(compiler, EMIT_FPU_OPERATION(VMOV_F32, + 0, (new_offset >> 1) + 1, (offset >> 1) + 1, 0) | ((new_offset & 0x1) ? 0x400000 : 0))); + + offset += 2; + } + else if ((arg_types & SLJIT_DEF_MASK) == SLJIT_ARG_TYPE_F64) { + new_offset = 0; + mask = 3; + + while (remap & mask) { + new_offset += 2; + mask <<= 2; + } + remap |= mask; + + if (offset != new_offset) + FAIL_IF(push_inst(compiler, EMIT_FPU_OPERATION(VMOV_F32, SLJIT_F32_OP, (new_offset >> 1) + 1, (offset >> 1) + 1, 0))); + + offset += 2; + } + arg_types >>= SLJIT_DEF_SHIFT; + } + + return SLJIT_SUCCESS; +} + +#endif /* __SOFTFP__ */ + +#undef EMIT_FPU_OPERATION + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ +#ifdef __SOFTFP__ + struct sljit_jump *jump; +#endif + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_call(compiler, type, arg_types)); + +#ifdef __SOFTFP__ + PTR_FAIL_IF(softfloat_call_with_args(compiler, arg_types, NULL)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + jump = sljit_emit_jump(compiler, type); + PTR_FAIL_IF(jump == NULL); + + PTR_FAIL_IF(softfloat_post_call_with_args(compiler, arg_types)); + return jump; +#else /* !__SOFTFP__ */ + PTR_FAIL_IF(hardfloat_call_with_args(compiler, arg_types)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_jump(compiler, type); +#endif /* __SOFTFP__ */ +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) { struct sljit_jump *jump; @@ -2181,16 +2386,20 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi CHECK(check_sljit_emit_ijump(compiler, type, src, srcw)); ADJUST_LOCAL_OFFSET(src, srcw); - /* In ARM, we don't need to touch the arguments. */ + SLJIT_ASSERT(reg_map[TMP_REG1] != 14); + if (!(src & SLJIT_IMM)) { - if (FAST_IS_REG(src)) + if (FAST_IS_REG(src)) { + SLJIT_ASSERT(reg_map[src] != 14); return push_inst(compiler, (type <= SLJIT_JUMP ? BX : BLX) | RM(src)); + } SLJIT_ASSERT(src & SLJIT_MEM); - FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_REG2, src, srcw, TMP_REG2)); - return push_inst(compiler, (type <= SLJIT_JUMP ? BX : BLX) | RM(TMP_REG2)); + FAIL_IF(emit_op_mem(compiler, WORD_SIZE | LOAD_DATA, TMP_REG1, src, srcw, TMP_REG1)); + return push_inst(compiler, (type <= SLJIT_JUMP ? BX : BLX) | RM(TMP_REG1)); } + /* These jumps are converted to jump/call instructions when possible. */ jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); FAIL_IF(!jump); set_jump(jump, compiler, JUMP_ADDR | ((type >= SLJIT_FAST_CALL) ? IS_BL : 0)); @@ -2199,22 +2408,57 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) if (type >= SLJIT_FAST_CALL) FAIL_IF(prepare_blx(compiler)); - FAIL_IF(push_inst_with_unique_literal(compiler, EMIT_DATA_TRANSFER(WORD_DATA | LOAD_DATA, 1, 0, type <= SLJIT_JUMP ? TMP_PC : TMP_REG2, TMP_PC, 0), 0)); + FAIL_IF(push_inst_with_unique_literal(compiler, EMIT_DATA_TRANSFER(WORD_SIZE | LOAD_DATA, 1, type <= SLJIT_JUMP ? TMP_PC : TMP_REG1, TMP_PC, 0), 0)); if (type >= SLJIT_FAST_CALL) FAIL_IF(emit_blx(compiler)); #else - FAIL_IF(emit_imm(compiler, TMP_REG2, 0)); - FAIL_IF(push_inst(compiler, (type <= SLJIT_JUMP ? BX : BLX) | RM(TMP_REG2))); + FAIL_IF(emit_imm(compiler, TMP_REG1, 0)); + FAIL_IF(push_inst(compiler, (type <= SLJIT_JUMP ? BX : BLX) | RM(TMP_REG1))); #endif jump->addr = compiler->size; return SLJIT_SUCCESS; } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ + CHECK_ERROR(); + CHECK(check_sljit_emit_icall(compiler, type, arg_types, src, srcw)); + +#ifdef __SOFTFP__ + if (src & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, WORD_SIZE | LOAD_DATA, TMP_REG1, src, srcw, TMP_REG1)); + src = TMP_REG1; + } + + FAIL_IF(softfloat_call_with_args(compiler, arg_types, &src)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + FAIL_IF(sljit_emit_ijump(compiler, type, src, srcw)); + + return softfloat_post_call_with_args(compiler, arg_types); +#else /* !__SOFTFP__ */ + FAIL_IF(hardfloat_call_with_args(compiler, arg_types)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_ijump(compiler, type, src, srcw); +#endif /* __SOFTFP__ */ +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 dst, sljit_sw dstw, sljit_s32 type) { - sljit_s32 dst_r, flags = GET_ALL_FLAGS(op); + sljit_s32 dst_reg, flags = GET_ALL_FLAGS(op); sljit_uw cc, ins; CHECK_ERROR(); @@ -2223,31 +2467,31 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co op = GET_OPCODE(op); cc = get_cc(type & 0xff); - dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1; + dst_reg = FAST_IS_REG(dst) ? dst : TMP_REG1; if (op < SLJIT_ADD) { - FAIL_IF(push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, 0, dst_r, SLJIT_UNUSED, SRC2_IMM | 0))); - FAIL_IF(push_inst(compiler, (EMIT_DATA_PROCESS_INS(MOV_DP, 0, dst_r, SLJIT_UNUSED, SRC2_IMM | 1) & ~COND_MASK) | cc)); + FAIL_IF(push_inst(compiler, MOV | RD(dst_reg) | SRC2_IMM | 0)); + FAIL_IF(push_inst(compiler, ((MOV | RD(dst_reg) | SRC2_IMM | 1) & ~COND_MASK) | cc)); if (dst & SLJIT_MEM) - return emit_op_mem(compiler, WORD_DATA, TMP_REG1, dst, dstw, TMP_REG2); + return emit_op_mem(compiler, WORD_SIZE, TMP_REG1, dst, dstw, TMP_REG2); return SLJIT_SUCCESS; } - ins = (op == SLJIT_AND ? AND_DP : (op == SLJIT_OR ? ORR_DP : EOR_DP)); + ins = (op == SLJIT_AND ? AND : (op == SLJIT_OR ? ORR : EOR)); if (dst & SLJIT_MEM) - FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_REG1, dst, dstw, TMP_REG2)); + FAIL_IF(emit_op_mem(compiler, WORD_SIZE | LOAD_DATA, TMP_REG1, dst, dstw, TMP_REG2)); - FAIL_IF(push_inst(compiler, (EMIT_DATA_PROCESS_INS(ins, 0, dst_r, dst_r, SRC2_IMM | 1) & ~COND_MASK) | cc)); + FAIL_IF(push_inst(compiler, ((ins | RD(dst_reg) | RN(dst_reg) | SRC2_IMM | 1) & ~COND_MASK) | cc)); if (op == SLJIT_AND) - FAIL_IF(push_inst(compiler, (EMIT_DATA_PROCESS_INS(ins, 0, dst_r, dst_r, SRC2_IMM | 0) & ~COND_MASK) | (cc ^ 0x10000000))); + FAIL_IF(push_inst(compiler, ((ins | RD(dst_reg) | RN(dst_reg) | SRC2_IMM | 0) & ~COND_MASK) | (cc ^ 0x10000000))); if (dst & SLJIT_MEM) - FAIL_IF(emit_op_mem(compiler, WORD_DATA, TMP_REG1, dst, dstw, TMP_REG2)); + FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG1, dst, dstw, TMP_REG2)); if (flags & SLJIT_SET_Z) - return push_inst(compiler, EMIT_DATA_PROCESS_INS(MOV_DP, SET_FLAGS, TMP_REG2, SLJIT_UNUSED, RM(dst_r))); + return push_inst(compiler, MOV | SET_FLAGS | RD(TMP_REG2) | RM(dst_reg)); return SLJIT_SUCCESS; } @@ -2267,11 +2511,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compil if (SLJIT_UNLIKELY(src & SLJIT_IMM)) { tmp = get_imm(srcw); if (tmp) - return push_inst(compiler, (EMIT_DATA_PROCESS_INS(MOV_DP, 0, dst_reg, SLJIT_UNUSED, tmp) & ~COND_MASK) | cc); + return push_inst(compiler, ((MOV | RD(dst_reg) | tmp) & ~COND_MASK) | cc); tmp = get_imm(~srcw); if (tmp) - return push_inst(compiler, (EMIT_DATA_PROCESS_INS(MVN_DP, 0, dst_reg, SLJIT_UNUSED, tmp) & ~COND_MASK) | cc); + return push_inst(compiler, ((MVN | RD(dst_reg) | tmp) & ~COND_MASK) | cc); #if (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) tmp = (sljit_uw) srcw; @@ -2285,7 +2529,111 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compil #endif } - return push_inst(compiler, (EMIT_DATA_PROCESS_INS(MOV_DP, 0, dst_reg, SLJIT_UNUSED, RM(src)) & ~COND_MASK) | cc); + return push_inst(compiler, ((MOV | RD(dst_reg) | RM(src)) & ~COND_MASK) | cc); +} + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 reg, + sljit_s32 mem, sljit_sw memw) +{ + sljit_s32 flags; + sljit_uw is_type1_transfer, inst; + + CHECK_ERROR(); + CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw)); + + is_type1_transfer = 1; + + switch (type & 0xff) { + case SLJIT_MOV: + case SLJIT_MOV_U32: + case SLJIT_MOV_S32: + case SLJIT_MOV_P: + flags = WORD_SIZE; + break; + case SLJIT_MOV_U8: + flags = BYTE_SIZE; + break; + case SLJIT_MOV_S8: + if (!(type & SLJIT_MEM_STORE)) + is_type1_transfer = 0; + flags = BYTE_SIZE | SIGNED; + break; + case SLJIT_MOV_U16: + is_type1_transfer = 0; + flags = HALF_SIZE; + break; + case SLJIT_MOV_S16: + is_type1_transfer = 0; + flags = HALF_SIZE | SIGNED; + break; + default: + SLJIT_UNREACHABLE(); + flags = WORD_SIZE; + break; + } + + if (!(type & SLJIT_MEM_STORE)) + flags |= LOAD_DATA; + + SLJIT_ASSERT(is_type1_transfer == !!IS_TYPE1_TRANSFER(flags)); + + if (SLJIT_UNLIKELY(mem & OFFS_REG_MASK)) { + if (!is_type1_transfer && memw != 0) + return SLJIT_ERR_UNSUPPORTED; + } + else { + if (is_type1_transfer) { + if (memw > 4095 && memw < -4095) + return SLJIT_ERR_UNSUPPORTED; + } + else { + if (memw > 255 && memw < -255) + return SLJIT_ERR_UNSUPPORTED; + } + } + + if (type & SLJIT_MEM_SUPP) + return SLJIT_SUCCESS; + + if (SLJIT_UNLIKELY(mem & OFFS_REG_MASK)) { + memw &= 0x3; + + inst = EMIT_DATA_TRANSFER(flags, 1, reg, mem & REG_MASK, RM(OFFS_REG(mem)) | (memw << 7)); + + if (is_type1_transfer) + inst |= (1 << 25); + + if (type & SLJIT_MEM_PRE) + inst |= (1 << 21); + else + inst ^= (1 << 24); + + return push_inst(compiler, inst); + } + + inst = EMIT_DATA_TRANSFER(flags, 0, reg, mem & REG_MASK, 0); + + if (type & SLJIT_MEM_PRE) + inst |= (1 << 21); + else + inst ^= (1 << 24); + + if (is_type1_transfer) { + if (memw >= 0) + inst |= (1 << 23); + else + memw = -memw; + + return push_inst(compiler, inst | memw); + } + + if (memw >= 0) + inst |= (1 << 23); + else + memw = -memw; + + return push_inst(compiler, inst | TYPE2_TRANSFER_IMM(memw)); } SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) @@ -2303,7 +2651,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi reg = SLOW_IS_REG(dst) ? dst : TMP_REG2; #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) - PTR_FAIL_IF(push_inst_with_unique_literal(compiler, EMIT_DATA_TRANSFER(WORD_DATA | LOAD_DATA, 1, 0, reg, TMP_PC, 0), init_value)); + PTR_FAIL_IF(push_inst_with_unique_literal(compiler, EMIT_DATA_TRANSFER(WORD_SIZE | LOAD_DATA, 1, reg, TMP_PC, 0), init_value)); compiler->patches++; #else PTR_FAIL_IF(emit_imm(compiler, reg, init_value)); @@ -2311,7 +2659,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, TMP_REG2, dst, dstw, TMP_REG1)); + PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG2, dst, dstw, TMP_REG1)); return const_; } diff --git a/pcre/sljit/sljitNativeARM_64.c b/pcre/sljit/sljitNativeARM_64.c index fd67f502536..27af7414877 100644 --- a/pcre/sljit/sljitNativeARM_64.c +++ b/pcre/sljit/sljitNativeARM_64.c @@ -36,15 +36,19 @@ typedef sljit_u32 sljit_ins; #define TMP_REG1 (SLJIT_NUMBER_OF_REGISTERS + 2) #define TMP_REG2 (SLJIT_NUMBER_OF_REGISTERS + 3) -#define TMP_REG3 (SLJIT_NUMBER_OF_REGISTERS + 4) -#define TMP_LR (SLJIT_NUMBER_OF_REGISTERS + 5) -#define TMP_SP (SLJIT_NUMBER_OF_REGISTERS + 6) +#define TMP_LR (SLJIT_NUMBER_OF_REGISTERS + 4) +#define TMP_FP (SLJIT_NUMBER_OF_REGISTERS + 5) -#define TMP_FREG1 (0) -#define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) +#define TMP_FREG1 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) +#define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2) +/* r18 - platform register, currently not used */ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 8] = { - 31, 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 17, 8, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 29, 9, 10, 11, 30, 31 + 31, 0, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 15, 16, 17, 8, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 31, 9, 10, 30, 29 +}; + +static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = { + 0, 0, 1, 2, 3, 4, 5, 6, 7 }; #define W_OP (1 << 31) @@ -53,10 +57,10 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 8] = { #define RN(rn) (reg_map[rn] << 5) #define RT2(rt2) (reg_map[rt2] << 10) #define RM(rm) (reg_map[rm] << 16) -#define VD(vd) (vd) -#define VT(vt) (vt) -#define VN(vn) ((vn) << 5) -#define VM(vm) ((vm) << 16) +#define VD(vd) (freg_map[vd]) +#define VT(vt) (freg_map[vt]) +#define VN(vn) (freg_map[vn] << 5) +#define VM(vm) (freg_map[vm] << 16) /* --------------------------------------------------------------------- */ /* Instrucion forms */ @@ -64,6 +68,7 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 8] = { #define ADC 0x9a000000 #define ADD 0x8b000000 +#define ADDE 0x8b200000 #define ADDI 0x91000000 #define AND 0x8a000000 #define ANDI 0x92000000 @@ -92,7 +97,8 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 8] = { #define FSUB 0x1e603800 #define LDRI 0xf9400000 #define LDP 0xa9400000 -#define LDP_PST 0xa8c00000 +#define LDP_PRE 0xa9c00000 +#define LDR_PRE 0xf8400c00 #define LSLV 0x9ac02000 #define LSRV 0x9ac02400 #define MADD 0x9b000000 @@ -112,10 +118,13 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 8] = { #define SMULH 0x9b403c00 #define STP 0xa9000000 #define STP_PRE 0xa9800000 +#define STRB 0x38206800 +#define STRBI 0x39000000 #define STRI 0xf9000000 #define STR_FI 0x3d000000 #define STR_FR 0x3c206800 #define STUR_FI 0x3c000000 +#define STURBI 0x38000000 #define SUB 0xcb000000 #define SUBI 0xd1000000 #define SUBS 0xeb000000 @@ -193,6 +202,7 @@ static SLJIT_INLINE sljit_s32 detect_jump_type(struct sljit_jump *jump, sljit_in code_ptr[-2] = code_ptr[0]; return 2; } + if (target_addr <= 0xffffffffffffl) { if (jump->flags & IS_COND) code_ptr[-5] -= (1 << 5); @@ -335,7 +345,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) return 1; #endif - case SLJIT_HAS_PRE_UPDATE: case SLJIT_HAS_CLZ: case SLJIT_HAS_CMOV: return 1; @@ -394,12 +403,14 @@ static sljit_ins logical_imm(sljit_sw imm, sljit_s32 len) SLJIT_ASSERT((len == 32 && imm != 0 && imm != -1) || (len == 16 && (sljit_s32)imm != 0 && (sljit_s32)imm != -1)); + uimm = (sljit_uw)imm; while (1) { if (len <= 0) { SLJIT_UNREACHABLE(); return 0; } + mask = ((sljit_uw)1 << len) - 1; if ((uimm & mask) != ((uimm >> len) & mask)) break; @@ -448,39 +459,42 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst, sljit_s32 i, zeros, ones, first; sljit_ins bitmask; + /* Handling simple immediates first. */ if (imm <= 0xffff) return push_inst(compiler, MOVZ | RD(dst) | (imm << 5)); - if (simm >= -0x10000 && simm < 0) + if (simm < 0 && simm >= -0x10000) return push_inst(compiler, MOVN | RD(dst) | ((~imm & 0xffff) << 5)); if (imm <= 0xffffffffl) { + if ((imm & 0xffff) == 0) + return push_inst(compiler, MOVZ | RD(dst) | ((imm >> 16) << 5) | (1 << 21)); if ((imm & 0xffff0000l) == 0xffff0000) return push_inst(compiler, (MOVN ^ W_OP) | RD(dst) | ((~imm & 0xffff) << 5)); if ((imm & 0xffff) == 0xffff) return push_inst(compiler, (MOVN ^ W_OP) | RD(dst) | ((~imm & 0xffff0000l) >> (16 - 5)) | (1 << 21)); + bitmask = logical_imm(simm, 16); if (bitmask != 0) return push_inst(compiler, (ORRI ^ W_OP) | RD(dst) | RN(TMP_ZERO) | bitmask); - } - else { - bitmask = logical_imm(simm, 32); - if (bitmask != 0) - return push_inst(compiler, ORRI | RD(dst) | RN(TMP_ZERO) | bitmask); - } - if (imm <= 0xffffffffl) { FAIL_IF(push_inst(compiler, MOVZ | RD(dst) | ((imm & 0xffff) << 5))); return push_inst(compiler, MOVK | RD(dst) | ((imm & 0xffff0000l) >> (16 - 5)) | (1 << 21)); } - if (simm >= -0x100000000l && simm < 0) { + bitmask = logical_imm(simm, 32); + if (bitmask != 0) + return push_inst(compiler, ORRI | RD(dst) | RN(TMP_ZERO) | bitmask); + + if (simm < 0 && simm >= -0x100000000l) { + if ((imm & 0xffff) == 0xffff) + return push_inst(compiler, MOVN | RD(dst) | ((~imm & 0xffff0000l) >> (16 - 5)) | (1 << 21)); + FAIL_IF(push_inst(compiler, MOVN | RD(dst) | ((~imm & 0xffff) << 5))); return push_inst(compiler, MOVK | RD(dst) | ((imm & 0xffff0000l) >> (16 - 5)) | (1 << 21)); } - /* A large amount of number can be constructed from ORR and MOVx, - but computing them is costly. We don't */ + /* A large amount of number can be constructed from ORR and MOVx, but computing them is costly. */ zeros = 0; ones = 0; @@ -533,9 +547,6 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst, #define INT_OP 0x0040000 #define SET_FLAGS 0x0080000 #define UNUSED_RETURN 0x0100000 -#define SLOW_DEST 0x0200000 -#define SLOW_SRC1 0x0400000 -#define SLOW_SRC2 0x0800000 #define CHECK_FLAGS(flag_bits) \ if (flags & SET_FLAGS) { \ @@ -693,40 +704,32 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s switch (op) { case SLJIT_MOV: case SLJIT_MOV_P: - case SLJIT_MOVU: - case SLJIT_MOVU_P: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1); if (dst == arg2) return SLJIT_SUCCESS; return push_inst(compiler, ORR | RD(dst) | RN(TMP_ZERO) | RM(arg2)); case SLJIT_MOV_U8: - case SLJIT_MOVU_U8: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1); return push_inst(compiler, (UBFM ^ (1 << 31)) | RD(dst) | RN(arg2) | (7 << 10)); case SLJIT_MOV_S8: - case SLJIT_MOVU_S8: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1); if (!(flags & INT_OP)) inv_bits |= 1 << 22; return push_inst(compiler, (SBFM ^ inv_bits) | RD(dst) | RN(arg2) | (7 << 10)); case SLJIT_MOV_U16: - case SLJIT_MOVU_U16: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1); return push_inst(compiler, (UBFM ^ (1 << 31)) | RD(dst) | RN(arg2) | (15 << 10)); case SLJIT_MOV_S16: - case SLJIT_MOVU_S16: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1); if (!(flags & INT_OP)) inv_bits |= 1 << 22; return push_inst(compiler, (SBFM ^ inv_bits) | RD(dst) | RN(arg2) | (15 << 10)); case SLJIT_MOV_U32: - case SLJIT_MOVU_U32: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1); if ((flags & INT_OP) && dst == arg2) return SLJIT_SUCCESS; return push_inst(compiler, (ORR ^ (1 << 31)) | RD(dst) | RN(TMP_ZERO) | RM(arg2)); case SLJIT_MOV_S32: - case SLJIT_MOVU_S32: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1); if ((flags & INT_OP) && dst == arg2) return SLJIT_SUCCESS; @@ -795,292 +798,67 @@ set_flags: return SLJIT_SUCCESS; } -#define STORE 0x01 -#define SIGNED 0x02 - -#define UPDATE 0x04 -#define ARG_TEST 0x08 +#define STORE 0x10 +#define SIGNED 0x20 -#define BYTE_SIZE 0x000 -#define HALF_SIZE 0x100 -#define INT_SIZE 0x200 -#define WORD_SIZE 0x300 +#define BYTE_SIZE 0x0 +#define HALF_SIZE 0x1 +#define INT_SIZE 0x2 +#define WORD_SIZE 0x3 -#define MEM_SIZE_SHIFT(flags) ((flags) >> 8) - -static const sljit_ins sljit_mem_imm[4] = { -/* u l */ 0x39400000 /* ldrb [reg,imm] */, -/* u s */ 0x39000000 /* strb [reg,imm] */, -/* s l */ 0x39800000 /* ldrsb [reg,imm] */, -/* s s */ 0x39000000 /* strb [reg,imm] */, -}; - -static const sljit_ins sljit_mem_simm[4] = { -/* u l */ 0x38400000 /* ldurb [reg,imm] */, -/* u s */ 0x38000000 /* sturb [reg,imm] */, -/* s l */ 0x38800000 /* ldursb [reg,imm] */, -/* s s */ 0x38000000 /* sturb [reg,imm] */, -}; +#define MEM_SIZE_SHIFT(flags) ((flags) & 0x3) -static const sljit_ins sljit_mem_pre_simm[4] = { -/* u l */ 0x38400c00 /* ldrb [reg,imm]! */, -/* u s */ 0x38000c00 /* strb [reg,imm]! */, -/* s l */ 0x38800c00 /* ldrsb [reg,imm]! */, -/* s s */ 0x38000c00 /* strb [reg,imm]! */, -}; - -static const sljit_ins sljit_mem_reg[4] = { -/* u l */ 0x38606800 /* ldrb [reg,reg] */, -/* u s */ 0x38206800 /* strb [reg,reg] */, -/* s l */ 0x38a06800 /* ldrsb [reg,reg] */, -/* s s */ 0x38206800 /* strb [reg,reg] */, -}; - -/* Helper function. Dst should be reg + value, using at most 1 instruction, flags does not set. */ -static sljit_s32 emit_set_delta(struct sljit_compiler *compiler, sljit_s32 dst, sljit_s32 reg, sljit_sw value) -{ - if (value >= 0) { - if (value <= 0xfff) - return push_inst(compiler, ADDI | RD(dst) | RN(reg) | (value << 10)); - if (value <= 0xffffff && !(value & 0xfff)) - return push_inst(compiler, ADDI | (1 << 22) | RD(dst) | RN(reg) | (value >> 2)); - } - else { - value = -value; - if (value <= 0xfff) - return push_inst(compiler, SUBI | RD(dst) | RN(reg) | (value << 10)); - if (value <= 0xffffff && !(value & 0xfff)) - return push_inst(compiler, SUBI | (1 << 22) | RD(dst) | RN(reg) | (value >> 2)); - } - return SLJIT_ERR_UNSUPPORTED; -} - -/* Can perform an operation using at most 1 instruction. */ -static sljit_s32 getput_arg_fast(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw) +static sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, + sljit_s32 arg, sljit_sw argw, sljit_s32 tmp_reg) { sljit_u32 shift = MEM_SIZE_SHIFT(flags); + sljit_u32 type = (shift << 30); - SLJIT_ASSERT(arg & SLJIT_MEM); - - if (SLJIT_UNLIKELY(flags & UPDATE)) { - if ((arg & REG_MASK) && !(arg & OFFS_REG_MASK) && argw <= 255 && argw >= -256) { - if (SLJIT_UNLIKELY(flags & ARG_TEST)) - return 1; + if (!(flags & STORE)) + type |= (flags & SIGNED) ? 0x00800000 : 0x00400000; - arg &= REG_MASK; - argw &= 0x1ff; - FAIL_IF(push_inst(compiler, sljit_mem_pre_simm[flags & 0x3] - | (shift << 30) | RT(reg) | RN(arg) | (argw << 12))); - return -1; - } - return 0; - } + SLJIT_ASSERT(arg & SLJIT_MEM); if (SLJIT_UNLIKELY(arg & OFFS_REG_MASK)) { argw &= 0x3; - if (argw && argw != shift) - return 0; - if (SLJIT_UNLIKELY(flags & ARG_TEST)) - return 1; + if (argw == 0 || argw == shift) + return push_inst(compiler, STRB | type | RT(reg) + | RN(arg & REG_MASK) | RM(OFFS_REG(arg)) | (argw ? (1 << 12) : 0)); - FAIL_IF(push_inst(compiler, sljit_mem_reg[flags & 0x3] | (shift << 30) | RT(reg) - | RN(arg & REG_MASK) | RM(OFFS_REG(arg)) | (argw ? (1 << 12) : 0))); - return -1; + FAIL_IF(push_inst(compiler, ADD | RD(tmp_reg) | RN(arg & REG_MASK) | RM(OFFS_REG(arg)) | (argw << 10))); + return push_inst(compiler, STRBI | type | RT(reg) | RN(tmp_reg)); } arg &= REG_MASK; - if (arg == SLJIT_UNUSED) - return 0; - - if (argw >= 0 && (argw >> shift) <= 0xfff && (argw & ((1 << shift) - 1)) == 0) { - if (SLJIT_UNLIKELY(flags & ARG_TEST)) - return 1; - - FAIL_IF(push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) - | RT(reg) | RN(arg) | (argw << (10 - shift)))); - return -1; - } - - if (argw > 255 || argw < -256) - return 0; - - if (SLJIT_UNLIKELY(flags & ARG_TEST)) - return 1; - - FAIL_IF(push_inst(compiler, sljit_mem_simm[flags & 0x3] | (shift << 30) - | RT(reg) | RN(arg) | ((argw & 0x1ff) << 12))); - return -1; -} - -/* see getput_arg below. - Note: can_cache is called only for binary operators. Those - operators always uses word arguments without write back. */ -static sljit_s32 can_cache(sljit_s32 arg, sljit_sw argw, sljit_s32 next_arg, sljit_sw next_argw) -{ - sljit_sw diff; - if ((arg & OFFS_REG_MASK) || !(next_arg & SLJIT_MEM)) - return 0; - - if (!(arg & REG_MASK)) { - diff = argw - next_argw; - if (diff <= 0xfff && diff >= -0xfff) - return 1; - return 0; - } - - if (argw == next_argw) - return 1; - - diff = argw - next_argw; - if (arg == next_arg && diff <= 0xfff && diff >= -0xfff) - return 1; - - return 0; -} - -/* Emit the necessary instructions. See can_cache above. */ -static sljit_s32 getput_arg(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, - sljit_s32 arg, sljit_sw argw, sljit_s32 next_arg, sljit_sw next_argw) -{ - sljit_u32 shift = MEM_SIZE_SHIFT(flags); - sljit_s32 tmp_r, other_r; - sljit_sw diff; - - SLJIT_ASSERT(arg & SLJIT_MEM); - if (!(next_arg & SLJIT_MEM)) { - next_arg = 0; - next_argw = 0; - } - - tmp_r = ((flags & STORE) || (flags == (WORD_SIZE | SIGNED))) ? TMP_REG3 : reg; - - if (SLJIT_UNLIKELY((flags & UPDATE) && (arg & REG_MASK))) { - /* Update only applies if a base register exists. */ - other_r = OFFS_REG(arg); - if (!other_r) { - other_r = arg & REG_MASK; - SLJIT_ASSERT(other_r != reg); - - if (argw >= 0 && argw <= 0xffffff) { - if ((argw & 0xfff) != 0) - FAIL_IF(push_inst(compiler, ADDI | RD(other_r) | RN(other_r) | ((argw & 0xfff) << 10))); - if (argw >> 12) - FAIL_IF(push_inst(compiler, ADDI | (1 << 22) | RD(other_r) | RN(other_r) | ((argw >> 12) << 10))); - return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(other_r)); - } - else if (argw < 0 && argw >= -0xffffff) { - argw = -argw; - if ((argw & 0xfff) != 0) - FAIL_IF(push_inst(compiler, SUBI | RD(other_r) | RN(other_r) | ((argw & 0xfff) << 10))); - if (argw >> 12) - FAIL_IF(push_inst(compiler, SUBI | (1 << 22) | RD(other_r) | RN(other_r) | ((argw >> 12) << 10))); - return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(other_r)); - } - - if (compiler->cache_arg == SLJIT_MEM) { - if (argw == compiler->cache_argw) { - other_r = TMP_REG3; - argw = 0; - } - else if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, argw - compiler->cache_argw) != SLJIT_ERR_UNSUPPORTED) { - FAIL_IF(compiler->error); - compiler->cache_argw = argw; - other_r = TMP_REG3; - argw = 0; - } - } - - if (argw) { - FAIL_IF(load_immediate(compiler, TMP_REG3, argw)); - compiler->cache_arg = SLJIT_MEM; - compiler->cache_argw = argw; - other_r = TMP_REG3; - argw = 0; - } - } - - /* No caching here. */ - arg &= REG_MASK; - FAIL_IF(push_inst(compiler, sljit_mem_reg[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg) | RM(other_r))); - return push_inst(compiler, ADD | RD(arg) | RN(arg) | RM(other_r)); - } - - if (arg & OFFS_REG_MASK) { - other_r = OFFS_REG(arg); - arg &= REG_MASK; - FAIL_IF(push_inst(compiler, ADD | RD(tmp_r) | RN(arg) | RM(other_r) | ((argw & 0x3) << 10))); - return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(tmp_r)); - } - - if (compiler->cache_arg == arg) { - diff = argw - compiler->cache_argw; - if (diff <= 255 && diff >= -256) - return push_inst(compiler, sljit_mem_simm[flags & 0x3] | (shift << 30) - | RT(reg) | RN(TMP_REG3) | ((diff & 0x1ff) << 12)); - if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, diff) != SLJIT_ERR_UNSUPPORTED) { - FAIL_IF(compiler->error); - return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg)); - } - } + if (arg == SLJIT_UNUSED) { + FAIL_IF(load_immediate(compiler, tmp_reg, argw & ~(0xfff << shift))); - diff = argw - next_argw; - next_arg = (arg & REG_MASK) && (arg == next_arg) && diff <= 0xfff && diff >= -0xfff && diff != 0; - arg &= REG_MASK; + argw = (argw >> shift) & 0xfff; - if (arg != SLJIT_UNUSED && argw >= 0 && argw <= 0xffffff && (argw & ((1 << shift) - 1)) == 0) { - FAIL_IF(push_inst(compiler, ADDI | (1 << 22) | RD(tmp_r) | RN(arg) | ((argw >> 12) << 10))); - return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) - | RT(reg) | RN(tmp_r) | ((argw & 0xfff) << (10 - shift))); + return push_inst(compiler, STRBI | type | RT(reg) | RN(tmp_reg) | (argw << 10)); } - if (arg && compiler->cache_arg == SLJIT_MEM) { - if (compiler->cache_argw == argw) - return push_inst(compiler, sljit_mem_reg[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg) | RM(TMP_REG3)); - if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, argw - compiler->cache_argw) != SLJIT_ERR_UNSUPPORTED) { - FAIL_IF(compiler->error); - compiler->cache_argw = argw; - return push_inst(compiler, sljit_mem_reg[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg) | RM(TMP_REG3)); + if (argw >= 0 && (argw & ((1 << shift) - 1)) == 0) { + if ((argw >> shift) <= 0xfff) { + return push_inst(compiler, STRBI | type | RT(reg) | RN(arg) | (argw << (10 - shift))); } - } - compiler->cache_argw = argw; - if (next_arg && emit_set_delta(compiler, TMP_REG3, arg, argw) != SLJIT_ERR_UNSUPPORTED) { - FAIL_IF(compiler->error); - compiler->cache_arg = SLJIT_MEM | arg; - arg = 0; - } - else { - FAIL_IF(load_immediate(compiler, TMP_REG3, argw)); - compiler->cache_arg = SLJIT_MEM; + if (argw <= 0xffffff) { + FAIL_IF(push_inst(compiler, ADDI | (1 << 22) | RD(tmp_reg) | RN(arg) | ((argw >> 12) << 10))); - if (next_arg) { - FAIL_IF(push_inst(compiler, ADD | RD(TMP_REG3) | RN(TMP_REG3) | RM(arg))); - compiler->cache_arg = SLJIT_MEM | arg; - arg = 0; + argw = ((argw & 0xfff) >> shift); + return push_inst(compiler, STRBI | type | RT(reg) | RN(tmp_reg) | (argw << 10)); } } - if (arg) - return push_inst(compiler, sljit_mem_reg[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg) | RM(TMP_REG3)); - return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(TMP_REG3)); -} + if (argw <= 255 && argw >= -256) + return push_inst(compiler, STURBI | type | RT(reg) | RN(arg) | ((argw & 0x1ff) << 12)); -static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw) -{ - if (getput_arg_fast(compiler, flags, reg, arg, argw)) - return compiler->error; - compiler->cache_arg = 0; - compiler->cache_argw = 0; - return getput_arg(compiler, flags, reg, arg, argw, 0, 0); -} + FAIL_IF(load_immediate(compiler, tmp_reg, argw)); -static SLJIT_INLINE sljit_s32 emit_op_mem2(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg1, sljit_sw arg1w, sljit_s32 arg2, sljit_sw arg2w) -{ - if (getput_arg_fast(compiler, flags, reg, arg1, arg1w)) - return compiler->error; - return getput_arg(compiler, flags, reg, arg1, arg1w, arg2, arg2w); + return push_inst(compiler, STRB | type | RT(reg) | RN(arg) | RM(tmp_reg)); } /* --------------------------------------------------------------------- */ @@ -1088,82 +866,62 @@ static SLJIT_INLINE sljit_s32 emit_op_mem2(struct sljit_compiler *compiler, slji /* --------------------------------------------------------------------- */ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { - sljit_s32 i, tmp, offs, prev, saved_regs_size; + sljit_s32 args, i, tmp, offs, prev, saved_regs_size; CHECK_ERROR(); - CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); + + saved_regs_size = GET_SAVED_REGISTERS_SIZE(scratches, saveds, 2); + if (saved_regs_size & 0x8) + saved_regs_size += sizeof(sljit_sw); - saved_regs_size = GET_SAVED_REGISTERS_SIZE(scratches, saveds, 0); - local_size += saved_regs_size + SLJIT_LOCALS_OFFSET; local_size = (local_size + 15) & ~0xf; - compiler->local_size = local_size; - - if (local_size <= (63 * sizeof(sljit_sw))) { - FAIL_IF(push_inst(compiler, STP_PRE | 29 | RT2(TMP_LR) - | RN(TMP_SP) | ((-(local_size >> 3) & 0x7f) << 15))); - FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RN(TMP_SP) | (0 << 10))); - offs = (local_size - saved_regs_size) << (15 - 3); - } else { - offs = 0 << 15; - if (saved_regs_size & 0x8) { - offs = 1 << 15; - saved_regs_size += sizeof(sljit_sw); - } - local_size -= saved_regs_size + SLJIT_LOCALS_OFFSET; - if (saved_regs_size > 0) - FAIL_IF(push_inst(compiler, SUBI | RD(TMP_SP) | RN(TMP_SP) | (saved_regs_size << 10))); - } + compiler->local_size = local_size + saved_regs_size; + + FAIL_IF(push_inst(compiler, STP_PRE | RT(TMP_FP) | RT2(TMP_LR) + | RN(SLJIT_SP) | ((-(saved_regs_size >> 3) & 0x7f) << 15))); + +#ifdef _WIN32 + if (local_size >= 4096) + FAIL_IF(push_inst(compiler, SUBI | RD(TMP_REG1) | RN(SLJIT_SP) | (1 << 10) | (1 << 22))); + else if (local_size > 256) + FAIL_IF(push_inst(compiler, SUBI | RD(TMP_REG1) | RN(SLJIT_SP) | (local_size << 10))); +#endif tmp = saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? (SLJIT_S0 + 1 - saveds) : SLJIT_FIRST_SAVED_REG; prev = -1; + offs = 2 << 15; for (i = SLJIT_S0; i >= tmp; i--) { if (prev == -1) { - if (!(offs & (1 << 15))) { - prev = i; - continue; - } - FAIL_IF(push_inst(compiler, STRI | RT(i) | RN(TMP_SP) | (offs >> 5))); - offs += 1 << 15; + prev = i; continue; } - FAIL_IF(push_inst(compiler, STP | RT(prev) | RT2(i) | RN(TMP_SP) | offs)); + FAIL_IF(push_inst(compiler, STP | RT(prev) | RT2(i) | RN(SLJIT_SP) | offs)); offs += 2 << 15; prev = -1; } for (i = scratches; i >= SLJIT_FIRST_SAVED_REG; i--) { if (prev == -1) { - if (!(offs & (1 << 15))) { - prev = i; - continue; - } - FAIL_IF(push_inst(compiler, STRI | RT(i) | RN(TMP_SP) | (offs >> 5))); - offs += 1 << 15; + prev = i; continue; } - FAIL_IF(push_inst(compiler, STP | RT(prev) | RT2(i) | RN(TMP_SP) | offs)); + FAIL_IF(push_inst(compiler, STP | RT(prev) | RT2(i) | RN(SLJIT_SP) | offs)); offs += 2 << 15; prev = -1; } - SLJIT_ASSERT(prev == -1); + if (prev != -1) + FAIL_IF(push_inst(compiler, STRI | RT(prev) | RN(SLJIT_SP) | (offs >> 5))); - if (compiler->local_size > (63 * sizeof(sljit_sw))) { - /* The local_size is already adjusted by the saved registers. */ - if (local_size > 0xfff) { - FAIL_IF(push_inst(compiler, SUBI | RD(TMP_SP) | RN(TMP_SP) | ((local_size >> 12) << 10) | (1 << 22))); - local_size &= 0xfff; - } - if (local_size) - FAIL_IF(push_inst(compiler, SUBI | RD(TMP_SP) | RN(TMP_SP) | (local_size << 10))); - FAIL_IF(push_inst(compiler, STP_PRE | 29 | RT2(TMP_LR) - | RN(TMP_SP) | ((-(16 >> 3) & 0x7f) << 15))); - FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RN(TMP_SP) | (0 << 10))); - } + + FAIL_IF(push_inst(compiler, ADDI | RD(TMP_FP) | RN(SLJIT_SP) | (0 << 10))); + + args = get_arg_count(arg_types); if (args >= 1) FAIL_IF(push_inst(compiler, ORR | RD(SLJIT_S0) | RN(TMP_ZERO) | RM(SLJIT_R0))); @@ -1172,20 +930,82 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi if (args >= 3) FAIL_IF(push_inst(compiler, ORR | RD(SLJIT_S2) | RN(TMP_ZERO) | RM(SLJIT_R2))); +#ifdef _WIN32 + if (local_size >= 4096) { + if (local_size < 4 * 4096) { + /* No need for a loop. */ + if (local_size >= 2 * 4096) { + FAIL_IF(push_inst(compiler, LDRI | RT(TMP_ZERO) | RN(TMP_REG1))); + FAIL_IF(push_inst(compiler, SUBI | RD(TMP_REG1) | RN(TMP_REG1) | (1 << 10) | (1 << 22))); + local_size -= 4096; + } + + if (local_size >= 2 * 4096) { + FAIL_IF(push_inst(compiler, LDRI | RT(TMP_ZERO) | RN(TMP_REG1))); + FAIL_IF(push_inst(compiler, SUBI | RD(TMP_REG1) | RN(TMP_REG1) | (1 << 10) | (1 << 22))); + local_size -= 4096; + } + + FAIL_IF(push_inst(compiler, LDRI | RT(TMP_ZERO) | RN(TMP_REG1))); + local_size -= 4096; + } + else { + FAIL_IF(push_inst(compiler, MOVZ | RD(TMP_REG2) | (((local_size >> 12) - 1) << 5))); + FAIL_IF(push_inst(compiler, LDRI | RT(TMP_ZERO) | RN(TMP_REG1))); + FAIL_IF(push_inst(compiler, SUBI | RD(TMP_REG1) | RN(TMP_REG1) | (1 << 10) | (1 << 22))); + FAIL_IF(push_inst(compiler, SUBI | (1 << 29) | RD(TMP_REG2) | RN(TMP_REG2) | (1 << 10))); + FAIL_IF(push_inst(compiler, B_CC | ((((sljit_ins) -3) & 0x7ffff) << 5) | 0x1 /* not-equal */)); + FAIL_IF(push_inst(compiler, LDRI | RT(TMP_ZERO) | RN(TMP_REG1))); + + local_size &= 0xfff; + } + + if (local_size > 256) { + FAIL_IF(push_inst(compiler, SUBI | RD(TMP_REG1) | RN(TMP_REG1) | (local_size << 10))); + FAIL_IF(push_inst(compiler, LDRI | RT(TMP_ZERO) | RN(TMP_REG1))); + } + else if (local_size > 0) + FAIL_IF(push_inst(compiler, LDR_PRE | RT(TMP_ZERO) | RN(TMP_REG1) | ((-local_size & 0x1ff) << 12))); + + FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RN(TMP_REG1) | (0 << 10))); + } + else if (local_size > 256) { + FAIL_IF(push_inst(compiler, LDRI | RT(TMP_ZERO) | RN(TMP_REG1))); + FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RN(TMP_REG1) | (0 << 10))); + } + else if (local_size > 0) + FAIL_IF(push_inst(compiler, LDR_PRE | RT(TMP_ZERO) | RN(SLJIT_SP) | ((-local_size & 0x1ff) << 12))); + +#else /* !_WIN32 */ + + /* The local_size does not include saved registers size. */ + if (local_size > 0xfff) { + FAIL_IF(push_inst(compiler, SUBI | RD(SLJIT_SP) | RN(SLJIT_SP) | ((local_size >> 12) << 10) | (1 << 22))); + local_size &= 0xfff; + } + if (local_size != 0) + FAIL_IF(push_inst(compiler, SUBI | RD(SLJIT_SP) | RN(SLJIT_SP) | (local_size << 10))); + +#endif /* _WIN32 */ + return SLJIT_SUCCESS; } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { + sljit_s32 saved_regs_size; + CHECK_ERROR(); - CHECK(check_sljit_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); - local_size += GET_SAVED_REGISTERS_SIZE(scratches, saveds, 0) + SLJIT_LOCALS_OFFSET; - local_size = (local_size + 15) & ~0xf; - compiler->local_size = local_size; + saved_regs_size = GET_SAVED_REGISTERS_SIZE(scratches, saveds, 2); + if (saved_regs_size & 0x8) + saved_regs_size += sizeof(sljit_sw); + + compiler->local_size = saved_regs_size + ((local_size + 15) & ~0xf); return SLJIT_SUCCESS; } @@ -1199,71 +1019,59 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *comp FAIL_IF(emit_mov_before_return(compiler, op, src, srcw)); - local_size = compiler->local_size; + saved_regs_size = GET_SAVED_REGISTERS_SIZE(compiler->scratches, compiler->saveds, 2); + if (saved_regs_size & 0x8) + saved_regs_size += sizeof(sljit_sw); + + local_size = compiler->local_size - saved_regs_size; - saved_regs_size = GET_SAVED_REGISTERS_SIZE(compiler->scratches, compiler->saveds, 0); - if (local_size <= (63 * sizeof(sljit_sw))) - offs = (local_size - saved_regs_size) << (15 - 3); + /* Load LR as early as possible. */ + if (local_size == 0) + FAIL_IF(push_inst(compiler, LDP | RT(TMP_FP) | RT2(TMP_LR) | RN(SLJIT_SP))); + else if (local_size < 63 * sizeof(sljit_sw)) { + FAIL_IF(push_inst(compiler, LDP_PRE | RT(TMP_FP) | RT2(TMP_LR) + | RN(SLJIT_SP) | (local_size << (15 - 3)))); + } else { - FAIL_IF(push_inst(compiler, LDP_PST | 29 | RT2(TMP_LR) - | RN(TMP_SP) | (((16 >> 3) & 0x7f) << 15))); - offs = 0 << 15; - if (saved_regs_size & 0x8) { - offs = 1 << 15; - saved_regs_size += sizeof(sljit_sw); - } - local_size -= saved_regs_size + SLJIT_LOCALS_OFFSET; if (local_size > 0xfff) { - FAIL_IF(push_inst(compiler, ADDI | RD(TMP_SP) | RN(TMP_SP) | ((local_size >> 12) << 10) | (1 << 22))); + FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RN(SLJIT_SP) | ((local_size >> 12) << 10) | (1 << 22))); local_size &= 0xfff; } if (local_size) - FAIL_IF(push_inst(compiler, ADDI | RD(TMP_SP) | RN(TMP_SP) | (local_size << 10))); + FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RN(SLJIT_SP) | (local_size << 10))); + + FAIL_IF(push_inst(compiler, LDP | RT(TMP_FP) | RT2(TMP_LR) | RN(SLJIT_SP))); } tmp = compiler->saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? (SLJIT_S0 + 1 - compiler->saveds) : SLJIT_FIRST_SAVED_REG; prev = -1; + offs = 2 << 15; for (i = SLJIT_S0; i >= tmp; i--) { if (prev == -1) { - if (!(offs & (1 << 15))) { - prev = i; - continue; - } - FAIL_IF(push_inst(compiler, LDRI | RT(i) | RN(TMP_SP) | (offs >> 5))); - offs += 1 << 15; + prev = i; continue; } - FAIL_IF(push_inst(compiler, LDP | RT(prev) | RT2(i) | RN(TMP_SP) | offs)); + FAIL_IF(push_inst(compiler, LDP | RT(prev) | RT2(i) | RN(SLJIT_SP) | offs)); offs += 2 << 15; prev = -1; } for (i = compiler->scratches; i >= SLJIT_FIRST_SAVED_REG; i--) { if (prev == -1) { - if (!(offs & (1 << 15))) { - prev = i; - continue; - } - FAIL_IF(push_inst(compiler, LDRI | RT(i) | RN(TMP_SP) | (offs >> 5))); - offs += 1 << 15; + prev = i; continue; } - FAIL_IF(push_inst(compiler, LDP | RT(prev) | RT2(i) | RN(TMP_SP) | offs)); + FAIL_IF(push_inst(compiler, LDP | RT(prev) | RT2(i) | RN(SLJIT_SP) | offs)); offs += 2 << 15; prev = -1; } - SLJIT_ASSERT(prev == -1); + if (prev != -1) + FAIL_IF(push_inst(compiler, LDRI | RT(prev) | RN(SLJIT_SP) | (offs >> 5))); - if (compiler->local_size <= (63 * sizeof(sljit_sw))) { - FAIL_IF(push_inst(compiler, LDP_PST | 29 | RT2(TMP_LR) - | RN(TMP_SP) | (((local_size >> 3) & 0x7f) << 15))); - } else if (saved_regs_size > 0) { - FAIL_IF(push_inst(compiler, ADDI | RD(TMP_SP) | RN(TMP_SP) | (saved_regs_size << 10))); - } - - FAIL_IF(push_inst(compiler, RET | RN(TMP_LR))); - return SLJIT_SUCCESS; + /* These two can be executed in parallel. */ + FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RN(SLJIT_SP) | (saved_regs_size << 10))); + return push_inst(compiler, RET | RN(TMP_LR)); } /* --------------------------------------------------------------------- */ @@ -1314,9 +1122,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile ADJUST_LOCAL_OFFSET(dst, dstw); ADJUST_LOCAL_OFFSET(src, srcw); - compiler->cache_arg = 0; - compiler->cache_argw = 0; - if (dst == SLJIT_UNUSED && !HAS_FLAGS(op)) { if (op <= SLJIT_MOV_P && (src & SLJIT_MEM)) { SLJIT_ASSERT(reg_map[1] == 0 && reg_map[3] == 2 && reg_map[5] == 4); @@ -1329,7 +1134,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile dst = 1; /* Signed word sized load is the prefetch instruction. */ - return emit_op_mem(compiler, WORD_SIZE | SIGNED, dst, src, srcw); + return emit_op_mem(compiler, WORD_SIZE | SIGNED, dst, src, srcw, TMP_REG1); } return SLJIT_SUCCESS; } @@ -1337,106 +1142,67 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile dst_r = SLOW_IS_REG(dst) ? dst : TMP_REG1; op = GET_OPCODE(op); - if (op >= SLJIT_MOV && op <= SLJIT_MOVU_P) { + if (op >= SLJIT_MOV && op <= SLJIT_MOV_P) { + /* Both operands are registers. */ + if (dst_r != TMP_REG1 && FAST_IS_REG(src)) + return emit_op_imm(compiler, op | ((op_flags & SLJIT_I32_OP) ? INT_OP : 0), dst_r, TMP_REG1, src); + switch (op) { case SLJIT_MOV: case SLJIT_MOV_P: - flags = WORD_SIZE; + mem_flags = WORD_SIZE; break; case SLJIT_MOV_U8: - flags = BYTE_SIZE; + mem_flags = BYTE_SIZE; if (src & SLJIT_IMM) srcw = (sljit_u8)srcw; break; case SLJIT_MOV_S8: - flags = BYTE_SIZE | SIGNED; + mem_flags = BYTE_SIZE | SIGNED; if (src & SLJIT_IMM) srcw = (sljit_s8)srcw; break; case SLJIT_MOV_U16: - flags = HALF_SIZE; + mem_flags = HALF_SIZE; if (src & SLJIT_IMM) srcw = (sljit_u16)srcw; break; case SLJIT_MOV_S16: - flags = HALF_SIZE | SIGNED; + mem_flags = HALF_SIZE | SIGNED; if (src & SLJIT_IMM) srcw = (sljit_s16)srcw; break; case SLJIT_MOV_U32: - flags = INT_SIZE; + mem_flags = INT_SIZE; if (src & SLJIT_IMM) srcw = (sljit_u32)srcw; break; case SLJIT_MOV_S32: - flags = INT_SIZE | SIGNED; - if (src & SLJIT_IMM) - srcw = (sljit_s32)srcw; - break; - case SLJIT_MOVU: - case SLJIT_MOVU_P: - flags = WORD_SIZE | UPDATE; - break; - case SLJIT_MOVU_U8: - flags = BYTE_SIZE | UPDATE; - if (src & SLJIT_IMM) - srcw = (sljit_u8)srcw; - break; - case SLJIT_MOVU_S8: - flags = BYTE_SIZE | SIGNED | UPDATE; - if (src & SLJIT_IMM) - srcw = (sljit_s8)srcw; - break; - case SLJIT_MOVU_U16: - flags = HALF_SIZE | UPDATE; - if (src & SLJIT_IMM) - srcw = (sljit_u16)srcw; - break; - case SLJIT_MOVU_S16: - flags = HALF_SIZE | SIGNED | UPDATE; - if (src & SLJIT_IMM) - srcw = (sljit_s16)srcw; - break; - case SLJIT_MOVU_U32: - flags = INT_SIZE | UPDATE; - if (src & SLJIT_IMM) - srcw = (sljit_u32)srcw; - break; - case SLJIT_MOVU_S32: - flags = INT_SIZE | SIGNED | UPDATE; + mem_flags = INT_SIZE | SIGNED; if (src & SLJIT_IMM) srcw = (sljit_s32)srcw; break; default: SLJIT_UNREACHABLE(); - flags = 0; + mem_flags = 0; break; } if (src & SLJIT_IMM) FAIL_IF(emit_op_imm(compiler, SLJIT_MOV | ARG2_IMM, dst_r, TMP_REG1, srcw)); - else if (src & SLJIT_MEM) { - if (getput_arg_fast(compiler, flags, dst_r, src, srcw)) - FAIL_IF(compiler->error); - else - FAIL_IF(getput_arg(compiler, flags, dst_r, src, srcw, dst, dstw)); - } else { - if (dst_r != TMP_REG1) - return emit_op_imm(compiler, op | ((op_flags & SLJIT_I32_OP) ? INT_OP : 0), dst_r, TMP_REG1, src); + else if (!(src & SLJIT_MEM)) dst_r = src; - } + else + FAIL_IF(emit_op_mem(compiler, mem_flags, dst_r, src, srcw, TMP_REG1)); - if (dst & SLJIT_MEM) { - if (getput_arg_fast(compiler, flags | STORE, dst_r, dst, dstw)) - return compiler->error; - else - return getput_arg(compiler, flags | STORE, dst_r, dst, dstw, 0, 0); - } + if (dst & SLJIT_MEM) + return emit_op_mem(compiler, mem_flags | STORE, dst_r, dst, dstw, TMP_REG2); return SLJIT_SUCCESS; } flags = HAS_FLAGS(op_flags) ? SET_FLAGS : 0; mem_flags = WORD_SIZE; + if (op_flags & SLJIT_I32_OP) { flags |= INT_OP; mem_flags = INT_SIZE; @@ -1446,28 +1212,14 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile flags |= UNUSED_RETURN; if (src & SLJIT_MEM) { - if (getput_arg_fast(compiler, mem_flags, TMP_REG2, src, srcw)) - FAIL_IF(compiler->error); - else - FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG2, src, srcw, dst, dstw)); + FAIL_IF(emit_op_mem(compiler, mem_flags, TMP_REG2, src, srcw, TMP_REG2)); src = TMP_REG2; } - if (src & SLJIT_IMM) { - flags |= ARG2_IMM; - if (op_flags & SLJIT_I32_OP) - srcw = (sljit_s32)srcw; - } else - srcw = src; - - emit_op_imm(compiler, flags | op, dst_r, TMP_REG1, srcw); + emit_op_imm(compiler, flags | op, dst_r, TMP_REG1, src); - if (dst & SLJIT_MEM) { - if (getput_arg_fast(compiler, mem_flags | STORE, dst_r, dst, dstw)) - return compiler->error; - else - return getput_arg(compiler, mem_flags | STORE, dst_r, dst, dstw, 0, 0); - } + if (SLJIT_UNLIKELY(dst & SLJIT_MEM)) + return emit_op_mem(compiler, mem_flags | STORE, dst_r, dst, dstw, TMP_REG2); return SLJIT_SUCCESS; } @@ -1484,15 +1236,13 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile ADJUST_LOCAL_OFFSET(src1, src1w); ADJUST_LOCAL_OFFSET(src2, src2w); - compiler->cache_arg = 0; - compiler->cache_argw = 0; - if (dst == SLJIT_UNUSED && !HAS_FLAGS(op)) return SLJIT_SUCCESS; dst_r = SLOW_IS_REG(dst) ? dst : TMP_REG1; flags = HAS_FLAGS(op) ? SET_FLAGS : 0; mem_flags = WORD_SIZE; + if (op & SLJIT_I32_OP) { flags |= INT_OP; mem_flags = INT_SIZE; @@ -1501,46 +1251,21 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile if (dst == SLJIT_UNUSED) flags |= UNUSED_RETURN; - if ((dst & SLJIT_MEM) && !getput_arg_fast(compiler, mem_flags | STORE | ARG_TEST, TMP_REG1, dst, dstw)) - flags |= SLOW_DEST; - if (src1 & SLJIT_MEM) { - if (getput_arg_fast(compiler, mem_flags, TMP_REG1, src1, src1w)) - FAIL_IF(compiler->error); - else - flags |= SLOW_SRC1; - } - if (src2 & SLJIT_MEM) { - if (getput_arg_fast(compiler, mem_flags, TMP_REG2, src2, src2w)) - FAIL_IF(compiler->error); - else - flags |= SLOW_SRC2; - } - - if ((flags & (SLOW_SRC1 | SLOW_SRC2)) == (SLOW_SRC1 | SLOW_SRC2)) { - if (!can_cache(src1, src1w, src2, src2w) && can_cache(src1, src1w, dst, dstw)) { - FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG2, src2, src2w, src1, src1w)); - FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG1, src1, src1w, dst, dstw)); - } - else { - FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG1, src1, src1w, src2, src2w)); - FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG2, src2, src2w, dst, dstw)); - } + FAIL_IF(emit_op_mem(compiler, mem_flags, TMP_REG1, src1, src1w, TMP_REG1)); + src1 = TMP_REG1; } - else if (flags & SLOW_SRC1) - FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG1, src1, src1w, dst, dstw)); - else if (flags & SLOW_SRC2) - FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG2, src2, src2w, dst, dstw)); - if (src1 & SLJIT_MEM) - src1 = TMP_REG1; - if (src2 & SLJIT_MEM) + if (src2 & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, mem_flags, TMP_REG2, src2, src2w, TMP_REG2)); src2 = TMP_REG2; + } if (src1 & SLJIT_IMM) flags |= ARG1_IMM; else src1w = src1; + if (src2 & SLJIT_IMM) flags |= ARG2_IMM; else @@ -1548,14 +1273,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile emit_op_imm(compiler, flags | GET_OPCODE(op), dst_r, src1w, src2w); - if (dst & SLJIT_MEM) { - if (!(flags & SLOW_DEST)) { - getput_arg_fast(compiler, mem_flags | STORE, dst_r, dst, dstw); - return compiler->error; - } - return getput_arg(compiler, mem_flags | STORE, TMP_REG1, dst, dstw, 0, 0); - } - + if (dst & SLJIT_MEM) + return emit_op_mem(compiler, mem_flags | STORE, dst_r, dst, dstw, TMP_REG2); return SLJIT_SUCCESS; } @@ -1568,7 +1287,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg) SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_float_register_index(sljit_s32 reg) { CHECK_REG_INDEX(check_sljit_get_float_register_index(reg)); - return reg; + return freg_map[reg]; } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler, @@ -1587,54 +1306,50 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *c static sljit_s32 emit_fop_mem(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw) { sljit_u32 shift = MEM_SIZE_SHIFT(flags); - sljit_ins ins_bits = (shift << 30); - sljit_s32 other_r; - sljit_sw diff; + sljit_ins type = (shift << 30); SLJIT_ASSERT(arg & SLJIT_MEM); if (!(flags & STORE)) - ins_bits |= 1 << 22; + type |= 0x00400000; if (arg & OFFS_REG_MASK) { argw &= 3; - if (!argw || argw == shift) - return push_inst(compiler, STR_FR | ins_bits | VT(reg) + if (argw == 0 || argw == shift) + return push_inst(compiler, STR_FR | type | VT(reg) | RN(arg & REG_MASK) | RM(OFFS_REG(arg)) | (argw ? (1 << 12) : 0)); - other_r = OFFS_REG(arg); - arg &= REG_MASK; - FAIL_IF(push_inst(compiler, ADD | RD(TMP_REG1) | RN(arg) | RM(other_r) | (argw << 10))); - arg = TMP_REG1; - argw = 0; + + FAIL_IF(push_inst(compiler, ADD | RD(TMP_REG1) | RN(arg & REG_MASK) | RM(OFFS_REG(arg)) | (argw << 10))); + return push_inst(compiler, STR_FI | type | VT(reg) | RN(TMP_REG1)); } arg &= REG_MASK; - if (arg && argw >= 0 && ((argw >> shift) <= 0xfff) && (argw & ((1 << shift) - 1)) == 0) - return push_inst(compiler, STR_FI | ins_bits | VT(reg) | RN(arg) | (argw << (10 - shift))); - - if (arg && argw <= 255 && argw >= -256) - return push_inst(compiler, STUR_FI | ins_bits | VT(reg) | RN(arg) | ((argw & 0x1ff) << 12)); - - /* Slow cases */ - if (compiler->cache_arg == SLJIT_MEM && argw != compiler->cache_argw) { - diff = argw - compiler->cache_argw; - if (!arg && diff <= 255 && diff >= -256) - return push_inst(compiler, STUR_FI | ins_bits | VT(reg) | RN(TMP_REG3) | ((diff & 0x1ff) << 12)); - if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, argw - compiler->cache_argw) != SLJIT_ERR_UNSUPPORTED) { - FAIL_IF(compiler->error); - compiler->cache_argw = argw; - } + + if (arg == SLJIT_UNUSED) { + FAIL_IF(load_immediate(compiler, TMP_REG1, argw & ~(0xfff << shift))); + + argw = (argw >> shift) & 0xfff; + + return push_inst(compiler, STR_FI | type | VT(reg) | RN(TMP_REG1) | (argw << 10)); } - if (compiler->cache_arg != SLJIT_MEM || argw != compiler->cache_argw) { - compiler->cache_arg = SLJIT_MEM; - compiler->cache_argw = argw; - FAIL_IF(load_immediate(compiler, TMP_REG3, argw)); + if (argw >= 0 && (argw & ((1 << shift) - 1)) == 0) { + if ((argw >> shift) <= 0xfff) + return push_inst(compiler, STR_FI | type | VT(reg) | RN(arg) | (argw << (10 - shift))); + + if (argw <= 0xffffff) { + FAIL_IF(push_inst(compiler, ADDI | (1 << 22) | RD(TMP_REG1) | RN(arg) | ((argw >> 12) << 10))); + + argw = ((argw & 0xfff) >> shift); + return push_inst(compiler, STR_FI | type | VT(reg) | RN(TMP_REG1) | (argw << 10)); + } } - if (arg & REG_MASK) - return push_inst(compiler, STR_FR | ins_bits | VT(reg) | RN(arg) | RM(TMP_REG3)); - return push_inst(compiler, STR_FI | ins_bits | VT(reg) | RN(TMP_REG3)); + if (argw <= 255 && argw >= -256) + return push_inst(compiler, STUR_FI | type | VT(reg) | RN(arg) | ((argw & 0x1ff) << 12)); + + FAIL_IF(load_immediate(compiler, TMP_REG1, argw)); + return push_inst(compiler, STR_FR | type | VT(reg) | RN(arg) | RM(TMP_REG1)); } static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op, @@ -1655,7 +1370,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_comp FAIL_IF(push_inst(compiler, (FCVTZS ^ inv_bits) | RD(dst_r) | VN(src))); if (dst & SLJIT_MEM) - return emit_op_mem(compiler, ((GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? INT_SIZE : WORD_SIZE) | STORE, TMP_REG1, dst, dstw); + return emit_op_mem(compiler, ((GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? INT_SIZE : WORD_SIZE) | STORE, TMP_REG1, dst, dstw, TMP_REG2); return SLJIT_SUCCESS; } @@ -1670,7 +1385,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_comp inv_bits |= (1 << 31); if (src & SLJIT_MEM) { - emit_op_mem(compiler, ((GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? INT_SIZE : WORD_SIZE), TMP_REG1, src, srcw); + emit_op_mem(compiler, ((GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? INT_SIZE : WORD_SIZE), TMP_REG1, src, srcw, TMP_REG1); src = TMP_REG1; } else if (src & SLJIT_IMM) { #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) @@ -1716,17 +1431,15 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compil sljit_ins inv_bits; CHECK_ERROR(); - compiler->cache_arg = 0; - compiler->cache_argw = 0; - SLJIT_COMPILE_ASSERT((INT_SIZE ^ 0x100) == WORD_SIZE, must_be_one_bit_difference); + SLJIT_COMPILE_ASSERT((INT_SIZE ^ 0x1) == WORD_SIZE, must_be_one_bit_difference); SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw); inv_bits = (op & SLJIT_F32_OP) ? (1 << 22) : 0; dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG1; if (src & SLJIT_MEM) { - emit_fop_mem(compiler, (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32) ? (mem_flags ^ 0x100) : mem_flags, dst_r, src, srcw); + emit_fop_mem(compiler, (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32) ? (mem_flags ^ 0x1) : mem_flags, dst_r, src, srcw); src = dst_r; } @@ -1769,9 +1482,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil ADJUST_LOCAL_OFFSET(src1, src1w); ADJUST_LOCAL_OFFSET(src2, src2w); - compiler->cache_arg = 0; - compiler->cache_argw = 0; - dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG1; if (src1 & SLJIT_MEM) { emit_fop_mem(compiler, mem_flags, TMP_FREG1, src1, src1w); @@ -1816,7 +1526,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler * return push_inst(compiler, ORR | RD(dst) | RN(TMP_ZERO) | RM(TMP_LR)); /* Memory. */ - return emit_op_mem(compiler, WORD_SIZE | STORE, TMP_LR, dst, dstw); + return emit_op_mem(compiler, WORD_SIZE | STORE, TMP_LR, dst, dstw, TMP_REG1); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw) @@ -1827,10 +1537,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler if (FAST_IS_REG(src)) FAIL_IF(push_inst(compiler, ORR | RD(TMP_LR) | RN(TMP_ZERO) | RM(src))); - else if (src & SLJIT_MEM) - FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_LR, src, srcw)); - else if (src & SLJIT_IMM) - FAIL_IF(load_immediate(compiler, TMP_LR, srcw)); + else + FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_LR, src, srcw, TMP_REG1)); return push_inst(compiler, RET | RN(TMP_LR)); } @@ -1936,6 +1644,20 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile return jump; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_call(compiler, type, arg_types)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_jump(compiler, type); +} + static SLJIT_INLINE struct sljit_jump* emit_cmp_to0(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) { @@ -1951,13 +1673,14 @@ static SLJIT_INLINE struct sljit_jump* emit_cmp_to0(struct sljit_compiler *compi jump->flags |= IS_CBZ | IS_COND; if (src & SLJIT_MEM) { - PTR_FAIL_IF(emit_op_mem(compiler, inv_bits ? INT_SIZE : WORD_SIZE, TMP_REG1, src, srcw)); + PTR_FAIL_IF(emit_op_mem(compiler, inv_bits ? INT_SIZE : WORD_SIZE, TMP_REG1, src, srcw, TMP_REG1)); src = TMP_REG1; } else if (src & SLJIT_IMM) { PTR_FAIL_IF(load_immediate(compiler, TMP_REG1, srcw)); src = TMP_REG1; } + SLJIT_ASSERT(FAST_IS_REG(src)); if ((type & 0xff) == SLJIT_EQUAL) @@ -1978,15 +1701,15 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi CHECK(check_sljit_emit_ijump(compiler, type, src, srcw)); ADJUST_LOCAL_OFFSET(src, srcw); - /* In ARM, we don't need to touch the arguments. */ if (!(src & SLJIT_IMM)) { if (src & SLJIT_MEM) { - FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG1, src, srcw)); + FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG1, src, srcw, TMP_REG1)); src = TMP_REG1; } return push_inst(compiler, ((type >= SLJIT_FAST_CALL) ? BLR : BR) | RN(src)); } + /* These jumps are converted to jump/call instructions when possible. */ jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); FAIL_IF(!jump); set_jump(jump, compiler, JUMP_ADDR | ((type >= SLJIT_FAST_CALL) ? IS_BL : 0)); @@ -1997,6 +1720,21 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi return push_inst(compiler, ((type >= SLJIT_FAST_CALL) ? BLR : BR) | RN(TMP_REG1)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ + CHECK_ERROR(); + CHECK(check_sljit_emit_icall(compiler, type, arg_types, src, srcw)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_ijump(compiler, type, src, srcw); +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 dst, sljit_sw dstw, sljit_s32 type) @@ -2013,15 +1751,18 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co if (GET_OPCODE(op) < SLJIT_ADD) { FAIL_IF(push_inst(compiler, CSINC | (cc << 12) | RD(dst_r) | RN(TMP_ZERO) | RM(TMP_ZERO))); - if (dst_r != TMP_REG1) - return SLJIT_SUCCESS; - return emit_op_mem(compiler, (GET_OPCODE(op) == SLJIT_MOV ? WORD_SIZE : INT_SIZE) | STORE, TMP_REG1, dst, dstw); + + if (dst_r == TMP_REG1) { + mem_flags = (GET_OPCODE(op) == SLJIT_MOV ? WORD_SIZE : INT_SIZE) | STORE; + return emit_op_mem(compiler, mem_flags, TMP_REG1, dst, dstw, TMP_REG2); + } + + return SLJIT_SUCCESS; } - compiler->cache_arg = 0; - compiler->cache_argw = 0; flags = HAS_FLAGS(op) ? SET_FLAGS : 0; mem_flags = WORD_SIZE; + if (op & SLJIT_I32_OP) { flags |= INT_OP; mem_flags = INT_SIZE; @@ -2030,7 +1771,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co src_r = dst; if (dst & SLJIT_MEM) { - FAIL_IF(emit_op_mem2(compiler, mem_flags, TMP_REG1, dst, dstw, dst, dstw)); + FAIL_IF(emit_op_mem(compiler, mem_flags, TMP_REG1, dst, dstw, TMP_REG1)); src_r = TMP_REG1; } @@ -2038,7 +1779,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co emit_op_imm(compiler, flags | GET_OPCODE(op), dst_r, src_r, TMP_REG2); if (dst & SLJIT_MEM) - return emit_op_mem2(compiler, mem_flags | STORE, TMP_REG1, dst, dstw, 0, 0); + return emit_op_mem(compiler, mem_flags | STORE, TMP_REG1, dst, dstw, TMP_REG2); return SLJIT_SUCCESS; } @@ -2066,6 +1807,125 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compil return push_inst(compiler, (CSEL ^ inv_bits) | (cc << 12) | RD(dst_reg) | RN(dst_reg) | RM(src)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 reg, + sljit_s32 mem, sljit_sw memw) +{ + sljit_u32 sign = 0, inst; + + CHECK_ERROR(); + CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw)); + + if ((mem & OFFS_REG_MASK) || (memw > 255 && memw < -256)) + return SLJIT_ERR_UNSUPPORTED; + + if (type & SLJIT_MEM_SUPP) + return SLJIT_SUCCESS; + + switch (type & 0xff) { + case SLJIT_MOV: + case SLJIT_MOV_P: + inst = STURBI | (MEM_SIZE_SHIFT(WORD_SIZE) << 30) | 0x400; + break; + case SLJIT_MOV_S8: + sign = 1; + case SLJIT_MOV_U8: + inst = STURBI | (MEM_SIZE_SHIFT(BYTE_SIZE) << 30) | 0x400; + break; + case SLJIT_MOV_S16: + sign = 1; + case SLJIT_MOV_U16: + inst = STURBI | (MEM_SIZE_SHIFT(HALF_SIZE) << 30) | 0x400; + break; + case SLJIT_MOV_S32: + sign = 1; + case SLJIT_MOV_U32: + inst = STURBI | (MEM_SIZE_SHIFT(INT_SIZE) << 30) | 0x400; + break; + default: + SLJIT_UNREACHABLE(); + inst = STURBI | (MEM_SIZE_SHIFT(WORD_SIZE) << 30) | 0x400; + break; + } + + if (!(type & SLJIT_MEM_STORE)) + inst |= sign ? 0x00800000 : 0x00400000; + + if (type & SLJIT_MEM_PRE) + inst |= 0x800; + + return push_inst(compiler, inst | RT(reg) | RN(mem & REG_MASK) | ((memw & 0x1ff) << 12)); +} + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 freg, + sljit_s32 mem, sljit_sw memw) +{ + sljit_u32 inst; + + CHECK_ERROR(); + CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw)); + + if ((mem & OFFS_REG_MASK) || (memw > 255 && memw < -256)) + return SLJIT_ERR_UNSUPPORTED; + + if (type & SLJIT_MEM_SUPP) + return SLJIT_SUCCESS; + + inst = STUR_FI | 0x80000400; + + if (!(type & SLJIT_F32_OP)) + inst |= 0x40000000; + + if (!(type & SLJIT_MEM_STORE)) + inst |= 0x00400000; + + if (type & SLJIT_MEM_PRE) + inst |= 0x800; + + return push_inst(compiler, inst | VT(freg) | RN(mem & REG_MASK) | ((memw & 0x1ff) << 12)); +} + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset) +{ + sljit_s32 dst_reg; + sljit_ins ins; + + CHECK_ERROR(); + CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset)); + + SLJIT_ASSERT (SLJIT_LOCALS_OFFSET_BASE == 0); + + dst_reg = FAST_IS_REG(dst) ? dst : TMP_REG1; + + if (offset <= 0xffffff && offset >= -0xffffff) { + ins = ADDI; + if (offset < 0) { + offset = -offset; + ins = SUBI; + } + + if (offset <= 0xfff) + FAIL_IF(push_inst(compiler, ins | RD(dst_reg) | RN(SLJIT_SP) | (offset << 10))); + else { + FAIL_IF(push_inst(compiler, ins | RD(dst_reg) | RN(SLJIT_SP) | ((offset & 0xfff000) >> (12 - 10)) | (1 << 22))); + + offset &= 0xfff; + if (offset != 0) + FAIL_IF(push_inst(compiler, ins | RD(dst_reg) | RN(dst_reg) | (offset << 10))); + } + } + else { + FAIL_IF(load_immediate (compiler, dst_reg, offset)); + /* Add extended register form. */ + FAIL_IF(push_inst(compiler, ADDE | (0x3 << 13) | RD(dst_reg) | RN(SLJIT_SP) | RM(dst_reg))); + } + + if (SLJIT_UNLIKELY(dst & SLJIT_MEM)) + return emit_op_mem(compiler, WORD_SIZE | STORE, dst_reg, dst, dstw, TMP_REG1); + return SLJIT_SUCCESS; +} + SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) { struct sljit_const *const_; @@ -2083,7 +1943,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi PTR_FAIL_IF(emit_imm64_const(compiler, dst_r, init_value)); if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw)); + PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw, TMP_REG2)); return const_; } diff --git a/pcre/sljit/sljitNativeARM_T2_32.c b/pcre/sljit/sljitNativeARM_T2_32.c index 29e5566a820..d7024b6d7d4 100644 --- a/pcre/sljit/sljitNativeARM_T2_32.c +++ b/pcre/sljit/sljitNativeARM_T2_32.c @@ -26,7 +26,11 @@ SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void) { - return "ARM-Thumb2" SLJIT_CPUINFO; +#ifdef __SOFTFP__ + return "ARM-Thumb2" SLJIT_CPUINFO " ABI:softfp"; +#else + return "ARM-Thumb2" SLJIT_CPUINFO " ABI:hardfp"; +#endif } /* Length of an instruction word. */ @@ -37,12 +41,16 @@ typedef sljit_u32 sljit_ins; #define TMP_REG2 (SLJIT_NUMBER_OF_REGISTERS + 3) #define TMP_PC (SLJIT_NUMBER_OF_REGISTERS + 4) -#define TMP_FREG1 (0) -#define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) +#define TMP_FREG1 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) +#define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2) /* See sljit_emit_enter and sljit_emit_op0 if you want to change them. */ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { - 0, 0, 1, 2, 12, 11, 10, 9, 8, 7, 6, 5, 4, 13, 3, 14, 15 + 0, 0, 1, 2, 3, 11, 10, 9, 8, 7, 6, 5, 4, 13, 12, 14, 15 +}; + +static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = { + 0, 0, 1, 2, 3, 4, 5, 6, 7 }; #define COPY_BITS(src, from, to, bits) \ @@ -69,9 +77,9 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { #define RN4(rn) (reg_map[rn] << 16) #define RM4(rm) (reg_map[rm]) #define RT4(rt) (reg_map[rt] << 12) -#define DD4(dd) ((dd) << 12) -#define DN4(dn) ((dn) << 16) -#define DM4(dm) (dm) +#define DD4(dd) (freg_map[dd] << 12) +#define DN4(dn) (freg_map[dn] << 16) +#define DM4(dm) (freg_map[dm]) #define IMM5(imm) \ (COPY_BITS(imm, 2, 12, 3) | ((imm & 0x3) << 6)) #define IMM12(imm) \ @@ -102,6 +110,7 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { #define ASRSI 0x1000 #define ASR_W 0xfa40f000 #define ASR_WI 0xea4f0020 +#define BCC 0xd000 #define BICI 0xf0200000 #define BKPT 0xbe00 #define BLX 0x4780 @@ -117,6 +126,7 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { #define EORS 0x4040 #define EOR_W 0xea800000 #define IT 0xbf00 +#define LDRI 0xf8500800 #define LSLS 0x4080 #define LSLSI 0x0000 #define LSL_W 0xfa00f000 @@ -150,6 +160,7 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { #define SBCI 0xf1600000 #define SBCS 0x4180 #define SBC_W 0xeb600000 +#define SDIV 0xfb90f0f0 #define SMULL 0xfb800000 #define STR_SP 0x9000 #define SUBS 0x1a00 @@ -164,6 +175,7 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { #define SXTH 0xb200 #define SXTH_W 0xfa0ff080 #define TST 0x4200 +#define UDIV 0xfbb0f0f0 #define UMULL 0xfba00000 #define UXTB 0xb2c0 #define UXTB_W 0xfa5ff080 @@ -178,6 +190,7 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { #define VDIV_F32 0xee800a00 #define VMOV_F32 0xeeb00a40 #define VMOV 0xee000a10 +#define VMOV2 0xec400a10 #define VMRS 0xeef1fa10 #define VMUL_F32 0xee200a00 #define VNEG_F32 0xeeb10a40 @@ -208,10 +221,10 @@ static sljit_s32 push_inst32(struct sljit_compiler *compiler, sljit_ins inst) static SLJIT_INLINE sljit_s32 emit_imm32_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_uw imm) { - FAIL_IF(push_inst32(compiler, MOVW | RD4(dst) | - COPY_BITS(imm, 12, 16, 4) | COPY_BITS(imm, 11, 26, 1) | COPY_BITS(imm, 8, 12, 3) | (imm & 0xff))); - return push_inst32(compiler, MOVT | RD4(dst) | - COPY_BITS(imm, 12 + 16, 16, 4) | COPY_BITS(imm, 11 + 16, 26, 1) | COPY_BITS(imm, 8 + 16, 12, 3) | ((imm & 0xff0000) >> 16)); + FAIL_IF(push_inst32(compiler, MOVW | RD4(dst) + | COPY_BITS(imm, 12, 16, 4) | COPY_BITS(imm, 11, 26, 1) | COPY_BITS(imm, 8, 12, 3) | (imm & 0xff))); + return push_inst32(compiler, MOVT | RD4(dst) + | COPY_BITS(imm, 12 + 16, 16, 4) | COPY_BITS(imm, 11 + 16, 26, 1) | COPY_BITS(imm, 8 + 16, 12, 3) | ((imm & 0xff0000) >> 16)); } static SLJIT_INLINE void modify_imm32_const(sljit_u16 *inst, sljit_uw new_imm) @@ -330,8 +343,8 @@ static SLJIT_INLINE void set_jump_instruction(struct sljit_jump *jump, sljit_sw /* Really complex instruction form for branches. */ s = (diff >> 23) & 0x1; - j1 = (~(diff >> 21) ^ s) & 0x1; - j2 = (~(diff >> 22) ^ s) & 0x1; + j1 = (~(diff >> 22) ^ s) & 0x1; + j2 = (~(diff >> 21) ^ s) & 0x1; jump_inst[0] = 0xf000 | (s << 10) | COPY_BITS(diff, 11, 0, 10); jump_inst[1] = (j1 << 13) | (j2 << 11) | (diff & 0x7ff); @@ -444,7 +457,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) return 1; #endif - case SLJIT_HAS_PRE_UPDATE: case SLJIT_HAS_CLZ: case SLJIT_HAS_CMOV: return 1; @@ -512,6 +524,8 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst, { sljit_uw tmp; + /* MOVS cannot be used since it destroy flags. */ + if (imm >= 0x10000) { tmp = get_imm(imm); if (tmp != INVALID_IMM) @@ -522,13 +536,13 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst, } /* set low 16 bits, set hi 16 bits to 0. */ - FAIL_IF(push_inst32(compiler, MOVW | RD4(dst) | - COPY_BITS(imm, 12, 16, 4) | COPY_BITS(imm, 11, 26, 1) | COPY_BITS(imm, 8, 12, 3) | (imm & 0xff))); + FAIL_IF(push_inst32(compiler, MOVW | RD4(dst) + | COPY_BITS(imm, 12, 16, 4) | COPY_BITS(imm, 11, 26, 1) | COPY_BITS(imm, 8, 12, 3) | (imm & 0xff))); /* set hi 16 bit if needed. */ if (imm >= 0x10000) - return push_inst32(compiler, MOVT | RD4(dst) | - COPY_BITS(imm, 12 + 16, 16, 4) | COPY_BITS(imm, 11 + 16, 26, 1) | COPY_BITS(imm, 8 + 16, 12, 3) | ((imm & 0xff0000) >> 16)); + return push_inst32(compiler, MOVT | RD4(dst) + | COPY_BITS(imm, 12 + 16, 16, 4) | COPY_BITS(imm, 11 + 16, 26, 1) | COPY_BITS(imm, 8 + 16, 12, 3) | ((imm & 0xff0000) >> 16)); return SLJIT_SUCCESS; } @@ -729,34 +743,26 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s case SLJIT_MOV_U32: case SLJIT_MOV_S32: case SLJIT_MOV_P: - case SLJIT_MOVU: - case SLJIT_MOVU_U32: - case SLJIT_MOVU_S32: - case SLJIT_MOVU_P: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG2); if (dst == arg2) return SLJIT_SUCCESS; return push_inst16(compiler, MOV | SET_REGS44(dst, arg2)); case SLJIT_MOV_U8: - case SLJIT_MOVU_U8: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG2); if (IS_2_LO_REGS(dst, arg2)) return push_inst16(compiler, UXTB | RD3(dst) | RN3(arg2)); return push_inst32(compiler, UXTB_W | RD4(dst) | RM4(arg2)); case SLJIT_MOV_S8: - case SLJIT_MOVU_S8: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG2); if (IS_2_LO_REGS(dst, arg2)) return push_inst16(compiler, SXTB | RD3(dst) | RN3(arg2)); return push_inst32(compiler, SXTB_W | RD4(dst) | RM4(arg2)); case SLJIT_MOV_U16: - case SLJIT_MOVU_U16: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG2); if (IS_2_LO_REGS(dst, arg2)) return push_inst16(compiler, UXTH | RD3(dst) | RN3(arg2)); return push_inst32(compiler, UXTH_W | RD4(dst) | RM4(arg2)); case SLJIT_MOV_S16: - case SLJIT_MOVU_S16: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG2); if (IS_2_LO_REGS(dst, arg2)) return push_inst16(compiler, SXTH | RD3(dst) | RN3(arg2)); @@ -840,8 +846,6 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s #define HALF_SIZE 0x08 #define PRELOAD 0x0c -#define UPDATE 0x10 - #define IS_WORD_SIZE(flags) (!(flags & (BYTE_SIZE | HALF_SIZE))) #define OFFSET_CHECK(imm, shift) (!(argw & ~(imm << shift))) @@ -940,12 +944,10 @@ static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit sljit_s32 arg, sljit_sw argw, sljit_s32 tmp_reg) { sljit_s32 other_r; - sljit_s32 update = flags & UPDATE; sljit_uw tmp; SLJIT_ASSERT(arg & SLJIT_MEM); SLJIT_ASSERT((arg & REG_MASK) != tmp_reg); - flags &= ~UPDATE; arg &= ~SLJIT_MEM; if (SLJIT_UNLIKELY(!(arg & REG_MASK))) { @@ -961,63 +963,6 @@ static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit return push_inst32(compiler, sljit_mem32[flags] | MEM_IMM12 | RT4(reg) | RN4(tmp_reg)); } - if (SLJIT_UNLIKELY(update)) { - SLJIT_ASSERT(reg != arg); - - if (SLJIT_UNLIKELY(arg & OFFS_REG_MASK)) { - other_r = OFFS_REG(arg); - arg &= 0xf; - - if (IS_3_LO_REGS(reg, arg, other_r)) - FAIL_IF(push_inst16(compiler, sljit_mem16[flags] | RD3(reg) | RN3(arg) | RM3(other_r))); - else - FAIL_IF(push_inst32(compiler, sljit_mem32[flags] | RT4(reg) | RN4(arg) | RM4(other_r))); - return push_inst16(compiler, ADD | SET_REGS44(arg, other_r)); - } - - if (argw > 0xff) { - tmp = get_imm(argw & ~0xff); - if (tmp != INVALID_IMM) { - push_inst32(compiler, ADD_WI | RD4(arg) | RN4(arg) | tmp); - argw = argw & 0xff; - } - } - else if (argw < -0xff) { - tmp = get_imm(-argw & ~0xff); - if (tmp != INVALID_IMM) { - push_inst32(compiler, SUB_WI | RD4(arg) | RN4(arg) | tmp); - argw = -(-argw & 0xff); - } - } - - if (argw == 0) { - if (IS_2_LO_REGS(reg, arg) && sljit_mem16_imm5[flags]) - return push_inst16(compiler, sljit_mem16_imm5[flags] | RD3(reg) | RN3(arg)); - return push_inst32(compiler, sljit_mem32[flags] | MEM_IMM12 | RT4(reg) | RN4(arg)); - } - - if (argw <= 0xff && argw >= -0xff) { - if (argw >= 0) - argw |= 0x200; - else { - argw = -argw; - } - - SLJIT_ASSERT(argw >= 0 && (argw & 0xff) <= 0xff); - return push_inst32(compiler, sljit_mem32[flags] | MEM_IMM8 | RT4(reg) | RN4(arg) | 0x100 | argw); - } - - FAIL_IF(load_immediate(compiler, tmp_reg, argw)); - - SLJIT_ASSERT(reg != tmp_reg); - - if (IS_3_LO_REGS(reg, arg, tmp_reg)) - FAIL_IF(push_inst16(compiler, sljit_mem16[flags] | RD3(reg) | RN3(arg) | RM3(tmp_reg))); - else - FAIL_IF(push_inst32(compiler, sljit_mem32[flags] | RT4(reg) | RN4(arg) | RM4(tmp_reg))); - return push_inst16(compiler, ADD | SET_REGS44(arg, tmp_reg)); - } - if (SLJIT_UNLIKELY(arg & OFFS_REG_MASK)) { argw &= 0x3; other_r = OFFS_REG(arg); @@ -1088,15 +1033,18 @@ static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit /* --------------------------------------------------------------------- */ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { - sljit_s32 size, i, tmp; + sljit_s32 args, size, i, tmp; sljit_ins push = 0; +#ifdef _WIN32 + sljit_uw imm; +#endif CHECK_ERROR(); - CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); tmp = saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? (SLJIT_S0 + 1 - saveds) : SLJIT_FIRST_SAVED_REG; for (i = SLJIT_S0; i >= tmp; i--) @@ -1113,12 +1061,27 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi size = GET_SAVED_REGISTERS_SIZE(scratches, saveds, 1); local_size = ((size + local_size + 7) & ~7) - size; compiler->local_size = local_size; + +#ifdef _WIN32 + if (local_size >= 256) { + if (local_size > 4096) + imm = get_imm(4096); + else + imm = get_imm(local_size & ~0xff); + + SLJIT_ASSERT(imm != INVALID_IMM); + FAIL_IF(push_inst32(compiler, SUB_WI | RD4(TMP_REG1) | RN4(SLJIT_SP) | imm)); + } +#else if (local_size > 0) { if (local_size <= (127 << 2)) FAIL_IF(push_inst16(compiler, SUB_SP | (local_size >> 2))); else FAIL_IF(emit_op_imm(compiler, SLJIT_SUB | ARG2_IMM, SLJIT_SP, SLJIT_SP, local_size)); } +#endif + + args = get_arg_count(arg_types); if (args >= 1) FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(SLJIT_S0, SLJIT_R0))); @@ -1127,18 +1090,73 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi if (args >= 3) FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(SLJIT_S2, SLJIT_R2))); +#ifdef _WIN32 + if (local_size >= 256) { + if (local_size > 4096) { + imm = get_imm(4096); + SLJIT_ASSERT(imm != INVALID_IMM); + + if (local_size < 4 * 4096) { + if (local_size > 2 * 4096) { + FAIL_IF(push_inst32(compiler, LDRI | 0x400 | RT4(TMP_REG2) | RN4(TMP_REG1))); + FAIL_IF(push_inst32(compiler, SUB_WI | RD4(TMP_REG1) | RN4(TMP_REG1) | imm)); + local_size -= 4096; + } + + if (local_size > 2 * 4096) { + FAIL_IF(push_inst32(compiler, LDRI | 0x400 | RT4(TMP_REG2) | RN4(TMP_REG1))); + FAIL_IF(push_inst32(compiler, SUB_WI | RD4(TMP_REG1) | RN4(TMP_REG1) | imm)); + local_size -= 4096; + } + + FAIL_IF(push_inst32(compiler, LDRI | 0x400 | RT4(TMP_REG2) | RN4(TMP_REG1))); + local_size -= 4096; + + SLJIT_ASSERT(local_size > 0); + } + else { + FAIL_IF(load_immediate(compiler, SLJIT_R3, (local_size >> 12) - 1)); + FAIL_IF(push_inst32(compiler, LDRI | 0x400 | RT4(TMP_REG2) | RN4(TMP_REG1))); + FAIL_IF(push_inst32(compiler, SUB_WI | RD4(TMP_REG1) | RN4(TMP_REG1) | imm)); + SLJIT_ASSERT(reg_map[SLJIT_R3] < 7); + FAIL_IF(push_inst16(compiler, SUBSI8 | RDN3(SLJIT_R3) | 1)); + FAIL_IF(push_inst16(compiler, BCC | (0x1 << 8) /* not-equal */ | (-7 & 0xff))); + + local_size &= 0xfff; + + if (local_size != 0) + FAIL_IF(push_inst32(compiler, LDRI | 0x400 | RT4(TMP_REG2) | RN4(TMP_REG1))); + } + + if (local_size >= 256) { + imm = get_imm(local_size & ~0xff); + SLJIT_ASSERT(imm != INVALID_IMM); + + FAIL_IF(push_inst32(compiler, SUB_WI | RD4(TMP_REG1) | RN4(TMP_REG1) | imm)); + } + } + + local_size &= 0xff; + FAIL_IF(push_inst32(compiler, LDRI | 0x400 | (local_size > 0 ? 0x100 : 0) | RT4(TMP_REG2) | RN4(TMP_REG1) | local_size)); + + FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(SLJIT_SP, TMP_REG1))); + } + else if (local_size > 0) + FAIL_IF(push_inst32(compiler, LDRI | 0x500 | RT4(TMP_REG1) | RN4(SLJIT_SP) | local_size)); +#endif + return SLJIT_SUCCESS; } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { sljit_s32 size; CHECK_ERROR(); - CHECK(check_sljit_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); size = GET_SAVED_REGISTERS_SIZE(scratches, saveds, 1); compiler->local_size = ((size + local_size + 7) & ~7) - size; @@ -1178,11 +1196,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *comp /* Operators */ /* --------------------------------------------------------------------- */ +#if !(defined __ARM_FEATURE_IDIV) && !(defined __ARM_ARCH_EXT_IDIV__) + #ifdef __cplusplus extern "C" { #endif -#if defined(__GNUC__) +#ifdef _WIN32 +extern unsigned long long __rt_udiv(unsigned int denominator, unsigned int numerator); +extern long long __rt_sdiv(int denominator, int numerator); +#elif defined(__GNUC__) extern unsigned int __aeabi_uidivmod(unsigned int numerator, int unsigned denominator); extern int __aeabi_idivmod(int numerator, int denominator); #else @@ -1193,10 +1216,14 @@ extern int __aeabi_idivmod(int numerator, int denominator); } #endif +#endif /* !__ARM_FEATURE_IDIV && !__ARM_ARCH_EXT_IDIV__ */ + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op) { +#if !(defined __ARM_FEATURE_IDIV) && !(defined __ARM_ARCH_EXT_IDIV__) sljit_sw saved_reg_list[3]; sljit_sw saved_reg_count; +#endif CHECK_ERROR(); CHECK(check_sljit_emit_op0(compiler, op)); @@ -1214,16 +1241,27 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compile | (reg_map[SLJIT_R0] << 12) | (reg_map[SLJIT_R0] << 16) | reg_map[SLJIT_R1]); +#if (defined __ARM_FEATURE_IDIV) || (defined __ARM_ARCH_EXT_IDIV__) + case SLJIT_DIVMOD_UW: + case SLJIT_DIVMOD_SW: + FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(TMP_REG1, SLJIT_R0))); + FAIL_IF(push_inst32(compiler, (op == SLJIT_DIVMOD_UW ? UDIV : SDIV) | RD4(SLJIT_R0) | RN4(SLJIT_R0) | RM4(SLJIT_R1))); + FAIL_IF(push_inst32(compiler, MUL | RD4(SLJIT_R1) | RN4(SLJIT_R0) | RM4(SLJIT_R1))); + return push_inst32(compiler, SUB_W | RD4(SLJIT_R1) | RN4(TMP_REG1) | RM4(SLJIT_R1)); + case SLJIT_DIV_UW: + case SLJIT_DIV_SW: + return push_inst32(compiler, (op == SLJIT_DIV_UW ? UDIV : SDIV) | RD4(SLJIT_R0) | RN4(SLJIT_R0) | RM4(SLJIT_R1)); +#else /* !__ARM_FEATURE_IDIV && !__ARM_ARCH_EXT_IDIV__ */ case SLJIT_DIVMOD_UW: case SLJIT_DIVMOD_SW: case SLJIT_DIV_UW: case SLJIT_DIV_SW: SLJIT_COMPILE_ASSERT((SLJIT_DIVMOD_UW & 0x2) == 0 && SLJIT_DIV_UW - 0x2 == SLJIT_DIVMOD_UW, bad_div_opcode_assignments); - SLJIT_ASSERT(reg_map[2] == 1 && reg_map[3] == 2 && reg_map[4] == 12); + SLJIT_ASSERT(reg_map[2] == 1 && reg_map[3] == 2 && reg_map[4] == 3); saved_reg_count = 0; if (compiler->scratches >= 4) - saved_reg_list[saved_reg_count++] = 12; + saved_reg_list[saved_reg_count++] = 3; if (compiler->scratches >= 3) saved_reg_list[saved_reg_count++] = 2; if (op >= SLJIT_DIV_UW) @@ -1242,7 +1280,13 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compile } } -#if defined(__GNUC__) +#ifdef _WIN32 + FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(TMP_REG1, SLJIT_R0))); + FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(SLJIT_R0, SLJIT_R1))); + FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(SLJIT_R1, TMP_REG1))); + FAIL_IF(sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, + ((op | 0x2) == SLJIT_DIV_UW ? SLJIT_FUNC_OFFSET(__rt_udiv) : SLJIT_FUNC_OFFSET(__rt_sdiv)))); +#elif defined(__GNUC__) FAIL_IF(sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, ((op | 0x2) == SLJIT_DIV_UW ? SLJIT_FUNC_OFFSET(__aeabi_uidivmod) : SLJIT_FUNC_OFFSET(__aeabi_idivmod)))); #else @@ -1262,6 +1306,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compile | (saved_reg_list[0] << 12) /* ldr rX, [sp], #8/16 */); } return SLJIT_SUCCESS; +#endif /* __ARM_FEATURE_IDIV || __ARM_ARCH_EXT_IDIV__ */ } return SLJIT_SUCCESS; @@ -1289,7 +1334,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile dst_r = SLOW_IS_REG(dst) ? dst : TMP_REG1; op = GET_OPCODE(op); - if (op >= SLJIT_MOV && op <= SLJIT_MOVU_P) { + if (op >= SLJIT_MOV && op <= SLJIT_MOV_P) { switch (op) { case SLJIT_MOV: case SLJIT_MOV_U32: @@ -1317,32 +1362,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile if (src & SLJIT_IMM) srcw = (sljit_s16)srcw; break; - case SLJIT_MOVU: - case SLJIT_MOVU_U32: - case SLJIT_MOVU_S32: - case SLJIT_MOVU_P: - flags = WORD_SIZE | UPDATE; - break; - case SLJIT_MOVU_U8: - flags = BYTE_SIZE | UPDATE; - if (src & SLJIT_IMM) - srcw = (sljit_u8)srcw; - break; - case SLJIT_MOVU_S8: - flags = BYTE_SIZE | SIGNED | UPDATE; - if (src & SLJIT_IMM) - srcw = (sljit_s8)srcw; - break; - case SLJIT_MOVU_U16: - flags = HALF_SIZE | UPDATE; - if (src & SLJIT_IMM) - srcw = (sljit_u16)srcw; - break; - case SLJIT_MOVU_S16: - flags = HALF_SIZE | SIGNED | UPDATE; - if (src & SLJIT_IMM) - srcw = (sljit_s16)srcw; - break; default: SLJIT_UNREACHABLE(); flags = 0; @@ -1352,7 +1371,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile if (src & SLJIT_IMM) FAIL_IF(emit_op_imm(compiler, SLJIT_MOV | ARG2_IMM, dst_r, TMP_REG2, srcw)); else if (src & SLJIT_MEM) { - FAIL_IF(emit_op_mem(compiler, flags, dst_r, src, srcw, ((flags & UPDATE) && dst_r == TMP_REG1) ? TMP_REG2 : TMP_REG1)); + FAIL_IF(emit_op_mem(compiler, flags, dst_r, src, srcw, TMP_REG1)); } else { if (dst_r != TMP_REG1) return emit_op_imm(compiler, op, dst_r, TMP_REG2, src); @@ -1362,7 +1381,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile if (!(dst & SLJIT_MEM)) return SLJIT_SUCCESS; - return emit_op_mem(compiler, flags | STORE, dst_r, dst, dstw, (dst_r == TMP_REG1) ? TMP_REG2 : TMP_REG1); + return emit_op_mem(compiler, flags | STORE, dst_r, dst, dstw, TMP_REG2); } if (op == SLJIT_NEG) { @@ -1375,20 +1394,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile flags = HAS_FLAGS(op_flags) ? SET_FLAGS : 0; - if (src & SLJIT_IMM) - flags |= ARG2_IMM; - else if (src & SLJIT_MEM) { + if (src & SLJIT_MEM) { FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG1, src, srcw, TMP_REG1)); - srcw = TMP_REG1; + src = TMP_REG1; } - else - srcw = src; - emit_op_imm(compiler, flags | op, dst_r, TMP_REG2, srcw); + emit_op_imm(compiler, flags | op, dst_r, TMP_REG2, src); - if (!(dst & SLJIT_MEM)) - return SLJIT_SUCCESS; - return emit_op_mem(compiler, flags | STORE, dst_r, dst, dstw, TMP_REG2); + if (SLJIT_UNLIKELY(dst & SLJIT_MEM)) + return emit_op_mem(compiler, flags | STORE, dst_r, dst, dstw, TMP_REG2); + return SLJIT_SUCCESS; } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, @@ -1448,7 +1463,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg) SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_float_register_index(sljit_s32 reg) { CHECK_REG_INDEX(check_sljit_get_float_register_index(reg)); - return reg << 1; + return (freg_map[reg] << 1); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler, @@ -1702,11 +1717,9 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler if (FAST_IS_REG(src)) FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(TMP_REG2, src))); - else if (src & SLJIT_MEM) { + else FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG2, src, srcw, TMP_REG2)); - } - else if (src & SLJIT_IMM) - FAIL_IF(load_immediate(compiler, TMP_REG2, srcw)); + return push_inst16(compiler, BX | RN3(TMP_REG2)); } @@ -1798,7 +1811,6 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP); type &= 0xff; - /* In ARM, we don't need to touch the arguments. */ PTR_FAIL_IF(emit_imm32_const(compiler, TMP_REG1, 0)); if (type < SLJIT_JUMP) { jump->flags |= IS_COND; @@ -1818,6 +1830,241 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile return jump; } +#ifdef __SOFTFP__ + +static sljit_s32 softfloat_call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_s32 *src) +{ + sljit_s32 stack_offset = 0; + sljit_s32 arg_count = 0; + sljit_s32 word_arg_offset = 0; + sljit_s32 float_arg_count = 0; + sljit_s32 types = 0; + sljit_s32 src_offset = 4 * sizeof(sljit_sw); + sljit_u8 offsets[4]; + + if (src && FAST_IS_REG(*src)) + src_offset = reg_map[*src] * sizeof(sljit_sw); + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + types = (types << SLJIT_DEF_SHIFT) | (arg_types & SLJIT_DEF_MASK); + + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + offsets[arg_count] = (sljit_u8)stack_offset; + stack_offset += sizeof(sljit_f32); + arg_count++; + float_arg_count++; + break; + case SLJIT_ARG_TYPE_F64: + if (stack_offset & 0x7) + stack_offset += sizeof(sljit_sw); + offsets[arg_count] = (sljit_u8)stack_offset; + stack_offset += sizeof(sljit_f64); + arg_count++; + float_arg_count++; + break; + default: + offsets[arg_count] = (sljit_u8)stack_offset; + stack_offset += sizeof(sljit_sw); + arg_count++; + word_arg_offset += sizeof(sljit_sw); + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + if (stack_offset > 16) + FAIL_IF(push_inst16(compiler, SUB_SP | (((stack_offset - 16) + 0x7) & ~0x7) >> 2)); + + SLJIT_ASSERT(reg_map[TMP_REG1] == 12); + + /* Process arguments in reversed direction. */ + while (types) { + switch (types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + arg_count--; + float_arg_count--; + stack_offset = offsets[arg_count]; + + if (stack_offset < 16) { + if (src_offset == stack_offset) { + FAIL_IF(push_inst16(compiler, MOV | (src_offset << 1) | 4 | (1 << 7))); + *src = TMP_REG1; + } + FAIL_IF(push_inst32(compiler, VMOV | 0x100000 | (float_arg_count << 16) | (stack_offset << 10))); + } else + FAIL_IF(push_inst32(compiler, VSTR_F32 | 0x800000 | RN4(SLJIT_SP) | (float_arg_count << 12) | ((stack_offset - 16) >> 2))); + break; + case SLJIT_ARG_TYPE_F64: + arg_count--; + float_arg_count--; + stack_offset = offsets[arg_count]; + + SLJIT_ASSERT((stack_offset & 0x7) == 0); + + if (stack_offset < 16) { + if (src_offset == stack_offset || src_offset == stack_offset + sizeof(sljit_sw)) { + FAIL_IF(push_inst16(compiler, MOV | (src_offset << 1) | 4 | (1 << 7))); + *src = TMP_REG1; + } + FAIL_IF(push_inst32(compiler, VMOV2 | 0x100000 | (stack_offset << 10) | ((stack_offset + sizeof(sljit_sw)) << 14) | float_arg_count)); + } else + FAIL_IF(push_inst32(compiler, VSTR_F32 | 0x800100 | RN4(SLJIT_SP) | (float_arg_count << 12) | ((stack_offset - 16) >> 2))); + break; + default: + arg_count--; + word_arg_offset -= sizeof(sljit_sw); + stack_offset = offsets[arg_count]; + + SLJIT_ASSERT(stack_offset >= word_arg_offset); + + if (stack_offset != word_arg_offset) { + if (stack_offset < 16) { + if (src_offset == stack_offset) { + FAIL_IF(push_inst16(compiler, MOV | (src_offset << 1) | 4 | (1 << 7))); + *src = TMP_REG1; + } + else if (src_offset == word_arg_offset) { + *src = 1 + (stack_offset >> 2); + src_offset = stack_offset; + } + FAIL_IF(push_inst16(compiler, MOV | (stack_offset >> 2) | (word_arg_offset << 1))); + } else + FAIL_IF(push_inst16(compiler, STR_SP | (word_arg_offset << 6) | ((stack_offset - 16) >> 2))); + } + break; + } + + types >>= SLJIT_DEF_SHIFT; + } + + return SLJIT_SUCCESS; +} + +static sljit_s32 softfloat_post_call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types) +{ + sljit_s32 stack_size = 0; + + if ((arg_types & SLJIT_DEF_MASK) == SLJIT_ARG_TYPE_F32) + FAIL_IF(push_inst32(compiler, VMOV | (0 << 16) | (0 << 12))); + if ((arg_types & SLJIT_DEF_MASK) == SLJIT_ARG_TYPE_F64) + FAIL_IF(push_inst32(compiler, VMOV2 | (1 << 16) | (0 << 12) | 0)); + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + stack_size += sizeof(sljit_f32); + break; + case SLJIT_ARG_TYPE_F64: + if (stack_size & 0x7) + stack_size += sizeof(sljit_sw); + stack_size += sizeof(sljit_f64); + break; + default: + stack_size += sizeof(sljit_sw); + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + if (stack_size <= 16) + return SLJIT_SUCCESS; + + return push_inst16(compiler, ADD_SP | ((((stack_size - 16) + 0x7) & ~0x7) >> 2)); +} + +#else + +static sljit_s32 hardfloat_call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types) +{ + sljit_u32 remap = 0; + sljit_u32 offset = 0; + sljit_u32 new_offset, mask; + + /* Remove return value. */ + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + if ((arg_types & SLJIT_DEF_MASK) == SLJIT_ARG_TYPE_F32) { + new_offset = 0; + mask = 1; + + while (remap & mask) { + new_offset++; + mask <<= 1; + } + remap |= mask; + + if (offset != new_offset) + FAIL_IF(push_inst32(compiler, VMOV_F32 | DD4((new_offset >> 1) + 1) + | ((new_offset & 0x1) ? 0x400000 : 0) | DM4((offset >> 1) + 1))); + + offset += 2; + } + else if ((arg_types & SLJIT_DEF_MASK) == SLJIT_ARG_TYPE_F64) { + new_offset = 0; + mask = 3; + + while (remap & mask) { + new_offset += 2; + mask <<= 2; + } + remap |= mask; + + if (offset != new_offset) + FAIL_IF(push_inst32(compiler, VMOV_F32 | SLJIT_F32_OP | DD4((new_offset >> 1) + 1) | DM4((offset >> 1) + 1))); + + offset += 2; + } + arg_types >>= SLJIT_DEF_SHIFT; + } + + return SLJIT_SUCCESS; +} + +#endif + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ +#ifdef __SOFTFP__ + struct sljit_jump *jump; +#endif + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_call(compiler, type, arg_types)); + +#ifdef __SOFTFP__ + PTR_FAIL_IF(softfloat_call_with_args(compiler, arg_types, NULL)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + jump = sljit_emit_jump(compiler, type); + PTR_FAIL_IF(jump == NULL); + + PTR_FAIL_IF(softfloat_post_call_with_args(compiler, arg_types)); + return jump; +#else + PTR_FAIL_IF(hardfloat_call_with_args(compiler, arg_types)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_jump(compiler, type); +#endif +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) { struct sljit_jump *jump; @@ -1826,16 +2073,20 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi CHECK(check_sljit_emit_ijump(compiler, type, src, srcw)); ADJUST_LOCAL_OFFSET(src, srcw); - /* In ARM, we don't need to touch the arguments. */ + SLJIT_ASSERT(reg_map[TMP_REG1] != 14); + if (!(src & SLJIT_IMM)) { - if (FAST_IS_REG(src)) + if (FAST_IS_REG(src)) { + SLJIT_ASSERT(reg_map[src] != 14); return push_inst16(compiler, (type <= SLJIT_JUMP ? BX : BLX) | RN3(src)); + } FAIL_IF(emit_op_mem(compiler, WORD_SIZE, type <= SLJIT_JUMP ? TMP_PC : TMP_REG1, src, srcw, TMP_REG1)); if (type >= SLJIT_FAST_CALL) return push_inst16(compiler, BLX | RN3(TMP_REG1)); } + /* These jumps are converted to jump/call instructions when possible. */ jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); FAIL_IF(!jump); set_jump(jump, compiler, JUMP_ADDR | ((type >= SLJIT_FAST_CALL) ? IS_BL : 0)); @@ -1846,6 +2097,41 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi return push_inst16(compiler, (type <= SLJIT_JUMP ? BX : BLX) | RN3(TMP_REG1)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ + CHECK_ERROR(); + CHECK(check_sljit_emit_icall(compiler, type, arg_types, src, srcw)); + +#ifdef __SOFTFP__ + if (src & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG1, src, srcw, TMP_REG1)); + src = TMP_REG1; + } + + FAIL_IF(softfloat_call_with_args(compiler, arg_types, &src)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + FAIL_IF(sljit_emit_ijump(compiler, type, src, srcw)); + + return softfloat_post_call_with_args(compiler, arg_types); +#else /* !__SOFTFP__ */ + FAIL_IF(hardfloat_call_with_args(compiler, arg_types)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_ijump(compiler, type, src, srcw); +#endif /* __SOFTFP__ */ +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 dst, sljit_sw dstw, sljit_s32 type) @@ -1896,8 +2182,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co return SLJIT_SUCCESS; /* The condition must always be set, even if the ORR/EORI is not executed above. */ - if (reg_map[dst_r] <= 7) - return push_inst16(compiler, MOVS | RD3(TMP_REG1) | RN3(dst_r)); return push_inst32(compiler, MOV_W | SET_FLAGS | RD4(TMP_REG1) | RM4(dst_r)); } @@ -1924,8 +2208,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compil if (tmp < 0x10000) { /* set low 16 bits, set hi 16 bits to 0. */ FAIL_IF(push_inst16(compiler, IT | (cc << 4) | 0x8)); - return push_inst32(compiler, MOVW | RD4(dst_reg) | - COPY_BITS(tmp, 12, 16, 4) | COPY_BITS(tmp, 11, 26, 1) | COPY_BITS(tmp, 8, 12, 3) | (tmp & 0xff)); + return push_inst32(compiler, MOVW | RD4(dst_reg) + | COPY_BITS(tmp, 12, 16, 4) | COPY_BITS(tmp, 11, 26, 1) | COPY_BITS(tmp, 8, 12, 3) | (tmp & 0xff)); } tmp = get_imm(srcw); @@ -1943,10 +2227,67 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compil FAIL_IF(push_inst16(compiler, IT | (cc << 4) | ((cc & 0x1) << 3) | 0x4)); tmp = (sljit_uw) srcw; - FAIL_IF(push_inst32(compiler, MOVW | RD4(dst_reg) | - COPY_BITS(tmp, 12, 16, 4) | COPY_BITS(tmp, 11, 26, 1) | COPY_BITS(tmp, 8, 12, 3) | (tmp & 0xff))); - return push_inst32(compiler, MOVT | RD4(dst_reg) | - COPY_BITS(tmp, 12 + 16, 16, 4) | COPY_BITS(tmp, 11 + 16, 26, 1) | COPY_BITS(tmp, 8 + 16, 12, 3) | ((tmp & 0xff0000) >> 16)); + FAIL_IF(push_inst32(compiler, MOVW | RD4(dst_reg) + | COPY_BITS(tmp, 12, 16, 4) | COPY_BITS(tmp, 11, 26, 1) | COPY_BITS(tmp, 8, 12, 3) | (tmp & 0xff))); + return push_inst32(compiler, MOVT | RD4(dst_reg) + | COPY_BITS(tmp, 12 + 16, 16, 4) | COPY_BITS(tmp, 11 + 16, 26, 1) | COPY_BITS(tmp, 8 + 16, 12, 3) | ((tmp & 0xff0000) >> 16)); +} + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 reg, + sljit_s32 mem, sljit_sw memw) +{ + sljit_s32 flags; + sljit_ins inst; + + CHECK_ERROR(); + CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw)); + + if ((mem & OFFS_REG_MASK) || (memw > 255 && memw < -255)) + return SLJIT_ERR_UNSUPPORTED; + + if (type & SLJIT_MEM_SUPP) + return SLJIT_SUCCESS; + + switch (type & 0xff) { + case SLJIT_MOV: + case SLJIT_MOV_U32: + case SLJIT_MOV_S32: + case SLJIT_MOV_P: + flags = WORD_SIZE; + break; + case SLJIT_MOV_U8: + flags = BYTE_SIZE; + break; + case SLJIT_MOV_S8: + flags = BYTE_SIZE | SIGNED; + break; + case SLJIT_MOV_U16: + flags = HALF_SIZE; + break; + case SLJIT_MOV_S16: + flags = HALF_SIZE | SIGNED; + break; + default: + SLJIT_UNREACHABLE(); + flags = WORD_SIZE; + break; + } + + if (type & SLJIT_MEM_STORE) + flags |= STORE; + + inst = sljit_mem32[flags] | 0x900; + + if (type & SLJIT_MEM_PRE) + inst |= 0x400; + + if (memw >= 0) + inst |= 0x200; + else + memw = -memw; + + return push_inst32(compiler, inst | RT4(reg) | RN4(mem & REG_MASK) | memw); } SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) diff --git a/pcre/sljit/sljitNativeMIPS_32.c b/pcre/sljit/sljitNativeMIPS_32.c index 62e16106b12..094c9923bcd 100644 --- a/pcre/sljit/sljitNativeMIPS_32.c +++ b/pcre/sljit/sljitNativeMIPS_32.c @@ -435,3 +435,232 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_consta inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); SLJIT_CACHE_FLUSH(inst, inst + 2); } + +static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_ins *ins_ptr) +{ + sljit_s32 stack_offset = 0; + sljit_s32 arg_count = 0; + sljit_s32 float_arg_count = 0; + sljit_s32 word_arg_count = 0; + sljit_s32 types = 0; + sljit_s32 arg_count_save, types_save; + sljit_ins prev_ins = NOP; + sljit_ins ins = NOP; + sljit_u8 offsets[4]; + + SLJIT_ASSERT(reg_map[TMP_REG1] == 4 && freg_map[TMP_FREG1] == 12); + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + types = (types << SLJIT_DEF_SHIFT) | (arg_types & SLJIT_DEF_MASK); + + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + offsets[arg_count] = (sljit_u8)stack_offset; + + if (word_arg_count == 0 && arg_count <= 1) + offsets[arg_count] = 254 + arg_count; + + stack_offset += sizeof(sljit_f32); + arg_count++; + float_arg_count++; + break; + case SLJIT_ARG_TYPE_F64: + if (stack_offset & 0x7) + stack_offset += sizeof(sljit_sw); + offsets[arg_count] = (sljit_u8)stack_offset; + + if (word_arg_count == 0 && arg_count <= 1) + offsets[arg_count] = 254 + arg_count; + + stack_offset += sizeof(sljit_f64); + arg_count++; + float_arg_count++; + break; + default: + offsets[arg_count] = (sljit_u8)stack_offset; + stack_offset += sizeof(sljit_sw); + arg_count++; + word_arg_count++; + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + /* Stack is aligned to 16 bytes, max two doubles can be placed on the stack. */ + if (stack_offset > 16) + FAIL_IF(push_inst(compiler, ADDIU | S(SLJIT_SP) | T(SLJIT_SP) | IMM(-16), DR(SLJIT_SP))); + + types_save = types; + arg_count_save = arg_count; + + while (types) { + switch (types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + arg_count--; + if (offsets[arg_count] < 254) + ins = SWC1 | S(SLJIT_SP) | FT(float_arg_count) | IMM(offsets[arg_count]); + float_arg_count--; + break; + case SLJIT_ARG_TYPE_F64: + arg_count--; + if (offsets[arg_count] < 254) + ins = SDC1 | S(SLJIT_SP) | FT(float_arg_count) | IMM(offsets[arg_count]); + float_arg_count--; + break; + default: + if (offsets[arg_count - 1] >= 16) + ins = SW | S(SLJIT_SP) | T(word_arg_count) | IMM(offsets[arg_count - 1]); + else if (arg_count != word_arg_count) + ins = ADDU | S(word_arg_count) | TA(0) | DA(4 + (offsets[arg_count - 1] >> 2)); + else if (arg_count == 1) + ins = ADDU | S(SLJIT_R0) | TA(0) | DA(4); + + arg_count--; + word_arg_count--; + break; + } + + if (ins != NOP) { + if (prev_ins != NOP) + FAIL_IF(push_inst(compiler, prev_ins, MOVABLE_INS)); + prev_ins = ins; + ins = NOP; + } + + types >>= SLJIT_DEF_SHIFT; + } + + types = types_save; + arg_count = arg_count_save; + + while (types) { + switch (types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + arg_count--; + if (offsets[arg_count] == 254) + ins = MOV_S | FMT_S | FS(SLJIT_FR0) | FD(TMP_FREG1); + else if (offsets[arg_count] < 16) + ins = LW | S(SLJIT_SP) | TA(4 + (offsets[arg_count] >> 2)) | IMM(offsets[arg_count]); + break; + case SLJIT_ARG_TYPE_F64: + arg_count--; + if (offsets[arg_count] == 254) + ins = MOV_S | FMT_D | FS(SLJIT_FR0) | FD(TMP_FREG1); + else if (offsets[arg_count] < 16) { + if (prev_ins != NOP) + FAIL_IF(push_inst(compiler, prev_ins, MOVABLE_INS)); + prev_ins = LW | S(SLJIT_SP) | TA(4 + (offsets[arg_count] >> 2)) | IMM(offsets[arg_count]); + ins = LW | S(SLJIT_SP) | TA(5 + (offsets[arg_count] >> 2)) | IMM(offsets[arg_count] + sizeof(sljit_sw)); + } + break; + default: + arg_count--; + break; + } + + if (ins != NOP) { + if (prev_ins != NOP) + FAIL_IF(push_inst(compiler, prev_ins, MOVABLE_INS)); + prev_ins = ins; + ins = NOP; + } + + types >>= SLJIT_DEF_SHIFT; + } + + *ins_ptr = prev_ins; + + return SLJIT_SUCCESS; +} + +static sljit_s32 post_call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types) +{ + sljit_s32 stack_offset = 0; + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + stack_offset += sizeof(sljit_f32); + break; + case SLJIT_ARG_TYPE_F64: + if (stack_offset & 0x7) + stack_offset += sizeof(sljit_sw); + stack_offset += sizeof(sljit_f64); + break; + default: + stack_offset += sizeof(sljit_sw); + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + /* Stack is aligned to 16 bytes, max two doubles can be placed on the stack. */ + if (stack_offset > 16) + return push_inst(compiler, ADDIU | S(SLJIT_SP) | T(SLJIT_SP) | IMM(16), DR(SLJIT_SP)); + + return SLJIT_SUCCESS; +} + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ + struct sljit_jump *jump; + sljit_ins ins; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_call(compiler, type, arg_types)); + + jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); + PTR_FAIL_IF(!jump); + set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP); + type &= 0xff; + + PTR_FAIL_IF(call_with_args(compiler, arg_types, &ins)); + + SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25 && PIC_ADDR_REG == TMP_REG2); + + PTR_FAIL_IF(emit_const(compiler, PIC_ADDR_REG, 0)); + + jump->flags |= IS_JAL | IS_CALL; + PTR_FAIL_IF(push_inst(compiler, JALR | S(PIC_ADDR_REG) | DA(RETURN_ADDR_REG), UNMOVABLE_INS)); + jump->addr = compiler->size; + PTR_FAIL_IF(push_inst(compiler, ins, UNMOVABLE_INS)); + + PTR_FAIL_IF(post_call_with_args(compiler, arg_types)); + + return jump; +} + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ + sljit_ins ins; + + CHECK_ERROR(); + CHECK(check_sljit_emit_icall(compiler, type, arg_types, src, srcw)); + + SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25 && PIC_ADDR_REG == TMP_REG2); + + if (src & SLJIT_IMM) + FAIL_IF(load_immediate(compiler, DR(PIC_ADDR_REG), srcw)); + else if (FAST_IS_REG(src)) + FAIL_IF(push_inst(compiler, ADDU | S(src) | TA(0) | D(PIC_ADDR_REG), DR(PIC_ADDR_REG))); + else if (src & SLJIT_MEM) { + ADJUST_LOCAL_OFFSET(src, srcw); + FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, DR(PIC_ADDR_REG), src, srcw)); + } + + FAIL_IF(call_with_args(compiler, arg_types, &ins)); + + /* Register input. */ + FAIL_IF(push_inst(compiler, JALR | S(PIC_ADDR_REG) | DA(RETURN_ADDR_REG), UNMOVABLE_INS)); + FAIL_IF(push_inst(compiler, ins, UNMOVABLE_INS)); + return post_call_with_args(compiler, arg_types); +} diff --git a/pcre/sljit/sljitNativeMIPS_64.c b/pcre/sljit/sljitNativeMIPS_64.c index dd114bb27af..f841aef5ddc 100644 --- a/pcre/sljit/sljitNativeMIPS_64.c +++ b/pcre/sljit/sljitNativeMIPS_64.c @@ -537,3 +537,132 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_consta inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); SLJIT_CACHE_FLUSH(inst, inst + 6); } + +static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_ins *ins_ptr) +{ + sljit_s32 arg_count = 0; + sljit_s32 word_arg_count = 0; + sljit_s32 float_arg_count = 0; + sljit_s32 types = 0; + sljit_ins prev_ins = NOP; + sljit_ins ins = NOP; + + SLJIT_ASSERT(reg_map[TMP_REG1] == 4 && freg_map[TMP_FREG1] == 12); + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + types = (types << SLJIT_DEF_SHIFT) | (arg_types & SLJIT_DEF_MASK); + + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + case SLJIT_ARG_TYPE_F64: + arg_count++; + float_arg_count++; + break; + default: + arg_count++; + word_arg_count++; + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + while (types) { + switch (types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + if (arg_count != float_arg_count) + ins = MOV_S | FMT_S | FS(float_arg_count) | FD(arg_count); + else if (arg_count == 1) + ins = MOV_S | FMT_S | FS(SLJIT_FR0) | FD(TMP_FREG1); + arg_count--; + float_arg_count--; + break; + case SLJIT_ARG_TYPE_F64: + if (arg_count != float_arg_count) + ins = MOV_S | FMT_D | FS(float_arg_count) | FD(arg_count); + else if (arg_count == 1) + ins = MOV_S | FMT_D | FS(SLJIT_FR0) | FD(TMP_FREG1); + arg_count--; + float_arg_count--; + break; + default: + if (arg_count != word_arg_count) + ins = DADDU | S(word_arg_count) | TA(0) | D(arg_count); + else if (arg_count == 1) + ins = DADDU | S(SLJIT_R0) | TA(0) | DA(4); + arg_count--; + word_arg_count--; + break; + } + + if (ins != NOP) { + if (prev_ins != NOP) + FAIL_IF(push_inst(compiler, prev_ins, MOVABLE_INS)); + prev_ins = ins; + ins = NOP; + } + + types >>= SLJIT_DEF_SHIFT; + } + + *ins_ptr = prev_ins; + + return SLJIT_SUCCESS; +} + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ + struct sljit_jump *jump; + sljit_ins ins; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_call(compiler, type, arg_types)); + + jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); + PTR_FAIL_IF(!jump); + set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP); + type &= 0xff; + + PTR_FAIL_IF(call_with_args(compiler, arg_types, &ins)); + + SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25 && PIC_ADDR_REG == TMP_REG2); + + PTR_FAIL_IF(emit_const(compiler, PIC_ADDR_REG, 0)); + + jump->flags |= IS_JAL | IS_CALL; + PTR_FAIL_IF(push_inst(compiler, JALR | S(PIC_ADDR_REG) | DA(RETURN_ADDR_REG), UNMOVABLE_INS)); + jump->addr = compiler->size; + PTR_FAIL_IF(push_inst(compiler, ins, UNMOVABLE_INS)); + + return jump; +} + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ + sljit_ins ins; + + CHECK_ERROR(); + CHECK(check_sljit_emit_icall(compiler, type, arg_types, src, srcw)); + + SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25 && PIC_ADDR_REG == TMP_REG2); + + if (src & SLJIT_IMM) + FAIL_IF(load_immediate(compiler, DR(PIC_ADDR_REG), srcw)); + else if (FAST_IS_REG(src)) + FAIL_IF(push_inst(compiler, DADDU | S(src) | TA(0) | D(PIC_ADDR_REG), DR(PIC_ADDR_REG))); + else if (src & SLJIT_MEM) { + ADJUST_LOCAL_OFFSET(src, srcw); + FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, DR(PIC_ADDR_REG), src, srcw)); + } + + FAIL_IF(call_with_args(compiler, arg_types, &ins)); + + /* Register input. */ + FAIL_IF(push_inst(compiler, JALR | S(PIC_ADDR_REG) | DA(RETURN_ADDR_REG), UNMOVABLE_INS)); + return push_inst(compiler, ins, UNMOVABLE_INS); +} diff --git a/pcre/sljit/sljitNativeMIPS_common.c b/pcre/sljit/sljitNativeMIPS_common.c index ee207fe1191..894e21304bb 100644 --- a/pcre/sljit/sljitNativeMIPS_common.c +++ b/pcre/sljit/sljitNativeMIPS_common.c @@ -57,16 +57,30 @@ typedef sljit_u32 sljit_ins; #define RETURN_ADDR_REG 31 /* Flags are kept in volatile registers. */ -#define EQUAL_FLAG 31 +#define EQUAL_FLAG 3 #define OTHER_FLAG 1 -#define TMP_FREG1 (0) -#define TMP_FREG2 ((SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) << 1) +#define TMP_FREG1 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) +#define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2) static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { - 0, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 24, 23, 22, 21, 20, 19, 18, 17, 16, 29, 3, 25, 4 + 0, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 24, 23, 22, 21, 20, 19, 18, 17, 16, 29, 4, 25, 31 }; +#if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) + +static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = { + 0, 0, 14, 2, 4, 6, 8, 12, 10 +}; + +#else + +static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = { + 0, 0, 13, 14, 15, 16, 17, 12, 18 +}; + +#endif + /* --------------------------------------------------------------------- */ /* Instrucion forms */ /* --------------------------------------------------------------------- */ @@ -74,21 +88,23 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { #define S(s) (reg_map[s] << 21) #define T(t) (reg_map[t] << 16) #define D(d) (reg_map[d] << 11) +#define FT(t) (freg_map[t] << 16) +#define FS(s) (freg_map[s] << 11) +#define FD(d) (freg_map[d] << 6) /* Absolute registers. */ #define SA(s) ((s) << 21) #define TA(t) ((t) << 16) #define DA(d) ((d) << 11) -#define FT(t) ((t) << 16) -#define FS(s) ((s) << 11) -#define FD(d) ((d) << 6) #define IMM(imm) ((imm) & 0xffff) #define SH_IMM(imm) ((imm) << 6) #define DR(dr) (reg_map[dr]) +#define FR(dr) (freg_map[dr]) #define HI(opcode) ((opcode) << 26) #define LO(opcode) (opcode) /* S = (16 << 21) D = (17 << 21) */ #define FMT_S (16 << 21) +#define FMT_D (17 << 21) #define ABS_S (HI(17) | FMT_S | LO(5)) #define ADD_S (HI(17) | FMT_S | LO(0)) @@ -153,6 +169,7 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { #define OR (HI(0) | LO(37)) #define ORI (HI(13)) #define SD (HI(63)) +#define SDC1 (HI(61)) #define SLT (HI(0) | LO(42)) #define SLTI (HI(10)) #define SLTIU (HI(11)) @@ -166,6 +183,7 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 5] = { #define SUB_S (HI(17) | FMT_S | LO(1)) #define SUBU (HI(0) | LO(35)) #define SW (HI(43)) +#define SWC1 (HI(57)) #define TRUNC_W_S (HI(17) | FMT_S | LO(13)) #define XOR (HI(0) | LO(38)) #define XORI (HI(14)) @@ -498,12 +516,13 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) { + sljit_sw fir = 0; + switch (feature_type) { case SLJIT_HAS_FPU: #ifdef SLJIT_IS_FPU_AVAILABLE return SLJIT_IS_FPU_AVAILABLE; #elif defined(__GNUC__) - sljit_sw fir; asm ("cfc1 %0, $0" : "=r"(fir)); return (fir >> 22) & 0x1; #else @@ -517,7 +536,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) #endif default: - return 0; + return fir; } } @@ -539,21 +558,20 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) #define MEM_MASK 0x1f -#define WRITE_BACK 0x00020 -#define ARG_TEST 0x00040 -#define ALT_KEEP_CACHE 0x00080 -#define CUMULATIVE_OP 0x00100 -#define LOGICAL_OP 0x00200 -#define IMM_OP 0x00400 -#define SRC2_IMM 0x00800 - -#define UNUSED_DEST 0x01000 -#define REG_DEST 0x02000 -#define REG1_SOURCE 0x04000 -#define REG2_SOURCE 0x08000 -#define SLOW_SRC1 0x10000 -#define SLOW_SRC2 0x20000 -#define SLOW_DEST 0x40000 +#define ARG_TEST 0x00020 +#define ALT_KEEP_CACHE 0x00040 +#define CUMULATIVE_OP 0x00080 +#define LOGICAL_OP 0x00100 +#define IMM_OP 0x00200 +#define SRC2_IMM 0x00400 + +#define UNUSED_DEST 0x00800 +#define REG_DEST 0x01000 +#define REG1_SOURCE 0x02000 +#define REG2_SOURCE 0x04000 +#define SLOW_SRC1 0x08000 +#define SLOW_SRC2 0x10000 +#define SLOW_DEST 0x20000 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) #define STACK_STORE SW @@ -563,6 +581,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) #define STACK_LOAD LD #endif +static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg_ar, sljit_s32 arg, sljit_sw argw); + #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) #include "sljitNativeMIPS_32.c" #else @@ -570,15 +590,15 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) #endif SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { sljit_ins base; - sljit_s32 i, tmp, offs; + sljit_s32 args, i, tmp, offs; CHECK_ERROR(); - CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); local_size += GET_SAVED_REGISTERS_SIZE(scratches, saveds, 1) + SLJIT_LOCALS_OFFSET; #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) @@ -592,16 +612,17 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi /* Frequent case. */ FAIL_IF(push_inst(compiler, ADDIU_W | S(SLJIT_SP) | T(SLJIT_SP) | IMM(-local_size), DR(SLJIT_SP))); base = S(SLJIT_SP); + offs = local_size - (sljit_sw)sizeof(sljit_sw); } else { - FAIL_IF(load_immediate(compiler, DR(TMP_REG1), local_size)); + FAIL_IF(load_immediate(compiler, DR(OTHER_FLAG), local_size)); FAIL_IF(push_inst(compiler, ADDU_W | S(SLJIT_SP) | TA(0) | D(TMP_REG2), DR(TMP_REG2))); - FAIL_IF(push_inst(compiler, SUBU_W | S(SLJIT_SP) | T(TMP_REG1) | D(SLJIT_SP), DR(SLJIT_SP))); + FAIL_IF(push_inst(compiler, SUBU_W | S(SLJIT_SP) | T(OTHER_FLAG) | D(SLJIT_SP), DR(SLJIT_SP))); base = S(TMP_REG2); local_size = 0; + offs = -(sljit_sw)sizeof(sljit_sw); } - offs = local_size - (sljit_sw)(sizeof(sljit_sw)); FAIL_IF(push_inst(compiler, STACK_STORE | base | TA(RETURN_ADDR_REG) | IMM(offs), MOVABLE_INS)); tmp = saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? (SLJIT_S0 + 1 - saveds) : SLJIT_FIRST_SAVED_REG; @@ -615,6 +636,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi FAIL_IF(push_inst(compiler, STACK_STORE | base | T(i) | IMM(offs), MOVABLE_INS)); } + args = get_arg_count(arg_types); + if (args >= 1) FAIL_IF(push_inst(compiler, ADDU_W | SA(4) | TA(0) | D(SLJIT_S0), DR(SLJIT_S0))); if (args >= 2) @@ -626,12 +649,12 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { CHECK_ERROR(); - CHECK(check_sljit_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); local_size += GET_SAVED_REGISTERS_SIZE(scratches, saveds, 1) + SLJIT_LOCALS_OFFSET; #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) @@ -733,7 +756,7 @@ static sljit_s32 getput_arg_fast(struct sljit_compiler *compiler, sljit_s32 flag { SLJIT_ASSERT(arg & SLJIT_MEM); - if ((!(flags & WRITE_BACK) || !(arg & REG_MASK)) && !(arg & OFFS_REG_MASK) && argw <= SIMM_MAX && argw >= SIMM_MIN) { + if (!(arg & OFFS_REG_MASK) && argw <= SIMM_MAX && argw >= SIMM_MIN) { /* Works for both absoulte and relative addresses. */ if (SLJIT_UNLIKELY(flags & ARG_TEST)) return 1; @@ -783,19 +806,14 @@ static sljit_s32 getput_arg(struct sljit_compiler *compiler, sljit_s32 flags, sl if ((flags & MEM_MASK) <= GPR_REG && (flags & LOAD_DATA)) { tmp_ar = reg_ar; delay_slot = reg_ar; - } else { + } + else { tmp_ar = DR(TMP_REG1); delay_slot = MOVABLE_INS; } base = arg & REG_MASK; if (SLJIT_UNLIKELY(arg & OFFS_REG_MASK)) { - if (SLJIT_UNLIKELY(flags & WRITE_BACK)) { - SLJIT_ASSERT(argw == 0); - FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(OFFS_REG(arg)) | D(base), DR(base))); - return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(base) | TA(reg_ar), delay_slot); - } - argw &= 0x3; /* Using the cache. */ @@ -832,29 +850,6 @@ static sljit_s32 getput_arg(struct sljit_compiler *compiler, sljit_s32 flags, sl return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | SA(tmp_ar) | TA(reg_ar), delay_slot); } - if (SLJIT_UNLIKELY(flags & WRITE_BACK) && base) { - if (argw <= SIMM_MAX && argw >= SIMM_MIN) { - if (argw) - FAIL_IF(push_inst(compiler, ADDIU_W | S(base) | T(base) | IMM(argw), DR(base))); - } - else { - if (compiler->cache_arg == SLJIT_MEM && argw - compiler->cache_argw <= SIMM_MAX && argw - compiler->cache_argw >= SIMM_MIN) { - if (argw != compiler->cache_argw) { - FAIL_IF(push_inst(compiler, ADDIU_W | S(TMP_REG3) | T(TMP_REG3) | IMM(argw - compiler->cache_argw), DR(TMP_REG3))); - compiler->cache_argw = argw; - } - FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | D(base), DR(base))); - } - else { - compiler->cache_arg = SLJIT_MEM; - compiler->cache_argw = argw; - FAIL_IF(load_immediate(compiler, DR(TMP_REG3), argw)); - FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | D(base), DR(base))); - } - } - return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(base) | TA(reg_ar), delay_slot); - } - if (compiler->cache_arg == arg && argw - compiler->cache_argw <= SIMM_MAX && argw - compiler->cache_argw >= SIMM_MIN) { if (argw != compiler->cache_argw) { FAIL_IF(push_inst(compiler, ADDIU_W | S(TMP_REG3) | T(TMP_REG3) | IMM(argw - compiler->cache_argw), DR(TMP_REG3))); @@ -888,11 +883,39 @@ static sljit_s32 getput_arg(struct sljit_compiler *compiler, sljit_s32 flags, sl static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg_ar, sljit_s32 arg, sljit_sw argw) { + sljit_s32 tmp_ar, base, delay_slot; + if (getput_arg_fast(compiler, flags, reg_ar, arg, argw)) return compiler->error; - compiler->cache_arg = 0; - compiler->cache_argw = 0; - return getput_arg(compiler, flags, reg_ar, arg, argw, 0, 0); + + if ((flags & MEM_MASK) <= GPR_REG && (flags & LOAD_DATA)) { + tmp_ar = reg_ar; + delay_slot = reg_ar; + } + else { + tmp_ar = DR(TMP_REG1); + delay_slot = MOVABLE_INS; + } + base = arg & REG_MASK; + + if (SLJIT_UNLIKELY(arg & OFFS_REG_MASK)) { + argw &= 0x3; + + if (SLJIT_UNLIKELY(argw)) { + FAIL_IF(push_inst(compiler, SLL_W | T(OFFS_REG(arg)) | DA(tmp_ar) | SH_IMM(argw), tmp_ar)); + FAIL_IF(push_inst(compiler, ADDU_W | S(base) | TA(tmp_ar) | DA(tmp_ar), tmp_ar)); + } + else + FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(OFFS_REG(arg)) | DA(tmp_ar), tmp_ar)); + return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | SA(tmp_ar) | TA(reg_ar), delay_slot); + } + + FAIL_IF(load_immediate(compiler, tmp_ar, argw)); + + if (base != 0) + FAIL_IF(push_inst(compiler, ADDU_W | S(base) | TA(tmp_ar) | DA(tmp_ar), tmp_ar)); + + return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | SA(tmp_ar) | TA(reg_ar), delay_slot); } static SLJIT_INLINE sljit_s32 emit_op_mem2(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg1, sljit_sw arg1w, sljit_s32 arg2, sljit_sw arg2w) @@ -928,7 +951,7 @@ static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s3 else if (FAST_IS_REG(dst)) { dst_r = dst; flags |= REG_DEST; - if (op >= SLJIT_MOV && op <= SLJIT_MOVU_S32) + if (op >= SLJIT_MOV && op <= SLJIT_MOV_P) sugg_src2_r = dst_r; } else if ((dst & SLJIT_MEM) && !getput_arg_fast(compiler, flags | ARG_TEST, DR(TMP_REG1), dst, dstw)) @@ -982,7 +1005,7 @@ static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s3 if (FAST_IS_REG(src2)) { src2_r = src2; flags |= REG2_SOURCE; - if (!(flags & REG_DEST) && op >= SLJIT_MOV && op <= SLJIT_MOVU_S32) + if (!(flags & REG_DEST) && op >= SLJIT_MOV && op <= SLJIT_MOV_P) dst_r = src2_r; } else if (src2 & SLJIT_IMM) { @@ -993,7 +1016,7 @@ static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s3 } else { src2_r = 0; - if ((op >= SLJIT_MOV && op <= SLJIT_MOVU_S32) && (dst & SLJIT_MEM)) + if ((op >= SLJIT_MOV && op <= SLJIT_MOV_P) && (dst & SLJIT_MEM)) dst_r = 0; } } @@ -1132,11 +1155,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile } #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) - if ((op & SLJIT_I32_OP) && GET_OPCODE(op) >= SLJIT_NOT) { + if ((op & SLJIT_I32_OP) && GET_OPCODE(op) >= SLJIT_NOT) flags |= INT_DATA | SIGNED_DATA; - if (src & SLJIT_IMM) - srcw = (sljit_s32)srcw; - } #endif switch (GET_OPCODE(op)) { @@ -1170,36 +1190,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile case SLJIT_MOV_S16: return emit_op(compiler, SLJIT_MOV_S16, HALF_DATA | SIGNED_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s16)srcw : srcw); - case SLJIT_MOVU: - case SLJIT_MOVU_P: - return emit_op(compiler, SLJIT_MOV, WORD_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw); - - case SLJIT_MOVU_U32: -#if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) - return emit_op(compiler, SLJIT_MOV_U32, INT_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw); -#else - return emit_op(compiler, SLJIT_MOV_U32, INT_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u32)srcw : srcw); -#endif - - case SLJIT_MOVU_S32: -#if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) - return emit_op(compiler, SLJIT_MOV_S32, INT_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw); -#else - return emit_op(compiler, SLJIT_MOV_S32, INT_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s32)srcw : srcw); -#endif - - case SLJIT_MOVU_U8: - return emit_op(compiler, SLJIT_MOV_U8, BYTE_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u8)srcw : srcw); - - case SLJIT_MOVU_S8: - return emit_op(compiler, SLJIT_MOV_S8, BYTE_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s8)srcw : srcw); - - case SLJIT_MOVU_U16: - return emit_op(compiler, SLJIT_MOV_U16, HALF_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u16)srcw : srcw); - - case SLJIT_MOVU_S16: - return emit_op(compiler, SLJIT_MOV_S16, HALF_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s16)srcw : srcw); - case SLJIT_NOT: return emit_op(compiler, op, flags, dst, dstw, TMP_REG1, 0, src, srcw); @@ -1210,6 +1200,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile return emit_op(compiler, op, flags, dst, dstw, TMP_REG1, 0, src, srcw); } + SLJIT_UNREACHABLE(); return SLJIT_SUCCESS; #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) @@ -1281,6 +1272,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile return emit_op(compiler, op, flags | IMM_OP, dst, dstw, src1, src1w, src2, src2w); } + SLJIT_UNREACHABLE(); return SLJIT_SUCCESS; #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) @@ -1297,7 +1289,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg) SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_float_register_index(sljit_s32 reg) { CHECK_REG_INDEX(check_sljit_get_float_register_index(reg)); - return reg << 1; + return FR(reg); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler, @@ -1327,11 +1319,9 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_comp #endif if (src & SLJIT_MEM) { - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src, srcw, dst, dstw)); + FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG1), src, srcw, dst, dstw)); src = TMP_FREG1; } - else - src <<= 1; FAIL_IF(push_inst(compiler, (TRUNC_W_S ^ (flags >> 19)) | FMT(op) | FS(src) | FD(TMP_FREG1), MOVABLE_INS)); @@ -1339,7 +1329,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_comp return push_inst(compiler, MFC1 | flags | T(dst) | FS(TMP_FREG1), MOVABLE_INS); /* Store the integer value from a VFP register. */ - return emit_op_mem2(compiler, flags ? DOUBLE_DATA : SINGLE_DATA, TMP_FREG1, dst, dstw, 0, 0); + return emit_op_mem2(compiler, flags ? DOUBLE_DATA : SINGLE_DATA, FR(TMP_FREG1), dst, dstw, 0, 0); #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) # undef is_long @@ -1356,13 +1346,13 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_comp sljit_s32 flags = (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_SW) << 21; #endif - sljit_s32 dst_r = FAST_IS_REG(dst) ? (dst << 1) : TMP_FREG1; + sljit_s32 dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG1; if (FAST_IS_REG(src)) FAIL_IF(push_inst(compiler, MTC1 | flags | T(src) | FS(TMP_FREG1), MOVABLE_INS)); else if (src & SLJIT_MEM) { /* Load the integer value into a VFP register. */ - FAIL_IF(emit_op_mem2(compiler, ((flags) ? DOUBLE_DATA : SINGLE_DATA) | LOAD_DATA, TMP_FREG1, src, srcw, dst, dstw)); + FAIL_IF(emit_op_mem2(compiler, ((flags) ? DOUBLE_DATA : SINGLE_DATA) | LOAD_DATA, FR(TMP_FREG1), src, srcw, dst, dstw)); } else { #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) @@ -1376,7 +1366,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_comp FAIL_IF(push_inst(compiler, CVT_S_S | flags | (4 << 21) | (((op & SLJIT_F32_OP) ^ SLJIT_F32_OP) >> 8) | FS(TMP_FREG1) | FD(dst_r), MOVABLE_INS)); if (dst & SLJIT_MEM) - return emit_op_mem2(compiler, FLOAT_DATA(op), TMP_FREG1, dst, dstw, 0, 0); + return emit_op_mem2(compiler, FLOAT_DATA(op), FR(TMP_FREG1), dst, dstw, 0, 0); return SLJIT_SUCCESS; #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) @@ -1391,18 +1381,14 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_cmp(struct sljit_compiler *compile sljit_ins inst; if (src1 & SLJIT_MEM) { - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, src2, src2w)); + FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG1), src1, src1w, src2, src2w)); src1 = TMP_FREG1; } - else - src1 <<= 1; if (src2 & SLJIT_MEM) { - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, 0, 0)); + FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG2), src2, src2w, 0, 0)); src2 = TMP_FREG2; } - else - src2 <<= 1; switch (GET_FLAG_TYPE(op)) { case SLJIT_EQUAL_F64: @@ -1442,14 +1428,12 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compil if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32) op ^= SLJIT_F32_OP; - dst_r = FAST_IS_REG(dst) ? (dst << 1) : TMP_FREG1; + dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG1; if (src & SLJIT_MEM) { - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, dst_r, src, srcw, dst, dstw)); + FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(dst_r), src, srcw, dst, dstw)); src = dst_r; } - else - src <<= 1; switch (GET_OPCODE(op)) { case SLJIT_MOV_F64: @@ -1473,7 +1457,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compil } if (dst & SLJIT_MEM) - return emit_op_mem2(compiler, FLOAT_DATA(op), dst_r, dst, dstw, 0, 0); + return emit_op_mem2(compiler, FLOAT_DATA(op), FR(dst_r), dst, dstw, 0, 0); return SLJIT_SUCCESS; } @@ -1493,42 +1477,38 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil compiler->cache_arg = 0; compiler->cache_argw = 0; - dst_r = FAST_IS_REG(dst) ? (dst << 1) : TMP_FREG2; + dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG2; if (src1 & SLJIT_MEM) { - if (getput_arg_fast(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w)) { + if (getput_arg_fast(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG1), src1, src1w)) { FAIL_IF(compiler->error); src1 = TMP_FREG1; } else flags |= SLOW_SRC1; } - else - src1 <<= 1; if (src2 & SLJIT_MEM) { - if (getput_arg_fast(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w)) { + if (getput_arg_fast(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG2), src2, src2w)) { FAIL_IF(compiler->error); src2 = TMP_FREG2; } else flags |= SLOW_SRC2; } - else - src2 <<= 1; if ((flags & (SLOW_SRC1 | SLOW_SRC2)) == (SLOW_SRC1 | SLOW_SRC2)) { if (!can_cache(src1, src1w, src2, src2w) && can_cache(src1, src1w, dst, dstw)) { - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, src1, src1w)); - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, dst, dstw)); + FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG2), src2, src2w, src1, src1w)); + FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG1), src1, src1w, dst, dstw)); } else { - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, src2, src2w)); - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, dst, dstw)); + FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG1), src1, src1w, src2, src2w)); + FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG2), src2, src2w, dst, dstw)); } } else if (flags & SLOW_SRC1) - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, dst, dstw)); + FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG1), src1, src1w, dst, dstw)); else if (flags & SLOW_SRC2) - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, dst, dstw)); + FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, FR(TMP_FREG2), src2, src2w, dst, dstw)); if (flags & SLOW_SRC1) src1 = TMP_FREG1; @@ -1554,7 +1534,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil } if (dst_r == TMP_FREG2) - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op), TMP_FREG2, dst, dstw, 0, 0)); + FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op), FR(TMP_FREG2), dst, dstw, 0, 0)); return SLJIT_SUCCESS; } @@ -1584,10 +1564,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler if (FAST_IS_REG(src)) FAIL_IF(push_inst(compiler, ADDU_W | S(src) | TA(0) | DA(RETURN_ADDR_REG), RETURN_ADDR_REG)); - else if (src & SLJIT_MEM) + else FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, RETURN_ADDR_REG, src, srcw)); - else if (src & SLJIT_IMM) - FAIL_IF(load_immediate(compiler, RETURN_ADDR_REG, srcw)); FAIL_IF(push_inst(compiler, JR | SA(RETURN_ADDR_REG), UNMOVABLE_INS)); return push_inst(compiler, NOP, UNMOVABLE_INS); @@ -1704,19 +1682,16 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile PTR_FAIL_IF(push_inst(compiler, inst, UNMOVABLE_INS)); PTR_FAIL_IF(emit_const(compiler, TMP_REG2, 0)); - if (type <= SLJIT_JUMP) { + + if (type <= SLJIT_JUMP) PTR_FAIL_IF(push_inst(compiler, JR | S(TMP_REG2), UNMOVABLE_INS)); - jump->addr = compiler->size; - PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS)); - } else { - SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25 && PIC_ADDR_REG == TMP_REG2); - /* Cannot be optimized out if type is >= CALL0. */ - jump->flags |= IS_JAL | (type >= SLJIT_CALL0 ? IS_CALL : 0); + else { + jump->flags |= IS_JAL; PTR_FAIL_IF(push_inst(compiler, JALR | S(TMP_REG2) | DA(RETURN_ADDR_REG), UNMOVABLE_INS)); - jump->addr = compiler->size; - /* A NOP if type < CALL1. */ - PTR_FAIL_IF(push_inst(compiler, ADDU_W | S(SLJIT_R0) | TA(0) | DA(4), UNMOVABLE_INS)); } + + jump->addr = compiler->size; + PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS)); return jump; } @@ -1872,41 +1847,12 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) { - sljit_s32 src_r = TMP_REG2; struct sljit_jump *jump = NULL; CHECK_ERROR(); CHECK(check_sljit_emit_ijump(compiler, type, src, srcw)); ADJUST_LOCAL_OFFSET(src, srcw); - if (FAST_IS_REG(src)) { - if (DR(src) != 4) - src_r = src; - else - FAIL_IF(push_inst(compiler, ADDU_W | S(src) | TA(0) | D(TMP_REG2), DR(TMP_REG2))); - } - - if (type >= SLJIT_CALL0) { - SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25 && PIC_ADDR_REG == TMP_REG2); - if (src & (SLJIT_IMM | SLJIT_MEM)) { - if (src & SLJIT_IMM) - FAIL_IF(load_immediate(compiler, DR(PIC_ADDR_REG), srcw)); - else { - SLJIT_ASSERT(src_r == TMP_REG2 && (src & SLJIT_MEM)); - FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, TMP_REG2, 0, TMP_REG1, 0, src, srcw)); - } - FAIL_IF(push_inst(compiler, JALR | S(PIC_ADDR_REG) | DA(RETURN_ADDR_REG), UNMOVABLE_INS)); - /* We need an extra instruction in any case. */ - return push_inst(compiler, ADDU_W | S(SLJIT_R0) | TA(0) | DA(4), UNMOVABLE_INS); - } - - /* Register input. */ - if (type >= SLJIT_CALL1) - FAIL_IF(push_inst(compiler, ADDU_W | S(SLJIT_R0) | TA(0) | DA(4), 4)); - FAIL_IF(push_inst(compiler, JALR | S(src_r) | DA(RETURN_ADDR_REG), UNMOVABLE_INS)); - return push_inst(compiler, ADDU_W | S(src_r) | TA(0) | D(PIC_ADDR_REG), UNMOVABLE_INS); - } - if (src & SLJIT_IMM) { jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); FAIL_IF(!jump); @@ -1917,11 +1863,14 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi jump->flags |= IS_MOVABLE; FAIL_IF(emit_const(compiler, TMP_REG2, 0)); + src = TMP_REG2; + } + else if (src & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, DR(TMP_REG2), src, srcw)); + src = TMP_REG2; } - else if (src & SLJIT_MEM) - FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, TMP_REG2, 0, TMP_REG1, 0, src, srcw)); - FAIL_IF(push_inst(compiler, JR | S(src_r), UNMOVABLE_INS)); + FAIL_IF(push_inst(compiler, JR | S(src), UNMOVABLE_INS)); if (jump) jump->addr = compiler->size; FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS)); diff --git a/pcre/sljit/sljitNativePPC_64.c b/pcre/sljit/sljitNativePPC_64.c index 5366c30d90c..706b2ba20b5 100644 --- a/pcre/sljit/sljitNativePPC_64.c +++ b/pcre/sljit/sljitNativePPC_64.c @@ -413,6 +413,61 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl return SLJIT_SUCCESS; } +static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_s32 *src) +{ + sljit_s32 arg_count = 0; + sljit_s32 word_arg_count = 0; + sljit_s32 types = 0; + sljit_s32 reg = 0; + + if (src) + reg = *src & REG_MASK; + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + types = (types << SLJIT_DEF_SHIFT) | (arg_types & SLJIT_DEF_MASK); + + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + case SLJIT_ARG_TYPE_F64: + arg_count++; + break; + default: + arg_count++; + word_arg_count++; + + if (arg_count != word_arg_count && arg_count == reg) { + FAIL_IF(push_inst(compiler, OR | S(reg) | A(TMP_CALL_REG) | B(reg))); + *src = TMP_CALL_REG; + } + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + while (types) { + switch (types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + case SLJIT_ARG_TYPE_F64: + arg_count--; + break; + default: + if (arg_count != word_arg_count) + FAIL_IF(push_inst(compiler, OR | S(word_arg_count) | A(arg_count) | B(word_arg_count))); + + arg_count--; + word_arg_count--; + break; + } + + types >>= SLJIT_DEF_SHIFT; + } + + return SLJIT_SUCCESS; +} + static SLJIT_INLINE sljit_s32 emit_const(struct sljit_compiler *compiler, sljit_s32 reg, sljit_sw init_value) { FAIL_IF(push_inst(compiler, ADDIS | D(reg) | A(0) | IMM(init_value >> 48))); diff --git a/pcre/sljit/sljitNativePPC_common.c b/pcre/sljit/sljitNativePPC_common.c index 775c708f2f9..5ef4ac96c4a 100644 --- a/pcre/sljit/sljitNativePPC_common.c +++ b/pcre/sljit/sljitNativePPC_common.c @@ -93,20 +93,23 @@ static void ppc_cache_flush(sljit_ins *from, sljit_ins *to) #define TMP_REG1 (SLJIT_NUMBER_OF_REGISTERS + 2) #define TMP_REG2 (SLJIT_NUMBER_OF_REGISTERS + 3) -#define TMP_REG3 (SLJIT_NUMBER_OF_REGISTERS + 4) -#define TMP_ZERO (SLJIT_NUMBER_OF_REGISTERS + 5) +#define TMP_ZERO (SLJIT_NUMBER_OF_REGISTERS + 4) #if (defined SLJIT_PASS_ENTRY_ADDR_TO_CALL && SLJIT_PASS_ENTRY_ADDR_TO_CALL) -#define TMP_CALL_REG (SLJIT_NUMBER_OF_REGISTERS + 6) +#define TMP_CALL_REG (SLJIT_NUMBER_OF_REGISTERS + 5) #else #define TMP_CALL_REG TMP_REG2 #endif -#define TMP_FREG1 (0) -#define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) +#define TMP_FREG1 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) +#define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2) static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 7] = { - 0, 3, 4, 5, 6, 7, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 8, 9, 10, 31, 12 + 0, 3, 4, 5, 6, 7, 8, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 9, 10, 31, 12 +}; + +static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = { + 0, 1, 2, 3, 4, 5, 6, 0, 7 }; /* --------------------------------------------------------------------- */ @@ -117,11 +120,11 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 7] = { #define A(a) (reg_map[a] << 16) #define B(b) (reg_map[b] << 11) #define C(c) (reg_map[c] << 6) -#define FD(fd) ((fd) << 21) -#define FS(fs) ((fs) << 21) -#define FA(fa) ((fa) << 16) -#define FB(fb) ((fb) << 11) -#define FC(fc) ((fc) << 6) +#define FD(fd) (freg_map[fd] << 21) +#define FS(fs) (freg_map[fs] << 21) +#define FA(fa) (freg_map[fa] << 16) +#define FB(fb) (freg_map[fb] << 11) +#define FC(fc) (freg_map[fc] << 6) #define IMM(imm) ((imm) & 0xffff) #define CRD(d) ((d) << 21) @@ -536,7 +539,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) return 1; #endif - case SLJIT_HAS_PRE_UPDATE: case SLJIT_HAS_CLZ: return 1; @@ -554,46 +556,40 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) /* Creates an index in data_transfer_insts array. */ #define LOAD_DATA 0x01 #define INDEXED 0x02 -#define WRITE_BACK 0x04 +#define SIGNED_DATA 0x04 + #define WORD_DATA 0x00 #define BYTE_DATA 0x08 #define HALF_DATA 0x10 #define INT_DATA 0x18 -#define SIGNED_DATA 0x20 /* Separates integer and floating point registers */ -#define GPR_REG 0x3f -#define DOUBLE_DATA 0x40 +#define GPR_REG 0x1f +#define DOUBLE_DATA 0x20 #define MEM_MASK 0x7f /* Other inp_flags. */ -#define ARG_TEST 0x000100 /* Integer opertion and set flags -> requires exts on 64 bit systems. */ -#define ALT_SIGN_EXT 0x000200 +#define ALT_SIGN_EXT 0x000100 /* This flag affects the RC() and OERC() macros. */ #define ALT_SET_FLAGS 0x000400 -#define ALT_KEEP_CACHE 0x000800 -#define ALT_FORM1 0x010000 -#define ALT_FORM2 0x020000 -#define ALT_FORM3 0x040000 -#define ALT_FORM4 0x080000 -#define ALT_FORM5 0x100000 +#define ALT_FORM1 0x001000 +#define ALT_FORM2 0x002000 +#define ALT_FORM3 0x004000 +#define ALT_FORM4 0x008000 +#define ALT_FORM5 0x010000 /* Source and destination is register. */ #define REG_DEST 0x000001 #define REG1_SOURCE 0x000002 #define REG2_SOURCE 0x000004 -/* getput_arg_fast returned true. */ -#define FAST_DEST 0x000008 -/* Multiple instructions are required. */ -#define SLOW_DEST 0x000010 /* -ALT_SIGN_EXT 0x000200 -ALT_SET_FLAGS 0x000400 -ALT_FORM1 0x010000 +ALT_SIGN_EXT 0x000100 +ALT_SET_FLAGS 0x000200 +ALT_FORM1 0x001000 ... -ALT_FORM5 0x100000 */ +ALT_FORM5 0x010000 */ #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) #include "sljitNativePPC_32.c" @@ -610,14 +606,14 @@ ALT_FORM5 0x100000 */ #endif SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { - sljit_s32 i, tmp, offs; + sljit_s32 args, i, tmp, offs; CHECK_ERROR(); - CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); FAIL_IF(push_inst(compiler, MFLR | D(0))); offs = -(sljit_s32)(sizeof(sljit_sw)); @@ -643,6 +639,9 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi #endif FAIL_IF(push_inst(compiler, ADDI | D(TMP_ZERO) | A(0) | 0)); + + args = get_arg_count(arg_types); + if (args >= 1) FAIL_IF(push_inst(compiler, OR | S(SLJIT_R0) | A(SLJIT_S0) | B(SLJIT_R0))); if (args >= 2) @@ -674,12 +673,12 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { CHECK_ERROR(); - CHECK(check_sljit_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); local_size += GET_SAVED_REGISTERS_SIZE(scratches, saveds, 1) + SLJIT_LOCALS_OFFSET; compiler->local_size = (local_size + 15) & ~0xf; @@ -738,17 +737,17 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *comp /* Operators */ /* --------------------------------------------------------------------- */ -/* i/x - immediate/indexed form - n/w - no write-back / write-back (1 bit) - s/l - store/load (1 bit) +/* s/l - store/load (1 bit) + i/x - immediate/indexed form u/s - signed/unsigned (1 bit) w/b/h/i - word/byte/half/int allowed (2 bit) - It contans 32 items, but not all are different. */ + + Some opcodes are repeated (e.g. store signed / unsigned byte is the same instruction). */ /* 64 bit only: [reg+imm] must be aligned to 4 bytes. */ +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) #define INT_ALIGNED 0x10000 -/* 64-bit only: there is no lwau instruction. */ -#define UPDATE_REQ 0x20000 +#endif #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) #define ARCH_32_64(a, b) a @@ -757,397 +756,217 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *comp #else #define ARCH_32_64(a, b) b #define INST_CODE_AND_DST(inst, flags, reg) \ - (((inst) & ~(INT_ALIGNED | UPDATE_REQ)) | (((flags) & MEM_MASK) <= GPR_REG ? D(reg) : FD(reg))) + (((inst) & ~INT_ALIGNED) | (((flags) & MEM_MASK) <= GPR_REG ? D(reg) : FD(reg))) #endif -static const sljit_ins data_transfer_insts[64 + 8] = { +static const sljit_ins data_transfer_insts[64 + 16] = { -/* -------- Unsigned -------- */ +/* -------- Integer -------- */ /* Word. */ -/* u w n i s */ ARCH_32_64(HI(36) /* stw */, HI(62) | INT_ALIGNED | 0x0 /* std */), -/* u w n i l */ ARCH_32_64(HI(32) /* lwz */, HI(58) | INT_ALIGNED | 0x0 /* ld */), -/* u w n x s */ ARCH_32_64(HI(31) | LO(151) /* stwx */, HI(31) | LO(149) /* stdx */), -/* u w n x l */ ARCH_32_64(HI(31) | LO(23) /* lwzx */, HI(31) | LO(21) /* ldx */), +/* w u i s */ ARCH_32_64(HI(36) /* stw */, HI(62) | INT_ALIGNED | 0x0 /* std */), +/* w u i l */ ARCH_32_64(HI(32) /* lwz */, HI(58) | INT_ALIGNED | 0x0 /* ld */), +/* w u x s */ ARCH_32_64(HI(31) | LO(151) /* stwx */, HI(31) | LO(149) /* stdx */), +/* w u x l */ ARCH_32_64(HI(31) | LO(23) /* lwzx */, HI(31) | LO(21) /* ldx */), -/* u w w i s */ ARCH_32_64(HI(37) /* stwu */, HI(62) | INT_ALIGNED | 0x1 /* stdu */), -/* u w w i l */ ARCH_32_64(HI(33) /* lwzu */, HI(58) | INT_ALIGNED | 0x1 /* ldu */), -/* u w w x s */ ARCH_32_64(HI(31) | LO(183) /* stwux */, HI(31) | LO(181) /* stdux */), -/* u w w x l */ ARCH_32_64(HI(31) | LO(55) /* lwzux */, HI(31) | LO(53) /* ldux */), +/* w s i s */ ARCH_32_64(HI(36) /* stw */, HI(62) | INT_ALIGNED | 0x0 /* std */), +/* w s i l */ ARCH_32_64(HI(32) /* lwz */, HI(58) | INT_ALIGNED | 0x0 /* ld */), +/* w s x s */ ARCH_32_64(HI(31) | LO(151) /* stwx */, HI(31) | LO(149) /* stdx */), +/* w s x l */ ARCH_32_64(HI(31) | LO(23) /* lwzx */, HI(31) | LO(21) /* ldx */), /* Byte. */ -/* u b n i s */ HI(38) /* stb */, -/* u b n i l */ HI(34) /* lbz */, -/* u b n x s */ HI(31) | LO(215) /* stbx */, -/* u b n x l */ HI(31) | LO(87) /* lbzx */, +/* b u i s */ HI(38) /* stb */, +/* b u i l */ HI(34) /* lbz */, +/* b u x s */ HI(31) | LO(215) /* stbx */, +/* b u x l */ HI(31) | LO(87) /* lbzx */, -/* u b w i s */ HI(39) /* stbu */, -/* u b w i l */ HI(35) /* lbzu */, -/* u b w x s */ HI(31) | LO(247) /* stbux */, -/* u b w x l */ HI(31) | LO(119) /* lbzux */, +/* b s i s */ HI(38) /* stb */, +/* b s i l */ HI(34) /* lbz */ /* EXTS_REQ */, +/* b s x s */ HI(31) | LO(215) /* stbx */, +/* b s x l */ HI(31) | LO(87) /* lbzx */ /* EXTS_REQ */, /* Half. */ -/* u h n i s */ HI(44) /* sth */, -/* u h n i l */ HI(40) /* lhz */, -/* u h n x s */ HI(31) | LO(407) /* sthx */, -/* u h n x l */ HI(31) | LO(279) /* lhzx */, +/* h u i s */ HI(44) /* sth */, +/* h u i l */ HI(40) /* lhz */, +/* h u x s */ HI(31) | LO(407) /* sthx */, +/* h u x l */ HI(31) | LO(279) /* lhzx */, -/* u h w i s */ HI(45) /* sthu */, -/* u h w i l */ HI(41) /* lhzu */, -/* u h w x s */ HI(31) | LO(439) /* sthux */, -/* u h w x l */ HI(31) | LO(311) /* lhzux */, +/* h s i s */ HI(44) /* sth */, +/* h s i l */ HI(42) /* lha */, +/* h s x s */ HI(31) | LO(407) /* sthx */, +/* h s x l */ HI(31) | LO(343) /* lhax */, /* Int. */ -/* u i n i s */ HI(36) /* stw */, -/* u i n i l */ HI(32) /* lwz */, -/* u i n x s */ HI(31) | LO(151) /* stwx */, -/* u i n x l */ HI(31) | LO(23) /* lwzx */, +/* i u i s */ HI(36) /* stw */, +/* i u i l */ HI(32) /* lwz */, +/* i u x s */ HI(31) | LO(151) /* stwx */, +/* i u x l */ HI(31) | LO(23) /* lwzx */, + +/* i s i s */ HI(36) /* stw */, +/* i s i l */ ARCH_32_64(HI(32) /* lwz */, HI(58) | INT_ALIGNED | 0x2 /* lwa */), +/* i s x s */ HI(31) | LO(151) /* stwx */, +/* i s x l */ ARCH_32_64(HI(31) | LO(23) /* lwzx */, HI(31) | LO(341) /* lwax */), -/* u i w i s */ HI(37) /* stwu */, -/* u i w i l */ HI(33) /* lwzu */, -/* u i w x s */ HI(31) | LO(183) /* stwux */, -/* u i w x l */ HI(31) | LO(55) /* lwzux */, +/* -------- Floating point -------- */ -/* -------- Signed -------- */ +/* d i s */ HI(54) /* stfd */, +/* d i l */ HI(50) /* lfd */, +/* d x s */ HI(31) | LO(727) /* stfdx */, +/* d x l */ HI(31) | LO(599) /* lfdx */, + +/* s i s */ HI(52) /* stfs */, +/* s i l */ HI(48) /* lfs */, +/* s x s */ HI(31) | LO(663) /* stfsx */, +/* s x l */ HI(31) | LO(535) /* lfsx */, +}; + +static const sljit_ins updated_data_transfer_insts[64] = { + +/* -------- Integer -------- */ /* Word. */ -/* s w n i s */ ARCH_32_64(HI(36) /* stw */, HI(62) | INT_ALIGNED | 0x0 /* std */), -/* s w n i l */ ARCH_32_64(HI(32) /* lwz */, HI(58) | INT_ALIGNED | 0x0 /* ld */), -/* s w n x s */ ARCH_32_64(HI(31) | LO(151) /* stwx */, HI(31) | LO(149) /* stdx */), -/* s w n x l */ ARCH_32_64(HI(31) | LO(23) /* lwzx */, HI(31) | LO(21) /* ldx */), +/* w u i s */ ARCH_32_64(HI(37) /* stwu */, HI(62) | INT_ALIGNED | 0x1 /* stdu */), +/* w u i l */ ARCH_32_64(HI(33) /* lwzu */, HI(58) | INT_ALIGNED | 0x1 /* ldu */), +/* w u x s */ ARCH_32_64(HI(31) | LO(183) /* stwux */, HI(31) | LO(181) /* stdux */), +/* w u x l */ ARCH_32_64(HI(31) | LO(55) /* lwzux */, HI(31) | LO(53) /* ldux */), -/* s w w i s */ ARCH_32_64(HI(37) /* stwu */, HI(62) | INT_ALIGNED | 0x1 /* stdu */), -/* s w w i l */ ARCH_32_64(HI(33) /* lwzu */, HI(58) | INT_ALIGNED | 0x1 /* ldu */), -/* s w w x s */ ARCH_32_64(HI(31) | LO(183) /* stwux */, HI(31) | LO(181) /* stdux */), -/* s w w x l */ ARCH_32_64(HI(31) | LO(55) /* lwzux */, HI(31) | LO(53) /* ldux */), +/* w s i s */ ARCH_32_64(HI(37) /* stwu */, HI(62) | INT_ALIGNED | 0x1 /* stdu */), +/* w s i l */ ARCH_32_64(HI(33) /* lwzu */, HI(58) | INT_ALIGNED | 0x1 /* ldu */), +/* w s x s */ ARCH_32_64(HI(31) | LO(183) /* stwux */, HI(31) | LO(181) /* stdux */), +/* w s x l */ ARCH_32_64(HI(31) | LO(55) /* lwzux */, HI(31) | LO(53) /* ldux */), /* Byte. */ -/* s b n i s */ HI(38) /* stb */, -/* s b n i l */ HI(34) /* lbz */ /* EXTS_REQ */, -/* s b n x s */ HI(31) | LO(215) /* stbx */, -/* s b n x l */ HI(31) | LO(87) /* lbzx */ /* EXTS_REQ */, +/* b u i s */ HI(39) /* stbu */, +/* b u i l */ HI(35) /* lbzu */, +/* b u x s */ HI(31) | LO(247) /* stbux */, +/* b u x l */ HI(31) | LO(119) /* lbzux */, -/* s b w i s */ HI(39) /* stbu */, -/* s b w i l */ HI(35) /* lbzu */ /* EXTS_REQ */, -/* s b w x s */ HI(31) | LO(247) /* stbux */, -/* s b w x l */ HI(31) | LO(119) /* lbzux */ /* EXTS_REQ */, +/* b s i s */ HI(39) /* stbu */, +/* b s i l */ 0 /* no such instruction */, +/* b s x s */ HI(31) | LO(247) /* stbux */, +/* b s x l */ 0 /* no such instruction */, /* Half. */ -/* s h n i s */ HI(44) /* sth */, -/* s h n i l */ HI(42) /* lha */, -/* s h n x s */ HI(31) | LO(407) /* sthx */, -/* s h n x l */ HI(31) | LO(343) /* lhax */, +/* h u i s */ HI(45) /* sthu */, +/* h u i l */ HI(41) /* lhzu */, +/* h u x s */ HI(31) | LO(439) /* sthux */, +/* h u x l */ HI(31) | LO(311) /* lhzux */, -/* s h w i s */ HI(45) /* sthu */, -/* s h w i l */ HI(43) /* lhau */, -/* s h w x s */ HI(31) | LO(439) /* sthux */, -/* s h w x l */ HI(31) | LO(375) /* lhaux */, +/* h s i s */ HI(45) /* sthu */, +/* h s i l */ HI(43) /* lhau */, +/* h s x s */ HI(31) | LO(439) /* sthux */, +/* h s x l */ HI(31) | LO(375) /* lhaux */, /* Int. */ -/* s i n i s */ HI(36) /* stw */, -/* s i n i l */ ARCH_32_64(HI(32) /* lwz */, HI(58) | INT_ALIGNED | 0x2 /* lwa */), -/* s i n x s */ HI(31) | LO(151) /* stwx */, -/* s i n x l */ ARCH_32_64(HI(31) | LO(23) /* lwzx */, HI(31) | LO(341) /* lwax */), - -/* s i w i s */ HI(37) /* stwu */, -/* s i w i l */ ARCH_32_64(HI(33) /* lwzu */, HI(58) | INT_ALIGNED | UPDATE_REQ | 0x2 /* lwa */), -/* s i w x s */ HI(31) | LO(183) /* stwux */, -/* s i w x l */ ARCH_32_64(HI(31) | LO(55) /* lwzux */, HI(31) | LO(373) /* lwaux */), +/* i u i s */ HI(37) /* stwu */, +/* i u i l */ HI(33) /* lwzu */, +/* i u x s */ HI(31) | LO(183) /* stwux */, +/* i u x l */ HI(31) | LO(55) /* lwzux */, -/* -------- Double -------- */ +/* i s i s */ HI(37) /* stwu */, +/* i s i l */ ARCH_32_64(HI(33) /* lwzu */, 0 /* no such instruction */), +/* i s x s */ HI(31) | LO(183) /* stwux */, +/* i s x l */ ARCH_32_64(HI(31) | LO(55) /* lwzux */, HI(31) | LO(373) /* lwaux */), -/* d n i s */ HI(54) /* stfd */, -/* d n i l */ HI(50) /* lfd */, -/* d n x s */ HI(31) | LO(727) /* stfdx */, -/* d n x l */ HI(31) | LO(599) /* lfdx */, +/* -------- Floating point -------- */ -/* s n i s */ HI(52) /* stfs */, -/* s n i l */ HI(48) /* lfs */, -/* s n x s */ HI(31) | LO(663) /* stfsx */, -/* s n x l */ HI(31) | LO(535) /* lfsx */, +/* d i s */ HI(55) /* stfdu */, +/* d i l */ HI(51) /* lfdu */, +/* d x s */ HI(31) | LO(759) /* stfdux */, +/* d x l */ HI(31) | LO(631) /* lfdux */, +/* s i s */ HI(53) /* stfsu */, +/* s i l */ HI(49) /* lfsu */, +/* s x s */ HI(31) | LO(695) /* stfsux */, +/* s x l */ HI(31) | LO(567) /* lfsux */, }; #undef ARCH_32_64 /* Simple cases, (no caching is required). */ -static sljit_s32 getput_arg_fast(struct sljit_compiler *compiler, sljit_s32 inp_flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw) +static sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit_s32 inp_flags, sljit_s32 reg, + sljit_s32 arg, sljit_sw argw, sljit_s32 tmp_reg) { sljit_ins inst; + sljit_s32 offs_reg; + sljit_sw high_short; /* Should work when (arg & REG_MASK) == 0. */ SLJIT_ASSERT(A(0) == 0); SLJIT_ASSERT(arg & SLJIT_MEM); - if (arg & OFFS_REG_MASK) { - if (argw & 0x3) - return 0; - if (inp_flags & ARG_TEST) - return 1; - - inst = data_transfer_insts[(inp_flags | INDEXED) & MEM_MASK]; - SLJIT_ASSERT(!(inst & (INT_ALIGNED | UPDATE_REQ))); - FAIL_IF(push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(arg & REG_MASK) | B(OFFS_REG(arg)))); - return -1; - } - - if (SLJIT_UNLIKELY(!(arg & REG_MASK))) - inp_flags &= ~WRITE_BACK; - -#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) - inst = data_transfer_insts[inp_flags & MEM_MASK]; - SLJIT_ASSERT((arg & REG_MASK) || !(inst & UPDATE_REQ)); - - if (argw > SIMM_MAX || argw < SIMM_MIN || ((inst & INT_ALIGNED) && (argw & 0x3)) || (inst & UPDATE_REQ)) - return 0; - if (inp_flags & ARG_TEST) - return 1; -#endif + if (SLJIT_UNLIKELY(arg & OFFS_REG_MASK)) { + argw &= 0x3; + offs_reg = OFFS_REG(arg); + if (argw != 0) { #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) - if (argw > SIMM_MAX || argw < SIMM_MIN) - return 0; - if (inp_flags & ARG_TEST) - return 1; - - inst = data_transfer_insts[inp_flags & MEM_MASK]; - SLJIT_ASSERT(!(inst & (INT_ALIGNED | UPDATE_REQ))); + FAIL_IF(push_inst(compiler, RLWINM | S(OFFS_REG(arg)) | A(tmp_reg) | (argw << 11) | ((31 - argw) << 1))); +#else + FAIL_IF(push_inst(compiler, RLDI(tmp_reg, OFFS_REG(arg), argw, 63 - argw, 1))); #endif + offs_reg = tmp_reg; + } - FAIL_IF(push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(arg & REG_MASK) | IMM(argw))); - return -1; -} + inst = data_transfer_insts[(inp_flags | INDEXED) & MEM_MASK]; -/* See getput_arg below. - Note: can_cache is called only for binary operators. Those operator always - uses word arguments without write back. */ -static sljit_s32 can_cache(sljit_s32 arg, sljit_sw argw, sljit_s32 next_arg, sljit_sw next_argw) -{ - sljit_sw high_short, next_high_short; #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) - sljit_sw diff; + SLJIT_ASSERT(!(inst & INT_ALIGNED)); #endif - SLJIT_ASSERT((arg & SLJIT_MEM) && (next_arg & SLJIT_MEM)); - - if (arg & OFFS_REG_MASK) - return ((arg & OFFS_REG_MASK) == (next_arg & OFFS_REG_MASK) && (argw & 0x3) == (next_argw & 0x3)); - - if (next_arg & OFFS_REG_MASK) - return 0; - -#if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) - high_short = (argw + ((argw & 0x8000) << 1)) & ~0xffff; - next_high_short = (next_argw + ((next_argw & 0x8000) << 1)) & ~0xffff; - return high_short == next_high_short; -#else - if (argw <= 0x7fffffffl && argw >= -0x80000000l) { - high_short = (argw + ((argw & 0x8000) << 1)) & ~0xffff; - next_high_short = (next_argw + ((next_argw & 0x8000) << 1)) & ~0xffff; - if (high_short == next_high_short) - return 1; + return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(arg & REG_MASK) | B(offs_reg)); } - diff = argw - next_argw; - if (!(arg & REG_MASK)) - return diff <= SIMM_MAX && diff >= SIMM_MIN; - - if (arg == next_arg && diff <= SIMM_MAX && diff >= SIMM_MIN) - return 1; - - return 0; -#endif -} - -#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) -#define ADJUST_CACHED_IMM(imm) \ - if ((inst & INT_ALIGNED) && (imm & 0x3)) { \ - /* Adjust cached value. Fortunately this is really a rare case */ \ - compiler->cache_argw += imm & 0x3; \ - FAIL_IF(push_inst(compiler, ADDI | D(TMP_REG3) | A(TMP_REG3) | (imm & 0x3))); \ - imm &= ~0x3; \ - } -#endif + inst = data_transfer_insts[inp_flags & MEM_MASK]; + arg &= REG_MASK; -/* Emit the necessary instructions. See can_cache above. */ -static sljit_s32 getput_arg(struct sljit_compiler *compiler, sljit_s32 inp_flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw, sljit_s32 next_arg, sljit_sw next_argw) -{ - sljit_s32 tmp_r; - sljit_ins inst; - sljit_sw high_short, next_high_short; #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) - sljit_sw diff; -#endif - - SLJIT_ASSERT(arg & SLJIT_MEM); - - tmp_r = ((inp_flags & LOAD_DATA) && ((inp_flags) & MEM_MASK) <= GPR_REG) ? reg : TMP_REG1; - /* Special case for "mov reg, [reg, ... ]". */ - if ((arg & REG_MASK) == tmp_r) - tmp_r = TMP_REG1; - - if (SLJIT_UNLIKELY(arg & OFFS_REG_MASK)) { - argw &= 0x3; - /* Otherwise getput_arg_fast would capture it. */ - SLJIT_ASSERT(argw); + if ((inst & INT_ALIGNED) && (argw & 0x3) != 0) { + FAIL_IF(load_immediate(compiler, tmp_reg, argw)); - if ((SLJIT_MEM | (arg & OFFS_REG_MASK)) == compiler->cache_arg && argw == compiler->cache_argw) - tmp_r = TMP_REG3; - else { - if ((arg & OFFS_REG_MASK) == (next_arg & OFFS_REG_MASK) && argw == (next_argw & 0x3)) { - compiler->cache_arg = SLJIT_MEM | (arg & OFFS_REG_MASK); - compiler->cache_argw = argw; - tmp_r = TMP_REG3; - } -#if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) - FAIL_IF(push_inst(compiler, RLWINM | S(OFFS_REG(arg)) | A(tmp_r) | (argw << 11) | ((31 - argw) << 1))); -#else - FAIL_IF(push_inst(compiler, RLDI(tmp_r, OFFS_REG(arg), argw, 63 - argw, 1))); -#endif - } inst = data_transfer_insts[(inp_flags | INDEXED) & MEM_MASK]; - SLJIT_ASSERT(!(inst & (INT_ALIGNED | UPDATE_REQ))); - return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(arg & REG_MASK) | B(tmp_r)); + return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(arg) | B(tmp_reg)); } +#endif - if (SLJIT_UNLIKELY(!(arg & REG_MASK))) - inp_flags &= ~WRITE_BACK; - - inst = data_transfer_insts[inp_flags & MEM_MASK]; - SLJIT_ASSERT((arg & REG_MASK) || !(inst & UPDATE_REQ)); + if (argw <= SIMM_MAX && argw >= SIMM_MIN) + return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(arg) | IMM(argw)); #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) - if (argw <= 0x7fff7fffl && argw >= -0x80000000l - && (!(inst & INT_ALIGNED) || !(argw & 0x3)) && !(inst & UPDATE_REQ)) { + if (argw <= 0x7fff7fffl && argw >= -0x80000000l) { #endif - arg &= REG_MASK; high_short = (sljit_s32)(argw + ((argw & 0x8000) << 1)) & ~0xffff; - /* The getput_arg_fast should handle this otherwise. */ + #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) SLJIT_ASSERT(high_short && high_short <= 0x7fffffffl && high_short >= -0x80000000l); #else - SLJIT_ASSERT(high_short && !(inst & (INT_ALIGNED | UPDATE_REQ))); + SLJIT_ASSERT(high_short); #endif - if (inp_flags & WRITE_BACK) { - tmp_r = arg; - FAIL_IF(push_inst(compiler, ADDIS | D(arg) | A(arg) | IMM(high_short >> 16))); - } - else if (compiler->cache_arg != (SLJIT_MEM | arg) || high_short != compiler->cache_argw) { - if ((next_arg & SLJIT_MEM) && !(next_arg & OFFS_REG_MASK)) { - next_high_short = (sljit_s32)(next_argw + ((next_argw & 0x8000) << 1)) & ~0xffff; - if (high_short == next_high_short) { - compiler->cache_arg = SLJIT_MEM | arg; - compiler->cache_argw = high_short; - tmp_r = TMP_REG3; - } - } - FAIL_IF(push_inst(compiler, ADDIS | D(tmp_r) | A(arg & REG_MASK) | IMM(high_short >> 16))); - } - else - tmp_r = TMP_REG3; - - return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(tmp_r) | IMM(argw)); + FAIL_IF(push_inst(compiler, ADDIS | D(tmp_reg) | A(arg) | IMM(high_short >> 16))); + return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(tmp_reg) | IMM(argw)); #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) } - /* Everything else is PPC-64 only. */ - if (SLJIT_UNLIKELY(!(arg & REG_MASK))) { - diff = argw - compiler->cache_argw; - if ((compiler->cache_arg & SLJIT_IMM) && diff <= SIMM_MAX && diff >= SIMM_MIN) { - ADJUST_CACHED_IMM(diff); - return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(TMP_REG3) | IMM(diff)); - } + /* The rest is PPC-64 only. */ - diff = argw - next_argw; - if ((next_arg & SLJIT_MEM) && diff <= SIMM_MAX && diff >= SIMM_MIN) { - SLJIT_ASSERT(inp_flags & LOAD_DATA); + FAIL_IF(load_immediate(compiler, tmp_reg, argw)); - compiler->cache_arg = SLJIT_IMM; - compiler->cache_argw = argw; - tmp_r = TMP_REG3; - } - - FAIL_IF(load_immediate(compiler, tmp_r, argw)); - return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(tmp_r)); - } - - diff = argw - compiler->cache_argw; - if (compiler->cache_arg == arg && diff <= SIMM_MAX && diff >= SIMM_MIN) { - SLJIT_ASSERT(!(inp_flags & WRITE_BACK) && !(inst & UPDATE_REQ)); - ADJUST_CACHED_IMM(diff); - return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(TMP_REG3) | IMM(diff)); - } - - if ((compiler->cache_arg & SLJIT_IMM) && diff <= SIMM_MAX && diff >= SIMM_MIN) { - inst = data_transfer_insts[(inp_flags | INDEXED) & MEM_MASK]; - SLJIT_ASSERT(!(inst & (INT_ALIGNED | UPDATE_REQ))); - if (compiler->cache_argw != argw) { - FAIL_IF(push_inst(compiler, ADDI | D(TMP_REG3) | A(TMP_REG3) | IMM(diff))); - compiler->cache_argw = argw; - } - return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(arg & REG_MASK) | B(TMP_REG3)); - } - - if (argw == next_argw && (next_arg & SLJIT_MEM)) { - SLJIT_ASSERT(inp_flags & LOAD_DATA); - FAIL_IF(load_immediate(compiler, TMP_REG3, argw)); - - compiler->cache_arg = SLJIT_IMM; - compiler->cache_argw = argw; - - inst = data_transfer_insts[(inp_flags | INDEXED) & MEM_MASK]; - SLJIT_ASSERT(!(inst & (INT_ALIGNED | UPDATE_REQ))); - return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(arg & REG_MASK) | B(TMP_REG3)); - } - - diff = argw - next_argw; - if (arg == next_arg && !(inp_flags & WRITE_BACK) && diff <= SIMM_MAX && diff >= SIMM_MIN) { - SLJIT_ASSERT(inp_flags & LOAD_DATA); - FAIL_IF(load_immediate(compiler, TMP_REG3, argw)); - FAIL_IF(push_inst(compiler, ADD | D(TMP_REG3) | A(TMP_REG3) | B(arg & REG_MASK))); - - compiler->cache_arg = arg; - compiler->cache_argw = argw; - - return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(TMP_REG3)); - } - - if ((next_arg & SLJIT_MEM) && !(next_arg & OFFS_REG_MASK) && diff <= SIMM_MAX && diff >= SIMM_MIN) { - SLJIT_ASSERT(inp_flags & LOAD_DATA); - FAIL_IF(load_immediate(compiler, TMP_REG3, argw)); - - compiler->cache_arg = SLJIT_IMM; - compiler->cache_argw = argw; - tmp_r = TMP_REG3; - } - else - FAIL_IF(load_immediate(compiler, tmp_r, argw)); - - /* Get the indexed version instead of the normal one. */ inst = data_transfer_insts[(inp_flags | INDEXED) & MEM_MASK]; - SLJIT_ASSERT(!(inst & (INT_ALIGNED | UPDATE_REQ))); - return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(arg & REG_MASK) | B(tmp_r)); + return push_inst(compiler, INST_CODE_AND_DST(inst, inp_flags, reg) | A(arg) | B(tmp_reg)); #endif } -static SLJIT_INLINE sljit_s32 emit_op_mem2(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg1, sljit_sw arg1w, sljit_s32 arg2, sljit_sw arg2w) -{ - if (getput_arg_fast(compiler, flags, reg, arg1, arg1w)) - return compiler->error; - return getput_arg(compiler, flags, reg, arg1, arg1w, arg2, arg2w); -} - static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 input_flags, sljit_s32 dst, sljit_sw dstw, sljit_s32 src1, sljit_sw src1w, @@ -1155,40 +974,21 @@ static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s3 { /* arg1 goes to TMP_REG1 or src reg arg2 goes to TMP_REG2, imm or src reg - TMP_REG3 can be used for caching - result goes to TMP_REG2, so put result can use TMP_REG1 and TMP_REG3. */ - sljit_s32 dst_r; + result goes to TMP_REG2, so put result can use TMP_REG1. */ + sljit_s32 dst_r = TMP_REG2; sljit_s32 src1_r; sljit_s32 src2_r; sljit_s32 sugg_src2_r = TMP_REG2; sljit_s32 flags = input_flags & (ALT_FORM1 | ALT_FORM2 | ALT_FORM3 | ALT_FORM4 | ALT_FORM5 | ALT_SIGN_EXT | ALT_SET_FLAGS); - if (!(input_flags & ALT_KEEP_CACHE)) { - compiler->cache_arg = 0; - compiler->cache_argw = 0; - } - /* Destination check. */ - if (SLJIT_UNLIKELY(dst == SLJIT_UNUSED)) { - dst_r = TMP_REG2; - } - else if (FAST_IS_REG(dst)) { + if (SLOW_IS_REG(dst)) { dst_r = dst; flags |= REG_DEST; - if (op >= SLJIT_MOV && op <= SLJIT_MOVU_S32) + + if (op >= SLJIT_MOV && op <= SLJIT_MOV_P) sugg_src2_r = dst_r; } - else { - SLJIT_ASSERT(dst & SLJIT_MEM); - if (getput_arg_fast(compiler, input_flags | ARG_TEST, TMP_REG2, dst, dstw)) { - flags |= FAST_DEST; - dst_r = TMP_REG2; - } - else { - flags |= SLOW_DEST; - dst_r = 0; - } - } /* Source 1. */ if (FAST_IS_REG(src1)) { @@ -1199,80 +999,34 @@ static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s3 FAIL_IF(load_immediate(compiler, TMP_REG1, src1w)); src1_r = TMP_REG1; } - else if (getput_arg_fast(compiler, input_flags | LOAD_DATA, TMP_REG1, src1, src1w)) { - FAIL_IF(compiler->error); + else { + FAIL_IF(emit_op_mem(compiler, input_flags | LOAD_DATA, TMP_REG1, src1, src1w, TMP_REG1)); src1_r = TMP_REG1; } - else - src1_r = 0; /* Source 2. */ if (FAST_IS_REG(src2)) { src2_r = src2; flags |= REG2_SOURCE; - if (!(flags & REG_DEST) && op >= SLJIT_MOV && op <= SLJIT_MOVU_S32) + + if (!(flags & REG_DEST) && op >= SLJIT_MOV && op <= SLJIT_MOV_P) dst_r = src2_r; } else if (src2 & SLJIT_IMM) { FAIL_IF(load_immediate(compiler, sugg_src2_r, src2w)); src2_r = sugg_src2_r; } - else if (getput_arg_fast(compiler, input_flags | LOAD_DATA, sugg_src2_r, src2, src2w)) { - FAIL_IF(compiler->error); - src2_r = sugg_src2_r; - } - else - src2_r = 0; - - /* src1_r, src2_r and dst_r can be zero (=unprocessed). - All arguments are complex addressing modes, and it is a binary operator. */ - if (src1_r == 0 && src2_r == 0 && dst_r == 0) { - if (!can_cache(src1, src1w, src2, src2w) && can_cache(src1, src1w, dst, dstw)) { - FAIL_IF(getput_arg(compiler, input_flags | LOAD_DATA, TMP_REG2, src2, src2w, src1, src1w)); - FAIL_IF(getput_arg(compiler, input_flags | LOAD_DATA, TMP_REG1, src1, src1w, dst, dstw)); - } - else { - FAIL_IF(getput_arg(compiler, input_flags | LOAD_DATA, TMP_REG1, src1, src1w, src2, src2w)); - FAIL_IF(getput_arg(compiler, input_flags | LOAD_DATA, TMP_REG2, src2, src2w, dst, dstw)); - } - src1_r = TMP_REG1; - src2_r = TMP_REG2; - } - else if (src1_r == 0 && src2_r == 0) { - FAIL_IF(getput_arg(compiler, input_flags | LOAD_DATA, TMP_REG1, src1, src1w, src2, src2w)); - src1_r = TMP_REG1; - } - else if (src1_r == 0 && dst_r == 0) { - FAIL_IF(getput_arg(compiler, input_flags | LOAD_DATA, TMP_REG1, src1, src1w, dst, dstw)); - src1_r = TMP_REG1; - } - else if (src2_r == 0 && dst_r == 0) { - FAIL_IF(getput_arg(compiler, input_flags | LOAD_DATA, sugg_src2_r, src2, src2w, dst, dstw)); - src2_r = sugg_src2_r; - } - - if (dst_r == 0) - dst_r = TMP_REG2; - - if (src1_r == 0) { - FAIL_IF(getput_arg(compiler, input_flags | LOAD_DATA, TMP_REG1, src1, src1w, 0, 0)); - src1_r = TMP_REG1; - } - - if (src2_r == 0) { - FAIL_IF(getput_arg(compiler, input_flags | LOAD_DATA, sugg_src2_r, src2, src2w, 0, 0)); + else { + FAIL_IF(emit_op_mem(compiler, input_flags | LOAD_DATA, sugg_src2_r, src2, src2w, TMP_REG2)); src2_r = sugg_src2_r; } FAIL_IF(emit_single_op(compiler, op, flags, dst_r, src1_r, src2_r)); - if (flags & (FAST_DEST | SLOW_DEST)) { - if (flags & FAST_DEST) - FAIL_IF(getput_arg_fast(compiler, input_flags, dst_r, dst, dstw)); - else - FAIL_IF(getput_arg(compiler, input_flags, dst_r, dst, dstw, 0, 0)); - } - return SLJIT_SUCCESS; + if (!(dst & SLJIT_MEM)) + return SLJIT_SUCCESS; + + return emit_op_mem(compiler, input_flags, dst_r, dst, dstw, TMP_REG1); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op) @@ -1376,34 +1130,31 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile if (GET_FLAG_TYPE(op_flags) == SLJIT_OVERFLOW) FAIL_IF(push_inst(compiler, MTXER | S(TMP_ZERO))); + if (op < SLJIT_NOT && FAST_IS_REG(src) && src == dst) { + if (!TYPE_CAST_NEEDED(op)) + return SLJIT_SUCCESS; + } + +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) if (op_flags & SLJIT_I32_OP) { if (op < SLJIT_NOT) { - if (FAST_IS_REG(src) && src == dst) { - if (!TYPE_CAST_NEEDED(op)) - return SLJIT_SUCCESS; + if (src & SLJIT_MEM) { + if (op == SLJIT_MOV_S32) + op = SLJIT_MOV_U32; + } + else if (src & SLJIT_IMM) { + if (op == SLJIT_MOV_U32) + op = SLJIT_MOV_S32; } -#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) - if (op == SLJIT_MOV_S32 && (src & SLJIT_MEM)) - op = SLJIT_MOV_U32; - if (op == SLJIT_MOVU_S32 && (src & SLJIT_MEM)) - op = SLJIT_MOVU_U32; - if (op == SLJIT_MOV_U32 && (src & SLJIT_IMM)) - op = SLJIT_MOV_S32; - if (op == SLJIT_MOVU_U32 && (src & SLJIT_IMM)) - op = SLJIT_MOVU_S32; -#endif } -#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) else { /* Most operations expect sign extended arguments. */ flags |= INT_DATA | SIGNED_DATA; - if (src & SLJIT_IMM) - srcw = (sljit_s32)srcw; if (HAS_FLAGS(op_flags)) flags |= ALT_SIGN_EXT; } -#endif } +#endif switch (op) { case SLJIT_MOV: @@ -1434,34 +1185,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile case SLJIT_MOV_S16: return EMIT_MOV(SLJIT_MOV_S16, HALF_DATA | SIGNED_DATA, (sljit_s16)); - case SLJIT_MOVU: - case SLJIT_MOVU_P: -#if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) - case SLJIT_MOVU_U32: - case SLJIT_MOVU_S32: -#endif - return emit_op(compiler, SLJIT_MOV, flags | WORD_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw); - -#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) - case SLJIT_MOVU_U32: - return EMIT_MOV(SLJIT_MOV_U32, INT_DATA | WRITE_BACK, (sljit_u32)); - - case SLJIT_MOVU_S32: - return EMIT_MOV(SLJIT_MOV_S32, INT_DATA | SIGNED_DATA | WRITE_BACK, (sljit_s32)); -#endif - - case SLJIT_MOVU_U8: - return EMIT_MOV(SLJIT_MOV_U8, BYTE_DATA | WRITE_BACK, (sljit_u8)); - - case SLJIT_MOVU_S8: - return EMIT_MOV(SLJIT_MOV_S8, BYTE_DATA | SIGNED_DATA | WRITE_BACK, (sljit_s8)); - - case SLJIT_MOVU_U16: - return EMIT_MOV(SLJIT_MOV_U16, HALF_DATA | WRITE_BACK, (sljit_u16)); - - case SLJIT_MOVU_S16: - return EMIT_MOV(SLJIT_MOV_S16, HALF_DATA | SIGNED_DATA | WRITE_BACK, (sljit_s16)); - case SLJIT_NOT: return emit_op(compiler, SLJIT_NOT, flags, dst, dstw, TMP_REG1, 0, src, srcw); @@ -1549,8 +1272,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile #endif if (GET_FLAG_TYPE(op) == SLJIT_OVERFLOW) FAIL_IF(push_inst(compiler, MTXER | S(TMP_ZERO))); - if (src2 == TMP_REG2) - flags |= ALT_KEEP_CACHE; switch (GET_OPCODE(op)) { case SLJIT_ADD: @@ -1737,7 +1458,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg) SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_float_register_index(sljit_s32 reg) { CHECK_REG_INDEX(check_sljit_get_float_register_index(reg)); - return reg; + return freg_map[reg]; } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler, @@ -1777,7 +1498,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_comp { if (src & SLJIT_MEM) { /* We can ignore the temporary data store on the stack from caching point of view. */ - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src, srcw, dst, dstw)); + FAIL_IF(emit_op_mem(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src, srcw, TMP_REG1)); src = TMP_FREG1; } @@ -1787,10 +1508,10 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_comp if (op == SLJIT_CONV_SW_FROM_F64) { if (FAST_IS_REG(dst)) { - FAIL_IF(emit_op_mem2(compiler, DOUBLE_DATA, TMP_FREG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, 0, 0)); - return emit_op_mem2(compiler, WORD_DATA | LOAD_DATA, dst, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, 0, 0); + FAIL_IF(emit_op_mem(compiler, DOUBLE_DATA, TMP_FREG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, TMP_REG1)); + return emit_op_mem(compiler, WORD_DATA | LOAD_DATA, dst, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, TMP_REG1); } - return emit_op_mem2(compiler, DOUBLE_DATA, TMP_FREG1, dst, dstw, 0, 0); + return emit_op_mem(compiler, DOUBLE_DATA, TMP_FREG1, dst, dstw, TMP_REG1); } #else FAIL_IF(push_inst(compiler, FCTIWZ | FD(TMP_FREG1) | FB(src))); @@ -1799,7 +1520,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_comp if (FAST_IS_REG(dst)) { FAIL_IF(load_immediate(compiler, TMP_REG1, FLOAT_TMP_MEM_OFFSET)); FAIL_IF(push_inst(compiler, STFIWX | FS(TMP_FREG1) | A(SLJIT_SP) | B(TMP_REG1))); - return emit_op_mem2(compiler, INT_DATA | LOAD_DATA, dst, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, 0, 0); + return emit_op_mem(compiler, INT_DATA | LOAD_DATA, dst, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, TMP_REG1); } SLJIT_ASSERT(dst & SLJIT_MEM); @@ -1850,21 +1571,21 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_comp if (FAST_IS_REG(src)) FAIL_IF(push_inst(compiler, EXTSW | S(src) | A(TMP_REG1))); else - FAIL_IF(emit_op_mem2(compiler, INT_DATA | SIGNED_DATA | LOAD_DATA, TMP_REG1, src, srcw, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET)); + FAIL_IF(emit_op_mem(compiler, INT_DATA | SIGNED_DATA | LOAD_DATA, TMP_REG1, src, srcw, TMP_REG1)); src = TMP_REG1; } if (FAST_IS_REG(src)) { - FAIL_IF(emit_op_mem2(compiler, WORD_DATA, src, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET)); - FAIL_IF(emit_op_mem2(compiler, DOUBLE_DATA | LOAD_DATA, TMP_FREG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, dst, dstw)); + FAIL_IF(emit_op_mem(compiler, WORD_DATA, src, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, TMP_REG1)); + FAIL_IF(emit_op_mem(compiler, DOUBLE_DATA | LOAD_DATA, TMP_FREG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, TMP_REG1)); } else - FAIL_IF(emit_op_mem2(compiler, DOUBLE_DATA | LOAD_DATA, TMP_FREG1, src, srcw, dst, dstw)); + FAIL_IF(emit_op_mem(compiler, DOUBLE_DATA | LOAD_DATA, TMP_FREG1, src, srcw, TMP_REG1)); FAIL_IF(push_inst(compiler, FCFID | FD(dst_r) | FB(TMP_FREG1))); if (dst & SLJIT_MEM) - return emit_op_mem2(compiler, FLOAT_DATA(op), TMP_FREG1, dst, dstw, 0, 0); + return emit_op_mem(compiler, FLOAT_DATA(op), TMP_FREG1, dst, dstw, TMP_REG1); if (op & SLJIT_F32_OP) return push_inst(compiler, FRSP | FD(dst_r) | FB(dst_r)); return SLJIT_SUCCESS; @@ -1880,7 +1601,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_comp invert_sign = 0; } else if (!FAST_IS_REG(src)) { - FAIL_IF(emit_op_mem2(compiler, WORD_DATA | SIGNED_DATA | LOAD_DATA, TMP_REG1, src, srcw, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET_LOW)); + FAIL_IF(emit_op_mem(compiler, WORD_DATA | SIGNED_DATA | LOAD_DATA, TMP_REG1, src, srcw, TMP_REG1)); src = TMP_REG1; } @@ -1892,17 +1613,17 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_comp FAIL_IF(push_inst(compiler, ADDIS | D(TMP_REG2) | A(0) | 0x4330)); if (invert_sign) FAIL_IF(push_inst(compiler, XORIS | S(src) | A(TMP_REG1) | 0x8000)); - FAIL_IF(emit_op_mem2(compiler, WORD_DATA, TMP_REG2, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET_HI, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET)); - FAIL_IF(emit_op_mem2(compiler, WORD_DATA, TMP_REG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET_LOW, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET_HI)); + FAIL_IF(emit_op_mem(compiler, WORD_DATA, TMP_REG2, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET_HI, TMP_REG1)); + FAIL_IF(emit_op_mem(compiler, WORD_DATA, TMP_REG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET_LOW, TMP_REG2)); FAIL_IF(push_inst(compiler, ADDIS | D(TMP_REG1) | A(0) | 0x8000)); - FAIL_IF(emit_op_mem2(compiler, DOUBLE_DATA | LOAD_DATA, TMP_FREG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET_LOW)); - FAIL_IF(emit_op_mem2(compiler, WORD_DATA, TMP_REG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET_LOW, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET)); - FAIL_IF(emit_op_mem2(compiler, DOUBLE_DATA | LOAD_DATA, TMP_FREG2, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET_LOW)); + FAIL_IF(emit_op_mem(compiler, DOUBLE_DATA | LOAD_DATA, TMP_FREG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, TMP_REG1)); + FAIL_IF(emit_op_mem(compiler, WORD_DATA, TMP_REG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET_LOW, TMP_REG2)); + FAIL_IF(emit_op_mem(compiler, DOUBLE_DATA | LOAD_DATA, TMP_FREG2, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, TMP_REG1)); FAIL_IF(push_inst(compiler, FSUB | FD(dst_r) | FA(TMP_FREG1) | FB(TMP_FREG2))); if (dst & SLJIT_MEM) - return emit_op_mem2(compiler, FLOAT_DATA(op), TMP_FREG1, dst, dstw, 0, 0); + return emit_op_mem(compiler, FLOAT_DATA(op), TMP_FREG1, dst, dstw, TMP_REG1); if (op & SLJIT_F32_OP) return push_inst(compiler, FRSP | FD(dst_r) | FB(dst_r)); return SLJIT_SUCCESS; @@ -1915,12 +1636,12 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_cmp(struct sljit_compiler *compile sljit_s32 src2, sljit_sw src2w) { if (src1 & SLJIT_MEM) { - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, src2, src2w)); + FAIL_IF(emit_op_mem(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, TMP_REG1)); src1 = TMP_FREG1; } if (src2 & SLJIT_MEM) { - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, 0, 0)); + FAIL_IF(emit_op_mem(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, TMP_REG2)); src2 = TMP_FREG2; } @@ -1934,8 +1655,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compil sljit_s32 dst_r; CHECK_ERROR(); - compiler->cache_arg = 0; - compiler->cache_argw = 0; SLJIT_COMPILE_ASSERT((SLJIT_F32_OP == 0x100) && !(DOUBLE_DATA & 0x4), float_transfer_bit_error); SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw); @@ -1946,7 +1665,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compil dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG1; if (src & SLJIT_MEM) { - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, dst_r, src, srcw, dst, dstw)); + FAIL_IF(emit_op_mem(compiler, FLOAT_DATA(op) | LOAD_DATA, dst_r, src, srcw, TMP_REG1)); src = dst_r; } @@ -1975,7 +1694,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compil } if (dst & SLJIT_MEM) - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op), dst_r, dst, dstw, 0, 0)); + FAIL_IF(emit_op_mem(compiler, FLOAT_DATA(op), dst_r, dst, dstw, TMP_REG1)); return SLJIT_SUCCESS; } @@ -1984,7 +1703,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w) { - sljit_s32 dst_r, flags = 0; + sljit_s32 dst_r; CHECK_ERROR(); CHECK(check_sljit_emit_fop2(compiler, op, dst, dstw, src1, src1w, src2, src2w)); @@ -1992,46 +1711,17 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil ADJUST_LOCAL_OFFSET(src1, src1w); ADJUST_LOCAL_OFFSET(src2, src2w); - compiler->cache_arg = 0; - compiler->cache_argw = 0; - dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG2; if (src1 & SLJIT_MEM) { - if (getput_arg_fast(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w)) { - FAIL_IF(compiler->error); - src1 = TMP_FREG1; - } else - flags |= ALT_FORM1; + FAIL_IF(emit_op_mem(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, TMP_REG1)); + src1 = TMP_FREG1; } if (src2 & SLJIT_MEM) { - if (getput_arg_fast(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w)) { - FAIL_IF(compiler->error); - src2 = TMP_FREG2; - } else - flags |= ALT_FORM2; - } - - if ((flags & (ALT_FORM1 | ALT_FORM2)) == (ALT_FORM1 | ALT_FORM2)) { - if (!can_cache(src1, src1w, src2, src2w) && can_cache(src1, src1w, dst, dstw)) { - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, src1, src1w)); - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, dst, dstw)); - } - else { - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, src2, src2w)); - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, dst, dstw)); - } - } - else if (flags & ALT_FORM1) - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, dst, dstw)); - else if (flags & ALT_FORM2) - FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, dst, dstw)); - - if (flags & ALT_FORM1) - src1 = TMP_FREG1; - if (flags & ALT_FORM2) + FAIL_IF(emit_op_mem(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, TMP_REG2)); src2 = TMP_FREG2; + } switch (GET_OPCODE(op)) { case SLJIT_ADD_F64: @@ -2051,13 +1741,12 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil break; } - if (dst_r == TMP_FREG2) - FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op), TMP_FREG2, dst, dstw, 0, 0)); + if (dst & SLJIT_MEM) + FAIL_IF(emit_op_mem(compiler, FLOAT_DATA(op), TMP_FREG2, dst, dstw, TMP_REG1)); return SLJIT_SUCCESS; } -#undef FLOAT_DATA #undef SELECT_FOP /* --------------------------------------------------------------------- */ @@ -2087,12 +1776,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler if (FAST_IS_REG(src)) FAIL_IF(push_inst(compiler, MTLR | S(src))); else { - if (src & SLJIT_MEM) - FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, TMP_REG2, 0, TMP_REG1, 0, src, srcw)); - else if (src & SLJIT_IMM) - FAIL_IF(load_immediate(compiler, TMP_REG2, srcw)); + FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, TMP_REG2, 0, TMP_REG1, 0, src, srcw)); FAIL_IF(push_inst(compiler, MTLR | S(TMP_REG2))); } + return push_inst(compiler, BLR); } @@ -2174,7 +1861,7 @@ static sljit_ins get_bo_bi_flags(sljit_s32 type) return (4 << 21) | ((4 + 3) << 16); default: - SLJIT_ASSERT(type >= SLJIT_JUMP && type <= SLJIT_CALL3); + SLJIT_ASSERT(type >= SLJIT_JUMP && type <= SLJIT_CALL_CDECL); return (20 << 21); } } @@ -2200,7 +1887,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile if (type < SLJIT_JUMP) jump->flags |= IS_COND; #if (defined SLJIT_PASS_ENTRY_ADDR_TO_CALL && SLJIT_PASS_ENTRY_ADDR_TO_CALL) - if (type >= SLJIT_CALL0) + if (type >= SLJIT_CALL) jump->flags |= IS_CALL; #endif @@ -2211,6 +1898,24 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile return jump; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_call(compiler, type, arg_types)); + +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + PTR_FAIL_IF(call_with_args(compiler, arg_types, NULL)); +#endif + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_jump(compiler, type); +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) { struct sljit_jump *jump = NULL; @@ -2222,7 +1927,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi if (FAST_IS_REG(src)) { #if (defined SLJIT_PASS_ENTRY_ADDR_TO_CALL && SLJIT_PASS_ENTRY_ADDR_TO_CALL) - if (type >= SLJIT_CALL0) { + if (type >= SLJIT_CALL) { FAIL_IF(push_inst(compiler, OR | S(src) | A(TMP_CALL_REG) | B(src))); src_r = TMP_CALL_REG; } @@ -2232,12 +1937,13 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi src_r = src; #endif } else if (src & SLJIT_IMM) { + /* These jumps are converted to jump/call instructions when possible. */ jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); FAIL_IF(!jump); set_jump(jump, compiler, JUMP_ADDR); jump->u.target = srcw; #if (defined SLJIT_PASS_ENTRY_ADDR_TO_CALL && SLJIT_PASS_ENTRY_ADDR_TO_CALL) - if (type >= SLJIT_CALL0) + if (type >= SLJIT_CALL) jump->flags |= IS_CALL; #endif FAIL_IF(emit_const(compiler, TMP_CALL_REG, 0)); @@ -2254,6 +1960,31 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi return push_inst(compiler, BCCTR | (20 << 21) | (type >= SLJIT_FAST_CALL ? 1 : 0)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ + CHECK_ERROR(); + CHECK(check_sljit_emit_icall(compiler, type, arg_types, src, srcw)); + +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + if (src & SLJIT_MEM) { + ADJUST_LOCAL_OFFSET(src, srcw); + FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, TMP_CALL_REG, 0, TMP_REG1, 0, src, srcw)); + src = TMP_CALL_REG; + } + + FAIL_IF(call_with_args(compiler, arg_types, &src)); +#endif + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_ijump(compiler, type, src, srcw); +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 dst, sljit_sw dstw, sljit_s32 type) @@ -2275,23 +2006,19 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co op = GET_OPCODE(op); reg = (op < SLJIT_ADD && FAST_IS_REG(dst)) ? dst : TMP_REG2; - compiler->cache_arg = 0; - compiler->cache_argw = 0; - if (op >= SLJIT_ADD && (dst & SLJIT_MEM)) - FAIL_IF(emit_op_mem2(compiler, input_flags | LOAD_DATA, TMP_REG1, dst, dstw, dst, dstw)); + FAIL_IF(emit_op_mem(compiler, input_flags | LOAD_DATA, TMP_REG1, dst, dstw, TMP_REG1)); invert = 0; + cr_bit = 0; switch (type & 0xff) { case SLJIT_LESS: case SLJIT_SIG_LESS: - cr_bit = 0; break; case SLJIT_GREATER_EQUAL: case SLJIT_SIG_GREATER_EQUAL: - cr_bit = 0; invert = 1; break; @@ -2376,7 +2103,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co if (op < SLJIT_ADD) { if (!(dst & SLJIT_MEM)) return SLJIT_SUCCESS; - return emit_op_mem2(compiler, input_flags, reg, dst, dstw, reg, 0); + return emit_op_mem(compiler, input_flags, reg, dst, dstw, TMP_REG1); } #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ @@ -2398,6 +2125,139 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compil return sljit_emit_cmov_generic(compiler, type, dst_reg, src, srcw);; } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 reg, + sljit_s32 mem, sljit_sw memw) +{ + sljit_s32 mem_flags; + sljit_ins inst; + + CHECK_ERROR(); + CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw)); + + if (type & SLJIT_MEM_POST) + return SLJIT_ERR_UNSUPPORTED; + + switch (type & 0xff) { + case SLJIT_MOV: + case SLJIT_MOV_P: +#if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) + case SLJIT_MOV_U32: + case SLJIT_MOV_S32: +#endif + mem_flags = WORD_DATA; + break; + +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + case SLJIT_MOV_U32: + mem_flags = INT_DATA; + break; + + case SLJIT_MOV_S32: + mem_flags = INT_DATA; + + if (!(type & SLJIT_MEM_STORE) && !(type & SLJIT_I32_OP)) { + if (mem & OFFS_REG_MASK) + mem_flags |= SIGNED_DATA; + else + return SLJIT_ERR_UNSUPPORTED; + } + break; +#endif + + case SLJIT_MOV_U8: + case SLJIT_MOV_S8: + mem_flags = BYTE_DATA; + break; + + case SLJIT_MOV_U16: + mem_flags = HALF_DATA; + break; + + case SLJIT_MOV_S16: + mem_flags = HALF_DATA | SIGNED_DATA; + break; + + default: + SLJIT_UNREACHABLE(); + mem_flags = WORD_DATA; + break; + } + + if (!(type & SLJIT_MEM_STORE)) + mem_flags |= LOAD_DATA; + + if (SLJIT_UNLIKELY(mem & OFFS_REG_MASK)) { + if (memw != 0) + return SLJIT_ERR_UNSUPPORTED; + + if (type & SLJIT_MEM_SUPP) + return SLJIT_SUCCESS; + + inst = updated_data_transfer_insts[mem_flags | INDEXED]; + FAIL_IF(push_inst(compiler, INST_CODE_AND_DST(inst, 0, reg) | A(mem & REG_MASK) | B(OFFS_REG(mem)))); + } + else { + if (memw > SIMM_MAX || memw < SIMM_MIN) + return SLJIT_ERR_UNSUPPORTED; + + inst = updated_data_transfer_insts[mem_flags]; + +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + if ((inst & INT_ALIGNED) && (memw & 0x3) != 0) + return SLJIT_ERR_UNSUPPORTED; +#endif + + if (type & SLJIT_MEM_SUPP) + return SLJIT_SUCCESS; + + FAIL_IF(push_inst(compiler, INST_CODE_AND_DST(inst, 0, reg) | A(mem & REG_MASK) | IMM(memw))); + } + + if ((mem_flags & LOAD_DATA) && (type & 0xff) == SLJIT_MOV_S8) + return push_inst(compiler, EXTSB | S(reg) | A(reg)); + return SLJIT_SUCCESS; +} + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 freg, + sljit_s32 mem, sljit_sw memw) +{ + sljit_s32 mem_flags; + sljit_ins inst; + + CHECK_ERROR(); + CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw)); + + if (type & SLJIT_MEM_POST) + return SLJIT_ERR_UNSUPPORTED; + + if (SLJIT_UNLIKELY(mem & OFFS_REG_MASK)) { + if (memw != 0) + return SLJIT_ERR_UNSUPPORTED; + } + else { + if (memw > SIMM_MAX || memw < SIMM_MIN) + return SLJIT_ERR_UNSUPPORTED; + } + + if (type & SLJIT_MEM_SUPP) + return SLJIT_SUCCESS; + + mem_flags = FLOAT_DATA(type); + + if (!(type & SLJIT_MEM_STORE)) + mem_flags |= LOAD_DATA; + + if (SLJIT_UNLIKELY(mem & OFFS_REG_MASK)) { + inst = updated_data_transfer_insts[mem_flags | INDEXED]; + return push_inst(compiler, INST_CODE_AND_DST(inst, DOUBLE_DATA, freg) | A(mem & REG_MASK) | B(OFFS_REG(mem))); + } + + inst = updated_data_transfer_insts[mem_flags]; + return push_inst(compiler, INST_CODE_AND_DST(inst, DOUBLE_DATA, freg) | A(mem & REG_MASK) | IMM(memw)); +} + SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) { struct sljit_const *const_; diff --git a/pcre/sljit/sljitNativeSPARC_32.c b/pcre/sljit/sljitNativeSPARC_32.c index ee42130e87e..0671b130cc6 100644 --- a/pcre/sljit/sljitNativeSPARC_32.c +++ b/pcre/sljit/sljitNativeSPARC_32.c @@ -138,6 +138,125 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl return SLJIT_SUCCESS; } +static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_s32 *src) +{ + sljit_s32 reg_index = 8; + sljit_s32 word_reg_index = 8; + sljit_s32 float_arg_index = 1; + sljit_s32 double_arg_count = 0; + sljit_s32 float_offset = (16 + 6) * sizeof(sljit_sw); + sljit_s32 types = 0; + sljit_s32 reg = 0; + sljit_s32 move_to_tmp2 = 0; + + if (src) + reg = reg_map[*src & REG_MASK]; + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + types = (types << SLJIT_DEF_SHIFT) | (arg_types & SLJIT_DEF_MASK); + + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + float_arg_index++; + if (reg_index == reg) + move_to_tmp2 = 1; + reg_index++; + break; + case SLJIT_ARG_TYPE_F64: + float_arg_index++; + double_arg_count++; + if (reg_index == reg || reg_index + 1 == reg) + move_to_tmp2 = 1; + reg_index += 2; + break; + default: + if (reg_index != word_reg_index && reg_index < 14 && reg_index == reg) + move_to_tmp2 = 1; + reg_index++; + word_reg_index++; + break; + } + + if (move_to_tmp2) { + move_to_tmp2 = 0; + if (reg < 14) + FAIL_IF(push_inst(compiler, OR | D(TMP_REG1) | S1(0) | S2A(reg), DR(TMP_REG1))); + *src = TMP_REG1; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + arg_types = types; + + while (arg_types) { + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + float_arg_index--; + FAIL_IF(push_inst(compiler, STF | FD(float_arg_index) | S1(SLJIT_SP) | IMM(float_offset), MOVABLE_INS)); + float_offset -= sizeof(sljit_f64); + break; + case SLJIT_ARG_TYPE_F64: + float_arg_index--; + if (float_arg_index == 4 && double_arg_count == 4) { + FAIL_IF(push_inst(compiler, STF | FD(float_arg_index) | S1(SLJIT_SP) | IMM((16 + 7) * sizeof(sljit_sw)), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, STF | FD(float_arg_index) | (1 << 25) | S1(SLJIT_SP) | IMM((16 + 8) * sizeof(sljit_sw)), MOVABLE_INS)); + } + else + FAIL_IF(push_inst(compiler, STDF | FD(float_arg_index) | S1(SLJIT_SP) | IMM(float_offset), MOVABLE_INS)); + float_offset -= sizeof(sljit_f64); + break; + default: + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + float_offset = (16 + 6) * sizeof(sljit_sw); + + while (types) { + switch (types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + reg_index--; + if (reg_index < 14) + FAIL_IF(push_inst(compiler, LDUW | DA(reg_index) | S1(SLJIT_SP) | IMM(float_offset), reg_index)); + float_offset -= sizeof(sljit_f64); + break; + case SLJIT_ARG_TYPE_F64: + reg_index -= 2; + if (reg_index < 14) { + if ((reg_index & 0x1) != 0) { + FAIL_IF(push_inst(compiler, LDUW | DA(reg_index) | S1(SLJIT_SP) | IMM(float_offset), reg_index)); + if (reg_index < 13) + FAIL_IF(push_inst(compiler, LDUW | DA(reg_index + 1) | S1(SLJIT_SP) | IMM(float_offset + sizeof(sljit_sw)), reg_index + 1)); + } + else + FAIL_IF(push_inst(compiler, LDD | DA(reg_index) | S1(SLJIT_SP) | IMM(float_offset), reg_index)); + } + float_offset -= sizeof(sljit_f64); + break; + default: + reg_index--; + word_reg_index--; + + if (reg_index != word_reg_index) { + if (reg_index < 14) + FAIL_IF(push_inst(compiler, OR | DA(reg_index) | S1(0) | S2A(word_reg_index), reg_index)); + else + FAIL_IF(push_inst(compiler, STW | DA(word_reg_index) | S1(SLJIT_SP) | IMM(92), word_reg_index)); + } + break; + } + + types >>= SLJIT_DEF_SHIFT; + } + + return SLJIT_SUCCESS; +} + static SLJIT_INLINE sljit_s32 emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw init_value) { FAIL_IF(push_inst(compiler, SETHI | D(dst) | ((init_value >> 10) & 0x3fffff), DR(dst))); diff --git a/pcre/sljit/sljitNativeSPARC_common.c b/pcre/sljit/sljitNativeSPARC_common.c index 9831bd83d72..669ecd81528 100644 --- a/pcre/sljit/sljitNativeSPARC_common.c +++ b/pcre/sljit/sljitNativeSPARC_common.c @@ -90,13 +90,19 @@ static void sparc_cache_flush(sljit_ins *from, sljit_ins *to) #define TMP_REG1 (SLJIT_NUMBER_OF_REGISTERS + 2) #define TMP_REG2 (SLJIT_NUMBER_OF_REGISTERS + 3) #define TMP_REG3 (SLJIT_NUMBER_OF_REGISTERS + 4) +/* This register is modified by calls, which affects the instruction + in the delay slot if it is used as a source register. */ #define TMP_LINK (SLJIT_NUMBER_OF_REGISTERS + 5) -#define TMP_FREG1 (0) -#define TMP_FREG2 ((SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) << 1) +#define TMP_FREG1 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) +#define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2) static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 6] = { - 0, 8, 9, 10, 13, 29, 28, 27, 23, 22, 21, 20, 19, 18, 17, 16, 26, 25, 24, 14, 1, 11, 12, 15 + 0, 8, 9, 10, 11, 29, 28, 27, 23, 22, 21, 20, 19, 18, 17, 16, 26, 25, 24, 14, 1, 12, 13, 15 +}; + +static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = { + 0, 0, 2, 4, 6, 8, 10, 12, 14 }; /* --------------------------------------------------------------------- */ @@ -104,10 +110,15 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 6] = { /* --------------------------------------------------------------------- */ #define D(d) (reg_map[d] << 25) +#define FD(d) (freg_map[d] << 25) +#define FDN(d) ((freg_map[d] | 0x1) << 25) #define DA(d) ((d) << 25) #define S1(s1) (reg_map[s1] << 14) -#define S2(s2) (reg_map[s2]) +#define FS1(s1) (freg_map[s1] << 14) #define S1A(s1) ((s1) << 14) +#define S2(s2) (reg_map[s2]) +#define FS2(s2) (freg_map[s2]) +#define FS2N(s2) (freg_map[s2] | 0x1) #define S2A(s2) (s2) #define IMM_ARG 0x2000 #define DOP(op) ((op) << 5) @@ -144,6 +155,8 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 6] = { #define FSUBD (OPC1(0x2) | OPC3(0x34) | DOP(0x46)) #define FSUBS (OPC1(0x2) | OPC3(0x34) | DOP(0x45)) #define JMPL (OPC1(0x2) | OPC3(0x38)) +#define LDD (OPC1(0x3) | OPC3(0x03)) +#define LDUW (OPC1(0x3) | OPC3(0x00)) #define NOP (OPC1(0x0) | OPC2(0x04)) #define OR (OPC1(0x2) | OPC3(0x02)) #define ORN (OPC1(0x2) | OPC3(0x06)) @@ -157,6 +170,9 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 6] = { #define SRAX (OPC1(0x2) | OPC3(0x27) | (1 << 12)) #define SRL (OPC1(0x2) | OPC3(0x26)) #define SRLX (OPC1(0x2) | OPC3(0x26) | (1 << 12)) +#define STDF (OPC1(0x3) | OPC3(0x27)) +#define STF (OPC1(0x3) | OPC3(0x24)) +#define STW (OPC1(0x3) | OPC3(0x04)) #define SUB (OPC1(0x2) | OPC3(0x04)) #define SUBC (OPC1(0x2) | OPC3(0x0c)) #define TA (OPC1(0x2) | OPC3(0x3a) | (8 << 25)) @@ -433,18 +449,17 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) #define MEM_MASK 0x1f -#define WRITE_BACK 0x00020 -#define ARG_TEST 0x00040 -#define ALT_KEEP_CACHE 0x00080 -#define CUMULATIVE_OP 0x00100 -#define IMM_OP 0x00200 -#define SRC2_IMM 0x00400 +#define ARG_TEST 0x00020 +#define ALT_KEEP_CACHE 0x00040 +#define CUMULATIVE_OP 0x00080 +#define IMM_OP 0x00100 +#define SRC2_IMM 0x00200 -#define REG_DEST 0x00800 -#define REG2_SOURCE 0x01000 -#define SLOW_SRC1 0x02000 -#define SLOW_SRC2 0x04000 -#define SLOW_DEST 0x08000 +#define REG_DEST 0x00400 +#define REG2_SOURCE 0x00800 +#define SLOW_SRC1 0x01000 +#define SLOW_SRC2 0x02000 +#define SLOW_DEST 0x04000 /* SET_FLAGS (0x10 << 19) also belong here! */ @@ -455,12 +470,12 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) #endif SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { CHECK_ERROR(); - CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); local_size = (local_size + SLJIT_LOCALS_OFFSET + 7) & ~0x7; compiler->local_size = local_size; @@ -479,12 +494,12 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { CHECK_ERROR(); - CHECK(check_sljit_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); compiler->local_size = (local_size + SLJIT_LOCALS_OFFSET + 7) & ~0x7; return SLJIT_SUCCESS; @@ -546,18 +561,16 @@ static sljit_s32 getput_arg_fast(struct sljit_compiler *compiler, sljit_s32 flag { SLJIT_ASSERT(arg & SLJIT_MEM); - if (!(flags & WRITE_BACK) || !(arg & REG_MASK)) { - if ((!(arg & OFFS_REG_MASK) && argw <= SIMM_MAX && argw >= SIMM_MIN) - || ((arg & OFFS_REG_MASK) && (argw & 0x3) == 0)) { - /* Works for both absoulte and relative addresses (immediate case). */ - if (SLJIT_UNLIKELY(flags & ARG_TEST)) - return 1; - FAIL_IF(push_inst(compiler, data_transfer_insts[flags & MEM_MASK] - | ((flags & MEM_MASK) <= GPR_REG ? D(reg) : DA(reg)) - | S1(arg & REG_MASK) | ((arg & OFFS_REG_MASK) ? S2(OFFS_REG(arg)) : IMM(argw)), - ((flags & MEM_MASK) <= GPR_REG && (flags & LOAD_DATA)) ? DR(reg) : MOVABLE_INS)); - return -1; - } + if ((!(arg & OFFS_REG_MASK) && argw <= SIMM_MAX && argw >= SIMM_MIN) + || ((arg & OFFS_REG_MASK) && (argw & 0x3) == 0)) { + /* Works for both absoulte and relative addresses (immediate case). */ + if (SLJIT_UNLIKELY(flags & ARG_TEST)) + return 1; + FAIL_IF(push_inst(compiler, data_transfer_insts[flags & MEM_MASK] + | ((flags & MEM_MASK) <= GPR_REG ? D(reg) : FD(reg)) + | S1(arg & REG_MASK) | ((arg & OFFS_REG_MASK) ? S2(OFFS_REG(arg)) : IMM(argw)), + ((flags & MEM_MASK) <= GPR_REG && (flags & LOAD_DATA)) ? DR(reg) : MOVABLE_INS)); + return -1; } return 0; } @@ -638,14 +651,11 @@ static sljit_s32 getput_arg(struct sljit_compiler *compiler, sljit_s32 flags, sl } } - dest = ((flags & MEM_MASK) <= GPR_REG ? D(reg) : DA(reg)); + dest = ((flags & MEM_MASK) <= GPR_REG ? D(reg) : FD(reg)); delay_slot = ((flags & MEM_MASK) <= GPR_REG && (flags & LOAD_DATA)) ? DR(reg) : MOVABLE_INS; if (!base) return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | dest | S1(arg2) | IMM(0), delay_slot); - if (!(flags & WRITE_BACK)) - return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | dest | S1(base) | S2(arg2), delay_slot); - FAIL_IF(push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | dest | S1(base) | S2(arg2), delay_slot)); - return push_inst(compiler, ADD | D(base) | S1(base) | S2(arg2), DR(base)); + return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | dest | S1(base) | S2(arg2), delay_slot); } static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw) @@ -687,7 +697,7 @@ static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s3 if (FAST_IS_REG(dst)) { dst_r = dst; flags |= REG_DEST; - if (op >= SLJIT_MOV && op <= SLJIT_MOVU_S32) + if (op >= SLJIT_MOV && op <= SLJIT_MOV_P) sugg_src2_r = dst_r; } else if ((dst & SLJIT_MEM) && !getput_arg_fast(compiler, flags | ARG_TEST, TMP_REG1, dst, dstw)) @@ -738,7 +748,7 @@ static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s3 if (FAST_IS_REG(src2)) { src2_r = src2; flags |= REG2_SOURCE; - if (!(flags & REG_DEST) && op >= SLJIT_MOV && op <= SLJIT_MOVU_S32) + if (!(flags & REG_DEST) && op >= SLJIT_MOV && op <= SLJIT_MOV_P) dst_r = src2_r; } else if (src2 & SLJIT_IMM) { @@ -749,7 +759,7 @@ static sljit_s32 emit_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s3 } else { src2_r = 0; - if ((op >= SLJIT_MOV && op <= SLJIT_MOVU_S32) && (dst & SLJIT_MEM)) + if ((op >= SLJIT_MOV && op <= SLJIT_MOV_P) && (dst & SLJIT_MEM)) dst_r = 0; } } @@ -875,28 +885,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile case SLJIT_MOV_S16: return emit_op(compiler, SLJIT_MOV_S16, flags | HALF_DATA | SIGNED_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s16)srcw : srcw); - case SLJIT_MOVU: - case SLJIT_MOVU_P: - return emit_op(compiler, SLJIT_MOV, flags | WORD_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw); - - case SLJIT_MOVU_U32: - return emit_op(compiler, SLJIT_MOV_U32, flags | INT_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw); - - case SLJIT_MOVU_S32: - return emit_op(compiler, SLJIT_MOV_S32, flags | INT_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw); - - case SLJIT_MOVU_U8: - return emit_op(compiler, SLJIT_MOV_U8, flags | BYTE_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u8)srcw : srcw); - - case SLJIT_MOVU_S8: - return emit_op(compiler, SLJIT_MOV_S8, flags | BYTE_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s8)srcw : srcw); - - case SLJIT_MOVU_U16: - return emit_op(compiler, SLJIT_MOV_U16, flags | HALF_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_u16)srcw : srcw); - - case SLJIT_MOVU_S16: - return emit_op(compiler, SLJIT_MOV_S16, flags | HALF_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_s16)srcw : srcw); - case SLJIT_NOT: case SLJIT_CLZ: return emit_op(compiler, op, flags, dst, dstw, TMP_REG1, 0, src, srcw); @@ -962,7 +950,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg) SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_float_register_index(sljit_s32 reg) { CHECK_REG_INDEX(check_sljit_get_float_register_index(reg)); - return reg << 1; + return freg_map[reg]; } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler, @@ -990,10 +978,8 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_comp FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src, srcw, dst, dstw)); src = TMP_FREG1; } - else - src <<= 1; - FAIL_IF(push_inst(compiler, SELECT_FOP(op, FSTOI, FDTOI) | DA(TMP_FREG1) | S2A(src), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, SELECT_FOP(op, FSTOI, FDTOI) | FD(TMP_FREG1) | FS2(src), MOVABLE_INS)); if (FAST_IS_REG(dst)) { FAIL_IF(emit_op_mem2(compiler, SINGLE_DATA, TMP_FREG1, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET, SLJIT_MEM1(SLJIT_SP), FLOAT_TMP_MEM_OFFSET)); @@ -1008,7 +994,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_comp sljit_s32 dst, sljit_sw dstw, sljit_s32 src, sljit_sw srcw) { - sljit_s32 dst_r = FAST_IS_REG(dst) ? (dst << 1) : TMP_FREG1; + sljit_s32 dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG1; if (src & SLJIT_IMM) { #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) @@ -1027,7 +1013,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_comp } FAIL_IF(emit_op_mem2(compiler, SINGLE_DATA | LOAD_DATA, TMP_FREG1, src, srcw, dst, dstw)); - FAIL_IF(push_inst(compiler, SELECT_FOP(op, FITOS, FITOD) | DA(dst_r) | S2A(TMP_FREG1), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, SELECT_FOP(op, FITOS, FITOD) | FD(dst_r) | FS2(TMP_FREG1), MOVABLE_INS)); if (dst & SLJIT_MEM) return emit_op_mem2(compiler, FLOAT_DATA(op), TMP_FREG1, dst, dstw, 0, 0); @@ -1042,17 +1028,13 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_cmp(struct sljit_compiler *compile FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, src2, src2w)); src1 = TMP_FREG1; } - else - src1 <<= 1; if (src2 & SLJIT_MEM) { FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, 0, 0)); src2 = TMP_FREG2; } - else - src2 <<= 1; - return push_inst(compiler, SELECT_FOP(op, FCMPS, FCMPD) | S1A(src1) | S2A(src2), FCC_IS_SET | MOVABLE_INS); + return push_inst(compiler, SELECT_FOP(op, FCMPS, FCMPD) | FS1(src1) | FS2(src2), FCC_IS_SET | MOVABLE_INS); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op, @@ -1071,39 +1053,37 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compil if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32) op ^= SLJIT_F32_OP; - dst_r = FAST_IS_REG(dst) ? (dst << 1) : TMP_FREG1; + dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG1; if (src & SLJIT_MEM) { FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, dst_r, src, srcw, dst, dstw)); src = dst_r; } - else - src <<= 1; switch (GET_OPCODE(op)) { case SLJIT_MOV_F64: if (src != dst_r) { if (dst_r != TMP_FREG1) { - FAIL_IF(push_inst(compiler, FMOVS | DA(dst_r) | S2A(src), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, FMOVS | FD(dst_r) | FS2(src), MOVABLE_INS)); if (!(op & SLJIT_F32_OP)) - FAIL_IF(push_inst(compiler, FMOVS | DA(dst_r | 1) | S2A(src | 1), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, FMOVS | FDN(dst_r) | FS2N(src), MOVABLE_INS)); } else dst_r = src; } break; case SLJIT_NEG_F64: - FAIL_IF(push_inst(compiler, FNEGS | DA(dst_r) | S2A(src), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, FNEGS | FD(dst_r) | FS2(src), MOVABLE_INS)); if (dst_r != src && !(op & SLJIT_F32_OP)) - FAIL_IF(push_inst(compiler, FMOVS | DA(dst_r | 1) | S2A(src | 1), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, FMOVS | FDN(dst_r) | FS2N(src), MOVABLE_INS)); break; case SLJIT_ABS_F64: - FAIL_IF(push_inst(compiler, FABSS | DA(dst_r) | S2A(src), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, FABSS | FD(dst_r) | FS2(src), MOVABLE_INS)); if (dst_r != src && !(op & SLJIT_F32_OP)) - FAIL_IF(push_inst(compiler, FMOVS | DA(dst_r | 1) | S2A(src | 1), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, FMOVS | FDN(dst_r) | FS2N(src), MOVABLE_INS)); break; case SLJIT_CONV_F64_FROM_F32: - FAIL_IF(push_inst(compiler, SELECT_FOP(op, FSTOD, FDTOS) | DA(dst_r) | S2A(src), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, SELECT_FOP(op, FSTOD, FDTOS) | FD(dst_r) | FS2(src), MOVABLE_INS)); op ^= SLJIT_F32_OP; break; } @@ -1129,7 +1109,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil compiler->cache_arg = 0; compiler->cache_argw = 0; - dst_r = FAST_IS_REG(dst) ? (dst << 1) : TMP_FREG2; + dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG2; if (src1 & SLJIT_MEM) { if (getput_arg_fast(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w)) { @@ -1138,8 +1118,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil } else flags |= SLOW_SRC1; } - else - src1 <<= 1; if (src2 & SLJIT_MEM) { if (getput_arg_fast(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w)) { @@ -1148,8 +1126,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil } else flags |= SLOW_SRC2; } - else - src2 <<= 1; if ((flags & (SLOW_SRC1 | SLOW_SRC2)) == (SLOW_SRC1 | SLOW_SRC2)) { if (!can_cache(src1, src1w, src2, src2w) && can_cache(src1, src1w, dst, dstw)) { @@ -1173,19 +1149,19 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compil switch (GET_OPCODE(op)) { case SLJIT_ADD_F64: - FAIL_IF(push_inst(compiler, SELECT_FOP(op, FADDS, FADDD) | DA(dst_r) | S1A(src1) | S2A(src2), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, SELECT_FOP(op, FADDS, FADDD) | FD(dst_r) | FS1(src1) | FS2(src2), MOVABLE_INS)); break; case SLJIT_SUB_F64: - FAIL_IF(push_inst(compiler, SELECT_FOP(op, FSUBS, FSUBD) | DA(dst_r) | S1A(src1) | S2A(src2), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, SELECT_FOP(op, FSUBS, FSUBD) | FD(dst_r) | FS1(src1) | FS2(src2), MOVABLE_INS)); break; case SLJIT_MUL_F64: - FAIL_IF(push_inst(compiler, SELECT_FOP(op, FMULS, FMULD) | DA(dst_r) | S1A(src1) | S2A(src2), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, SELECT_FOP(op, FMULS, FMULD) | FD(dst_r) | FS1(src1) | FS2(src2), MOVABLE_INS)); break; case SLJIT_DIV_F64: - FAIL_IF(push_inst(compiler, SELECT_FOP(op, FDIVS, FDIVD) | DA(dst_r) | S1A(src1) | S2A(src2), MOVABLE_INS)); + FAIL_IF(push_inst(compiler, SELECT_FOP(op, FDIVS, FDIVD) | FD(dst_r) | FS1(src1) | FS2(src2), MOVABLE_INS)); break; } @@ -1223,10 +1199,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler if (FAST_IS_REG(src)) FAIL_IF(push_inst(compiler, OR | D(TMP_LINK) | S1(0) | S2(src), DR(TMP_LINK))); - else if (src & SLJIT_MEM) + else FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_LINK, src, srcw)); - else if (src & SLJIT_IMM) - FAIL_IF(load_immediate(compiler, TMP_LINK, srcw)); FAIL_IF(push_inst(compiler, JMPL | D(0) | S1(TMP_LINK) | IMM(8), UNMOVABLE_INS)); return push_inst(compiler, NOP, UNMOVABLE_INS); @@ -1339,21 +1313,38 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile #else #error "Implementation required" #endif - } else { + } + else { if ((compiler->delay_slot & DST_INS_MASK) != UNMOVABLE_INS) jump->flags |= IS_MOVABLE; if (type >= SLJIT_FAST_CALL) jump->flags |= IS_CALL; } - PTR_FAIL_IF(emit_const(compiler, TMP_REG2, 0)); - PTR_FAIL_IF(push_inst(compiler, JMPL | D(type >= SLJIT_FAST_CALL ? TMP_LINK : 0) | S1(TMP_REG2) | IMM(0), UNMOVABLE_INS)); + PTR_FAIL_IF(emit_const(compiler, TMP_REG1, 0)); + PTR_FAIL_IF(push_inst(compiler, JMPL | D(type >= SLJIT_FAST_CALL ? TMP_LINK : 0) | S1(TMP_REG1) | IMM(0), UNMOVABLE_INS)); jump->addr = compiler->size; PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS)); return jump; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_call(compiler, type, arg_types)); + + PTR_FAIL_IF(call_with_args(compiler, arg_types, NULL)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_jump(compiler, type); +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) { struct sljit_jump *jump = NULL; @@ -1370,17 +1361,18 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi FAIL_IF(!jump); set_jump(jump, compiler, JUMP_ADDR); jump->u.target = srcw; + if ((compiler->delay_slot & DST_INS_MASK) != UNMOVABLE_INS) jump->flags |= IS_MOVABLE; if (type >= SLJIT_FAST_CALL) jump->flags |= IS_CALL; - FAIL_IF(emit_const(compiler, TMP_REG2, 0)); - src_r = TMP_REG2; + FAIL_IF(emit_const(compiler, TMP_REG1, 0)); + src_r = TMP_REG1; } else { - FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_REG2, src, srcw)); - src_r = TMP_REG2; + FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_REG1, src, srcw)); + src_r = TMP_REG1; } FAIL_IF(push_inst(compiler, JMPL | D(type >= SLJIT_FAST_CALL ? TMP_LINK : 0) | S1(src_r) | IMM(0), UNMOVABLE_INS)); @@ -1389,6 +1381,29 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi return push_inst(compiler, NOP, UNMOVABLE_INS); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ + CHECK_ERROR(); + CHECK(check_sljit_emit_icall(compiler, type, arg_types, src, srcw)); + + if (src & SLJIT_MEM) { + ADJUST_LOCAL_OFFSET(src, srcw); + FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_REG1, src, srcw)); + src = TMP_REG1; + } + + FAIL_IF(call_with_args(compiler, arg_types, &src)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_ijump(compiler, type, src, srcw); +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 dst, sljit_sw dstw, sljit_s32 type) diff --git a/pcre/sljit/sljitNativeX86_32.c b/pcre/sljit/sljitNativeX86_32.c index f5cf8834b08..074e64b9f2b 100644 --- a/pcre/sljit/sljitNativeX86_32.c +++ b/pcre/sljit/sljitNativeX86_32.c @@ -64,29 +64,28 @@ static sljit_u8* generate_far_jump_code(struct sljit_jump *jump, sljit_u8 *code_ } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { - sljit_s32 size; + sljit_s32 args, size; sljit_u8 *inst; CHECK_ERROR(); - CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); + args = get_arg_count(arg_types); compiler->args = args; -#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) - /* [esp+0] for saving temporaries and third argument for calls. */ - compiler->saveds_offset = 1 * sizeof(sljit_sw); -#else - /* [esp+0] for saving temporaries and space for maximum three arguments. */ - if (scratches <= 1) - compiler->saveds_offset = 1 * sizeof(sljit_sw); - else - compiler->saveds_offset = ((scratches == 2) ? 2 : 3) * sizeof(sljit_sw); + /* [esp+0] for saving temporaries and function calls. */ + compiler->stack_tmp_size = 2 * sizeof(sljit_sw); + +#if !(defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) + if (scratches > 3) + compiler->stack_tmp_size = 3 * sizeof(sljit_sw); #endif + compiler->saveds_offset = compiler->stack_tmp_size; if (scratches > 3) compiler->saveds_offset += ((scratches > (3 + 6)) ? 6 : (scratches - 3)) * sizeof(sljit_sw); @@ -124,34 +123,38 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi #if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) if (args > 0) { - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (reg_map[SLJIT_S0] << 3) | reg_map[SLJIT_R2]; + inst[0] = MOV_r_rm; + inst[1] = MOD_REG | (reg_map[SLJIT_S0] << 3) | reg_map[SLJIT_R2]; + inst += 2; } if (args > 1) { - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (reg_map[SLJIT_S1] << 3) | reg_map[SLJIT_R1]; + inst[0] = MOV_r_rm; + inst[1] = MOD_REG | (reg_map[SLJIT_S1] << 3) | reg_map[SLJIT_R1]; + inst += 2; } if (args > 2) { - *inst++ = MOV_r_rm; - *inst++ = MOD_DISP8 | (reg_map[SLJIT_S2] << 3) | 0x4 /* esp */; - *inst++ = 0x24; - *inst++ = sizeof(sljit_sw) * (3 + 2); /* saveds >= 3 as well. */ + inst[0] = MOV_r_rm; + inst[1] = MOD_DISP8 | (reg_map[SLJIT_S2] << 3) | 0x4 /* esp */; + inst[2] = 0x24; + inst[3] = sizeof(sljit_sw) * (3 + 2); /* saveds >= 3 as well. */ } #else if (args > 0) { - *inst++ = MOV_r_rm; - *inst++ = MOD_DISP8 | (reg_map[SLJIT_S0] << 3) | reg_map[TMP_REG1]; - *inst++ = sizeof(sljit_sw) * 2; + inst[0] = MOV_r_rm; + inst[1] = MOD_DISP8 | (reg_map[SLJIT_S0] << 3) | reg_map[TMP_REG1]; + inst[2] = sizeof(sljit_sw) * 2; + inst += 3; } if (args > 1) { - *inst++ = MOV_r_rm; - *inst++ = MOD_DISP8 | (reg_map[SLJIT_S1] << 3) | reg_map[TMP_REG1]; - *inst++ = sizeof(sljit_sw) * 3; + inst[0] = MOV_r_rm; + inst[1] = MOD_DISP8 | (reg_map[SLJIT_S1] << 3) | reg_map[TMP_REG1]; + inst[2] = sizeof(sljit_sw) * 3; + inst += 3; } if (args > 2) { - *inst++ = MOV_r_rm; - *inst++ = MOD_DISP8 | (reg_map[SLJIT_S2] << 3) | reg_map[TMP_REG1]; - *inst++ = sizeof(sljit_sw) * 4; + inst[0] = MOV_r_rm; + inst[1] = MOD_DISP8 | (reg_map[SLJIT_S2] << 3) | reg_map[TMP_REG1]; + inst[2] = sizeof(sljit_sw) * 4; } #endif @@ -171,17 +174,36 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi compiler->local_size = local_size; #ifdef _WIN32 - if (local_size > 1024) { -#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) - FAIL_IF(emit_do_imm(compiler, MOV_r_i32 + reg_map[SLJIT_R0], local_size)); -#else - /* Space for a single argument. This amount is excluded when the stack is allocated below. */ - local_size -= sizeof(sljit_sw); - FAIL_IF(emit_do_imm(compiler, MOV_r_i32 + reg_map[SLJIT_R0], local_size)); - FAIL_IF(emit_non_cum_binary(compiler, SUB_r_rm, SUB_rm_r, SUB, SUB_EAX_i32, - SLJIT_SP, 0, SLJIT_SP, 0, SLJIT_IMM, sizeof(sljit_sw))); -#endif - FAIL_IF(sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_grow_stack))); + if (local_size > 0) { + if (local_size <= 4 * 4096) { + if (local_size > 4096) + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_SP), -4096); + if (local_size > 2 * 4096) + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_SP), -4096 * 2); + if (local_size > 3 * 4096) + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_SP), -4096 * 3); + } + else { + EMIT_MOV(compiler, SLJIT_R0, 0, SLJIT_SP, 0); + EMIT_MOV(compiler, SLJIT_R1, 0, SLJIT_IMM, (local_size - 1) >> 12); + + SLJIT_ASSERT (reg_map[SLJIT_R0] == 0); + + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_R0), -4096); + FAIL_IF(emit_non_cum_binary(compiler, BINARY_OPCODE(SUB), + SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 4096)); + FAIL_IF(emit_non_cum_binary(compiler, BINARY_OPCODE(SUB), + SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1)); + + inst = (sljit_u8*)ensure_buf(compiler, 1 + 2); + FAIL_IF(!inst); + + INC_SIZE(2); + inst[0] = JNE_i8; + inst[1] = (sljit_s8) -16; + } + + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_SP), -local_size); } #endif @@ -192,12 +214,12 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_SP, 0); /* Some space might allocated during sljit_grow_stack() above on WIN32. */ - FAIL_IF(emit_non_cum_binary(compiler, SUB_r_rm, SUB_rm_r, SUB, SUB_EAX_i32, + FAIL_IF(emit_non_cum_binary(compiler, BINARY_OPCODE(SUB), SLJIT_SP, 0, SLJIT_SP, 0, SLJIT_IMM, local_size + sizeof(sljit_sw))); #if defined _WIN32 && !(defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) if (compiler->local_size > 1024) - FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32, + FAIL_IF(emit_cum_binary(compiler, BINARY_OPCODE(ADD), TMP_REG1, 0, TMP_REG1, 0, SLJIT_IMM, sizeof(sljit_sw))); #endif @@ -213,31 +235,29 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi return emit_mov(compiler, SLJIT_MEM1(SLJIT_SP), compiler->local_size, TMP_REG1, 0); } #endif - return emit_non_cum_binary(compiler, SUB_r_rm, SUB_rm_r, SUB, SUB_EAX_i32, + return emit_non_cum_binary(compiler, BINARY_OPCODE(SUB), SLJIT_SP, 0, SLJIT_SP, 0, SLJIT_IMM, local_size); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { CHECK_ERROR(); - CHECK(check_sljit_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); - compiler->args = args; + compiler->args = get_arg_count(arg_types); -#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) - /* [esp+0] for saving temporaries and third argument for calls. */ - compiler->saveds_offset = 1 * sizeof(sljit_sw); -#else - /* [esp+0] for saving temporaries and space for maximum three arguments. */ - if (scratches <= 1) - compiler->saveds_offset = 1 * sizeof(sljit_sw); - else - compiler->saveds_offset = ((scratches == 2) ? 2 : 3) * sizeof(sljit_sw); + /* [esp+0] for saving temporaries and function calls. */ + compiler->stack_tmp_size = 2 * sizeof(sljit_sw); + +#if !(defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) + if (scratches > 3) + compiler->stack_tmp_size = 3 * sizeof(sljit_sw); #endif + compiler->saveds_offset = compiler->stack_tmp_size; if (scratches > 3) compiler->saveds_offset += ((scratches > (3 + 6)) ? 6 : (scratches - 3)) * sizeof(sljit_sw); @@ -278,10 +298,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *comp if (compiler->options & SLJIT_F64_ALIGNMENT) EMIT_MOV(compiler, SLJIT_SP, 0, SLJIT_MEM1(SLJIT_SP), compiler->local_size) else - FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32, + FAIL_IF(emit_cum_binary(compiler, BINARY_OPCODE(ADD), SLJIT_SP, 0, SLJIT_SP, 0, SLJIT_IMM, compiler->local_size)); #else - FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32, + FAIL_IF(emit_cum_binary(compiler, BINARY_OPCODE(ADD), SLJIT_SP, 0, SLJIT_SP, 0, SLJIT_IMM, compiler->local_size)); #endif @@ -418,7 +438,7 @@ static sljit_u8* emit_x86_instruction(struct sljit_compiler *compiler, sljit_s32 if ((flags & EX86_BIN_INS) && (a & SLJIT_IMM)) *inst = (flags & EX86_BYTE_ARG) ? GROUP_BINARY_83 : GROUP_BINARY_81; - if ((a & SLJIT_IMM) || (a == 0)) + if (a & SLJIT_IMM) *buf_ptr = 0; else if (!(flags & EX86_SSE2_OP1)) *buf_ptr = reg_map[a] << 3; @@ -490,42 +510,324 @@ static sljit_u8* emit_x86_instruction(struct sljit_compiler *compiler, sljit_s32 /* Call / return instructions */ /* --------------------------------------------------------------------- */ -static SLJIT_INLINE sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 type) +#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) + +static sljit_s32 c_fast_call_get_stack_size(sljit_s32 arg_types, sljit_s32 *word_arg_count_ptr) { - sljit_u8 *inst; + sljit_s32 stack_size = 0; + sljit_s32 word_arg_count = 0; + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + stack_size += sizeof(sljit_f32); + break; + case SLJIT_ARG_TYPE_F64: + stack_size += sizeof(sljit_f64); + break; + default: + word_arg_count++; + if (word_arg_count > 2) + stack_size += sizeof(sljit_sw); + break; + } -#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) - inst = (sljit_u8*)ensure_buf(compiler, type >= SLJIT_CALL3 ? 1 + 2 + 1 : 1 + 2); - FAIL_IF(!inst); - INC_SIZE(type >= SLJIT_CALL3 ? 2 + 1 : 2); + arg_types >>= SLJIT_DEF_SHIFT; + } + + if (word_arg_count_ptr) + *word_arg_count_ptr = word_arg_count; + + return stack_size; +} + +static sljit_s32 c_fast_call_with_args(struct sljit_compiler *compiler, + sljit_s32 arg_types, sljit_s32 stack_size, sljit_s32 word_arg_count, sljit_s32 swap_args) +{ + sljit_u8 *inst; + sljit_s32 float_arg_count; - if (type >= SLJIT_CALL3) + if (stack_size == sizeof(sljit_sw) && word_arg_count == 3) { + inst = (sljit_u8*)ensure_buf(compiler, 1 + 1); + FAIL_IF(!inst); + INC_SIZE(1); PUSH_REG(reg_map[SLJIT_R2]); - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (reg_map[SLJIT_R2] << 3) | reg_map[SLJIT_R0]; + } + else if (stack_size > 0) { + if (word_arg_count >= 4) + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_SP), compiler->saveds_offset - sizeof(sljit_sw)); + + FAIL_IF(emit_non_cum_binary(compiler, BINARY_OPCODE(SUB), + SLJIT_SP, 0, SLJIT_SP, 0, SLJIT_IMM, stack_size)); + + stack_size = 0; + arg_types >>= SLJIT_DEF_SHIFT; + word_arg_count = 0; + float_arg_count = 0; + while (arg_types) { + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + float_arg_count++; + FAIL_IF(emit_sse2_store(compiler, 1, SLJIT_MEM1(SLJIT_SP), stack_size, float_arg_count)); + stack_size += sizeof(sljit_f32); + break; + case SLJIT_ARG_TYPE_F64: + float_arg_count++; + FAIL_IF(emit_sse2_store(compiler, 0, SLJIT_MEM1(SLJIT_SP), stack_size, float_arg_count)); + stack_size += sizeof(sljit_f64); + break; + default: + word_arg_count++; + if (word_arg_count == 3) { + EMIT_MOV(compiler, SLJIT_MEM1(SLJIT_SP), stack_size, SLJIT_R2, 0); + stack_size += sizeof(sljit_sw); + } + else if (word_arg_count == 4) { + EMIT_MOV(compiler, SLJIT_MEM1(SLJIT_SP), stack_size, TMP_REG1, 0); + stack_size += sizeof(sljit_sw); + } + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + } + + if (word_arg_count > 0) { + if (swap_args) { + inst = (sljit_u8*)ensure_buf(compiler, 1 + 1); + FAIL_IF(!inst); + INC_SIZE(1); + + *inst++ = XCHG_EAX_r | reg_map[SLJIT_R2]; + } + else { + inst = (sljit_u8*)ensure_buf(compiler, 1 + 2); + FAIL_IF(!inst); + INC_SIZE(2); + + *inst++ = MOV_r_rm; + *inst++ = MOD_REG | (reg_map[SLJIT_R2] << 3) | reg_map[SLJIT_R0]; + } + } + + return SLJIT_SUCCESS; +} + +#endif + +static sljit_s32 cdecl_call_get_stack_size(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_s32 *word_arg_count_ptr) +{ + sljit_s32 stack_size = 0; + sljit_s32 word_arg_count = 0; + + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + stack_size += sizeof(sljit_f32); + break; + case SLJIT_ARG_TYPE_F64: + stack_size += sizeof(sljit_f64); + break; + default: + word_arg_count++; + stack_size += sizeof(sljit_sw); + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + if (word_arg_count_ptr) + *word_arg_count_ptr = word_arg_count; + + if (stack_size <= compiler->stack_tmp_size) + return 0; + +#if defined(__APPLE__) + return ((stack_size - compiler->stack_tmp_size + 15) & ~15); #else - inst = (sljit_u8*)ensure_buf(compiler, 1 + 4 * (type - SLJIT_CALL0)); + return stack_size - compiler->stack_tmp_size; +#endif +} + +static sljit_s32 cdecl_call_with_args(struct sljit_compiler *compiler, + sljit_s32 arg_types, sljit_s32 stack_size, sljit_s32 word_arg_count) +{ + sljit_s32 float_arg_count = 0; + + if (word_arg_count >= 4) + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_SP), compiler->saveds_offset - sizeof(sljit_sw)); + + if (stack_size > 0) + FAIL_IF(emit_non_cum_binary(compiler, BINARY_OPCODE(SUB), + SLJIT_SP, 0, SLJIT_SP, 0, SLJIT_IMM, stack_size)); + + stack_size = 0; + word_arg_count = 0; + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + float_arg_count++; + FAIL_IF(emit_sse2_store(compiler, 1, SLJIT_MEM1(SLJIT_SP), stack_size, float_arg_count)); + stack_size += sizeof(sljit_f32); + break; + case SLJIT_ARG_TYPE_F64: + float_arg_count++; + FAIL_IF(emit_sse2_store(compiler, 0, SLJIT_MEM1(SLJIT_SP), stack_size, float_arg_count)); + stack_size += sizeof(sljit_f64); + break; + default: + word_arg_count++; + EMIT_MOV(compiler, SLJIT_MEM1(SLJIT_SP), stack_size, (word_arg_count >= 4) ? TMP_REG1 : word_arg_count, 0); + stack_size += sizeof(sljit_sw); + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; + } + + return SLJIT_SUCCESS; +} + +static sljit_s32 post_call_with_args(struct sljit_compiler *compiler, + sljit_s32 arg_types, sljit_s32 stack_size) +{ + sljit_u8 *inst; + sljit_s32 single; + + if (stack_size > 0) + FAIL_IF(emit_cum_binary(compiler, BINARY_OPCODE(ADD), + SLJIT_SP, 0, SLJIT_SP, 0, SLJIT_IMM, stack_size)); + + if ((arg_types & SLJIT_DEF_MASK) < SLJIT_ARG_TYPE_F32) + return SLJIT_SUCCESS; + + single = ((arg_types & SLJIT_DEF_MASK) == SLJIT_ARG_TYPE_F32); + + inst = (sljit_u8*)ensure_buf(compiler, 1 + 3); FAIL_IF(!inst); - INC_SIZE(4 * (type - SLJIT_CALL0)); - - *inst++ = MOV_rm_r; - *inst++ = MOD_DISP8 | (reg_map[SLJIT_R0] << 3) | 0x4 /* SIB */; - *inst++ = (0x4 /* none*/ << 3) | reg_map[SLJIT_SP]; - *inst++ = 0; - if (type >= SLJIT_CALL2) { - *inst++ = MOV_rm_r; - *inst++ = MOD_DISP8 | (reg_map[SLJIT_R1] << 3) | 0x4 /* SIB */; - *inst++ = (0x4 /* none*/ << 3) | reg_map[SLJIT_SP]; - *inst++ = sizeof(sljit_sw); + INC_SIZE(3); + inst[0] = single ? FSTPS : FSTPD; + inst[1] = (0x03 << 3) | 0x04; + inst[2] = (0x04 << 3) | reg_map[SLJIT_SP]; + + return emit_sse2_load(compiler, single, SLJIT_FR0, SLJIT_MEM1(SLJIT_SP), 0); +} + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ + struct sljit_jump *jump; + sljit_s32 stack_size = 0; + sljit_s32 word_arg_count; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_call(compiler, type, arg_types)); + +#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) + if ((type & 0xff) == SLJIT_CALL) { + stack_size = c_fast_call_get_stack_size(arg_types, &word_arg_count); + PTR_FAIL_IF(c_fast_call_with_args(compiler, arg_types, stack_size, word_arg_count, 0)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + jump = sljit_emit_jump(compiler, type); + PTR_FAIL_IF(jump == NULL); + + PTR_FAIL_IF(post_call_with_args(compiler, arg_types, 0)); + return jump; } - if (type >= SLJIT_CALL3) { - *inst++ = MOV_rm_r; - *inst++ = MOD_DISP8 | (reg_map[SLJIT_R2] << 3) | 0x4 /* SIB */; - *inst++ = (0x4 /* none*/ << 3) | reg_map[SLJIT_SP]; - *inst++ = 2 * sizeof(sljit_sw); +#endif + + stack_size = cdecl_call_get_stack_size(compiler, arg_types, &word_arg_count); + PTR_FAIL_IF(cdecl_call_with_args(compiler, arg_types, stack_size, word_arg_count)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + jump = sljit_emit_jump(compiler, type); + PTR_FAIL_IF(jump == NULL); + + PTR_FAIL_IF(post_call_with_args(compiler, arg_types, stack_size)); + return jump; +} + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ + sljit_s32 stack_size = 0; + sljit_s32 word_arg_count; +#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) + sljit_s32 swap_args; +#endif + + CHECK_ERROR(); + CHECK(check_sljit_emit_icall(compiler, type, arg_types, src, srcw)); + +#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) + SLJIT_ASSERT(reg_map[SLJIT_R0] == 0 && reg_map[SLJIT_R2] == 1 && SLJIT_R0 == 1 && SLJIT_R2 == 3); + + if ((type & 0xff) == SLJIT_CALL) { + stack_size = c_fast_call_get_stack_size(arg_types, &word_arg_count); + swap_args = 0; + + if (word_arg_count > 0) { + if ((src & REG_MASK) == SLJIT_R2 || OFFS_REG(src) == SLJIT_R2) { + swap_args = 1; + if (((src & REG_MASK) | 0x2) == SLJIT_R2) + src ^= 0x2; + if ((OFFS_REG(src) | 0x2) == SLJIT_R2) + src ^= TO_OFFS_REG(0x2); + } + } + + FAIL_IF(c_fast_call_with_args(compiler, arg_types, stack_size, word_arg_count, swap_args)); + + compiler->saveds_offset += stack_size; + compiler->locals_offset += stack_size; + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + FAIL_IF(sljit_emit_ijump(compiler, type, src, srcw)); + + compiler->saveds_offset -= stack_size; + compiler->locals_offset -= stack_size; + + return post_call_with_args(compiler, arg_types, 0); } #endif - return SLJIT_SUCCESS; + + stack_size = cdecl_call_get_stack_size(compiler, arg_types, &word_arg_count); + FAIL_IF(cdecl_call_with_args(compiler, arg_types, stack_size, word_arg_count)); + + compiler->saveds_offset += stack_size; + compiler->locals_offset += stack_size; + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + FAIL_IF(sljit_emit_ijump(compiler, type, src, srcw)); + + compiler->saveds_offset -= stack_size; + compiler->locals_offset -= stack_size; + + return post_call_with_args(compiler, arg_types, stack_size); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) @@ -576,7 +878,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler INC_SIZE(1 + 1); PUSH_REG(reg_map[src]); } - else if (src & SLJIT_MEM) { + else { inst = emit_x86_instruction(compiler, 1, 0, 0, src, srcw); FAIL_IF(!inst); *inst++ = GROUP_FF; @@ -586,16 +888,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler FAIL_IF(!inst); INC_SIZE(1); } - else { - /* SLJIT_IMM. */ - inst = (sljit_u8*)ensure_buf(compiler, 1 + 5 + 1); - FAIL_IF(!inst); - - INC_SIZE(5 + 1); - *inst++ = PUSH_i32; - sljit_unaligned_store_sw(inst, srcw); - inst += sizeof(sljit_sw); - } RET(); return SLJIT_SUCCESS; diff --git a/pcre/sljit/sljitNativeX86_64.c b/pcre/sljit/sljitNativeX86_64.c index 039b68c45ab..85065656144 100644 --- a/pcre/sljit/sljitNativeX86_64.c +++ b/pcre/sljit/sljitNativeX86_64.c @@ -41,24 +41,31 @@ static sljit_s32 emit_load_imm64(struct sljit_compiler *compiler, sljit_s32 reg, static sljit_u8* generate_far_jump_code(struct sljit_jump *jump, sljit_u8 *code_ptr, sljit_s32 type) { + int short_addr = !(jump->flags & SLJIT_REWRITABLE_JUMP) && !(jump->flags & JUMP_LABEL) && (jump->u.target <= 0xffffffff); + + /* The relative jump below specialized for this case. */ + SLJIT_ASSERT(reg_map[TMP_REG2] >= 8); + if (type < SLJIT_JUMP) { /* Invert type. */ *code_ptr++ = get_jump_code(type ^ 0x1) - 0x10; - *code_ptr++ = 10 + 3; + *code_ptr++ = short_addr ? (6 + 3) : (10 + 3); } - *code_ptr++ = REX_W | ((reg_map[TMP_REG2] <= 7) ? 0 : REX_B); + *code_ptr++ = short_addr ? REX_B : (REX_W | REX_B); *code_ptr++ = MOV_r_i32 | reg_lmap[TMP_REG2]; jump->addr = (sljit_uw)code_ptr; if (jump->flags & JUMP_LABEL) jump->flags |= PATCH_MD; + else if (short_addr) + sljit_unaligned_store_s32(code_ptr, (sljit_s32)jump->u.target); else sljit_unaligned_store_sw(code_ptr, jump->u.target); - code_ptr += sizeof(sljit_sw); - if (reg_map[TMP_REG2] >= 8) - *code_ptr++ = REX_B; + code_ptr += short_addr ? sizeof(sljit_s32) : sizeof(sljit_sw); + + *code_ptr++ = REX_B; *code_ptr++ = GROUP_FF; *code_ptr++ = MOD_REG | (type >= SLJIT_FAST_CALL ? CALL_rm : JMP_rm) | reg_lmap[TMP_REG2]; @@ -66,15 +73,17 @@ static sljit_u8* generate_far_jump_code(struct sljit_jump *jump, sljit_u8 *code_ } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { - sljit_s32 i, tmp, size, saved_register_size; + sljit_s32 args, i, tmp, size, saved_register_size; sljit_u8 *inst; CHECK_ERROR(); - CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_emit_enter(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); + + compiler->mode32 = 0; #ifdef _WIN64 /* Two/four register slots for parameters plus space for xmm6 register if needed. */ @@ -108,6 +117,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi PUSH_REG(reg_lmap[i]); } + args = get_arg_count(arg_types); + if (args > 0) { size = args * 3; inst = (sljit_u8*)ensure_buf(compiler, 1 + size); @@ -117,35 +128,39 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi #ifndef _WIN64 if (args > 0) { - *inst++ = REX_W; - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (reg_map[SLJIT_S0] << 3) | 0x7 /* rdi */; + inst[0] = REX_W; + inst[1] = MOV_r_rm; + inst[2] = MOD_REG | (reg_map[SLJIT_S0] << 3) | 0x7 /* rdi */; + inst += 3; } if (args > 1) { - *inst++ = REX_W | REX_R; - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (reg_lmap[SLJIT_S1] << 3) | 0x6 /* rsi */; + inst[0] = REX_W | REX_R; + inst[1] = MOV_r_rm; + inst[2] = MOD_REG | (reg_lmap[SLJIT_S1] << 3) | 0x6 /* rsi */; + inst += 3; } if (args > 2) { - *inst++ = REX_W | REX_R; - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (reg_lmap[SLJIT_S2] << 3) | 0x2 /* rdx */; + inst[0] = REX_W | REX_R; + inst[1] = MOV_r_rm; + inst[2] = MOD_REG | (reg_lmap[SLJIT_S2] << 3) | 0x2 /* rdx */; } #else if (args > 0) { - *inst++ = REX_W; - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (reg_map[SLJIT_S0] << 3) | 0x1 /* rcx */; + inst[0] = REX_W; + inst[1] = MOV_r_rm; + inst[2] = MOD_REG | (reg_map[SLJIT_S0] << 3) | 0x1 /* rcx */; + inst += 3; } if (args > 1) { - *inst++ = REX_W; - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (reg_map[SLJIT_S1] << 3) | 0x2 /* rdx */; + inst[0] = REX_W; + inst[1] = MOV_r_rm; + inst[2] = MOD_REG | (reg_map[SLJIT_S1] << 3) | 0x2 /* rdx */; + inst += 3; } if (args > 2) { - *inst++ = REX_W | REX_B; - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (reg_map[SLJIT_S2] << 3) | 0x0 /* r8 */; + inst[0] = REX_W | REX_B; + inst[1] = MOV_r_rm; + inst[2] = MOD_REG | (reg_map[SLJIT_S2] << 3) | 0x0 /* r8 */; } #endif } @@ -154,58 +169,42 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi compiler->local_size = local_size; #ifdef _WIN64 - if (local_size > 1024) { - /* Allocate stack for the callback, which grows the stack. */ - inst = (sljit_u8*)ensure_buf(compiler, 1 + 4 + (3 + sizeof(sljit_s32))); - FAIL_IF(!inst); - INC_SIZE(4 + (3 + sizeof(sljit_s32))); - *inst++ = REX_W; - *inst++ = GROUP_BINARY_83; - *inst++ = MOD_REG | SUB | reg_map[SLJIT_SP]; - /* Allocated size for registers must be divisible by 8. */ - SLJIT_ASSERT(!(saved_register_size & 0x7)); - /* Aligned to 16 byte. */ - if (saved_register_size & 0x8) { - *inst++ = 5 * sizeof(sljit_sw); - local_size -= 5 * sizeof(sljit_sw); - } else { - *inst++ = 4 * sizeof(sljit_sw); - local_size -= 4 * sizeof(sljit_sw); - } - /* Second instruction */ - SLJIT_ASSERT(reg_map[SLJIT_R0] < 8); - *inst++ = REX_W; - *inst++ = MOV_rm_i32; - *inst++ = MOD_REG | reg_lmap[SLJIT_R0]; - sljit_unaligned_store_s32(inst, local_size); -#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ - || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) - compiler->skip_checks = 1; -#endif - FAIL_IF(sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_grow_stack))); - } -#endif - if (local_size > 0) { - if (local_size <= 127) { - inst = (sljit_u8*)ensure_buf(compiler, 1 + 4); - FAIL_IF(!inst); - INC_SIZE(4); - *inst++ = REX_W; - *inst++ = GROUP_BINARY_83; - *inst++ = MOD_REG | SUB | reg_map[SLJIT_SP]; - *inst++ = local_size; + if (local_size <= 4 * 4096) { + if (local_size > 4096) + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_SP), -4096); + if (local_size > 2 * 4096) + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_SP), -4096 * 2); + if (local_size > 3 * 4096) + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_SP), -4096 * 3); } else { - inst = (sljit_u8*)ensure_buf(compiler, 1 + 7); + EMIT_MOV(compiler, SLJIT_R0, 0, SLJIT_SP, 0); + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_IMM, (local_size - 1) >> 12); + + SLJIT_ASSERT (reg_map[SLJIT_R0] == 0); + + EMIT_MOV(compiler, TMP_REG2, 0, SLJIT_MEM1(SLJIT_R0), -4096); + FAIL_IF(emit_non_cum_binary(compiler, BINARY_OPCODE(SUB), + SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 4096)); + FAIL_IF(emit_non_cum_binary(compiler, BINARY_OPCODE(SUB), + TMP_REG1, 0, TMP_REG1, 0, SLJIT_IMM, 1)); + + inst = (sljit_u8*)ensure_buf(compiler, 1 + 2); FAIL_IF(!inst); - INC_SIZE(7); - *inst++ = REX_W; - *inst++ = GROUP_BINARY_81; - *inst++ = MOD_REG | SUB | reg_map[SLJIT_SP]; - sljit_unaligned_store_s32(inst, local_size); - inst += sizeof(sljit_s32); + + INC_SIZE(2); + inst[0] = JNE_i8; + inst[1] = (sljit_s8) -19; } + + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_MEM1(SLJIT_SP), -local_size); + } +#endif + + if (local_size > 0) { + FAIL_IF(emit_non_cum_binary(compiler, BINARY_OPCODE(SUB), + SLJIT_SP, 0, SLJIT_SP, 0, SLJIT_IMM, local_size)); } #ifdef _WIN64 @@ -223,14 +222,14 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, - sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds, + sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size) { sljit_s32 saved_register_size; CHECK_ERROR(); - CHECK(check_sljit_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size)); - set_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size); + CHECK(check_sljit_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size)); + set_set_context(compiler, options, arg_types, scratches, saveds, fscratches, fsaveds, local_size); #ifdef _WIN64 /* Two/four register slots for parameters plus space for xmm6 register if needed. */ @@ -414,7 +413,11 @@ static sljit_u8* emit_x86_instruction(struct sljit_compiler *compiler, sljit_s32 } } } - else if (!(flags & EX86_SSE2_OP2) && reg_map[b] >= 8) + else if (!(flags & EX86_SSE2_OP2)) { + if (reg_map[b] >= 8) + rex |= REX_B; + } + else if (freg_map[b] >= 8) rex |= REX_B; if (a & SLJIT_IMM) { @@ -441,7 +444,11 @@ static sljit_u8* emit_x86_instruction(struct sljit_compiler *compiler, sljit_s32 else { SLJIT_ASSERT(!(flags & EX86_SHIFT_INS) || a == SLJIT_PREF_SHIFT_REG); /* reg_map[SLJIT_PREF_SHIFT_REG] is less than 8. */ - if (!(flags & EX86_SSE2_OP1) && reg_map[a] >= 8) + if (!(flags & EX86_SSE2_OP1)) { + if (reg_map[a] >= 8) + rex |= REX_R; + } + else if (freg_map[a] >= 8) rex |= REX_R; } @@ -468,12 +475,12 @@ static sljit_u8* emit_x86_instruction(struct sljit_compiler *compiler, sljit_s32 if ((flags & EX86_BIN_INS) && (a & SLJIT_IMM)) *inst = (flags & EX86_BYTE_ARG) ? GROUP_BINARY_83 : GROUP_BINARY_81; - if ((a & SLJIT_IMM) || (a == 0)) + if (a & SLJIT_IMM) *buf_ptr = 0; else if (!(flags & EX86_SSE2_OP1)) *buf_ptr = reg_lmap[a] << 3; else - *buf_ptr = a << 3; + *buf_ptr = freg_lmap[a] << 3; } else { if (a & SLJIT_IMM) { @@ -487,7 +494,7 @@ static sljit_u8* emit_x86_instruction(struct sljit_compiler *compiler, sljit_s32 } if (!(b & SLJIT_MEM)) - *buf_ptr++ |= MOD_REG + ((!(flags & EX86_SSE2_OP2)) ? reg_lmap[b] : b); + *buf_ptr++ |= MOD_REG + ((!(flags & EX86_SSE2_OP2)) ? reg_lmap[b] : freg_lmap[b]); else if ((b & REG_MASK) != SLJIT_UNUSED) { if ((b & OFFS_REG_MASK) == SLJIT_UNUSED || (b & OFFS_REG_MASK) == TO_OFFS_REG(SLJIT_SP)) { if (immb != 0 || reg_lmap[b & REG_MASK] == 5) { @@ -545,45 +552,161 @@ static sljit_u8* emit_x86_instruction(struct sljit_compiler *compiler, sljit_s32 /* Call / return instructions */ /* --------------------------------------------------------------------- */ -static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 type) +#ifndef _WIN64 + +static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_s32 *src_ptr, sljit_sw srcw) { - sljit_u8 *inst; + sljit_s32 src = src_ptr ? (*src_ptr) : 0; + sljit_s32 word_arg_count = 0; - /* After any change update IS_REG_CHANGED_BY_CALL as well. */ -#ifndef _WIN64 - SLJIT_ASSERT(reg_map[SLJIT_R1] == 6 && reg_map[SLJIT_R0] < 8 && reg_map[SLJIT_R2] < 8 && reg_map[TMP_REG1] == 2); + SLJIT_ASSERT(reg_map[SLJIT_R1] == 6 && reg_map[SLJIT_R3] == 1 && reg_map[TMP_REG1] == 2); - inst = (sljit_u8*)ensure_buf(compiler, 1 + ((type < SLJIT_CALL3) ? 3 : 6)); - FAIL_IF(!inst); - INC_SIZE((type < SLJIT_CALL3) ? 3 : 6); - if (type >= SLJIT_CALL3) { - /* Move third argument to TMP_REG1. */ - *inst++ = REX_W; - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (0x2 /* rdx */ << 3) | reg_lmap[SLJIT_R2]; + compiler->mode32 = 0; + + /* Remove return value. */ + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + if ((arg_types & SLJIT_DEF_MASK) < SLJIT_ARG_TYPE_F32) + word_arg_count++; + arg_types >>= SLJIT_DEF_SHIFT; + } + + if (word_arg_count == 0) + return SLJIT_SUCCESS; + + if (src & SLJIT_MEM) { + ADJUST_LOCAL_OFFSET(src, srcw); + EMIT_MOV(compiler, TMP_REG2, 0, src, srcw); + *src_ptr = TMP_REG2; } - *inst++ = REX_W; - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (0x7 /* rdi */ << 3) | reg_lmap[SLJIT_R0]; + else if (src == SLJIT_R2 && word_arg_count >= SLJIT_R2) + *src_ptr = TMP_REG1; + + if (word_arg_count >= 3) + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_R2, 0); + return emit_mov(compiler, SLJIT_R2, 0, SLJIT_R0, 0); +} + #else - SLJIT_ASSERT(reg_map[SLJIT_R1] == 2 && reg_map[SLJIT_R0] < 8 && reg_map[SLJIT_R2] < 8 && reg_map[TMP_REG1] == 8); - inst = (sljit_u8*)ensure_buf(compiler, 1 + ((type < SLJIT_CALL3) ? 3 : 6)); - FAIL_IF(!inst); - INC_SIZE((type < SLJIT_CALL3) ? 3 : 6); - if (type >= SLJIT_CALL3) { - /* Move third argument to TMP_REG1. */ - *inst++ = REX_W | REX_R; - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (0x0 /* r8 */ << 3) | reg_lmap[SLJIT_R2]; +static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_s32 *src_ptr, sljit_sw srcw) +{ + sljit_s32 src = src_ptr ? (*src_ptr) : 0; + sljit_s32 arg_count = 0; + sljit_s32 word_arg_count = 0; + sljit_s32 float_arg_count = 0; + sljit_s32 types = 0; + sljit_s32 data_trandfer = 0; + static sljit_u8 word_arg_regs[5] = { 0, SLJIT_R3, SLJIT_R1, SLJIT_R2, TMP_REG1 }; + + SLJIT_ASSERT(reg_map[SLJIT_R3] == 1 && reg_map[SLJIT_R1] == 2 && reg_map[SLJIT_R2] == 8 && reg_map[TMP_REG1] == 9); + + compiler->mode32 = 0; + arg_types >>= SLJIT_DEF_SHIFT; + + while (arg_types) { + types = (types << SLJIT_DEF_SHIFT) | (arg_types & SLJIT_DEF_MASK); + + switch (arg_types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + case SLJIT_ARG_TYPE_F64: + arg_count++; + float_arg_count++; + + if (arg_count != float_arg_count) + data_trandfer = 1; + break; + default: + arg_count++; + word_arg_count++; + + if (arg_count != word_arg_count || arg_count != word_arg_regs[arg_count]) { + data_trandfer = 1; + + if (src == word_arg_regs[arg_count]) { + EMIT_MOV(compiler, TMP_REG2, 0, src, 0); + *src_ptr = TMP_REG2; + } + } + break; + } + + arg_types >>= SLJIT_DEF_SHIFT; } - *inst++ = REX_W; - *inst++ = MOV_r_rm; - *inst++ = MOD_REG | (0x1 /* rcx */ << 3) | reg_lmap[SLJIT_R0]; -#endif + + if (!data_trandfer) + return SLJIT_SUCCESS; + + if (src & SLJIT_MEM) { + ADJUST_LOCAL_OFFSET(src, srcw); + EMIT_MOV(compiler, TMP_REG2, 0, src, srcw); + *src_ptr = TMP_REG2; + } + + while (types) { + switch (types & SLJIT_DEF_MASK) { + case SLJIT_ARG_TYPE_F32: + if (arg_count != float_arg_count) + FAIL_IF(emit_sse2_load(compiler, 1, arg_count, float_arg_count, 0)); + arg_count--; + float_arg_count--; + break; + case SLJIT_ARG_TYPE_F64: + if (arg_count != float_arg_count) + FAIL_IF(emit_sse2_load(compiler, 0, arg_count, float_arg_count, 0)); + arg_count--; + float_arg_count--; + break; + default: + if (arg_count != word_arg_count || arg_count != word_arg_regs[arg_count]) + EMIT_MOV(compiler, word_arg_regs[arg_count], 0, word_arg_count, 0); + arg_count--; + word_arg_count--; + break; + } + + types >>= SLJIT_DEF_SHIFT; + } + return SLJIT_SUCCESS; } +#endif + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types) +{ + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_call(compiler, type, arg_types)); + + PTR_FAIL_IF(call_with_args(compiler, arg_types, NULL, 0)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_jump(compiler, type); +} + +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, + sljit_s32 arg_types, + sljit_s32 src, sljit_sw srcw) +{ + CHECK_ERROR(); + CHECK(check_sljit_emit_icall(compiler, type, arg_types, src, srcw)); + + FAIL_IF(call_with_args(compiler, arg_types, &src, srcw)); + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ + || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + compiler->skip_checks = 1; +#endif + + return sljit_emit_ijump(compiler, type, src, srcw); +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) { sljit_u8 *inst; @@ -629,11 +752,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler CHECK(check_sljit_emit_fast_return(compiler, src, srcw)); ADJUST_LOCAL_OFFSET(src, srcw); - if ((src & SLJIT_IMM) && NOT_HALFWORD(srcw)) { - FAIL_IF(emit_load_imm64(compiler, TMP_REG1, srcw)); - src = TMP_REG1; - } - if (FAST_IS_REG(src)) { if (reg_map[src] < 8) { inst = (sljit_u8*)ensure_buf(compiler, 1 + 1 + 1); @@ -651,7 +769,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler PUSH_REG(reg_lmap[src]); } } - else if (src & SLJIT_MEM) { + else { /* REX_W is not necessary (src is not immediate). */ compiler->mode32 = 1; inst = emit_x86_instruction(compiler, 1, 0, 0, src, srcw); @@ -663,23 +781,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler FAIL_IF(!inst); INC_SIZE(1); } - else { - SLJIT_ASSERT(IS_HALFWORD(srcw)); - /* SLJIT_IMM. */ - inst = (sljit_u8*)ensure_buf(compiler, 1 + 5 + 1); - FAIL_IF(!inst); - - INC_SIZE(5 + 1); - *inst++ = PUSH_i32; - sljit_unaligned_store_s32(inst, srcw); - inst += sizeof(sljit_s32); - } RET(); return SLJIT_SUCCESS; } - /* --------------------------------------------------------------------- */ /* Extend input */ /* --------------------------------------------------------------------- */ diff --git a/pcre/sljit/sljitNativeX86_common.c b/pcre/sljit/sljitNativeX86_common.c index eb0886d6715..6f02ee3e8b4 100644 --- a/pcre/sljit/sljitNativeX86_common.c +++ b/pcre/sljit/sljitNativeX86_common.c @@ -26,7 +26,11 @@ SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void) { +#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) + return "x86" SLJIT_CPUINFO " ABI:fastcall"; +#else return "x86" SLJIT_CPUINFO; +#endif } /* @@ -35,7 +39,7 @@ SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void) 1 - ECX 2 - EDX 3 - EBX - 4 - none + 4 - ESP 5 - EBP 6 - ESI 7 - EDI @@ -47,7 +51,7 @@ SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void) 1 - RCX 2 - RDX 3 - RBX - 4 - none + 4 - RSP 5 - RBP 6 - RSI 7 - RDI @@ -92,23 +96,32 @@ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 3] = { #ifndef _WIN64 /* Args: rdi(=7), rsi(=6), rdx(=2), rcx(=1), r8, r9. Scratches: rax(=0), r10, r11 */ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 4] = { - 0, 0, 6, 1, 7, 8, 11, 10, 12, 5, 13, 14, 15, 3, 4, 2, 9 + 0, 0, 6, 7, 1, 8, 11, 10, 12, 5, 13, 14, 15, 3, 4, 2, 9 }; /* low-map. reg_map & 0x7. */ static const sljit_u8 reg_lmap[SLJIT_NUMBER_OF_REGISTERS + 4] = { - 0, 0, 6, 1, 7, 0, 3, 2, 4, 5, 5, 6, 7, 3, 4, 2, 1 + 0, 0, 6, 7, 1, 0, 3, 2, 4, 5, 5, 6, 7, 3, 4, 2, 1 }; #else /* Args: rcx(=1), rdx(=2), r8, r9. Scratches: rax(=0), r10, r11 */ static const sljit_u8 reg_map[SLJIT_NUMBER_OF_REGISTERS + 4] = { - 0, 0, 2, 1, 10, 11, 12, 5, 13, 14, 15, 7, 6, 3, 4, 8, 9 + 0, 0, 2, 8, 1, 11, 12, 5, 13, 14, 15, 7, 6, 3, 4, 9, 10 }; /* low-map. reg_map & 0x7. */ static const sljit_u8 reg_lmap[SLJIT_NUMBER_OF_REGISTERS + 4] = { - 0, 0, 2, 1, 2, 3, 4, 5, 5, 6, 7, 7, 6, 3, 4, 0, 1 + 0, 0, 2, 0, 1, 3, 4, 5, 5, 6, 7, 7, 6, 3, 4, 1, 2 }; #endif +/* Args: xmm0-xmm3 */ +static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1] = { + 4, 0, 1, 2, 3, 5, 6 +}; +/* low-map. freg_map & 0x7. */ +static const sljit_u8 freg_lmap[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1] = { + 4, 0, 1, 2, 3, 5, 6 +}; + #define REX_W 0x48 #define REX_R 0x44 #define REX_X 0x42 @@ -178,6 +191,8 @@ static const sljit_u8 reg_lmap[SLJIT_NUMBER_OF_REGISTERS + 4] = { #define CVTTSD2SI_r_xm 0x2c #define DIV (/* GROUP_F7 */ 6 << 3) #define DIVSD_x_xm 0x5e +#define FSTPS 0xd9 +#define FSTPD 0xdd #define INT3 0xcc #define IDIV (/* GROUP_F7 */ 7 << 3) #define IMUL (/* GROUP_F7 */ 5 << 3) @@ -462,11 +477,7 @@ static sljit_u8* generate_near_jump_code(struct sljit_jump *jump, sljit_u8 *code code_ptr += sizeof(sljit_s8); } else { jump->flags |= PATCH_MW; -#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) - code_ptr += sizeof(sljit_sw); -#else code_ptr += sizeof(sljit_s32); -#endif } return code_ptr; @@ -613,9 +624,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) get_cpu_features(); return cpu_has_cmov; - case SLJIT_HAS_PREF_SHIFT_REG: - return 1; - case SLJIT_HAS_SSE2: #if (defined SLJIT_DETECT_SSE2 && SLJIT_DETECT_SSE2) if (cpu_has_sse2 == -1) @@ -634,14 +642,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) /* Operators */ /* --------------------------------------------------------------------- */ +#define BINARY_OPCODE(opcode) (((opcode ## _EAX_i32) << 24) | ((opcode ## _r_rm) << 16) | ((opcode ## _rm_r) << 8) | (opcode)) + static sljit_s32 emit_cum_binary(struct sljit_compiler *compiler, - sljit_u8 op_rm, sljit_u8 op_mr, sljit_u8 op_imm, sljit_u8 op_eax_imm, + sljit_u32 op_types, sljit_s32 dst, sljit_sw dstw, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w); static sljit_s32 emit_non_cum_binary(struct sljit_compiler *compiler, - sljit_u8 op_rm, sljit_u8 op_mr, sljit_u8 op_imm, sljit_u8 op_eax_imm, + sljit_u32 op_types, sljit_s32 dst, sljit_sw dstw, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w); @@ -653,22 +663,11 @@ static sljit_s32 emit_mov(struct sljit_compiler *compiler, #define EMIT_MOV(compiler, dst, dstw, src, srcw) \ FAIL_IF(emit_mov(compiler, dst, dstw, src, srcw)); -#ifdef _WIN32 -#include - -static void SLJIT_CALL sljit_grow_stack(sljit_sw local_size) -{ - /* Workaround for calling the internal _chkstk() function on Windows. - This function touches all 4k pages belongs to the requested stack space, - which size is passed in local_size. This is necessary on Windows where - the stack can only grow in 4k steps. However, this function just burn - CPU cycles if the stack is large enough. However, you don't know it in - advance, so it must always be called. I think this is a bad design in - general even if it has some reasons. */ - *(volatile sljit_s32*)alloca(local_size) = 0; -} +static SLJIT_INLINE sljit_s32 emit_sse2_store(struct sljit_compiler *compiler, + sljit_s32 single, sljit_s32 dst, sljit_sw dstw, sljit_s32 src); -#endif +static SLJIT_INLINE sljit_s32 emit_sse2_load(struct sljit_compiler *compiler, + sljit_s32 single, sljit_s32 dst, sljit_s32 src, sljit_sw srcw); #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) #include "sljitNativeX86_32.c" @@ -1115,7 +1114,7 @@ static sljit_s32 emit_unary(struct sljit_compiler *compiler, sljit_u8 opcode, return SLJIT_SUCCESS; } - if (dst == SLJIT_UNUSED) + if (SLJIT_UNLIKELY(dst == SLJIT_UNUSED)) dst = TMP_REG1; if (FAST_IS_REG(dst)) { @@ -1182,12 +1181,6 @@ static sljit_s32 emit_clz(struct sljit_compiler *compiler, sljit_s32 op_flags, SLJIT_UNUSED_ARG(op_flags); - if (SLJIT_UNLIKELY(src & SLJIT_IMM)) { - EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_IMM, srcw); - src = TMP_REG1; - srcw = 0; - } - if (cpu_has_cmov == -1) get_cpu_features(); @@ -1242,13 +1235,9 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile sljit_s32 dst, sljit_sw dstw, sljit_s32 src, sljit_sw srcw) { - sljit_s32 update = 0; sljit_s32 op_flags = GET_ALL_FLAGS(op); #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) sljit_s32 dst_is_ereg = 0; - sljit_s32 src_is_ereg = 0; -#else -# define src_is_ereg 0 #endif CHECK_ERROR(); @@ -1257,7 +1246,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile ADJUST_LOCAL_OFFSET(src, srcw); CHECK_EXTRA_REGS(dst, dstw, dst_is_ereg = 1); - CHECK_EXTRA_REGS(src, srcw, src_is_ereg = 1); + CHECK_EXTRA_REGS(src, srcw, (void)0); #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) compiler->mode32 = op_flags & SLJIT_I32_OP; #endif @@ -1270,34 +1259,29 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile op = GET_OPCODE(op); - if (op >= SLJIT_MOV && op <= SLJIT_MOVU_P) { + if (op >= SLJIT_MOV && op <= SLJIT_MOV_P) { #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) compiler->mode32 = 0; #endif + if (FAST_IS_REG(src) && src == dst) { + if (!TYPE_CAST_NEEDED(op)) + return SLJIT_SUCCESS; + } + if (op_flags & SLJIT_I32_OP) { - if (FAST_IS_REG(src) && src == dst) { - if (!TYPE_CAST_NEEDED(op)) - return SLJIT_SUCCESS; - } #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) - if (op == SLJIT_MOV_S32 && (src & SLJIT_MEM)) - op = SLJIT_MOV_U32; - if (op == SLJIT_MOVU_S32 && (src & SLJIT_MEM)) - op = SLJIT_MOVU_U32; - if (op == SLJIT_MOV_U32 && (src & SLJIT_IMM)) - op = SLJIT_MOV_S32; - if (op == SLJIT_MOVU_U32 && (src & SLJIT_IMM)) - op = SLJIT_MOVU_S32; + if (src & SLJIT_MEM) { + if (op == SLJIT_MOV_S32) + op = SLJIT_MOV_U32; + } + else if (src & SLJIT_IMM) { + if (op == SLJIT_MOV_U32) + op = SLJIT_MOV_S32; + } #endif } - SLJIT_COMPILE_ASSERT(SLJIT_MOV + 8 == SLJIT_MOVU, movu_offset); - if (op >= SLJIT_MOVU) { - update = 1; - op -= 8; - } - if (src & SLJIT_IMM) { switch (op) { case SLJIT_MOV_U8: @@ -1369,28 +1353,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile if (SLJIT_UNLIKELY(dst_is_ereg) && dst == TMP_REG1) return emit_mov(compiler, SLJIT_MEM1(SLJIT_SP), dstw, TMP_REG1, 0); #endif - - if (SLJIT_UNLIKELY(update) && (src & SLJIT_MEM) && !src_is_ereg && (src & REG_MASK)) { - if ((src & OFFS_REG_MASK) != 0) { - FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32, - (src & REG_MASK), 0, (src & REG_MASK), 0, OFFS_REG(dst), 0)); - } - else if (srcw != 0) { - FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32, - (src & REG_MASK), 0, (src & REG_MASK), 0, SLJIT_IMM, srcw)); - } - } - - if (SLJIT_UNLIKELY(update) && (dst & SLJIT_MEM) && (dst & REG_MASK)) { - if ((dst & OFFS_REG_MASK) != 0) { - FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32, - (dst & REG_MASK), 0, (dst & REG_MASK), 0, OFFS_REG(dst), 0)); - } - else if (dstw != 0) { - FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32, - (dst & REG_MASK), 0, (dst & REG_MASK), 0, SLJIT_IMM, dstw)); - } - } return SLJIT_SUCCESS; } @@ -1408,10 +1370,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile } return SLJIT_SUCCESS; - -#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) -# undef src_is_ereg -#endif } #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) @@ -1445,12 +1403,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile #endif static sljit_s32 emit_cum_binary(struct sljit_compiler *compiler, - sljit_u8 op_rm, sljit_u8 op_mr, sljit_u8 op_imm, sljit_u8 op_eax_imm, + sljit_u32 op_types, sljit_s32 dst, sljit_sw dstw, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w) { sljit_u8* inst; + sljit_u8 op_eax_imm = (op_types >> 24); + sljit_u8 op_rm = (op_types >> 16) & 0xff; + sljit_u8 op_mr = (op_types >> 8) & 0xff; + sljit_u8 op_imm = op_types & 0xff; if (dst == SLJIT_UNUSED) { EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w); @@ -1561,12 +1523,16 @@ static sljit_s32 emit_cum_binary(struct sljit_compiler *compiler, } static sljit_s32 emit_non_cum_binary(struct sljit_compiler *compiler, - sljit_u8 op_rm, sljit_u8 op_mr, sljit_u8 op_imm, sljit_u8 op_eax_imm, + sljit_u32 op_types, sljit_s32 dst, sljit_sw dstw, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w) { sljit_u8* inst; + sljit_u8 op_eax_imm = (op_types >> 24); + sljit_u8 op_rm = (op_types >> 16) & 0xff; + sljit_u8 op_mr = (op_types >> 8) & 0xff; + sljit_u8 op_imm = op_types & 0xff; if (dst == SLJIT_UNUSED) { EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w); @@ -2044,7 +2010,7 @@ static sljit_s32 emit_shift(struct sljit_compiler *compiler, *inst |= mode; EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, TMP_REG1, 0); } - else if (FAST_IS_REG(dst) && dst != src2 && !ADDRESSING_DEPENDS_ON(src2, dst)) { + else if (SLOW_IS_REG(dst) && dst != src2 && !ADDRESSING_DEPENDS_ON(src2, dst)) { if (src1 != dst) EMIT_MOV(compiler, dst, 0, src1, src1w); EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_PREF_SHIFT_REG, 0); @@ -2057,27 +2023,24 @@ static sljit_s32 emit_shift(struct sljit_compiler *compiler, else { /* This case is complex since ecx itself may be used for addressing, and this case must be supported as well. */ -#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w); +#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) EMIT_MOV(compiler, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_PREF_SHIFT_REG, 0); EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, src2, src2w); inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_PREF_SHIFT_REG, 0, TMP_REG1, 0); FAIL_IF(!inst); *inst |= mode; EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, SLJIT_MEM1(SLJIT_SP), 0); - EMIT_MOV(compiler, dst, dstw, TMP_REG1, 0); #else - EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w); - EMIT_MOV(compiler, TMP_REG2, 0, src2, src2w); - inst = emit_x86_instruction(compiler, 1, TMP_REG2, 0, SLJIT_PREF_SHIFT_REG, 0); - FAIL_IF(!inst); - *inst = XCHG_r_rm; + EMIT_MOV(compiler, TMP_REG2, 0, SLJIT_PREF_SHIFT_REG, 0); + EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, src2, src2w); inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_PREF_SHIFT_REG, 0, TMP_REG1, 0); FAIL_IF(!inst); *inst |= mode; EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, TMP_REG2, 0); - EMIT_MOV(compiler, dst, dstw, TMP_REG1, 0); #endif + if (dst != SLJIT_UNUSED) + return emit_mov(compiler, dst, dstw, TMP_REG1, 0); } return SLJIT_SUCCESS; @@ -2101,7 +2064,7 @@ static sljit_s32 emit_shift_with_flags(struct sljit_compiler *compiler, if (!set_flags) return emit_mov(compiler, dst, dstw, src1, src1w); /* OR dst, src, 0 */ - return emit_cum_binary(compiler, OR_r_rm, OR_rm_r, OR, OR_EAX_i32, + return emit_cum_binary(compiler, BINARY_OPCODE(OR), dst, dstw, src1, src1w, SLJIT_IMM, 0); } @@ -2111,10 +2074,10 @@ static sljit_s32 emit_shift_with_flags(struct sljit_compiler *compiler, if (!FAST_IS_REG(dst)) FAIL_IF(emit_cmp_binary(compiler, src1, src1w, SLJIT_IMM, 0)); - FAIL_IF(emit_shift(compiler,mode, dst, dstw, src1, src1w, src2, src2w)); + FAIL_IF(emit_shift(compiler, mode, dst, dstw, src1, src1w, src2, src2w)); if (FAST_IS_REG(dst)) - return emit_cmp_binary(compiler, dst, dstw, SLJIT_IMM, 0); + return emit_cmp_binary(compiler, (dst == SLJIT_UNUSED) ? TMP_REG1 : dst, dstw, SLJIT_IMM, 0); return SLJIT_SUCCESS; } @@ -2145,10 +2108,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile if (emit_lea_binary(compiler, dst, dstw, src1, src1w, src2, src2w) != SLJIT_ERR_UNSUPPORTED) return compiler->error; } - return emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32, + return emit_cum_binary(compiler, BINARY_OPCODE(ADD), dst, dstw, src1, src1w, src2, src2w); case SLJIT_ADDC: - return emit_cum_binary(compiler, ADC_r_rm, ADC_rm_r, ADC, ADC_EAX_i32, + return emit_cum_binary(compiler, BINARY_OPCODE(ADC), dst, dstw, src1, src1w, src2, src2w); case SLJIT_SUB: if (!HAS_FLAGS(op)) { @@ -2158,23 +2121,23 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile if (dst == SLJIT_UNUSED) return emit_cmp_binary(compiler, src1, src1w, src2, src2w); - return emit_non_cum_binary(compiler, SUB_r_rm, SUB_rm_r, SUB, SUB_EAX_i32, + return emit_non_cum_binary(compiler, BINARY_OPCODE(SUB), dst, dstw, src1, src1w, src2, src2w); case SLJIT_SUBC: - return emit_non_cum_binary(compiler, SBB_r_rm, SBB_rm_r, SBB, SBB_EAX_i32, + return emit_non_cum_binary(compiler, BINARY_OPCODE(SBB), dst, dstw, src1, src1w, src2, src2w); case SLJIT_MUL: return emit_mul(compiler, dst, dstw, src1, src1w, src2, src2w); case SLJIT_AND: if (dst == SLJIT_UNUSED) return emit_test_binary(compiler, src1, src1w, src2, src2w); - return emit_cum_binary(compiler, AND_r_rm, AND_rm_r, AND, AND_EAX_i32, + return emit_cum_binary(compiler, BINARY_OPCODE(AND), dst, dstw, src1, src1w, src2, src2w); case SLJIT_OR: - return emit_cum_binary(compiler, OR_r_rm, OR_rm_r, OR, OR_EAX_i32, + return emit_cum_binary(compiler, BINARY_OPCODE(OR), dst, dstw, src1, src1w, src2, src2w); case SLJIT_XOR: - return emit_cum_binary(compiler, XOR_r_rm, XOR_rm_r, XOR, XOR_EAX_i32, + return emit_cum_binary(compiler, BINARY_OPCODE(XOR), dst, dstw, src1, src1w, src2, src2w); case SLJIT_SHL: return emit_shift_with_flags(compiler, SHL, HAS_FLAGS(op), @@ -2203,7 +2166,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg) SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_float_register_index(sljit_s32 reg) { CHECK_REG_INDEX(check_sljit_get_float_register_index(reg)); +#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) return reg; +#else + return freg_map[reg]; +#endif } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler, @@ -2345,6 +2312,7 @@ static SLJIT_INLINE sljit_s32 sljit_emit_fop1_cmp(struct sljit_compiler *compile FAIL_IF(emit_sse2_load(compiler, op & SLJIT_F32_OP, TMP_FREG, src1, src1w)); src1 = TMP_FREG; } + return emit_sse2_logic(compiler, UCOMISD_x_xm, !(op & SLJIT_F32_OP), src1, src2, src2w); } @@ -2516,9 +2484,6 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP); type &= 0xff; - if (type >= SLJIT_CALL1) - PTR_FAIL_IF(call_with_args(compiler, type)); - /* Worst case size. */ #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) compiler->size += (type >= SLJIT_JUMP) ? 5 : 6; @@ -2534,14 +2499,6 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile return jump; } -#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) -#ifndef _WIN64 -#define IS_REG_CHANGED_BY_CALL(src, type) ((src) == SLJIT_R3) -#else -#define IS_REG_CHANGED_BY_CALL(src, type) ((src) == SLJIT_R2) -#endif -#endif - SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) { sljit_u8 *inst; @@ -2553,25 +2510,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi CHECK_EXTRA_REGS(src, srcw, (void)0); - if (type >= SLJIT_CALL1) { -#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) -#if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) - if (src == SLJIT_R2) { - EMIT_MOV(compiler, TMP_REG1, 0, src, 0); - src = TMP_REG1; - } - if (src == SLJIT_MEM1(SLJIT_SP) && type >= SLJIT_CALL3) - srcw += sizeof(sljit_sw); -#endif -#else - if ((src & SLJIT_MEM) || IS_REG_CHANGED_BY_CALL(src, type)) { - EMIT_MOV(compiler, TMP_REG2, 0, src, srcw); - src = TMP_REG2; - } -#endif - FAIL_IF(call_with_args(compiler, type)); - } - if (src == SLJIT_IMM) { jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); FAIL_IF_NULL(jump); diff --git a/pcre/sljit/sljitUtils.c b/pcre/sljit/sljitUtils.c index 9029db292c0..5c2a8389328 100644 --- a/pcre/sljit/sljitUtils.c +++ b/pcre/sljit/sljitUtils.c @@ -48,12 +48,12 @@ static SLJIT_INLINE void allocator_release_lock(void) #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK) -SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_grab_lock(void) +SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_grab_lock(void) { /* Always successful. */ } -SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_release_lock(void) +SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_release_lock(void) { /* Always successful. */ } @@ -88,7 +88,7 @@ static SLJIT_INLINE void allocator_release_lock(void) static HANDLE global_mutex = 0; -SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_grab_lock(void) +SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_grab_lock(void) { /* No idea what to do if an error occures. Static mutexes should never fail... */ if (!global_mutex) @@ -97,7 +97,7 @@ SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_grab_lock(void) WaitForSingleObject(global_mutex, INFINITE); } -SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_release_lock(void) +SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_release_lock(void) { ReleaseMutex(global_mutex); } @@ -130,12 +130,12 @@ static SLJIT_INLINE void allocator_release_lock(void) static pthread_mutex_t global_mutex = PTHREAD_MUTEX_INITIALIZER; -SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_grab_lock(void) +SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_grab_lock(void) { pthread_mutex_lock(&global_mutex); } -SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_release_lock(void) +SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_release_lock(void) { pthread_mutex_unlock(&global_mutex); } @@ -203,7 +203,7 @@ static SLJIT_INLINE sljit_s32 open_dev_zero(void) /* Planning to make it even more clever in the future. */ static sljit_sw sljit_page_align = 0; -SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(sljit_uw limit, sljit_uw max_limit, void *allocator_data) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_FUNC sljit_allocate_stack(sljit_uw start_size, sljit_uw max_size, void *allocator_data) { struct sljit_stack *stack; void *ptr; @@ -212,7 +212,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(slj #endif SLJIT_UNUSED_ARG(allocator_data); - if (limit > max_limit || limit < 1) + if (start_size > max_size || start_size < 1) return NULL; #ifdef _WIN32 @@ -234,25 +234,27 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(slj if (!stack) return NULL; - /* Align max_limit. */ - max_limit = (max_limit + sljit_page_align) & ~sljit_page_align; + /* Align max_size. */ + max_size = (max_size + sljit_page_align) & ~sljit_page_align; #ifdef _WIN32 - ptr = VirtualAlloc(NULL, max_limit, MEM_RESERVE, PAGE_READWRITE); + ptr = VirtualAlloc(NULL, max_size, MEM_RESERVE, PAGE_READWRITE); if (!ptr) { SLJIT_FREE(stack, allocator_data); return NULL; } - stack->max_limit = (sljit_u8 *)ptr; - stack->base = stack->max_limit + max_limit; - stack->limit = stack->base; - if (sljit_stack_resize(stack, stack->base - limit)) { + + stack->min_start = (sljit_u8 *)ptr; + stack->end = stack->min_start + max_size; + stack->start = stack->end; + + if (sljit_stack_resize(stack, stack->end - start_size) == NULL) { sljit_free_stack(stack, allocator_data); return NULL; } #else #ifdef MAP_ANON - ptr = mmap(NULL, max_limit, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); + ptr = mmap(NULL, max_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); #else if (dev_zero < 0) { if (open_dev_zero()) { @@ -260,73 +262,70 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(slj return NULL; } } - ptr = mmap(NULL, max_limit, PROT_READ | PROT_WRITE, MAP_PRIVATE, dev_zero, 0); + ptr = mmap(NULL, max_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, dev_zero, 0); #endif if (ptr == MAP_FAILED) { SLJIT_FREE(stack, allocator_data); return NULL; } - stack->max_limit = (sljit_u8 *)ptr; - stack->base = stack->max_limit + max_limit; - stack->limit = stack->base - limit; + stack->min_start = (sljit_u8 *)ptr; + stack->end = stack->min_start + max_size; + stack->start = stack->end - start_size; #endif - stack->top = stack->base; + stack->top = stack->end; return stack; } #undef PAGE_ALIGN -SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_free_stack(struct sljit_stack *stack, void *allocator_data) +SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_free_stack(struct sljit_stack *stack, void *allocator_data) { SLJIT_UNUSED_ARG(allocator_data); #ifdef _WIN32 - VirtualFree((void*)stack->max_limit, 0, MEM_RELEASE); + VirtualFree((void*)stack->min_start, 0, MEM_RELEASE); #else - munmap((void*)stack->max_limit, stack->base - stack->max_limit); + munmap((void*)stack->min_start, stack->end - stack->min_start); #endif SLJIT_FREE(stack, allocator_data); } -SLJIT_API_FUNC_ATTRIBUTE sljit_sw SLJIT_CALL sljit_stack_resize(struct sljit_stack *stack, sljit_u8 *new_limit) +SLJIT_API_FUNC_ATTRIBUTE sljit_u8 *SLJIT_FUNC sljit_stack_resize(struct sljit_stack *stack, sljit_u8 *new_start) { - sljit_uw aligned_old_limit; - sljit_uw aligned_new_limit; + sljit_uw aligned_old_start; + sljit_uw aligned_new_start; + + if ((new_start < stack->min_start) || (new_start >= stack->end)) + return NULL; - if ((new_limit < stack->max_limit) || (new_limit >= stack->base)) - return -1; #ifdef _WIN32 - aligned_new_limit = (sljit_uw)new_limit & ~sljit_page_align; - aligned_old_limit = ((sljit_uw)stack->limit) & ~sljit_page_align; - if (aligned_new_limit != aligned_old_limit) { - if (aligned_new_limit < aligned_old_limit) { - if (!VirtualAlloc((void*)aligned_new_limit, aligned_old_limit - aligned_new_limit, MEM_COMMIT, PAGE_READWRITE)) - return -1; + aligned_new_start = (sljit_uw)new_start & ~sljit_page_align; + aligned_old_start = ((sljit_uw)stack->start) & ~sljit_page_align; + if (aligned_new_start != aligned_old_start) { + if (aligned_new_start < aligned_old_start) { + if (!VirtualAlloc((void*)aligned_new_start, aligned_old_start - aligned_new_start, MEM_COMMIT, PAGE_READWRITE)) + return NULL; } else { - if (!VirtualFree((void*)aligned_old_limit, aligned_new_limit - aligned_old_limit, MEM_DECOMMIT)) - return -1; + if (!VirtualFree((void*)aligned_old_start, aligned_new_start - aligned_old_start, MEM_DECOMMIT)) + return NULL; } } - stack->limit = new_limit; - return 0; #else - if (new_limit <= stack->limit) { - stack->limit = new_limit; - return 0; - } - aligned_new_limit = (sljit_uw)new_limit & ~sljit_page_align; - aligned_old_limit = ((sljit_uw)stack->limit) & ~sljit_page_align; - /* If madvise is available, we release the unnecessary space. */ + if (stack->start < new_start) { + aligned_new_start = (sljit_uw)new_start & ~sljit_page_align; + aligned_old_start = ((sljit_uw)stack->start) & ~sljit_page_align; + /* If madvise is available, we release the unnecessary space. */ #if defined(MADV_DONTNEED) - if (aligned_new_limit > aligned_old_limit) - madvise((void*)aligned_old_limit, aligned_new_limit - aligned_old_limit, MADV_DONTNEED); + if (aligned_new_start > aligned_old_start) + madvise((void*)aligned_old_start, aligned_new_start - aligned_old_start, MADV_DONTNEED); #elif defined(POSIX_MADV_DONTNEED) - if (aligned_new_limit > aligned_old_limit) - posix_madvise((void*)aligned_old_limit, aligned_new_limit - aligned_old_limit, POSIX_MADV_DONTNEED); + if (aligned_new_start > aligned_old_start) + posix_madvise((void*)aligned_old_start, aligned_new_start - aligned_old_start, POSIX_MADV_DONTNEED); #endif - stack->limit = new_limit; - return 0; + } #endif + stack->start = new_start; + return new_start; } #endif /* SLJIT_UTIL_STACK */ diff --git a/pcre/test-driver b/pcre/test-driver index 8e575b017d9..0218a01f616 100755 --- a/pcre/test-driver +++ b/pcre/test-driver @@ -1,9 +1,9 @@ #! /bin/sh # test-driver - basic testsuite driver script. -scriptversion=2013-07-13.22; # UTC +scriptversion=2016-01-11.22; # UTC -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2017 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -143,6 +143,6 @@ echo ":copy-in-global-log: $gcopy" >> $trs_file # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-time-zone: "UTC" +# time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: diff --git a/pcre/testdata/testinput2 b/pcre/testdata/testinput2 index 08c6f39a565..8ba4dc4ddab 100644 --- a/pcre/testdata/testinput2 +++ b/pcre/testdata/testinput2 @@ -4249,4 +4249,12 @@ backtracking verbs. --/ /(?=.*[A-Z])/I +"(?<=(a))\1?b" + ab + aaab + +"(?=(a))\1?b" + ab + aaab + /-- End of testinput2 --/ diff --git a/pcre/testdata/testinput5 b/pcre/testdata/testinput5 index 28561a93572..c94008c3f29 100644 --- a/pcre/testdata/testinput5 +++ b/pcre/testdata/testinput5 @@ -798,4 +798,10 @@ /(?<=\K\x{17f})/8G+ \x{17f}\x{17f}\x{17f}\x{17f}\x{17f} +/\C[^\v]+\x80/8 + [AΏBŀC] + +/\C[^\d]+\x80/8 + [AΏBŀC] + /-- End of testinput5 --/ diff --git a/pcre/testdata/testoutput2 b/pcre/testdata/testoutput2 index 811bbefc84c..61ed8d9d4e4 100644 --- a/pcre/testdata/testoutput2 +++ b/pcre/testdata/testoutput2 @@ -14705,4 +14705,20 @@ No options No first char No need char +"(?<=(a))\1?b" + ab + 0: b + 1: a + aaab + 0: ab + 1: a + +"(?=(a))\1?b" + ab + 0: ab + 1: a + aaab + 0: ab + 1: a + /-- End of testinput2 --/ diff --git a/pcre/testdata/testoutput5 b/pcre/testdata/testoutput5 index bab989ca7e5..090e1e1c85f 100644 --- a/pcre/testdata/testoutput5 +++ b/pcre/testdata/testoutput5 @@ -1942,4 +1942,12 @@ Need char = 'z' 0: \x{17f} 0+ +/\C[^\v]+\x80/8 + [AΏBŀC] +No match + +/\C[^\d]+\x80/8 + [AΏBŀC] +No match + /-- End of testinput5 --/ -- cgit v1.2.1 From adaa891ae7113069e402b40637dd9ddbd96d27bc Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Thu, 12 Apr 2018 14:55:43 +0200 Subject: MDEV-13699: Assertion `!new_field->field_name.str || strlen(new_field->field_name.str) == new_field->field_name.length' failed in create_tmp_table on 2nd execution of PS with semijoin The problem was that SJ (semi-join) used secondary list (array) of subquery select list. The items there was prepared once then cleaned up (but not really freed from memory because it was made in statement memory). Original list was not prepared after first execution because select was removed by conversion to SJ. The solution is to use original list but prepare it first. --- mysql-test/r/subselect_sj.result | 26 ++++++++++++++++++++++++++ mysql-test/r/subselect_sj_jcl6.result | 26 ++++++++++++++++++++++++++ mysql-test/t/subselect_sj.test | 30 ++++++++++++++++++++++++++++++ sql/opt_subselect.cc | 24 ++++++++++++++++-------- 4 files changed, 98 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/subselect_sj.result b/mysql-test/r/subselect_sj.result index 74384141998..519d53eb98f 100644 --- a/mysql-test/r/subselect_sj.result +++ b/mysql-test/r/subselect_sj.result @@ -3153,4 +3153,30 @@ id select_type table type possible_keys key key_len ref rows filtered Extra Warnings: Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2`,`test`.`t4`.`c4` AS `c4` from `test`.`t1` left join (`test`.`t2` join `test`.`t4`) on(((`test`.`t2`.`c2` = `test`.`t1`.`c1`) and (`test`.`t1`.`c1`,(select `test`.`t3`.`c3` from `test`.`t3` where ((`test`.`t2`.`c2`) = `test`.`t3`.`c3`))))) where 1 DROP TABLE t1,t2,t3,t4; +# +# MDEV-13699: Assertion `!new_field->field_name.str || +# strlen(new_field->field_name.str) == new_field->field_name.length' +# failed in create_tmp_table on 2nd execution of PS with semijoin +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (c INT); +CREATE ALGORITHM=MERGE VIEW v3 AS SELECT * FROM t3; +INSERT INTO t3 VALUES (5),(6); +PREPARE stmt FROM +"SELECT * FROM t1 + WHERE EXISTS ( + SELECT * FROM t2 WHERE t1.a IN ( SELECT c AS fld FROM v3 ) + )"; +EXECUTE stmt; +a +EXECUTE stmt; +a +EXECUTE stmt; +a +drop view v3; +drop table t1,t2,t3; +# End of 5.5 test set optimizer_switch=@subselect_sj_tmp; diff --git a/mysql-test/r/subselect_sj_jcl6.result b/mysql-test/r/subselect_sj_jcl6.result index 47dbdd782b5..32704060208 100644 --- a/mysql-test/r/subselect_sj_jcl6.result +++ b/mysql-test/r/subselect_sj_jcl6.result @@ -3167,6 +3167,32 @@ id select_type table type possible_keys key key_len ref rows filtered Extra Warnings: Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2`,`test`.`t4`.`c4` AS `c4` from `test`.`t1` left join (`test`.`t2` join `test`.`t4`) on(((`test`.`t2`.`c2` = `test`.`t1`.`c1`) and (`test`.`t1`.`c1`,(select `test`.`t3`.`c3` from `test`.`t3` where ((`test`.`t2`.`c2`) = `test`.`t3`.`c3`))))) where 1 DROP TABLE t1,t2,t3,t4; +# +# MDEV-13699: Assertion `!new_field->field_name.str || +# strlen(new_field->field_name.str) == new_field->field_name.length' +# failed in create_tmp_table on 2nd execution of PS with semijoin +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (c INT); +CREATE ALGORITHM=MERGE VIEW v3 AS SELECT * FROM t3; +INSERT INTO t3 VALUES (5),(6); +PREPARE stmt FROM +"SELECT * FROM t1 + WHERE EXISTS ( + SELECT * FROM t2 WHERE t1.a IN ( SELECT c AS fld FROM v3 ) + )"; +EXECUTE stmt; +a +EXECUTE stmt; +a +EXECUTE stmt; +a +drop view v3; +drop table t1,t2,t3; +# End of 5.5 test set optimizer_switch=@subselect_sj_tmp; # # BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off diff --git a/mysql-test/t/subselect_sj.test b/mysql-test/t/subselect_sj.test index acee1a67d63..0a35a61ecd3 100644 --- a/mysql-test/t/subselect_sj.test +++ b/mysql-test/t/subselect_sj.test @@ -2841,5 +2841,35 @@ eval EXPLAIN EXTENDED $q2; DROP TABLE t1,t2,t3,t4; +--echo # +--echo # MDEV-13699: Assertion `!new_field->field_name.str || +--echo # strlen(new_field->field_name.str) == new_field->field_name.length' +--echo # failed in create_tmp_table on 2nd execution of PS with semijoin +--echo # + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); + +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (3),(4); + +CREATE TABLE t3 (c INT); +CREATE ALGORITHM=MERGE VIEW v3 AS SELECT * FROM t3; +INSERT INTO t3 VALUES (5),(6); + +PREPARE stmt FROM + "SELECT * FROM t1 + WHERE EXISTS ( + SELECT * FROM t2 WHERE t1.a IN ( SELECT c AS fld FROM v3 ) + )"; +EXECUTE stmt; +EXECUTE stmt; +EXECUTE stmt; + +drop view v3; +drop table t1,t2,t3; + +--echo # End of 5.5 test + # The following command must be the last one the file set optimizer_switch=@subselect_sj_tmp; diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 1bda84bacd7..a7edd64e68b 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -3725,21 +3725,29 @@ bool setup_sj_materialization_part1(JOIN_TAB *sjm_tab) SJ_MATERIALIZATION_INFO *sjm= emb_sj_nest->sj_mat_info; THD *thd= tab->join->thd; /* First the calls come to the materialization function */ - //List &item_list= emb_sj_nest->sj_subq_pred->unit->first_select()->item_list; - + DBUG_ASSERT(sjm->is_used); /* Set up the table to write to, do as select_union::create_result_table does */ sjm->sjm_table_param.init(); sjm->sjm_table_param.bit_fields_as_long= TRUE; - //List_iterator it(item_list); SELECT_LEX *subq_select= emb_sj_nest->sj_subq_pred->unit->first_select(); - Item **p_item= subq_select->ref_pointer_array; - Item **p_end= p_item + subq_select->item_list.elements; - //while((right_expr= it++)) - for(;p_item != p_end; p_item++) - sjm->sjm_table_cols.push_back(*p_item); + List_iterator it(subq_select->item_list); + Item *item; + while((item= it++)) + { + /* + This semi-join replaced the subquery (subq_select) and so on + re-executing it will not be prepared. To use the Items from its + select list we have to prepare (fix_fields) them + */ + if (!item->fixed && item->fix_fields(thd, it.ref())) + DBUG_RETURN(TRUE); + item= *(it.ref()); // it can be changed by fix_fields + DBUG_ASSERT(!item->name_length || item->name_length == strlen(item->name)); + sjm->sjm_table_cols.push_back(item, thd->mem_root); + } sjm->sjm_table_param.field_count= subq_select->item_list.elements; sjm->sjm_table_param.force_not_null_cols= TRUE; -- cgit v1.2.1 From eb057dce2027b673b7b140bae42963774027e0a5 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 24 Apr 2018 15:51:49 -0700 Subject: MDEV-15035 Wrong results when calling a stored procedure multiple times with different arguments. If the ON expression of an outer join is an OR formula with one of the disjunct being a constant formula then the expression cannot be null-rejected if the constant formula is true. Otherwise it can be null-rejected and if so the outer join can be converted into inner join. This optimization was added in the patch for mdev-4817. Yet the code had a defect: if the query was used in a stored procedure with parameters and the constant item contained some of them then the value of this constant item depended on the values of the parameters. With some parameters it may be true, for others not. The validity of conversion to inner join is checked only once and it happens only for the first call of procedure. So if the parameters in the first call allowed the conversion it was done and next calls used the transformed query though there could be calls whose parameters made the conversion invalid. Fixed by cheking whether the constant disjunct in the ON expression originally contained an SP parameter. If so the expression is not considered as null-rejected. For this check a new item's attribute was intruduced: Item::with_param. It is calculated for each item by fix fields() functions. Also moved the call of optimize_constant_subqueries() in JOIN::optimize after the call of simplify_joins(). The reason for this is that after the optimization introduced by the patch for mdev-4817 simplify_joins() can use the results of execution of non-expensive constant subqueries and this is not valid. --- mysql-test/r/sp-innodb.result | 34 ++++++++++++++++++++++++++++++++++ mysql-test/t/sp-innodb.test | 42 ++++++++++++++++++++++++++++++++++++++++++ sql/item.cc | 7 +++++++ sql/item.h | 1 + sql/item_cmpfunc.cc | 43 +++++++++++++++++++++++++++++++------------ sql/item_func.cc | 1 + sql/item_func.h | 7 +++++++ sql/item_row.cc | 1 + sql/item_sum.cc | 3 +++ sql/sql_select.cc | 6 +++--- 10 files changed, 130 insertions(+), 15 deletions(-) diff --git a/mysql-test/r/sp-innodb.result b/mysql-test/r/sp-innodb.result index b5fe920c675..9daf2c457f5 100644 --- a/mysql-test/r/sp-innodb.result +++ b/mysql-test/r/sp-innodb.result @@ -138,3 +138,37 @@ SET @@innodb_lock_wait_timeout= @innodb_lock_wait_timeout_saved; # # BUG 16041903: End of test case # +# +# MDEV-15035: SP using query with outer join and a parameter +# in ON expression +# +CREATE TABLE t1 ( +id int NOT NULL, +PRIMARY KEY (id) +) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1), (2); +CREATE TABLE t2 ( +id int NOT NULL, +id_foo int NOT NULL, +PRIMARY KEY (id) +) ENGINE=InnoDB; +INSERT INTO t2 VALUES (1, 1); +DROP PROCEDURE IF EXISTS test_proc; +CREATE PROCEDURE test_proc(IN param int) +LANGUAGE SQL +READS SQL DATA +BEGIN +SELECT DISTINCT f.id +FROM t1 f +LEFT OUTER JOIN t2 b ON b.id_foo = f.id +WHERE (param <> 0 OR b.id IS NOT NULL); +END| +CALL test_proc(0); +id +1 +CALL test_proc(1); +id +1 +2 +DROP PROCEDURE IF EXISTS test_proc; +DROP TABLE t1, t2; diff --git a/mysql-test/t/sp-innodb.test b/mysql-test/t/sp-innodb.test index 23715166a02..e44a853e713 100644 --- a/mysql-test/t/sp-innodb.test +++ b/mysql-test/t/sp-innodb.test @@ -158,5 +158,47 @@ SET @@innodb_lock_wait_timeout= @innodb_lock_wait_timeout_saved; --echo # BUG 16041903: End of test case --echo # +--echo # +--echo # MDEV-15035: SP using query with outer join and a parameter +--echo # in ON expression +--echo # + +CREATE TABLE t1 ( + id int NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB; + +INSERT INTO t1 VALUES (1), (2); + +CREATE TABLE t2 ( + id int NOT NULL, + id_foo int NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB; + +INSERT INTO t2 VALUES (1, 1); + +--disable_warnings +DROP PROCEDURE IF EXISTS test_proc; +--enable_warnings + +DELIMITER |; +CREATE PROCEDURE test_proc(IN param int) +LANGUAGE SQL +READS SQL DATA +BEGIN + SELECT DISTINCT f.id + FROM t1 f + LEFT OUTER JOIN t2 b ON b.id_foo = f.id + WHERE (param <> 0 OR b.id IS NOT NULL); +END| +DELIMITER ;| + +CALL test_proc(0); +CALL test_proc(1); + +DROP PROCEDURE IF EXISTS test_proc; +DROP TABLE t1, t2; + # Wait till we reached the initial number of concurrent sessions --source include/wait_until_count_sessions.inc diff --git a/sql/item.cc b/sql/item.cc index 08a00615c0c..c5c6df0ec48 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -504,6 +504,7 @@ Item::Item(): in_rollup= 0; decimals= 0; max_length= 0; with_subselect= 0; + with_param= 0; cmp_context= IMPOSSIBLE_RESULT; /* Initially this item is not attached to any JOIN_TAB. */ join_tab_idx= MAX_TABLES; @@ -550,6 +551,7 @@ Item::Item(THD *thd, Item *item): null_value(item->null_value), unsigned_flag(item->unsigned_flag), with_sum_func(item->with_sum_func), + with_param(item->with_param), with_field(item->with_field), fixed(item->fixed), is_autogenerated_name(item->is_autogenerated_name), @@ -1486,6 +1488,9 @@ bool Item_sp_variable::fix_fields(THD *thd, Item **) max_length= it->max_length; decimals= it->decimals; unsigned_flag= it->unsigned_flag; + with_param= 1; + if (thd->lex->current_select->master_unit()->item) + thd->lex->current_select->master_unit()->item->with_param= 1; fixed= 1; collation.set(it->collation.collation, it->collation.derivation); @@ -7234,6 +7239,7 @@ void Item_ref::set_properties() split_sum_func() doesn't try to change the reference. */ with_sum_func= (*ref)->with_sum_func; + with_param= (*ref)->with_param; with_field= (*ref)->with_field; unsigned_flag= (*ref)->unsigned_flag; fixed= 1; @@ -7681,6 +7687,7 @@ Item_cache_wrapper::Item_cache_wrapper(Item *item_arg) decimals= orig_item->decimals; collation.set(orig_item->collation); with_sum_func= orig_item->with_sum_func; + with_param= orig_item->with_param; with_field= orig_item->with_field; unsigned_flag= orig_item->unsigned_flag; name= item_arg->name; diff --git a/sql/item.h b/sql/item.h index 830f8bf14a4..d756cf8301b 100644 --- a/sql/item.h +++ b/sql/item.h @@ -644,6 +644,7 @@ public: bool null_value; /* if item is null */ bool unsigned_flag; bool with_sum_func; /* True if item contains a sum func */ + bool with_param; /* True if contains an SP parameter */ /** True if any item except Item_sum_func contains a field. Set during parsing. */ diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 39f497e3828..6fb650b975b 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1546,6 +1546,7 @@ bool Item_in_optimizer::fix_left(THD *thd, Item **ref) } eval_not_null_tables(NULL); with_sum_func= args[0]->with_sum_func; + with_param= args[0]->with_param || args[1]->with_param; with_field= args[0]->with_field; if ((const_item_cache= args[0]->const_item())) { @@ -1587,6 +1588,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, Item **ref) with_subselect= 1; with_sum_func= with_sum_func || args[1]->with_sum_func; with_field= with_field || args[1]->with_field; + with_param= args[0]->with_param || args[1]->with_param; used_tables_cache|= args[1]->used_tables(); const_item_cache&= args[1]->const_item(); fixed= 1; @@ -2108,6 +2110,7 @@ void Item_func_interval::fix_length_and_dec() used_tables_cache|= row->used_tables(); not_null_tables_cache= row->not_null_tables(); with_sum_func= with_sum_func || row->with_sum_func; + with_param= with_param || row->with_param; with_field= with_field || row->with_field; const_item_cache&= row->const_item(); } @@ -4335,6 +4338,7 @@ Item_cond::fix_fields(THD *thd, Item **ref) List_iterator li(list); Item *item; uchar buff[sizeof(char*)]; // Max local vars in function + bool is_and_cond= functype() == Item_func::COND_AND_FUNC; not_null_tables_cache= used_tables_cache= 0; const_item_cache= 1; @@ -4396,26 +4400,33 @@ Item_cond::fix_fields(THD *thd, Item **ref) (item= *li.ref())->check_cols(1)) return TRUE; /* purecov: inspected */ used_tables_cache|= item->used_tables(); - if (item->const_item()) + if (item->const_item() && !item->with_param && + !item->is_expensive() && !cond_has_datetime_is_null(item)) { - if (!item->is_expensive() && !cond_has_datetime_is_null(item) && - item->val_int() == 0) + if (item->val_int() == is_and_cond && top_level()) { /* - This is "... OR false_cond OR ..." + a. This is "... AND true_cond AND ..." + In this case, true_cond has no effect on cond_and->not_null_tables() + b. This is "... OR false_cond/null cond OR ..." In this case, false_cond has no effect on cond_or->not_null_tables() */ } else { /* - This is "... OR const_cond OR ..." + a. This is "... AND false_cond/null_cond AND ..." + The whole condition is FALSE/UNKNOWN. + b. This is "... OR const_cond OR ..." In this case, cond_or->not_null_tables()=0, because the condition const_cond might evaluate to true (regardless of whether some tables were NULL-complemented). */ + not_null_tables_cache= (table_map) 0; and_tables_cache= (table_map) 0; } + if (thd->is_error()) + return TRUE; } else { @@ -4427,6 +4438,7 @@ Item_cond::fix_fields(THD *thd, Item **ref) } with_sum_func= with_sum_func || item->with_sum_func; + with_param= with_param || item->with_param; with_field= with_field || item->with_field; with_subselect|= item->has_subquery(); if (item->maybe_null) @@ -4443,30 +4455,36 @@ bool Item_cond::eval_not_null_tables(uchar *opt_arg) { Item *item; + bool is_and_cond= functype() == Item_func::COND_AND_FUNC; List_iterator li(list); not_null_tables_cache= (table_map) 0; and_tables_cache= ~(table_map) 0; while ((item=li++)) { table_map tmp_table_map; - if (item->const_item()) + if (item->const_item() && !item->with_param && + !item->is_expensive() && !cond_has_datetime_is_null(item)) { - if (!item->is_expensive() && !cond_has_datetime_is_null(item) && - item->val_int() == 0) + if (item->val_int() == is_and_cond && top_level()) { /* - This is "... OR false_cond OR ..." + a. This is "... AND true_cond AND ..." + In this case, true_cond has no effect on cond_and->not_null_tables() + b. This is "... OR false_cond/null cond OR ..." In this case, false_cond has no effect on cond_or->not_null_tables() */ } else { /* - This is "... OR const_cond OR ..." + a. This is "... AND false_cond/null_cond AND ..." + The whole condition is FALSE/UNKNOWN. + b. This is "... OR const_cond OR ..." In this case, cond_or->not_null_tables()=0, because the condition - some_cond_or might be true regardless of what tables are - NULL-complemented. + const_cond might evaluate to true (regardless of whether some tables + were NULL-complemented). */ + not_null_tables_cache= (table_map) 0; and_tables_cache= (table_map) 0; } } @@ -5118,6 +5136,7 @@ Item_func_regex::fix_fields(THD *thd, Item **ref) args[1]->fix_fields(thd, args + 1)) || args[1]->check_cols(1)) return TRUE; /* purecov: inspected */ with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func; + with_param=args[0]->with_param || args[1]->with_param; with_field= args[0]->with_field || args[1]->with_field; with_subselect= args[0]->has_subquery() || args[1]->has_subquery(); max_length= 1; diff --git a/sql/item_func.cc b/sql/item_func.cc index 9e4edfc14de..8b3c72dd328 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -222,6 +222,7 @@ Item_func::fix_fields(THD *thd, Item **ref) maybe_null=1; with_sum_func= with_sum_func || item->with_sum_func; + with_param= with_param || item->with_param; with_field= with_field || item->with_field; used_tables_cache|= item->used_tables(); const_item_cache&= item->const_item(); diff --git a/sql/item_func.h b/sql/item_func.h index 57818228b98..3a609fc0fe0 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -83,6 +83,7 @@ public: args= tmp_arg; args[0]= a; with_sum_func= a->with_sum_func; + with_param= a->with_param; with_field= a->with_field; } Item_func(Item *a,Item *b): @@ -91,6 +92,7 @@ public: args= tmp_arg; args[0]= a; args[1]= b; with_sum_func= a->with_sum_func || b->with_sum_func; + with_param= a->with_param || b->with_param; with_field= a->with_field || b->with_field; } Item_func(Item *a,Item *b,Item *c): @@ -102,6 +104,7 @@ public: arg_count= 3; args[0]= a; args[1]= b; args[2]= c; with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func; + with_param= a->with_param || b->with_param || c->with_param; with_field= a->with_field || b->with_field || c->with_field; } } @@ -115,6 +118,8 @@ public: args[0]= a; args[1]= b; args[2]= c; args[3]= d; with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func || d->with_sum_func; + with_param= a->with_param || b->with_param || + c->with_param || d->with_param; with_field= a->with_field || b->with_field || c->with_field || d->with_field; } @@ -128,6 +133,8 @@ public: args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e; with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func || d->with_sum_func || e->with_sum_func ; + with_param= a->with_param || b->with_param || + c->with_param || d->with_param || e->with_param; with_field= a->with_field || b->with_field || c->with_field || d->with_field || e->with_field; } diff --git a/sql/item_row.cc b/sql/item_row.cc index 9e81c053b69..9fe34dd00fd 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -125,6 +125,7 @@ bool Item_row::fix_fields(THD *thd, Item **ref) with_sum_func= with_sum_func || item->with_sum_func; with_field= with_field || item->with_field; with_subselect|= item->with_subselect; + with_param|= item->with_param; } fixed= 1; return FALSE; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 709c2b6f7b5..16334cd7b30 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1164,6 +1164,7 @@ Item_sum_num::fix_fields(THD *thd, Item **ref) return TRUE; set_if_bigger(decimals, args[i]->decimals); with_subselect|= args[i]->with_subselect; + with_param|= args[i]->with_param; } result_field=0; max_length=float_length(decimals); @@ -1195,6 +1196,7 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref) return TRUE; decimals=item->decimals; with_subselect= args[0]->with_subselect; + with_param= args[0]->with_param; switch (hybrid_type= item->result_type()) { case INT_RESULT: @@ -3430,6 +3432,7 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref) args[i]->check_cols(1)) return TRUE; with_subselect|= args[i]->with_subselect; + with_param|= args[i]->with_param; } /* skip charset aggregation for order columns */ diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 90bb536c0e2..1e9f1c0848b 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1034,9 +1034,6 @@ JOIN::optimize() eval_select_list_used_tables(); - if (optimize_constant_subqueries()) - DBUG_RETURN(1); - table_count= select_lex->leaf_tables.elements; if (setup_ftfuncs(select_lex)) /* should be after having->fix_fields */ @@ -1098,6 +1095,9 @@ JOIN::optimize() thd->restore_active_arena(arena, &backup); } + if (optimize_constant_subqueries()) + DBUG_RETURN(1); + if (setup_jtbm_semi_joins(this, join_list, &conds)) DBUG_RETURN(1); -- cgit v1.2.1 From e86c0a5f2aeb98fa06df01ec008bf70cab61da10 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 26 Apr 2018 14:21:36 +0300 Subject: Increase number of max table_open_cache instances This is a backport of MDEV-11429 from 10.1 --- mysql-test/suite/sys_vars/r/table_open_cache_basic.result | 4 ++-- sql/sys_vars.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/sys_vars/r/table_open_cache_basic.result b/mysql-test/suite/sys_vars/r/table_open_cache_basic.result index 2381dfe4900..465a61f2473 100644 --- a/mysql-test/suite/sys_vars/r/table_open_cache_basic.result +++ b/mysql-test/suite/sys_vars/r/table_open_cache_basic.result @@ -27,7 +27,7 @@ Warnings: Warning 1292 Truncated incorrect table_open_cache value: '1073741824' SELECT @@global.table_open_cache ; @@global.table_open_cache -524288 +1048576 SET @@global.table_open_cache = 18000; SELECT @@global.table_open_cache ; @@global.table_open_cache @@ -48,7 +48,7 @@ Warnings: Warning 1292 Truncated incorrect table_open_cache value: '100000000000' SELECT @@global.table_open_cache ; @@global.table_open_cache -524288 +1048576 SET @@global.table_open_cache = -1024; Warnings: Warning 1292 Truncated incorrect table_open_cache value: '-1024' diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index edcfd712e3b..a21fe5df247 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -3059,7 +3059,7 @@ static bool fix_table_open_cache(sys_var *, THD *, enum_var_type) static Sys_var_ulong Sys_table_cache_size( "table_open_cache", "The number of cached open tables", GLOBAL_VAR(tc_size), CMD_LINE(REQUIRED_ARG), - VALID_RANGE(1, 512*1024), DEFAULT(TABLE_OPEN_CACHE_DEFAULT), + VALID_RANGE(1, 1024*1024), DEFAULT(TABLE_OPEN_CACHE_DEFAULT), BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(fix_table_open_cache)); -- cgit v1.2.1 From 03da1253af4b1a9a47ffd7c6904af266718bc0b1 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 26 Apr 2018 14:22:09 +0300 Subject: Fix compilation error when compiling with valgrind --- storage/tokudb/PerconaFT/portability/toku_race_tools.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/tokudb/PerconaFT/portability/toku_race_tools.h b/storage/tokudb/PerconaFT/portability/toku_race_tools.h index 8482a164fb8..e7ce5a81ec3 100644 --- a/storage/tokudb/PerconaFT/portability/toku_race_tools.h +++ b/storage/tokudb/PerconaFT/portability/toku_race_tools.h @@ -90,8 +90,8 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. # define TOKU_ANNOTATE_IGNORE_WRITES_BEGIN() ((void) 0) # define TOKU_ANNOTATE_IGNORE_WRITES_END() ((void) 0) # define TOKU_VALGRIND_RESET_MUTEX_ORDERING_INFO(mutex) +#undef RUNNING_ON_VALGRIND # define RUNNING_ON_VALGRIND (0U) - #endif // Valgrind 3.10.1 (and previous versions). -- cgit v1.2.1 From 619afb151b38a538ef64d5387643c01f86e203d8 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 25 Apr 2018 13:20:44 +0200 Subject: MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION followup for bcb36ee21e2 move reopening before trans_commit_stmt(thd); --- mysql-test/suite/parts/inc/part_alter_values.inc | 2 +- mysql-test/suite/parts/r/partition_alter_innodb.result | 2 +- mysql-test/suite/parts/r/partition_alter_maria.result | 2 +- mysql-test/suite/parts/r/partition_alter_myisam.result | 2 +- sql/sql_base.cc | 3 --- sql/sql_parse.cc | 4 ++++ 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mysql-test/suite/parts/inc/part_alter_values.inc b/mysql-test/suite/parts/inc/part_alter_values.inc index 1b0605ff57b..ac69169a9ca 100644 --- a/mysql-test/suite/parts/inc/part_alter_values.inc +++ b/mysql-test/suite/parts/inc/part_alter_values.inc @@ -39,7 +39,7 @@ DROP TABLE t1; # # MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION # -create table t1 (i int) partition by range(i) (partition p0 values less than (10)); +--eval create table t1 (i int) engine=$engine partition by range(i) (partition p0 values less than (10)) lock table t1 write; --error ER_SAME_NAME_PARTITION alter table t1 add partition (partition p0 values less than (20)); diff --git a/mysql-test/suite/parts/r/partition_alter_innodb.result b/mysql-test/suite/parts/r/partition_alter_innodb.result index 08f0c321119..87c113a2720 100644 --- a/mysql-test/suite/parts/r/partition_alter_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter_innodb.result @@ -47,7 +47,7 @@ PARTITION p3 VALUES IN (4,5,6) ); ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition DROP TABLE t1; -create table t1 (i int) partition by range(i) (partition p0 values less than (10)); +create table t1 (i int) engine=InnoDB partition by range(i) (partition p0 values less than (10)); lock table t1 write; alter table t1 add partition (partition p0 values less than (20)); ERROR HY000: Duplicate partition name p0 diff --git a/mysql-test/suite/parts/r/partition_alter_maria.result b/mysql-test/suite/parts/r/partition_alter_maria.result index 5e53dc99db8..5f1f882d2ea 100644 --- a/mysql-test/suite/parts/r/partition_alter_maria.result +++ b/mysql-test/suite/parts/r/partition_alter_maria.result @@ -69,7 +69,7 @@ PARTITION p3 VALUES IN (4,5,6) ); ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition DROP TABLE t1; -create table t1 (i int) partition by range(i) (partition p0 values less than (10)); +create table t1 (i int) engine=Aria partition by range(i) (partition p0 values less than (10)); lock table t1 write; alter table t1 add partition (partition p0 values less than (20)); ERROR HY000: Duplicate partition name p0 diff --git a/mysql-test/suite/parts/r/partition_alter_myisam.result b/mysql-test/suite/parts/r/partition_alter_myisam.result index 0d3094418ff..248c8627b2f 100644 --- a/mysql-test/suite/parts/r/partition_alter_myisam.result +++ b/mysql-test/suite/parts/r/partition_alter_myisam.result @@ -42,7 +42,7 @@ PARTITION p3 VALUES IN (4,5,6) ); ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition DROP TABLE t1; -create table t1 (i int) partition by range(i) (partition p0 values less than (10)); +create table t1 (i int) engine=MyISAM partition by range(i) (partition p0 values less than (10)); lock table t1 write; alter table t1 add partition (partition p0 values less than (20)); ERROR HY000: Duplicate partition name p0 diff --git a/sql/sql_base.cc b/sql/sql_base.cc index f7de4e4f3c2..554c8cffeaf 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -952,10 +952,7 @@ void close_thread_tables(THD *thd) we will exit this function a few lines below. */ if (! thd->lex->requires_prelocking()) - { - thd->locked_tables_list.reopen_tables(thd, true); DBUG_VOID_RETURN; - } /* We are in the top-level statement of a prelocked statement, diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index fa95c852f53..4c0be4ebc8b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5136,6 +5136,10 @@ finish: lex->unit.cleanup(); + /* close/reopen tables that were marked to need reopen under LOCK TABLES */ + if (! thd->lex->requires_prelocking()) + thd->locked_tables_list.reopen_tables(thd, true); + if (! thd->in_sub_stmt) { if (thd->killed != NOT_KILLED) -- cgit v1.2.1 From 5ae2656b69e8a232107890aa0be517358739e997 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 24 Apr 2018 20:28:31 +0200 Subject: Squashed commit of connect/10.0: commit c545d544378483bf68c4fb713cd4ec872d0df2c4 Author: Olivier Bertrand Date: Tue Mar 27 23:13:14 2018 +0200 - Fix MDEV-15577 CONNECT engine JDBC remote index prevents UPDATE Fixed in TDBJDBC::OpenDB because query can be null for updates modified: storage/connect/tabjdbc.cpp commit c4f1fe2e8e74566e9c3296f435448d9f5c718b23 Author: Olivier Bertrand Date: Wed Mar 14 12:21:17 2018 +0100 - Fix MDEV-15429 CONNECT engine JDBC handling Postgresql UUID type Also handle Postgresql sending type VARCHAR for TEXT column and setting length to b x7FFFFFF when the length is unknown. modified: storage/connect/Client.java modified: storage/connect/JavaWrappers.jar modified: storage/connect/JdbcInterface.java modified: storage/connect/PostgresqlInterface.java modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/jdbconn.cpp modified: storage/connect/jdbconn.h modified: storage/connect/mysql-test/connect/r/jdbc_postgresql.result modified: storage/connect/mysql-test/connect/t/jdbc_postgresql.test modified: storage/connect/mysql-test/connect/t/jdbconn.inc modified: storage/connect/plgdbsem.h modified: storage/connect/tabjdbc.cpp modified: storage/connect/tabjdbc.h added: storage/connect/mysql-test/connect/std_data/JavaWrappers.jar commit 3068bb4882a316c6c32c624609db2bf24ae3ad40 Author: Olivier Bertrand Date: Mon Feb 26 19:40:27 2018 +0100 Revert to old cmake file to avoid compile error commit da8c1c0bd6a327fd03bd321be3170f468122ef67 Author: Olivier Bertrand Date: Mon Feb 26 16:13:39 2018 +0100 - Remove warning on not used tabtyp variable in connect_assisted_discovery modified: storage/connect/ha_connect.cc - Fix a bug causing CONNECT to loop when expanding a JSON column when the expanded column value is null or void array. - Adding the FullArray option to JSON tables. - Skipping expanded JSON lines when the expanded column value is null. modified: storage/connect/connect.cc modified: storage/connect/tabdos.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h - Fix MDEV-13353 No file privilege for ODBC, JDBC, MONGO, MAC, WMI file types. modified: storage/connect/ha_connect.cc - Make some Json UDFs to accept a non JSON item as 1st parameter. modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/jsonudf.cpp modified: storage/connect/jsonudf.h - Update Json UDF tests to cope with above changes. modified: storage/connect/mysql-test/connect/r/json_udf.result modified: storage/connect/mysql-test/connect/r/json_udf_bin.result modified: storage/connect/mysql-test/connect/r/vcol.result modified: storage/connect/mysql-test/connect/t/json_udf.test modified: storage/connect/mysql-test/connect/t/vcol.test - Fix some compiler warning treated as error PlugSubAlloc no more exported because it does throw. modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/jsonudf.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h - Other files modified (?) when going back to wrong merge modified: storage/connect/CMakeLists.txt modified: storage/connect/array.cpp modified: storage/connect/colblk.cpp modified: storage/connect/connect.cc modified: storage/connect/csort.cpp modified: storage/connect/domdoc.cpp modified: storage/connect/filamap.cpp modified: storage/connect/filamgz.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.cpp modified: storage/connect/fmdlex.c modified: storage/connect/jdbconn.cpp modified: storage/connect/macutil.cpp modified: storage/connect/myconn.cpp modified: storage/connect/odbconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.cpp modified: storage/connect/preparse.h modified: storage/connect/rcmsg.c modified: storage/connect/rcmsg.h modified: storage/connect/reldef.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabmac.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabmysql.h modified: storage/connect/tabodbc.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/value.cpp modified: storage/connect/xobject.cpp commit 5095628b31ed8c94bd7c794c6b0162894a9040b1 Author: Olivier Bertrand Date: Tue Feb 13 14:29:00 2018 +0100 - Fix a bug causing CONNECT to loop when expanding a JSON column when the expanded column value is null or void array. - Adding the FullArray option to JSON tables. - Skipping expanded JSON lines when the expanded column value is null. modified: storage/connect/connect.cc modified: storage/connect/tabdos.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h commit 9896174328da42016735630c893fd09eb128b48e Author: Olivier Bertrand Date: Fri Feb 2 15:48:57 2018 +0100 - Remove warning on not used tabtyp variable in connect_assisted_discovery modified: storage/connect/ha_connect.cc commit d7e254c05f88173eb04d8dafc813013eb42ccdbe Author: Olivier Bertrand Date: Wed Jan 31 14:42:45 2018 +0100 - Use delayed load for the MongoDB C Drive on Windows modified: storage/connect/CMakeLists.txt modified: storage/connect/cmgoconn.cpp modified: storage/connect/ha_connect.cc - Add FORCE to the connect_type_conv enum values This will translate binary values to TYPE_STRING modified: storage/connect/checklvl.h modified: storage/connect/ha_connect.cc modified: storage/connect/odbconn.cpp - Change the connect_xtrace variable to from int to set modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/cmgoconn.cpp modified: storage/connect/colblk.cpp modified: storage/connect/connect.cc modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamgz.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.cpp modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/inihandl.cpp modified: storage/connect/javaconn.cpp modified: storage/connect/jdbconn.cpp modified: storage/connect/jmgfam.cpp modified: storage/connect/jmgoconn.cpp modified: storage/connect/json.cpp modified: storage/connect/jsonudf.cpp modified: storage/connect/libdoc.cpp modified: storage/connect/mongo.cpp modified: storage/connect/mycat.cc modified: storage/connect/myconn.cpp modified: storage/connect/odbconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.cpp modified: storage/connect/reldef.cpp modified: storage/connect/tabcol.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabext.cpp modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabjdbc.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/table.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabutil.cpp modified: storage/connect/tabvct.cpp modified: storage/connect/tabwmi.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/user_connect.cc modified: storage/connect/valblk.cpp modified: storage/connect/value.cpp modified: storage/connect/xindex.cpp - Restore connect_enable_mongo variable (but undocumented) modified: storage/connect/ha_connect.cc modified: storage/connect/mycat.cc modified: storage/connect/mysql-test/connect/r/json_java_2.result modified: storage/connect/mysql-test/connect/r/json_java_3.result modified: storage/connect/mysql-test/connect/r/json_mongo_c.result modified: storage/connect/mysql-test/connect/r/mongo_c.result modified: storage/connect/mysql-test/connect/r/mongo_java_2.result modified: storage/connect/mysql-test/connect/r/mongo_java_3.result modified: storage/connect/mysql-test/connect/r/tbl_thread.result modified: storage/connect/mysql-test/connect/t/mongo.inc modified: storage/connect/mysql-test/connect/t/mongo_test.inc modified: storage/connect/mysql-test/connect/t/tbl_thread.test --- .gitattributes | 1 + storage/connect/CMakeLists.txt | 9 +- storage/connect/Client.java | 27 +- storage/connect/JavaWrappers.jar | Bin 44053 -> 19192 bytes storage/connect/JdbcInterface.java | 54 +- storage/connect/PostgresqlInterface.java | 5 +- storage/connect/array.cpp | 22 +- storage/connect/blkfil.cpp | 8 +- storage/connect/block.h | 4 +- storage/connect/checklvl.h | 3 +- storage/connect/cmgoconn.cpp | 18 +- storage/connect/colblk.cpp | 9 +- storage/connect/connect.cc | 43 +- storage/connect/csort.cpp | 16 +- storage/connect/domdoc.cpp | 3 +- storage/connect/filamap.cpp | 32 +- storage/connect/filamdbf.cpp | 12 +- storage/connect/filamfix.cpp | 68 +- storage/connect/filamgz.cpp | 20 +- storage/connect/filamtxt.cpp | 71 +- storage/connect/filamvct.cpp | 162 ++-- storage/connect/filamzip.cpp | 8 +- storage/connect/filter.cpp | 36 +- storage/connect/fmdlex.c | 24 +- storage/connect/global.h | 11 +- storage/connect/ha_connect.cc | 332 ++++---- storage/connect/inihandl.cpp | 54 +- storage/connect/javaconn.cpp | 6 +- storage/connect/jdbconn.cpp | 365 ++++++--- storage/connect/jdbconn.h | 11 +- storage/connect/jmgfam.cpp | 2 +- storage/connect/jmgoconn.cpp | 14 +- storage/connect/json.cpp | 41 +- storage/connect/json.h | 8 +- storage/connect/jsonudf.cpp | 862 ++++++++++++++------- storage/connect/jsonudf.h | 4 + storage/connect/libdoc.cpp | 98 +-- storage/connect/macutil.cpp | 4 +- storage/connect/mongo.cpp | 4 +- storage/connect/mycat.cc | 34 +- storage/connect/myconn.cpp | 10 +- .../mysql-test/connect/r/jdbc_postgresql.result | 35 +- .../mysql-test/connect/r/json_java_2.result | 7 +- .../mysql-test/connect/r/json_java_3.result | 4 +- .../mysql-test/connect/r/json_mongo_c.result | 2 + .../connect/mysql-test/connect/r/json_udf.result | 10 +- .../mysql-test/connect/r/json_udf_bin.result | 3 +- .../connect/mysql-test/connect/r/mongo_c.result | 2 + .../mysql-test/connect/r/mongo_java_2.result | 4 +- .../mysql-test/connect/r/mongo_java_3.result | 4 +- .../connect/mysql-test/connect/r/tbl_thread.result | 6 +- storage/connect/mysql-test/connect/r/vcol.result | 29 + .../mysql-test/connect/std_data/JavaWrappers.jar | Bin 0 -> 19192 bytes .../connect/mysql-test/connect/std_data/Mongo2.jar | Bin 3461358 -> 623907 bytes .../connect/mysql-test/connect/std_data/Mongo3.jar | Bin 1705776 -> 1705776 bytes .../mysql-test/connect/t/jdbc_postgresql.test | 33 +- storage/connect/mysql-test/connect/t/jdbconn.inc | 7 +- storage/connect/mysql-test/connect/t/json_udf.test | 6 +- storage/connect/mysql-test/connect/t/mongo.inc | 4 +- .../connect/mysql-test/connect/t/mongo_test.inc | 8 +- .../connect/mysql-test/connect/t/tbl_thread.test | 6 +- storage/connect/mysql-test/connect/t/vcol.test | 31 + storage/connect/odbconn.cpp | 103 +-- storage/connect/plgdbsem.h | 3 +- storage/connect/plgdbutl.cpp | 143 ++-- storage/connect/plugutil.cpp | 30 +- storage/connect/preparse.h | 2 +- storage/connect/rcmsg.c | 7 +- storage/connect/rcmsg.h | 2 +- storage/connect/reldef.cpp | 16 +- storage/connect/tabcol.cpp | 8 +- storage/connect/tabdos.cpp | 59 +- storage/connect/tabdos.h | 1 + storage/connect/tabext.cpp | 6 +- storage/connect/tabfix.cpp | 8 +- storage/connect/tabfmt.cpp | 36 +- storage/connect/tabjdbc.cpp | 35 +- storage/connect/tabjdbc.h | 2 + storage/connect/tabjson.cpp | 597 +++++++------- storage/connect/tabjson.h | 44 +- storage/connect/table.cpp | 16 +- storage/connect/tabmac.cpp | 4 +- storage/connect/tabmul.cpp | 26 +- storage/connect/tabmysql.cpp | 28 +- storage/connect/tabodbc.cpp | 20 +- storage/connect/tabpivot.cpp | 2 +- storage/connect/tabsys.cpp | 12 +- storage/connect/tabtbl.cpp | 41 +- storage/connect/tabutil.cpp | 8 +- storage/connect/tabvct.cpp | 8 +- storage/connect/tabwmi.cpp | 4 +- storage/connect/tabxml.cpp | 26 +- storage/connect/user_connect.cc | 2 +- storage/connect/valblk.cpp | 2 +- storage/connect/value.cpp | 52 +- storage/connect/xindex.cpp | 88 +-- storage/connect/xobject.cpp | 5 +- 97 files changed, 2463 insertions(+), 1699 deletions(-) create mode 100644 storage/connect/mysql-test/connect/r/vcol.result create mode 100644 storage/connect/mysql-test/connect/std_data/JavaWrappers.jar create mode 100644 storage/connect/mysql-test/connect/t/vcol.test diff --git a/.gitattributes b/.gitattributes index b2e324795aa..cbcf9c9c14f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -23,6 +23,7 @@ pcre/testdata/greppatN4 -text *.frm binary *.MYD binary *.MYI binary +*.jar binary *.c diff=cpp *.h diff=cpp diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index 0c05bd72750..5695e981413 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -247,7 +247,7 @@ ENDIF(CONNECT_WITH_ODBC) # # JDBC with MongoDB Java Driver included but disabled if without MONGO # -# OPTION(CONNECT_WITH_MONGO "Compile CONNECT storage engine with MONGO support" ON) +#OPTION(CONNECT_WITH_MONGO "Compile CONNECT storage engine with MONGO support" ON) OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON) IF(CONNECT_WITH_JDBC) @@ -343,6 +343,13 @@ IF(NOT TARGET connect) RETURN() ENDIF() +IF(WIN32) + IF (libmongoc-1.0_FOUND) + SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS + "/DELAYLOAD:libbson-1.0.dll /DELAYLOAD:libmongoc-1.0.dll") + ENDIF(libmongoc-1.0_FOUND) +ENDIF(WIN32) + # Install some extra files that belong to connect engine IF(WIN32) # install ha_connect.lib diff --git a/storage/connect/Client.java b/storage/connect/Client.java index aaf1b7bf2f8..afa54fa4256 100644 --- a/storage/connect/Client.java +++ b/storage/connect/Client.java @@ -1,9 +1,13 @@ + package wrappers; import java.io.BufferedReader; import java.io.Console; import java.io.IOException; import java.io.InputStreamReader; +import java.sql.Date; +import java.sql.Time; +import java.sql.Timestamp; public class Client { static boolean DEBUG = true; @@ -58,6 +62,9 @@ public class Client { String query; System.out.println("Successfully connected to " + parms[1]); + s = jdi.GetQuoteString(); + System.out.println("Qstr = '" + s + "'"); + while ((query = getLine("Query: ", false)) != null) { n = jdi.Execute(query); System.out.println("Returned n = " + n); @@ -79,7 +86,11 @@ public class Client { private static void PrintResult(int ncol) { // Get result set meta data int i; + Date date = new Date(0); + Time time = new Time(0); + Timestamp tsp = new Timestamp(0); String columnName; + Object job; // Get the column names; column indices start from 1 for (i = 1; i <= ncol; i++) { @@ -112,6 +123,7 @@ public class Client { case java.sql.Types.VARCHAR: case java.sql.Types.LONGVARCHAR: case java.sql.Types.CHAR: + case 1111: System.out.print(jdi.StringField(i, null)); break; case java.sql.Types.INTEGER: @@ -120,14 +132,17 @@ public class Client { case java.sql.Types.BIGINT: System.out.print(jdi.BigintField(i, null)); break; - case java.sql.Types.TIMESTAMP: - System.out.print(jdi.TimestampField(i, null)); - break; case java.sql.Types.TIME: - System.out.print(jdi.TimeField(i, null)); + time.setTime((long)jdi.TimeField(i, null) * 1000); + System.out.print(time); break; case java.sql.Types.DATE: - System.out.print(jdi.DateField(i, null)); + date.setTime((long)jdi.DateField(i, null) * 1000); + System.out.print(date); + break; + case java.sql.Types.TIMESTAMP: + tsp.setTime((long)jdi.TimestampField(i, null) * 1000); + System.out.print(tsp); break; case java.sql.Types.SMALLINT: System.out.print(jdi.IntField(i, null)); @@ -141,6 +156,8 @@ public class Client { case java.sql.Types.BOOLEAN: System.out.print(jdi.BooleanField(i, null)); default: + job = jdi.ObjectField(i, null); + System.out.print(job.toString()); break; } // endswitch Type diff --git a/storage/connect/JavaWrappers.jar b/storage/connect/JavaWrappers.jar index ef407f6a9c2..33b29e7685b 100644 Binary files a/storage/connect/JavaWrappers.jar and b/storage/connect/JavaWrappers.jar differ diff --git a/storage/connect/JdbcInterface.java b/storage/connect/JdbcInterface.java index a1b1360e6ea..72ee4ab0d39 100644 --- a/storage/connect/JdbcInterface.java +++ b/storage/connect/JdbcInterface.java @@ -1,10 +1,22 @@ package wrappers; -import java.math.*; -import java.sql.*; +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.Date; +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; import java.util.Collections; import java.util.Hashtable; import java.util.List; +import java.util.UUID; import javax.sql.DataSource; @@ -223,6 +235,24 @@ public class JdbcInterface { } // end of SetTimestampParm + public void SetUuidParm(int i, String s) { + try { + UUID uuid; + + if (s == null) + uuid = null; + else if (s.isEmpty()) + uuid = UUID.randomUUID(); + else + uuid = UUID.fromString(s); + + pstmt.setObject(i, uuid); + } catch (Exception e) { + SetErrmsg(e); + } // end try/catch + + } // end of SetUuidParm + public int SetNullParm(int i, int typ) { int rc = 0; @@ -481,6 +511,8 @@ public class JdbcInterface { System.out.println("Executing query '" + query + "'"); try { + if (rs != null) + rs.close(); rs = stmt.executeQuery(query); rsmd = rs.getMetaData(); ncol = rsmd.getColumnCount(); @@ -708,7 +740,7 @@ public class JdbcInterface { return 0; } // end of TimestampField - public Object ObjectField(int n, String name) { + public Object ObjectField(int n, String name) { if (rs == null) { System.out.println("No result set"); } else try { @@ -720,6 +752,22 @@ public class JdbcInterface { return null; } // end of ObjectField + public String UuidField(int n, String name) { + Object job; + + if (rs == null) { + System.out.println("No result set"); + } else + try { + job = (n > 0) ? rs.getObject(n) : rs.getObject(name); + return job.toString(); + } catch (SQLException se) { + SetErrmsg(se); + } // end try/catch + + return null; + } // end of UuidField + public int GetDrivers(String[] s, int mxs) { int n = 0; List drivers = Collections.list(DriverManager.getDrivers()); diff --git a/storage/connect/PostgresqlInterface.java b/storage/connect/PostgresqlInterface.java index adce0616a1b..9f611eeb23b 100644 --- a/storage/connect/PostgresqlInterface.java +++ b/storage/connect/PostgresqlInterface.java @@ -1,9 +1,10 @@ package wrappers; -import java.sql.*; +import java.sql.SQLException; import java.util.Hashtable; import javax.sql.DataSource; + import org.postgresql.jdbc2.optional.PoolingDataSource; public class PostgresqlInterface extends JdbcInterface { @@ -19,7 +20,7 @@ public class PostgresqlInterface extends JdbcInterface { } // end of constructor - @Override + @Override public int JdbcConnect(String[] parms, int fsize, boolean scrollable) { int rc = 0; String url = parms[1]; diff --git a/storage/connect/array.cpp b/storage/connect/array.cpp index 639edf63a1a..cd1785b48ac 100644 --- a/storage/connect/array.cpp +++ b/storage/connect/array.cpp @@ -82,7 +82,7 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp) if ((valtyp = pp->Type) != TYPE_STRING) len = 1; - if (trace) + if (trace(1)) htrc("valtyp=%d len=%d\n", valtyp, len); /*********************************************************************/ @@ -287,7 +287,7 @@ bool ARRAY::AddValue(PGLOBAL g, PSZ strp) return true; } // endif Type - if (trace) + if (trace(1)) htrc(" adding string(%d): '%s'\n", Nval, strp); //Value->SetValue_psz(strp); @@ -306,7 +306,7 @@ bool ARRAY::AddValue(PGLOBAL g, void *p) return true; } // endif Type - if (trace) + if (trace(1)) htrc(" adding pointer(%d): %p\n", Nval, p); Vblp->SetValue((PSZ)p, Nval++); @@ -323,7 +323,7 @@ bool ARRAY::AddValue(PGLOBAL g, short n) return true; } // endif Type - if (trace) + if (trace(1)) htrc(" adding SHORT(%d): %hd\n", Nval, n); //Value->SetValue(n); @@ -342,7 +342,7 @@ bool ARRAY::AddValue(PGLOBAL g, int n) return true; } // endif Type - if (trace) + if (trace(1)) htrc(" adding int(%d): %d\n", Nval, n); //Value->SetValue(n); @@ -361,7 +361,7 @@ bool ARRAY::AddValue(PGLOBAL g, double d) return true; } // endif Type - if (trace) + if (trace(1)) htrc(" adding float(%d): %lf\n", Nval, d); Value->SetValue(d); @@ -380,7 +380,7 @@ bool ARRAY::AddValue(PGLOBAL g, PXOB xp) return true; } // endif Type - if (trace) + if (trace(1)) htrc(" adding (%d) from xp=%p\n", Nval, xp); //AddValue(xp->GetValue()); @@ -399,7 +399,7 @@ bool ARRAY::AddValue(PGLOBAL g, PVAL vp) return true; } // endif Type - if (trace) + if (trace(1)) htrc(" adding (%d) from vp=%p\n", Nval, vp); Vblp->SetValue(vp, Nval++); @@ -520,7 +520,7 @@ bool ARRAY::FilTest(PGLOBAL g, PVAL valp, OPVAL opc, int opm) } else if (opc != OP_EXIST) { sprintf(g->Message, MSG(MISSING_ARG), opc); - throw (int)TYPE_ARRAY; + throw (int)TYPE_ARRAY; } else // OP_EXIST return Nval > 0; @@ -990,7 +990,7 @@ PSZ ARRAY::MakeArrayList(PGLOBAL g) len += strlen(tp); } // enfor i - if (trace) + if (trace(1)) htrc("Arraylist: len=%d\n", len); p = (char *)PlugSubAlloc(g, NULL, len); @@ -1003,7 +1003,7 @@ PSZ ARRAY::MakeArrayList(PGLOBAL g) strcat(p, (++i == Nval) ? ")" : ","); } // enfor i - if (trace) + if (trace(1)) htrc("Arraylist: newlen=%d\n", strlen(p)); return p; diff --git a/storage/connect/blkfil.cpp b/storage/connect/blkfil.cpp index 802095f2f82..76c9d09ac93 100644 --- a/storage/connect/blkfil.cpp +++ b/storage/connect/blkfil.cpp @@ -241,7 +241,7 @@ int BLKFILARI::BlockEval(PGLOBAL) break; } // endswitch Opc - if (trace) + if (trace(1)) htrc("BlockEval: op=%d n=%d rc=%d\n", Opc, n, Result); return Result; @@ -338,7 +338,7 @@ int BLKFILAR2::BlockEval(PGLOBAL) break; } // endswitch Opc - if (trace) + if (trace(1)) htrc("BlockEval2: op=%d n=%d rc=%d\n", Opc, n, Result); return Result; @@ -474,7 +474,7 @@ int BLKFILMR2::BlockEval(PGLOBAL) break; } // endswitch Opc - if (trace) + if (trace(1)) htrc("BlockEval2: op=%d n=%d rc=%d\n", Opc, n, Result); return Result; @@ -567,7 +567,7 @@ int BLKSPCARI::BlockEval(PGLOBAL) break; } // endswitch Opc - if (trace) + if (trace(1)) htrc("BlockEval: op=%d n=%d rc=%d\n", Opc, n, Result); return Result; diff --git a/storage/connect/block.h b/storage/connect/block.h index 8ac7be80988..737c74c1293 100644 --- a/storage/connect/block.h +++ b/storage/connect/block.h @@ -38,8 +38,8 @@ typedef class BLOCK *PBLOCK; class DllExport BLOCK { public: void * operator new(size_t size, PGLOBAL g, void *p = NULL) { -// if (trace > 3) -// htrc("New BLOCK: size=%d g=%p p=%p\n", size, g, p); + if (trace(256)) + htrc("New BLOCK: size=%d g=%p p=%p\n", size, g, p); return (PlugSubAlloc(g, p, size)); } // end of new diff --git a/storage/connect/checklvl.h b/storage/connect/checklvl.h index 0c234dfb8b8..9029e616bb6 100644 --- a/storage/connect/checklvl.h +++ b/storage/connect/checklvl.h @@ -45,6 +45,7 @@ enum USETEMP {TMP_NO = 0, /* Never */ /***********************************************************************/ enum TYPCONV {TPC_NO = 0, /* Never */ TPC_YES = 1, /* Always */ - TPC_SKIP = 2}; /* Skip TEXT columns */ + TPC_FORCE = 2, /* Also convert BLOBs */ + TPC_SKIP = 3}; /* Skip TEXT columns */ #endif // _CHKLVL_DEFINED_ diff --git a/storage/connect/cmgoconn.cpp b/storage/connect/cmgoconn.cpp index 44fac56137f..edee1874b97 100644 --- a/storage/connect/cmgoconn.cpp +++ b/storage/connect/cmgoconn.cpp @@ -280,7 +280,7 @@ bool CMgoConn::MakeCursor(PGLOBAL g) all = true; if (Pcg->Pipe) { - if (trace) + if (trace(1)) htrc("Pipeline: %s\n", options); p = strrchr(options, ']'); @@ -330,7 +330,7 @@ bool CMgoConn::MakeCursor(PGLOBAL g) *(char*)p = ']'; // Restore Colist for discovery p = s->GetStr(); - if (trace) + if (trace(33)) htrc("New Pipeline: %s\n", p); Query = bson_new_from_json((const uint8_t *)p, -1, &Error); @@ -350,7 +350,7 @@ bool CMgoConn::MakeCursor(PGLOBAL g) } else { if (Pcg->Filter || filp) { - if (trace) { + if (trace(1)) { if (Pcg->Filter) htrc("Filter: %s\n", Pcg->Filter); @@ -377,7 +377,7 @@ bool CMgoConn::MakeCursor(PGLOBAL g) tp->SetFilter(NULL); // Not needed anymore } // endif To_Filter - if (trace) + if (trace(33)) htrc("selector: %s\n", s->GetStr()); s->Resize(s->GetLength() + 1); @@ -393,7 +393,7 @@ bool CMgoConn::MakeCursor(PGLOBAL g) if (!all) { if (options && *options) { - if (trace) + if (trace(1)) htrc("options=%s\n", options); p = options; @@ -450,10 +450,10 @@ int CMgoConn::ReadNext(PGLOBAL g) if (!Cursor && MakeCursor(g)) { rc = RC_FX; } else if (mongoc_cursor_next(Cursor, &Document)) { - if (trace > 1) { + if (trace(512)) { bson_iter_t iter; ShowDocument(&iter, Document, ""); - } else if (trace == 1) + } else if (trace(1)) htrc("%s\n", GetDocument(g)); } else if (mongoc_cursor_error(Cursor, &Error)) { @@ -589,7 +589,7 @@ int CMgoConn::Write(PGLOBAL g) if (DocWrite(g, Fpc)) return RC_FX; - if (trace) { + if (trace(2)) { char *str = bson_as_json(Fpc->Child, NULL); htrc("Inserting: %s\n", str); bson_free(str); @@ -623,7 +623,7 @@ int CMgoConn::Write(PGLOBAL g) } // endif iter if (b) { - if (trace) { + if (trace(2)) { char *str = bson_as_json(query, NULL); htrc("update query: %s\n", str); bson_free(str); diff --git a/storage/connect/colblk.cpp b/storage/connect/colblk.cpp index 2ffe51d2009..a9cf43f3d96 100644 --- a/storage/connect/colblk.cpp +++ b/storage/connect/colblk.cpp @@ -76,7 +76,7 @@ COLBLK::COLBLK(PCOL col1, PTDB tdbp) //To_Orig = col1; To_Tdb = tdbp; - if (trace > 1) + if (trace(2)) htrc(" copying COLBLK %s from %p to %p\n", Name, col1, this); if (tdbp) @@ -115,7 +115,7 @@ bool COLBLK::SetFormat(PGLOBAL, FORMAT& fmt) { fmt = Format; - if (trace > 1) + if (trace(2)) htrc("COLBLK: %p format=%c(%d,%d)\n", this, *fmt.Type, fmt.Length, fmt.Prec); @@ -128,7 +128,7 @@ bool COLBLK::SetFormat(PGLOBAL, FORMAT& fmt) /***********************************************************************/ bool COLBLK::Eval(PGLOBAL g) { - if (trace > 1) + if (trace(2)) htrc("Col Eval: %s status=%.4X\n", Name, Status); if (!GetStatus(BUF_READ)) { @@ -165,7 +165,7 @@ bool COLBLK::InitValue(PGLOBAL g) AddStatus(BUF_READY); Value->SetNullable(Nullable); - if (trace > 1) + if (trace(2)) htrc(" colp=%p type=%d value=%p coluse=%.4X status=%.4X\n", this, Buf_Type, Value, ColUse, Status); @@ -412,4 +412,3 @@ void SIDBLK::ReadColumn(PGLOBAL) // } // endif Sname } // end of ReadColumn - diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index 5e80201fccf..39123b18c59 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -92,7 +92,7 @@ void CntEndDB(PGLOBAL g) free(dbuserp); - if (trace) + if (trace(1)) htrc("CntEndDB: Freeing Dup\n"); g->Activityp->Aptr = NULL; @@ -112,14 +112,14 @@ bool CntCheckDB(PGLOBAL g, PHC handler, const char *pathname) bool rc= false; PDBUSER dbuserp= PlgGetUser(g); - if (trace) { + if (trace(1)) { printf("CntCheckDB: dbuserp=%p\n", dbuserp); } // endif trace if (!dbuserp || !handler) return true; - if (trace) + if (trace(1)) printf("cat=%p oldhandler=%p newhandler=%p\n", dbuserp->Catalog, (dbuserp->Catalog) ? ((MYCAT*)dbuserp->Catalog)->GetHandler() : NULL, handler); @@ -150,7 +150,7 @@ bool CntCheckDB(PGLOBAL g, PHC handler, const char *pathname) /*********************************************************************/ sprintf(g->Message, MSG(DATABASE_LOADED), "???"); - if (trace) + if (trace(1)) printf("msg=%s\n", g->Message); return rc; @@ -198,7 +198,7 @@ PTDB CntGetTDB(PGLOBAL g, LPCSTR name, MODE mode, PHC h) PDBUSER dup = PlgGetUser(g); volatile PCATLG cat = (dup) ? dup->Catalog : NULL; // Safe over throw - if (trace) + if (trace(1)) printf("CntGetTDB: name=%s mode=%d cat=%p\n", name, mode, cat); if (!cat) @@ -208,7 +208,7 @@ PTDB CntGetTDB(PGLOBAL g, LPCSTR name, MODE mode, PHC h) // Get table object from the catalog tabp = new(g) XTAB(name); - if (trace) + if (trace(1)) printf("CntGetTDB: tabp=%p\n", tabp); // Perhaps this should be made thread safe @@ -218,13 +218,13 @@ PTDB CntGetTDB(PGLOBAL g, LPCSTR name, MODE mode, PHC h) printf("CntGetTDB: %s\n", g->Message); } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); } catch (const char *msg) { strcpy(g->Message, msg); } // end catch - if (trace) + if (trace(1)) printf("Returning tdbp=%p mode=%d\n", tdbp, mode); return tdbp; @@ -243,7 +243,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, //PCOLUMN cp; PDBUSER dup= PlgGetUser(g); - if (trace) + if (trace(1)) printf("CntOpenTable: tdbp=%p mode=%d\n", tdbp, mode); if (!tdbp) { @@ -260,7 +260,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, } else for (p = c1; *p; p += n) { // Allocate only used column blocks - if (trace) + if (trace(1)) printf("Allocating column %s\n", p); g->Message[0] = 0; // To check whether ColDB made an error message @@ -325,7 +325,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, tdbp->SetSetCols(tdbp->GetColumns()); // Now do open the physical table - if (trace) + if (trace(1)) printf("Opening table %s in mode %d tdbp=%p\n", tdbp->GetName(), mode, tdbp); @@ -341,7 +341,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, } // endif del - if (trace) + if (trace(1)) printf("About to open the table: tdbp=%p\n", tdbp); if (mode != MODE_ANY && mode != MODE_ALTER) { @@ -356,7 +356,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, rcop = false; } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); } catch (const char *msg) { strcpy(g->Message, msg); @@ -399,12 +399,13 @@ RCODE EvalColumns(PGLOBAL g, PTDB tdbp, bool reset, bool mrr) } // endfor colp } catch (int n) { - if (trace) + if (trace(1)) printf("Error %d reading columns: %s\n", n, g->Message); rc = RC_FX; } catch (const char *msg) { strcpy(g->Message, msg); + rc = RC_NF; } // end catch return rc; @@ -549,7 +550,7 @@ int CntCloseTable(PGLOBAL g, PTDB tdbp, bool nox, bool abort) return rc; } // endif !USE_OPEN - if (trace) + if (trace(1)) printf("CntCloseTable: tdbp=%p mode=%d nox=%d abort=%d\n", tdbp, tdbp->GetMode(), nox, abort); @@ -579,11 +580,11 @@ int CntCloseTable(PGLOBAL g, PTDB tdbp, bool nox, bool abort) tdbp->CloseDB(g); tdbp->SetAbort(false); - if (trace > 1) + if (trace(2)) printf("Table %s closed\n", tdbp->GetName()); if (!nox && tdbp->GetMode() != MODE_READ && tdbp->GetMode() != MODE_ANY) { - if (trace > 1) + if (trace(2)) printf("About to reset opt\n"); if (!tdbp->IsRemote()) { @@ -603,7 +604,7 @@ int CntCloseTable(PGLOBAL g, PTDB tdbp, bool nox, bool abort) rc = RC_FX; } // end catch - if (trace > 1) + if (trace(2)) htrc("Done rc=%d\n", rc); return (rc == RC_OK || rc == RC_INFO) ? 0 : rc; @@ -922,7 +923,7 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len, valp->SetBinValue((void*)p); #endif // !WORDS_BIGENDIAN - if (trace) { + if (trace(1)) { char bf[32]; printf("i=%d n=%d key=%s\n", i, n, valp->GetCharString(bf)); } // endif trace @@ -944,7 +945,7 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len, xbp->SetNval(n); - if (trace) + if (trace(1)) printf("xbp=%p Nval=%d i=%d incl=%d\n", xbp, n, i, incl[i]); k[i]= xbp->Range(g, i + 1, incl[i]); @@ -953,7 +954,7 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len, } // endfor i - if (trace) + if (trace(1)) printf("k1=%d k0=%d\n", k[1], k[0]); return k[1] - k[0]; diff --git a/storage/connect/csort.cpp b/storage/connect/csort.cpp index 13f325d8f3f..670131b8fd2 100644 --- a/storage/connect/csort.cpp +++ b/storage/connect/csort.cpp @@ -351,7 +351,7 @@ void CSORT::Qstx(int *base, int *max) zlo = zhi = cnm = 0; // Avoid warning message - lo = max - base; // Number of elements as longs + lo = (int)(max - base); // Number of elements as longs if (Dup) cnm = Cmpnum(lo); @@ -472,7 +472,7 @@ void CSORT::Qstx(int *base, int *max) i = him + 1; if (Pof) - Pof[him - Pex] = Pof[mid - Pex] = i - j; + Pof[him - Pex] = Pof[mid - Pex] = (int)(i - j); /*******************************************************************/ /* Look at sizes of the two partitions, do the smaller one first */ @@ -481,8 +481,8 @@ void CSORT::Qstx(int *base, int *max) /* But only repeat (recursively or by branching) if the partition */ /* is of at least size THRESH. */ /*******************************************************************/ - lo = j - base; - hi = max - i; + lo = (int)(j - base); + hi = (int)(max - i); if (Dup) { // Update progress information zlo = Cmpnum(lo); @@ -726,7 +726,7 @@ void CSORT::Qstc(int *base, int *max) zlo = zhi = cnm = 0; // Avoid warning message - lo = max - base; // Number of elements as longs + lo = (int)(max - base); // Number of elements as longs if (Dup) cnm = Cmpnum(lo); @@ -853,7 +853,7 @@ void CSORT::Qstc(int *base, int *max) /* the offset array values indicating break point and block size. */ /*******************************************************************/ if (Pof) - Pof[lt - Pex] = Pof[(jj - 1) - Pex] = jj - lt; + Pof[lt - Pex] = Pof[(jj - 1) - Pex] = (int)(jj - lt); /*******************************************************************/ /* Look at sizes of the two partitions, do the smaller one first */ @@ -862,8 +862,8 @@ void CSORT::Qstc(int *base, int *max) /* But only repeat (recursively or by branching) if the partition */ /* is of at least size THRESH. */ /*******************************************************************/ - lo = lt - base; - hi = gt - Swix; + lo = (int)(lt - base); + hi = (int)(gt - Swix); if (Dup) { // Update progress information zlo = Cmpnum(lo); diff --git a/storage/connect/domdoc.cpp b/storage/connect/domdoc.cpp index e24e10835c1..ba8eb829abd 100644 --- a/storage/connect/domdoc.cpp +++ b/storage/connect/domdoc.cpp @@ -13,6 +13,7 @@ #elif defined(MSX4) #import "msxml4.dll" //Causes error C2872: DOMNodeType: ambiguous symbol ?? #elif defined(MSX6) +#pragma warning(suppress : 4192) #import "msxml6.dll" //Causes error C2872: DOMNodeType: ambiguous symbol ?? #else // MSX4 #error MSX? is not defined @@ -540,7 +541,7 @@ PXNODE DOMNODE::AddChildNode(PGLOBAL g, PCSZ name, PXNODE np) // If name has the format m[n] only m is taken as node name if ((p = strchr(name, '['))) - pn = BufAlloc(g, name, p - name); + pn = BufAlloc(g, name, (int)(p - name)); else pn = name; diff --git a/storage/connect/filamap.cpp b/storage/connect/filamap.cpp index 84dff422db7..6e71e1bf2cd 100644 --- a/storage/connect/filamap.cpp +++ b/storage/connect/filamap.cpp @@ -90,7 +90,7 @@ int MAPFAM::GetFileLength(PGLOBAL g) len = (To_Fb && To_Fb->Count) ? To_Fb->Length : TXTFAM::GetFileLength(g); - if (trace) + if (trace(1)) htrc("Mapped file length=%d\n", len); return len; @@ -128,7 +128,7 @@ bool MAPFAM::OpenTableFile(PGLOBAL g) && fp->Count && fp->Mode == mode) break; - if (trace) + if (trace(1)) htrc("Mapping file, fp=%p\n", fp); } else @@ -166,7 +166,7 @@ bool MAPFAM::OpenTableFile(PGLOBAL g) sprintf(g->Message, MSG(OPEN_MODE_ERROR), "map", (int) rc, filename); - if (trace) + if (trace(1)) htrc("CreateFileMap: %s\n", g->Message); return (mode == MODE_READ && rc == ENOENT) @@ -227,7 +227,7 @@ bool MAPFAM::OpenTableFile(PGLOBAL g) Fpos = Mempos = Memory; Top = Memory + len; - if (trace) + if (trace(1)) htrc("fp=%p count=%d MapView=%p len=%d Top=%p\n", fp, fp->Count, Memory, len, Top); @@ -247,7 +247,7 @@ int MAPFAM::GetRowID(void) /***********************************************************************/ int MAPFAM::GetPos(void) { - return Fpos - Memory; + return (int)(Fpos - Memory); } // end of GetPos /***********************************************************************/ @@ -255,7 +255,7 @@ int MAPFAM::GetPos(void) /***********************************************************************/ int MAPFAM::GetNextPos(void) { - return Mempos - Memory; + return (int)(Mempos - Memory); } // end of GetNextPos /***********************************************************************/ @@ -368,7 +368,7 @@ int MAPFAM::ReadBuffer(PGLOBAL g) } // endif Mempos // Set caller line buffer - len = (Mempos - Fpos) - n; + len = (int)(Mempos - Fpos) - n; // Don't rely on ENDING setting if (len > 0 && *(Mempos - 2) == '\r') @@ -407,7 +407,7 @@ int MAPFAM::DeleteRecords(PGLOBAL g, int irc) { int n; - if (trace) + if (trace(1)) htrc("MAP DeleteDB: irc=%d mempos=%p tobuf=%p Tpos=%p Spos=%p\n", irc, Mempos, To_Buf, Tpos, Spos); @@ -417,7 +417,7 @@ int MAPFAM::DeleteRecords(PGLOBAL g, int irc) /*******************************************************************/ Fpos = Top; - if (trace) + if (trace(1)) htrc("Fpos placed at file top=%p\n", Fpos); } // endif irc @@ -428,14 +428,14 @@ int MAPFAM::DeleteRecords(PGLOBAL g, int irc) /* not required here, just setting of future Spos and Tpos. */ /*******************************************************************/ Tpos = Spos = Fpos; - } else if ((n = Fpos - Spos) > 0) { + } else if ((n = (int)(Fpos - Spos)) > 0) { /*******************************************************************/ /* Non consecutive line to delete. Move intermediate lines. */ /*******************************************************************/ memmove(Tpos, Spos, n); Tpos += n; - if (trace) + if (trace(1)) htrc("move %d bytes\n", n); } // endif n @@ -443,7 +443,7 @@ int MAPFAM::DeleteRecords(PGLOBAL g, int irc) if (irc == RC_OK) { Spos = Mempos; // New start position - if (trace) + if (trace(1)) htrc("after: Tpos=%p Spos=%p\n", Tpos, Spos); } else if (To_Fb) { // Can be NULL for deleted files @@ -461,7 +461,7 @@ int MAPFAM::DeleteRecords(PGLOBAL g, int irc) /*****************************************************************/ /* Remove extra records. */ /*****************************************************************/ - n = Tpos - Memory; + n = (int)(Tpos - Memory); #if defined(__WIN__) DWORD drc = SetFilePointer(fp->Handle, n, NULL, FILE_BEGIN); @@ -473,7 +473,7 @@ int MAPFAM::DeleteRecords(PGLOBAL g, int irc) return RC_FX; } // endif - if (trace) + if (trace(1)) htrc("done, Tpos=%p newsize=%d drc=%d\n", Tpos, n, drc); if (!SetEndOfFile(fp->Handle)) { @@ -511,7 +511,7 @@ void MAPFAM::CloseTableFile(PGLOBAL g, bool) PlugCloseFile(g, To_Fb); //To_Fb = NULL; // To get correct file size in Cardinality - if (trace) + if (trace(1)) htrc("MAP Close: closing %s count=%d\n", To_File, (To_Fb) ? To_Fb->Count : 0); @@ -627,7 +627,7 @@ int MBKFAM::ReadBuffer(PGLOBAL g) break; // Set caller line buffer - len = (Mempos - Fpos) - Ending; + len = (int)(Mempos - Fpos) - Ending; memcpy(Tdbp->GetLine(), Fpos, len); Tdbp->GetLine()[len] = '\0'; return RC_OK; diff --git a/storage/connect/filamdbf.cpp b/storage/connect/filamdbf.cpp index 44abd962c56..893e3da0d46 100644 --- a/storage/connect/filamdbf.cpp +++ b/storage/connect/filamdbf.cpp @@ -203,7 +203,7 @@ PQRYRES DBFColumns(PGLOBAL g, PCSZ dp, PCSZ fn, bool info) PQRYRES qrp; PCOLRES crp; - if (trace) + if (trace(1)) htrc("DBFColumns: File %s\n", SVP(fn)); if (!info) { @@ -245,7 +245,7 @@ PQRYRES DBFColumns(PGLOBAL g, PCSZ dp, PCSZ fn, bool info) return qrp; } // endif info - if (trace) { + if (trace(1)) { htrc("Structure of %s\n", filename); htrc("headlen=%hd reclen=%hd degree=%d\n", mainhead.Headlen(), mainhead.Reclen(), fields); @@ -271,7 +271,7 @@ PQRYRES DBFColumns(PGLOBAL g, PCSZ dp, PCSZ fn, bool info) } else len = thisfield.Length; - if (trace) + if (trace(1)) htrc("%-11s %c %6ld %3d %2d %3d %3d\n", thisfield.Name, thisfield.Type, thisfield.Offset, len, thisfield.Decimals, thisfield.Setfield, thisfield.Mdxfield); @@ -522,14 +522,14 @@ bool DBFFAM::OpenTableFile(PGLOBAL g) PlugSetPath(filename, To_File, Tdbp->GetPath()); if (!(Stream = PlugOpenFile(g, filename, opmode))) { - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return (mode == MODE_READ && errno == ENOENT) ? PushWarning(g, Tdbp) : true; } // endif Stream - if (trace) + if (trace(1)) htrc("File %s is open in mode %s\n", filename, opmode); To_Fb = dbuserp->Openlist; // Keep track of File block @@ -938,7 +938,7 @@ void DBFFAM::CloseTableFile(PGLOBAL g, bool abort) rc = PlugCloseFile(g, To_Fb); fin: - if (trace) + if (trace(1)) htrc("DBF CloseTableFile: closing %s mode=%d wrc=%d rc=%d\n", To_File, mode, wrc, rc); diff --git a/storage/connect/filamfix.cpp b/storage/connect/filamfix.cpp index 1d6194b154d..0a98ec5b54a 100644 --- a/storage/connect/filamfix.cpp +++ b/storage/connect/filamfix.cpp @@ -322,7 +322,7 @@ int FIXFAM::ReadBuffer(PGLOBAL g) return RC_FX; } // endif fseek - if (trace > 1) + if (trace(2)) htrc("File position is now %d\n", ftell(Stream)); if (Padded) @@ -344,7 +344,7 @@ int FIXFAM::ReadBuffer(PGLOBAL g) sprintf(g->Message, MSG(READ_ERROR), To_File, strerror(errno)); #endif - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return RC_FX; @@ -361,7 +361,7 @@ int FIXFAM::ReadBuffer(PGLOBAL g) /***********************************************************************/ int FIXFAM::WriteBuffer(PGLOBAL g) { - if (trace > 1) + if (trace(2)) htrc("FIX WriteDB: Mode=%d buf=%p line=%p Nrec=%d Rbuf=%d CurNum=%d\n", Tdbp->GetMode(), To_Buf, Tdbp->GetLine(), Nrec, Rbuf, CurNum); @@ -374,7 +374,7 @@ int FIXFAM::WriteBuffer(PGLOBAL g) return RC_OK; // We write only full blocks } // endif CurNum - if (trace > 1) + if (trace(2)) htrc(" First line is '%.*s'\n", Lrecl - 2, To_Buf); // Now start the writing process. @@ -388,7 +388,7 @@ int FIXFAM::WriteBuffer(PGLOBAL g) CurNum = 0; Tdbp->SetLine(To_Buf); - if (trace > 1) + if (trace(2)) htrc("write done\n"); } else { // Mode == MODE_UPDATE @@ -431,7 +431,7 @@ int FIXFAM::DeleteRecords(PGLOBAL g, int irc) /* file, and at the end erase all trailing records. */ /* This will be experimented. */ /*********************************************************************/ - if (trace > 1) + if (trace(2)) htrc("DOS DeleteDB: rc=%d UseTemp=%d Fpos=%d Tpos=%d Spos=%d\n", irc, UseTemp, Fpos, Tpos, Spos); @@ -441,7 +441,7 @@ int FIXFAM::DeleteRecords(PGLOBAL g, int irc) /*******************************************************************/ Fpos = Tdbp->Cardinality(g); - if (trace > 1) + if (trace(2)) htrc("Fpos placed at file end=%d\n", Fpos); } else // Fpos is the deleted line position @@ -491,7 +491,7 @@ int FIXFAM::DeleteRecords(PGLOBAL g, int irc) OldBlk = -2; // To force fseek to be executed on next block } // endif moved - if (trace > 1) + if (trace(2)) htrc("after: Tpos=%d Spos=%d\n", Tpos, Spos); } else { @@ -540,7 +540,7 @@ int FIXFAM::DeleteRecords(PGLOBAL g, int irc) close(h); - if (trace > 1) + if (trace(2)) htrc("done, h=%d irc=%d\n", h, irc); } // endif UseTemp @@ -572,7 +572,7 @@ bool FIXFAM::MoveIntermediateLines(PGLOBAL g, bool *b) req = (size_t)MY_MIN(n, Dbflen); len = fread(DelBuf, Lrecl, req, Stream); - if (trace > 1) + if (trace(2)) htrc("after read req=%d len=%d\n", req, len); if (len != req) { @@ -591,13 +591,13 @@ bool FIXFAM::MoveIntermediateLines(PGLOBAL g, bool *b) return true; } // endif - if (trace > 1) + if (trace(2)) htrc("after write pos=%d\n", ftell(Stream)); Tpos += (int)req; Spos += (int)req; - if (trace > 1) + if (trace(2)) htrc("loop: Tpos=%d Spos=%d\n", Tpos, Spos); *b = true; @@ -648,7 +648,7 @@ void FIXFAM::CloseTableFile(PGLOBAL g, bool abort) rc = PlugCloseFile(g, To_Fb); fin: - if (trace) + if (trace(1)) htrc("FIX CloseTableFile: closing %s mode=%d wrc=%d rc=%d\n", To_File, mode, wrc, rc); @@ -718,7 +718,7 @@ int BGXFAM::BigRead(PGLOBAL g __attribute__((unused)), DWORD nbr, drc, len = (DWORD)req; bool brc = ReadFile(h, inbuf, len, &nbr, NULL); - if (trace > 1) + if (trace(2)) htrc("after read req=%d brc=%d nbr=%d\n", req, brc, nbr); if (!brc) { @@ -730,7 +730,7 @@ int BGXFAM::BigRead(PGLOBAL g __attribute__((unused)), (LPTSTR)buf, sizeof(buf), NULL); sprintf(g->Message, MSG(READ_ERROR), To_File, buf); - if (trace > 1) + if (trace(2)) htrc("BIGREAD: %s\n", g->Message); rc = -1; @@ -757,7 +757,7 @@ bool BGXFAM::BigWrite(PGLOBAL g, HANDLE h, void *inbuf, int req) DWORD nbw, drc, len = (DWORD)req; bool brc = WriteFile(h, inbuf, len, &nbw, NULL); - if (trace > 1) + if (trace(2)) htrc("after write req=%d brc=%d nbw=%d\n", req, brc, nbw); if (!brc || nbw != len) { @@ -775,7 +775,7 @@ bool BGXFAM::BigWrite(PGLOBAL g, HANDLE h, void *inbuf, int req) sprintf(g->Message, MSG(WRITE_STRERROR), fn, buf); - if (trace > 1) + if (trace(2)) htrc("BIGWRITE: nbw=%d len=%d errno=%d %s\n", nbw, len, drc, g->Message); @@ -790,7 +790,7 @@ bool BGXFAM::BigWrite(PGLOBAL g, HANDLE h, void *inbuf, int req) sprintf(g->Message, MSG(WRITE_STRERROR), fn, strerror(errno)); - if (trace > 1) + if (trace(2)) htrc("BIGWRITE: nbw=%d len=%d errno=%d %s\n", nbw, len, errno, g->Message); @@ -828,7 +828,7 @@ bool BGXFAM::OpenTableFile(PGLOBAL g) PlugSetPath(filename, To_File, Tdbp->GetPath()); - if (trace) + if (trace(1)) htrc("OpenTableFile: filename=%s mode=%d\n", filename, mode); #if defined(__WIN__) @@ -888,7 +888,7 @@ bool BGXFAM::OpenTableFile(PGLOBAL g) } else rc = 0; - if (trace > 1) + if (trace(2)) htrc(" rc=%d access=%p share=%p creation=%d handle=%p fn=%s\n", rc, access, share, creation, Hfile, filename); @@ -942,7 +942,7 @@ bool BGXFAM::OpenTableFile(PGLOBAL g) } else rc = 0; - if (trace > 1) + if (trace(2)) htrc(" rc=%d oflag=%p tmode=%p handle=%p fn=%s\n", rc, oflag, tmode, Hfile, filename); @@ -1026,11 +1026,11 @@ int BGXFAM::Cardinality(PGLOBAL g) if (Hfile == INVALID_HANDLE_VALUE) { int h = open64(filename, O_RDONLY, 0); - if (trace) + if (trace(1)) htrc(" h=%d\n", h); if (h == INVALID_HANDLE_VALUE) { - if (trace) + if (trace(1)) htrc(" errno=%d ENOENT=%d\n", errno, ENOENT); if (errno != ENOENT) { @@ -1074,7 +1074,7 @@ int BGXFAM::Cardinality(PGLOBAL g) } else card = (int)(fsize / (BIGINT)Lrecl); // Fixed length file - if (trace) + if (trace(1)) htrc(" Computed max_K=%d fsize=%lf lrecl=%d\n", card, (double)fsize, Lrecl); @@ -1181,7 +1181,7 @@ int BGXFAM::ReadBuffer(PGLOBAL g) if (BigSeek(g, Hfile, (BIGINT)Fpos * (BIGINT)Lrecl)) return RC_FX; - if (trace > 1) + if (trace(2)) htrc("File position is now %d\n", Fpos); nbr = BigRead(g, Hfile, To_Buf, (Padded) ? Blksize : Lrecl * Nrec); @@ -1205,7 +1205,7 @@ int BGXFAM::ReadBuffer(PGLOBAL g) /***********************************************************************/ int BGXFAM::WriteBuffer(PGLOBAL g) { - if (trace > 1) + if (trace(2)) htrc("BIG WriteDB: Mode=%d buf=%p line=%p Nrec=%d Rbuf=%d CurNum=%d\n", Tdbp->GetMode(), To_Buf, Tdbp->GetLine(), Nrec, Rbuf, CurNum); @@ -1218,7 +1218,7 @@ int BGXFAM::WriteBuffer(PGLOBAL g) return RC_OK; // We write only full blocks } // endif CurNum - if (trace > 1) + if (trace(2)) htrc(" First line is '%.*s'\n", Lrecl - 2, To_Buf); // Now start the writing process. @@ -1229,7 +1229,7 @@ int BGXFAM::WriteBuffer(PGLOBAL g) CurNum = 0; Tdbp->SetLine(To_Buf); - if (trace > 1) + if (trace(2)) htrc("write done\n"); } else { // Mode == MODE_UPDATE @@ -1270,7 +1270,7 @@ int BGXFAM::DeleteRecords(PGLOBAL g, int irc) /* file, and at the end erase all trailing records. */ /* This will be experimented. */ /*********************************************************************/ - if (trace > 1) + if (trace(2)) htrc("BGX DeleteDB: rc=%d UseTemp=%d Fpos=%d Tpos=%d Spos=%d\n", irc, UseTemp, Fpos, Tpos, Spos); @@ -1280,7 +1280,7 @@ int BGXFAM::DeleteRecords(PGLOBAL g, int irc) /*******************************************************************/ Fpos = Tdbp->Cardinality(g); - if (trace > 1) + if (trace(2)) htrc("Fpos placed at file end=%d\n", Fpos); } else // Fpos is the deleted line position @@ -1318,7 +1318,7 @@ int BGXFAM::DeleteRecords(PGLOBAL g, int irc) return RC_FX; if (irc == RC_OK) { - if (trace) + if (trace(1)) assert(Spos == Fpos); Spos++; // New start position is on next line @@ -1330,7 +1330,7 @@ int BGXFAM::DeleteRecords(PGLOBAL g, int irc) OldBlk = -2; // To force fseek to be executed on next block } // endif moved - if (trace > 1) + if (trace(2)) htrc("after: Tpos=%d Spos=%d\n", Tpos, Spos); } else if (irc != RC_OK) { @@ -1459,7 +1459,7 @@ bool BGXFAM::MoveIntermediateLines(PGLOBAL g, bool *b) Tpos += (int)req; Spos += (int)req; - if (trace > 1) + if (trace(2)) htrc("loop: Tpos=%d Spos=%d\n", Tpos, Spos); *b = true; @@ -1510,7 +1510,7 @@ void BGXFAM::CloseTableFile(PGLOBAL g, bool abort) rc = PlugCloseFile(g, To_Fb); fin: - if (trace) + if (trace(1)) htrc("BGX CloseTableFile: closing %s mode=%d wrc=%d rc=%d\n", To_File, mode, wrc, rc); diff --git a/storage/connect/filamgz.cpp b/storage/connect/filamgz.cpp index df366ef15f9..880db54c91d 100644 --- a/storage/connect/filamgz.cpp +++ b/storage/connect/filamgz.cpp @@ -203,7 +203,7 @@ bool GZFAM::AllocateBuffer(PGLOBAL g) Buflen = Lrecl + 2; // Lrecl does not include CRLF //Buflen *= ((Mode == MODE_DELETE) ? DOS_BUFF_LEN : 1); NIY - if (trace) + if (trace(1)) htrc("SubAllocating a buffer of %d bytes\n", Buflen); To_Buf = (char*)PlugSubAlloc(g, NULL, Buflen); @@ -347,7 +347,7 @@ int GZFAM::ReadBuffer(PGLOBAL g) } else rc = Zerror(g); - if (trace > 1) + if (trace(2)) htrc(" Read: '%s' rc=%d\n", To_Buf, rc); return rc; @@ -389,7 +389,7 @@ void GZFAM::CloseTableFile(PGLOBAL, bool) { int rc = gzclose(Zfile); - if (trace) + if (trace(1)) htrc("GZ CloseDB: closing %s rc=%d\n", To_File, rc); Zfile = NULL; // So we can know whether table is open @@ -537,7 +537,7 @@ int ZBKFAM::ReadBuffer(PGLOBAL g) while (*NxtLine++ != '\n') ; // Set caller line buffer - n = NxtLine - CurLine - Ending; + n = (int)(NxtLine - CurLine - Ending); memcpy(Tdbp->GetLine(), CurLine, n); Tdbp->GetLine()[n] = '\0'; return RC_OK; @@ -588,7 +588,7 @@ int ZBKFAM::ReadBuffer(PGLOBAL g) for (NxtLine = CurLine; *NxtLine++ != '\n';) ; // Set caller line buffer - n = NxtLine - CurLine - Ending; + n = (int)(NxtLine - CurLine - Ending); memcpy(Tdbp->GetLine(), CurLine, n); Tdbp->GetLine()[n] = '\0'; Rbuf = (CurBlk == Block - 1) ? Last : Nrec; @@ -702,7 +702,7 @@ void ZBKFAM::CloseTableFile(PGLOBAL g, bool) } else rc = gzclose(Zfile); - if (trace) + if (trace(1)) htrc("GZ CloseDB: closing %s rc=%d\n", To_File, rc); Zfile = NULL; // So we can know whether table is open @@ -1087,7 +1087,7 @@ bool ZLBFAM::SetPos(PGLOBAL g, int pos __attribute__((unused))) /***********************************************************************/ int ZLBFAM::ReadBuffer(PGLOBAL g) { - int n; + size_t n; void *rdbuf; /*********************************************************************/ @@ -1299,7 +1299,7 @@ int ZLBFAM::WriteBuffer(PGLOBAL g) else NxtLine = CurLine + Lrecl; - BlkLen = NxtLine - To_Buf; + BlkLen = (int)(NxtLine - To_Buf); if (WriteCompressedBuffer(g)) { Closing = TRUE; // To tell CloseDB about a Write error @@ -1382,7 +1382,7 @@ void ZLBFAM::CloseTableFile(PGLOBAL g, bool) } else rc = fclose(Stream); - if (trace) + if (trace(1)) htrc("ZLB CloseTableFile: closing %s mode=%d rc=%d\n", To_File, Tdbp->GetMode(), rc); @@ -1408,7 +1408,7 @@ void ZLBFAM::Rewind(void) rewind(Stream); - if (!(st = fread(Zlenp, sizeof(int), 1, Stream)) && trace) + if (!(st = fread(Zlenp, sizeof(int), 1, Stream)) && trace(1)) htrc("fread error %d in Rewind", errno); fseek(Stream, *Zlenp + sizeof(int), SEEK_SET); diff --git a/storage/connect/filamtxt.cpp b/storage/connect/filamtxt.cpp index c456ee9e9b7..7c222eb3c80 100644 --- a/storage/connect/filamtxt.cpp +++ b/storage/connect/filamtxt.cpp @@ -194,12 +194,12 @@ int TXTFAM::GetFileLength(PGLOBAL g) PlugSetPath(filename, To_File, Tdbp->GetPath()); h= global_open(g, MSGID_OPEN_MODE_STRERROR, filename, _O_RDONLY); - if (trace) + if (trace(1)) htrc("GetFileLength: fn=%s h=%d\n", filename, h); if (h == -1) { if (errno != ENOENT) { - if (trace) + if (trace(1)) htrc("%s\n", g->Message); len = -1; @@ -249,7 +249,7 @@ int TXTFAM::Cardinality(PGLOBAL g) } // endif Padded - if (trace) + if (trace(1)) htrc(" Computed max_K=%d Filen=%d lrecl=%d\n", card, len, Lrecl); @@ -390,7 +390,7 @@ int TXTFAM::UpdateSortedRows(PGLOBAL g) return RC_OK; err: - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return RC_FX; @@ -439,7 +439,7 @@ int TXTFAM::DeleteSortedRows(PGLOBAL g) return RC_OK; err: - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return RC_FX; @@ -512,7 +512,7 @@ int DOSFAM::GetFileLength(PGLOBAL g) if ((len = _filelength(_fileno(Stream))) < 0) sprintf(g->Message, MSG(FILELEN_ERROR), "_filelength", To_File); - if (trace) + if (trace(1)) htrc("File length=%d\n", len); return len; @@ -598,14 +598,14 @@ bool DOSFAM::OpenTableFile(PGLOBAL g) PlugSetPath(filename, To_File, Tdbp->GetPath()); if (!(Stream = PlugOpenFile(g, filename, opmode))) { - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return (mode == MODE_READ && errno == ENOENT) ? PushWarning(g, Tdbp) : true; } // endif Stream - if (trace) + if (trace(1)) htrc("File %s open Stream=%p mode=%s\n", filename, Stream, opmode); To_Fb = dbuserp->Openlist; // Keep track of File block @@ -628,7 +628,7 @@ bool DOSFAM::AllocateBuffer(PGLOBAL g) // Lrecl does not include line ending Buflen = Lrecl + Ending + ((Bin) ? 1 : 0) + 1; // Sergei - if (trace) + if (trace(1)) htrc("SubAllocating a buffer of %d bytes\n", Buflen); To_Buf = (char*)PlugSubAlloc(g, NULL, Buflen); @@ -768,7 +768,7 @@ int DOSFAM::ReadBuffer(PGLOBAL g) if (!Stream) return RC_EF; - if (trace > 1) + if (trace(2)) htrc("ReadBuffer: Tdbp=%p To_Line=%p Placed=%d\n", Tdbp, Tdbp->To_Line, Placed); @@ -782,7 +782,7 @@ int DOSFAM::ReadBuffer(PGLOBAL g) CurBlk = (int)Rows++; - if (trace > 1) + if (trace(2)) htrc("ReadBuffer: CurBlk=%d\n", CurBlk); /********************************************************************/ @@ -803,14 +803,14 @@ int DOSFAM::ReadBuffer(PGLOBAL g) } else Placed = false; - if (trace > 1) + if (trace(2)) htrc(" About to read: stream=%p To_Buf=%p Buflen=%d\n", Stream, To_Buf, Buflen); if (fgets(To_Buf, Buflen, Stream)) { p = To_Buf + strlen(To_Buf) - 1; - if (trace > 1) + if (trace(2)) htrc(" Read: To_Buf=%p p=%c\n", To_Buf, To_Buf, p); #if defined(__WIN__) @@ -838,7 +838,7 @@ int DOSFAM::ReadBuffer(PGLOBAL g) } else if (*p == '\n') *p = '\0'; // Eliminate ending new-line character - if (trace > 1) + if (trace(2)) htrc(" To_Buf='%s'\n", To_Buf); strcpy(Tdbp->To_Line, To_Buf); @@ -853,13 +853,13 @@ int DOSFAM::ReadBuffer(PGLOBAL g) sprintf(g->Message, MSG(READ_ERROR), To_File, strerror(0)); #endif - if (trace) + if (trace(1)) htrc("%s\n", g->Message); rc = RC_FX; } // endif's fgets - if (trace > 1) + if (trace(2)) htrc("ReadBuffer: rc=%d\n", rc); IsRead = true; @@ -895,7 +895,7 @@ int DOSFAM::WriteBuffer(PGLOBAL g) /*******************************************************************/ curpos = ftell(Stream); - if (trace) + if (trace(1)) htrc("Last : %d cur: %d\n", Fpos, curpos); if (UseTemp) { @@ -937,7 +937,7 @@ int DOSFAM::WriteBuffer(PGLOBAL g) return RC_FX; } // endif - if (trace) + if (trace(1)) htrc("write done\n"); return RC_OK; @@ -960,7 +960,7 @@ int DOSFAM::DeleteRecords(PGLOBAL g, int irc) /* file, and at the end erase all trailing records. */ /* This will be experimented. */ /*********************************************************************/ - if (trace) + if (trace(1)) htrc( "DOS DeleteDB: rc=%d UseTemp=%d curpos=%d Fpos=%d Tpos=%d Spos=%d\n", irc, UseTemp, curpos, Fpos, Tpos, Spos); @@ -972,7 +972,7 @@ int DOSFAM::DeleteRecords(PGLOBAL g, int irc) fseek(Stream, 0, SEEK_END); Fpos = ftell(Stream); - if (trace) + if (trace(1)) htrc("Fpos placed at file end=%d\n", Fpos); } // endif irc @@ -1015,7 +1015,7 @@ int DOSFAM::DeleteRecords(PGLOBAL g, int irc) Spos = GetNextPos(); // New start position - if (trace) + if (trace(1)) htrc("after: Tpos=%d Spos=%d\n", Tpos, Spos); } else { @@ -1058,7 +1058,7 @@ int DOSFAM::DeleteRecords(PGLOBAL g, int irc) close(h); - if (trace) + if (trace(1)) htrc("done, h=%d irc=%d\n", h, irc); } // endif !UseTemp @@ -1083,7 +1083,7 @@ bool DOSFAM::OpenTempFile(PGLOBAL g) strcat(PlugRemoveType(tempname, tempname), ".t"); if (!(T_Stream = PlugOpenFile(g, tempname, "wb"))) { - if (trace) + if (trace(1)) htrc("%s\n", g->Message); rc = true; @@ -1112,7 +1112,7 @@ bool DOSFAM::MoveIntermediateLines(PGLOBAL g, bool *b) req = (size_t)MY_MIN(n, Dbflen); len = fread(DelBuf, 1, req, Stream); - if (trace) + if (trace(1)) htrc("after read req=%d len=%d\n", req, len); if (len != req) { @@ -1131,13 +1131,13 @@ bool DOSFAM::MoveIntermediateLines(PGLOBAL g, bool *b) return true; } // endif - if (trace) + if (trace(1)) htrc("after write pos=%d\n", ftell(Stream)); Tpos += (int)req; Spos += (int)req; - if (trace) + if (trace(1)) htrc("loop: Tpos=%d Spos=%d\n", Tpos, Spos); *b = true; @@ -1217,7 +1217,7 @@ void DOSFAM::CloseTableFile(PGLOBAL g, bool abort) } else { rc = PlugCloseFile(g, To_Fb); - if (trace) + if (trace(1)) htrc("DOS Close: closing %s rc=%d\n", To_File, rc); } // endif UseTemp @@ -1351,7 +1351,7 @@ int BLKFAM::GetPos(void) /***********************************************************************/ int BLKFAM::GetNextPos(void) { - return Fpos + NxtLine - CurLine; + return (int)(Fpos + NxtLine - CurLine); } // end of GetNextPos /***********************************************************************/ @@ -1396,7 +1396,8 @@ int BLKFAM::SkipRecord(PGLOBAL, bool header) /***********************************************************************/ int BLKFAM::ReadBuffer(PGLOBAL g) { - int i, n, rc = RC_OK; + int i, rc = RC_OK; + size_t n; /*********************************************************************/ /* Sequential reading when Placed is not true. */ @@ -1452,13 +1453,13 @@ int BLKFAM::ReadBuffer(PGLOBAL g) // Calculate the length of block to read BlkLen = BlkPos[CurBlk + 1] - BlkPos[CurBlk]; - if (trace) + if (trace(1)) htrc("File position is now %d\n", ftell(Stream)); // Read the entire next block n = fread(To_Buf, 1, (size_t)BlkLen, Stream); - if (n == BlkLen) { + if ((size_t) n == (size_t) BlkLen) { // ReadBlks++; num_read++; Rbuf = (CurBlk == Block - 1) ? Last : Nrec; @@ -1486,7 +1487,7 @@ int BLKFAM::ReadBuffer(PGLOBAL g) sprintf(g->Message, MSG(READ_ERROR), To_File, strerror(errno)); #endif - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return RC_FX; @@ -1497,7 +1498,7 @@ int BLKFAM::ReadBuffer(PGLOBAL g) fin: // Store the current record file position for Delete and Update - Fpos = BlkPos[CurBlk] + CurLine - To_Buf; + Fpos = (int)(BlkPos[CurBlk] + CurLine - To_Buf); return rc; } // end of ReadBuffer @@ -1524,7 +1525,7 @@ int BLKFAM::WriteBuffer(PGLOBAL g) // Now start the writing process. NxtLine = CurLine + strlen(CurLine); - BlkLen = NxtLine - To_Buf; + BlkLen = (int)(NxtLine - To_Buf); if (fwrite(To_Buf, 1, BlkLen, Stream) != (size_t)BlkLen) { sprintf(g->Message, MSG(FWRITE_ERROR), strerror(errno)); @@ -1636,7 +1637,7 @@ void BLKFAM::CloseTableFile(PGLOBAL g, bool abort) rc = PlugCloseFile(g, To_Fb); - if (trace) + if (trace(1)) htrc("BLK CloseTableFile: closing %s mode=%d wrc=%d rc=%d\n", To_File, Tdbp->GetMode(), wrc, rc); diff --git a/storage/connect/filamvct.cpp b/storage/connect/filamvct.cpp index 871613cb4b4..244acfdc5c8 100755 --- a/storage/connect/filamvct.cpp +++ b/storage/connect/filamvct.cpp @@ -336,7 +336,7 @@ int VCTFAM::Cardinality(PGLOBAL g) else sprintf(g->Message, MSG(NOT_FIXED_LEN), To_File, len, clen); - if (trace) + if (trace(1)) htrc(" Computed max_K=%d Filen=%d Clen=%d\n", card, len, clen); } else @@ -469,14 +469,14 @@ bool VCTFAM::OpenTableFile(PGLOBAL g) PlugSetPath(filename, To_File, Tdbp->GetPath()); if (!(Stream = PlugOpenFile(g, filename, opmode))) { - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return (mode == MODE_READ && errno == ENOENT) ? PushWarning(g, Tdbp) : true; } // endif Stream - if (trace) + if (trace(1)) htrc("File %s is open in mode %s\n", filename, opmode); To_Fb = dbuserp->Openlist; // Keep track of File block @@ -581,7 +581,7 @@ bool VCTFAM::InitInsert(PGLOBAL g) cp->ReadBlock(g); } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); rc = true; } catch (const char *msg) { @@ -652,7 +652,7 @@ int VCTFAM::ReadBuffer(PGLOBAL g) OldBlk = CurBlk; // Last block actually read } // endif oldblk - if (trace) + if (trace(1)) htrc(" Read: CurNum=%d CurBlk=%d rc=%d\n", CurNum, CurBlk, RC_OK); return rc; @@ -663,7 +663,7 @@ int VCTFAM::ReadBuffer(PGLOBAL g) /***********************************************************************/ int VCTFAM::WriteBuffer(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("VCT WriteBuffer: R%d Mode=%d CurNum=%d CurBlk=%d\n", Tdbp->GetTdb_No(), Tdbp->GetMode(), CurNum, CurBlk); @@ -756,7 +756,7 @@ int VCTFAM::DeleteRecords(PGLOBAL g, int irc) { bool eof = false; - if (trace) + if (trace(1)) htrc("VCT DeleteDB: rc=%d UseTemp=%d Fpos=%d Tpos=%d Spos=%d\n", irc, UseTemp, Fpos, Tpos, Spos); @@ -766,7 +766,7 @@ int VCTFAM::DeleteRecords(PGLOBAL g, int irc) /*******************************************************************/ Fpos = (Block - 1) * Nrec + Last; - if (trace) + if (trace(1)) htrc("Fpos placed at file end=%d\n", Fpos); eof = UseTemp && !MaxBlk; @@ -807,7 +807,7 @@ int VCTFAM::DeleteRecords(PGLOBAL g, int irc) #endif Spos++; // New start position is on next line - if (trace) + if (trace(1)) htrc("after: Tpos=%d Spos=%d\n", Tpos, Spos); } else { @@ -856,7 +856,7 @@ int VCTFAM::DeleteRecords(PGLOBAL g, int irc) close(h); - if (trace) + if (trace(1)) htrc("done, h=%d irc=%d\n", h, irc); } else @@ -899,7 +899,7 @@ bool VCTFAM::OpenTempFile(PGLOBAL g) opmode = "wb"; if (!(T_Stream = PlugOpenFile(g, tempname, opmode))) { - if (trace) + if (trace(1)) htrc("%s\n", g->Message); rc = true; @@ -947,7 +947,7 @@ bool VCTFAM::MoveIntermediateLines(PGLOBAL g, bool *b) len = fread(To_Buf, Clens[i], req, Stream); - if (trace) + if (trace(1)) htrc("after read req=%d len=%d\n", req, len); if (len != req) { @@ -976,7 +976,7 @@ bool VCTFAM::MoveIntermediateLines(PGLOBAL g, bool *b) } // endif UseTemp - if (trace) + if (trace(1)) htrc("after write pos=%d\n", ftell(Stream)); } // endfor i @@ -1007,7 +1007,7 @@ bool VCTFAM::MoveIntermediateLines(PGLOBAL g, bool *b) } // endif UseTemp - if (trace) + if (trace(1)) htrc("loop: Tpos=%d Spos=%d\n", Tpos, Spos); } // endfor n @@ -1144,7 +1144,7 @@ void VCTFAM::CloseTableFile(PGLOBAL g, bool abort) if (!(UseTemp && T_Stream)) rc = PlugCloseFile(g, To_Fb); - if (trace) + if (trace(1)) htrc("VCT CloseTableFile: closing %s wrc=%d rc=%d\n", To_File, wrc, rc); @@ -1217,7 +1217,7 @@ bool VCTFAM::ReadBlock(PGLOBAL g, PVCTCOL colp) else // Blocked vector format len = Nrec * (colp->Deplac + Lrecl * CurBlk); - if (trace) + if (trace(1)) htrc("len=%d Nrec=%d Deplac=%d Lrecl=%d CurBlk=%d maxblk=%d\n", len, Nrec, colp->Deplac, Lrecl, CurBlk, MaxBlk); @@ -1236,13 +1236,13 @@ bool VCTFAM::ReadBlock(PGLOBAL g, PVCTCOL colp) sprintf(g->Message, MSG(READ_ERROR), To_File, strerror(errno)); - if (trace) + if (trace(1)) htrc(" Read error: %s\n", g->Message); return true; } // endif - if (trace) + if (trace(1)) num_read++; return false; @@ -1268,7 +1268,7 @@ bool VCTFAM::WriteBlock(PGLOBAL g, PVCTCOL colp) else // Old VCT format len = Nrec * (colp->Deplac + Lrecl * colp->ColBlk); - if (trace) + if (trace(1)) htrc("modif=%d len=%d Nrec=%d Deplac=%d Lrecl=%d colblk=%d\n", Modif, len, Nrec, colp->Deplac, Lrecl, colp->ColBlk); @@ -1287,7 +1287,7 @@ bool VCTFAM::WriteBlock(PGLOBAL g, PVCTCOL colp) sprintf(g->Message, MSG(WRITE_STRERROR), (UseTemp) ? To_Fbt->Fname : To_File, strerror(errno)); - if (trace) + if (trace(1)) htrc("Write error: %s\n", strerror(errno)); return true; @@ -1358,7 +1358,7 @@ bool VCMFAM::OpenTableFile(PGLOBAL g) && fp->Count && fp->Mode == mode) break; - if (trace) + if (trace(1)) htrc("Mapping VCM file, fp=%p cnt=%d\n", fp, fp->Count); } else @@ -1416,7 +1416,7 @@ bool VCMFAM::OpenTableFile(PGLOBAL g) sprintf(g->Message, MSG(OPEN_MODE_ERROR), "map", (int) rc, filename); - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return (mode == MODE_READ && rc == ENOENT) @@ -1467,7 +1467,7 @@ bool VCMFAM::OpenTableFile(PGLOBAL g) To_Fb = fp; // Useful when closing - if (trace) + if (trace(1)) htrc("fp=%p count=%d MapView=%p len=%d Top=%p\n", fp, fp->Count, Memory, len); @@ -1551,7 +1551,7 @@ bool VCMFAM::InitInsert(PGLOBAL g) cp->ReadBlock(g); } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); rc = true; } catch (const char *msg) { @@ -1567,7 +1567,7 @@ bool VCMFAM::InitInsert(PGLOBAL g) /***********************************************************************/ int VCMFAM::WriteBuffer(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("VCM WriteBuffer: R%d Mode=%d CurNum=%d CurBlk=%d\n", Tdbp->GetTdb_No(), Tdbp->GetMode(), CurNum, CurBlk); @@ -1608,7 +1608,7 @@ int VCMFAM::WriteBuffer(PGLOBAL g) /***********************************************************************/ int VCMFAM::DeleteRecords(PGLOBAL g, int irc) { - if (trace) + if (trace(1)) htrc("VCM DeleteDB: irc=%d tobuf=%p Tpos=%p Spos=%p\n", irc, To_Buf, Tpos, Spos); @@ -1618,7 +1618,7 @@ int VCMFAM::DeleteRecords(PGLOBAL g, int irc) /*******************************************************************/ Fpos = (Block - 1) * Nrec + Last; - if (trace) + if (trace(1)) htrc("Fpos placed at file top=%p\n", Fpos); } else // Fpos is the Deleted line position @@ -1636,7 +1636,7 @@ int VCMFAM::DeleteRecords(PGLOBAL g, int irc) if (irc == RC_OK) { Spos = Fpos + 1; // New start position - if (trace) + if (trace(1)) htrc("after: Tpos=%p Spos=%p\n", Tpos, Spos); } else { @@ -1680,7 +1680,7 @@ int VCMFAM::DeleteRecords(PGLOBAL g, int irc) return RC_FX; } // endif - if (trace) + if (trace(1)) htrc("done, Tpos=%p newsize=%d drc=%d\n", Tpos, n, drc); if (!SetEndOfFile(fp->Handle)) { @@ -1755,7 +1755,7 @@ bool VCMFAM::MoveIntermediateLines(PGLOBAL, bool *) Tpos += n; } // endif MaxBlk - if (trace) + if (trace(1)) htrc("move %d bytes\n", n); } // endif n @@ -1812,14 +1812,14 @@ bool VCMFAM::ReadBlock(PGLOBAL, PVCTCOL colp) /*********************************************************************/ mempos = Memcol[i] + n * CurBlk; - if (trace) + if (trace(1)) htrc("mempos=%p i=%d Nrec=%d Clen=%d CurBlk=%d\n", mempos, i, Nrec, colp->Clen, CurBlk); if (colp->GetStatus(BUF_MAPPED)) colp->Blk->SetValPointer(mempos); - if (trace) + if (trace(1)) num_read++; return false; @@ -1843,7 +1843,7 @@ bool VCMFAM::WriteBlock(PGLOBAL, PVCTCOL colp __attribute__((unused))) /*********************************************************************/ mempos = Memcol[i] + n * CurBlk; - if (trace) + if (trace(1)) htrc("modif=%d mempos=%p i=%d Nrec=%d Clen=%d colblk=%d\n", Modif, mempos, i, Nrec, colp->Clen, colp->ColBlk); @@ -2008,14 +2008,14 @@ bool VECFAM::OpenColumnFile(PGLOBAL g, PCSZ opmode, int i) sprintf(filename, Colfn, i+1); if (!(Streams[i] = PlugOpenFile(g, filename, opmode))) { - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return (Tdbp->GetMode() == MODE_READ && errno == ENOENT) ? PushWarning(g, Tdbp) : true; } // endif Streams - if (trace) + if (trace(1)) htrc("File %s is open in mode %s\n", filename, opmode); To_Fbs[i] = dup->Openlist; // Keep track of File blocks @@ -2163,7 +2163,7 @@ void VECFAM::ResetBuffer(PGLOBAL g) /***********************************************************************/ int VECFAM::WriteBuffer(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("VCT WriteBuffer: R%d Mode=%d CurNum=%d CurBlk=%d\n", Tdbp->GetTdb_No(), Tdbp->GetMode(), CurNum, CurBlk); @@ -2205,7 +2205,7 @@ int VECFAM::WriteBuffer(PGLOBAL g) /***********************************************************************/ int VECFAM::DeleteRecords(PGLOBAL g, int irc) { - if (trace) + if (trace(1)) htrc("VEC DeleteDB: rc=%d UseTemp=%d Fpos=%d Tpos=%d Spos=%d\n", irc, UseTemp, Fpos, Tpos, Spos); @@ -2215,7 +2215,7 @@ int VECFAM::DeleteRecords(PGLOBAL g, int irc) /*******************************************************************/ Fpos = Cardinality(g); - if (trace) + if (trace(1)) htrc("Fpos placed at file end=%d\n", Fpos); } else // Fpos is the Deleted line position @@ -2251,7 +2251,7 @@ int VECFAM::DeleteRecords(PGLOBAL g, int irc) #endif Spos++; // New start position is on next line - if (trace) + if (trace(1)) htrc("after: Tpos=%d Spos=%d\n", Tpos, Spos); } else { @@ -2294,7 +2294,7 @@ int VECFAM::DeleteRecords(PGLOBAL g, int irc) close(h); - if (trace) + if (trace(1)) htrc("done, h=%d irc=%d\n", h, irc); } // endfor i @@ -2332,7 +2332,7 @@ bool VECFAM::OpenTempFile(PGLOBAL g) sprintf(tempname, Tempat, i+1); if (!(T_Streams[i] = PlugOpenFile(g, tempname, "wb"))) { - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return true; @@ -2391,7 +2391,7 @@ bool VECFAM::MoveIntermediateLines(PGLOBAL g, bool *) len = fread(To_Buf, Clens[i], req, Streams[i]); - if (trace) + if (trace(1)) htrc("after read req=%d len=%d\n", req, len); if (len != req) { @@ -2410,7 +2410,7 @@ bool VECFAM::MoveIntermediateLines(PGLOBAL g, bool *) return true; } // endif - if (trace) + if (trace(1)) htrc("after write pos=%d\n", ftell(Streams[i])); } // endfor i @@ -2418,7 +2418,7 @@ bool VECFAM::MoveIntermediateLines(PGLOBAL g, bool *) Tpos += (int)req; Spos += (int)req; - if (trace) + if (trace(1)) htrc("loop: Tpos=%d Spos=%d\n", Tpos, Spos); b = true; @@ -2541,7 +2541,7 @@ void VECFAM::CloseTableFile(PGLOBAL g, bool abort) To_Fbs[i] = NULL; } // endif Streams - if (trace) + if (trace(1)) htrc("VCT CloseTableFile: closing %s wrc=%d rc=%d\n", To_File, wrc, rc); } // end of CloseTableFile @@ -2560,7 +2560,7 @@ bool VECFAM::ReadBlock(PGLOBAL g, PVCTCOL colp) len = Nrec * colp->Clen * CurBlk; i = colp->Index - 1; - if (trace) + if (trace(1)) htrc("len=%d i=%d Nrec=%d Deplac=%d Lrecl=%d CurBlk=%d\n", len, i, Nrec, colp->Deplac, Lrecl, CurBlk); @@ -2586,13 +2586,13 @@ bool VECFAM::ReadBlock(PGLOBAL g, PVCTCOL colp) sprintf(g->Message, MSG(READ_ERROR), fn, strerror(errno)); - if (trace) + if (trace(1)) htrc(" Read error: %s\n", g->Message); return true; } // endif - if (trace) + if (trace(1)) num_read++; return false; @@ -2615,7 +2615,7 @@ bool VECFAM::WriteBlock(PGLOBAL g, PVCTCOL colp) len = Nrec * colp->Clen * colp->ColBlk; i = colp->Index - 1; - if (trace) + if (trace(1)) htrc("modif=%d len=%d i=%d Nrec=%d Deplac=%d Lrecl=%d colblk=%d\n", Modif, len, i, Nrec, colp->Deplac, Lrecl, colp->ColBlk); @@ -2638,7 +2638,7 @@ bool VECFAM::WriteBlock(PGLOBAL g, PVCTCOL colp) sprintf(fn, (UseTemp) ? Tempat : Colfn, colp->Index); sprintf(g->Message, MSG(WRITE_STRERROR), fn, strerror(errno)); - if (trace) + if (trace(1)) htrc("Write error: %s\n", strerror(errno)); return true; @@ -2782,7 +2782,7 @@ bool VMPFAM::MapColumnFile(PGLOBAL g, MODE mode, int i) && fp->Count && fp->Mode == mode) break; - if (trace) + if (trace(1)) htrc("Mapping file, fp=%p\n", fp); } else @@ -2807,7 +2807,7 @@ bool VMPFAM::MapColumnFile(PGLOBAL g, MODE mode, int i) if (!(*g->Message)) sprintf(g->Message, MSG(OPEN_MODE_ERROR), "map", (int) rc, filename); - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return (mode == MODE_READ && rc == ENOENT) @@ -2858,7 +2858,7 @@ bool VMPFAM::MapColumnFile(PGLOBAL g, MODE mode, int i) To_Fbs[i] = fp; // Useful when closing - if (trace) + if (trace(1)) htrc("fp=%p count=%d MapView=%p len=%d\n", fp, fp->Count, Memcol[i], len); @@ -2903,7 +2903,7 @@ int VMPFAM::DeleteRecords(PGLOBAL g, int irc) int i; int m, n; - if (trace) + if (trace(1)) htrc("VMP DeleteDB: irc=%d tobuf=%p Tpos=%p Spos=%p\n", irc, To_Buf, Tpos, Spos); @@ -2913,7 +2913,7 @@ int VMPFAM::DeleteRecords(PGLOBAL g, int irc) /*******************************************************************/ Fpos = (Block - 1) * Nrec + Last; - if (trace) + if (trace(1)) htrc("Fpos placed at file top=%p\n", Fpos); } else // Fpos is the Deleted line position @@ -2936,7 +2936,7 @@ int VMPFAM::DeleteRecords(PGLOBAL g, int irc) Tpos += n; - if (trace) + if (trace(1)) htrc("move %d bytes\n", n); } // endif n @@ -2944,7 +2944,7 @@ int VMPFAM::DeleteRecords(PGLOBAL g, int irc) if (irc == RC_OK) { Spos = Fpos + 1; // New start position - if (trace) + if (trace(1)) htrc("after: Tpos=%p Spos=%p\n", Tpos, Spos); } else { @@ -2981,7 +2981,7 @@ int VMPFAM::DeleteRecords(PGLOBAL g, int irc) return RC_FX; } // endif - if (trace) + if (trace(1)) htrc("done, Tpos=%p newsize=%d drc=%d\n", Tpos, n, drc); if (!SetEndOfFile(fp->Handle)) { @@ -3088,7 +3088,7 @@ bool BGVFAM::BigRead(PGLOBAL g, HANDLE h, void *inbuf, int req) DWORD nbr, drc, len = (DWORD)req; bool brc = ReadFile(h, inbuf, len, &nbr, NULL); - if (trace) + if (trace(1)) htrc("after read req=%d brc=%d nbr=%d\n", req, brc, nbr); if (!brc || nbr != len) { @@ -3105,7 +3105,7 @@ bool BGVFAM::BigRead(PGLOBAL g, HANDLE h, void *inbuf, int req) sprintf(g->Message, MSG(READ_ERROR), To_File, buf); - if (trace) + if (trace(1)) htrc("BIGREAD: %s\n", g->Message); rc = true; @@ -3119,7 +3119,7 @@ bool BGVFAM::BigRead(PGLOBAL g, HANDLE h, void *inbuf, int req) sprintf(g->Message, MSG(READ_ERROR), fn, strerror(errno)); - if (trace) + if (trace(1)) htrc("BIGREAD: nbr=%d len=%d errno=%d %s\n", nbr, len, errno, g->Message); @@ -3141,7 +3141,7 @@ bool BGVFAM::BigWrite(PGLOBAL g, HANDLE h, void *inbuf, int req) DWORD nbw, drc, len = (DWORD)req; bool brc = WriteFile(h, inbuf, len, &nbw, NULL); - if (trace) + if (trace(1)) htrc("after write req=%d brc=%d nbw=%d\n", req, brc, nbw); if (!brc || nbw != len) { @@ -3159,7 +3159,7 @@ bool BGVFAM::BigWrite(PGLOBAL g, HANDLE h, void *inbuf, int req) sprintf(g->Message, MSG(WRITE_STRERROR), fn, buf); - if (trace) + if (trace(1)) htrc("BIGWRITE: nbw=%d len=%d errno=%d %s\n", nbw, len, drc, g->Message); @@ -3174,7 +3174,7 @@ bool BGVFAM::BigWrite(PGLOBAL g, HANDLE h, void *inbuf, int req) sprintf(g->Message, MSG(WRITE_STRERROR), fn, strerror(errno)); - if (trace) + if (trace(1)) htrc("BIGWRITE: nbw=%d len=%d errno=%d %s\n", nbw, len, errno, g->Message); @@ -3224,7 +3224,7 @@ int BGVFAM::GetBlockInfo(PGLOBAL g) if (h == INVALID_HANDLE_VALUE || !_filelength(h)) { #endif // !__WIN__ // Consider this is a void table - if (trace) + if (trace(1)) htrc("Void table h=%d\n", h); Last = Nrec; @@ -3248,7 +3248,7 @@ int BGVFAM::GetBlockInfo(PGLOBAL g) Block = (vh.NumRec > 0) ? (vh.NumRec + Nrec - 1) / Nrec : 0; Last = (vh.NumRec + Nrec - 1) % Nrec + 1; - if (trace) + if (trace(1)) htrc("Block=%d Last=%d\n", Block, Last); } // endif's @@ -3348,7 +3348,7 @@ bool BGVFAM::MakeEmptyFile(PGLOBAL g, PCSZ fn) of.QuadPart = (BIGINT)n + (BIGINT)MaxBlk * (BIGINT)Blksize - (BIGINT)1; - if (trace) + if (trace(1)) htrc("MEF: of=%lld n=%d maxblk=%d blksize=%d\n", of.QuadPart, n, MaxBlk, Blksize); @@ -3394,7 +3394,7 @@ bool BGVFAM::MakeEmptyFile(PGLOBAL g, PCSZ fn) pos = (BIGINT)n + (BIGINT)MaxBlk * (BIGINT)Blksize - (BIGINT)1; - if (trace) + if (trace(1)) htrc("MEF: pos=%lld n=%d maxblk=%d blksize=%d\n", pos, n, MaxBlk, Blksize); @@ -3439,7 +3439,7 @@ bool BGVFAM::OpenTableFile(PGLOBAL g) PlugSetPath(filename, To_File, Tdbp->GetPath()); - if (trace) + if (trace(1)) htrc("OpenTableFile: filename=%s mode=%d Last=%d\n", filename, mode, Last); @@ -3516,7 +3516,7 @@ bool BGVFAM::OpenTableFile(PGLOBAL g) strcat(g->Message, filename); } // endif Hfile - if (trace) + if (trace(1)) htrc(" rc=%d access=%p share=%p creation=%d handle=%p fn=%s\n", rc, access, share, creation, Hfile, filename); @@ -3605,7 +3605,7 @@ bool BGVFAM::OpenTableFile(PGLOBAL g) strcat(g->Message, strerror(errno)); } // endif Hfile - if (trace) + if (trace(1)) htrc(" rc=%d oflag=%p mode=%p handle=%d fn=%s\n", rc, oflag, mode, Hfile, filename); #endif // UNIX @@ -3626,7 +3626,7 @@ bool BGVFAM::OpenTableFile(PGLOBAL g) To_Fb->Mode = mode; To_Fb->Handle = Hfile; - if (trace) + if (trace(1)) htrc("File %s is open in mode %d\n", filename, mode); if (del) @@ -3729,7 +3729,7 @@ bool BGVFAM::AllocateBuffer(PGLOBAL g) /***********************************************************************/ int BGVFAM::WriteBuffer(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("BGV WriteDB: R%d Mode=%d CurNum=%d CurBlk=%d\n", Tdbp->GetTdb_No(), Tdbp->GetMode(), CurNum, CurBlk); @@ -3829,7 +3829,7 @@ int BGVFAM::DeleteRecords(PGLOBAL g, int irc) /* 2 - directly move the not deleted lines inside the original */ /* file, and at the end erase all trailing records. */ /*********************************************************************/ - if (trace) + if (trace(1)) htrc("BGV DeleteDB: irc=%d UseTemp=%d Fpos=%d Tpos=%d Spos=%d\n", irc, UseTemp, Fpos, Tpos, Spos); @@ -3839,7 +3839,7 @@ int BGVFAM::DeleteRecords(PGLOBAL g, int irc) /*******************************************************************/ Fpos = (Block - 1) * Nrec + Last; - if (trace) + if (trace(1)) htrc("Fpos placed at file end=%d\n", Fpos); eof = UseTemp && !MaxBlk; @@ -3878,7 +3878,7 @@ int BGVFAM::DeleteRecords(PGLOBAL g, int irc) #endif Spos++; // New start position is on next line - if (trace) + if (trace(1)) htrc("after: Tpos=%d Spos=%d\n", Tpos, Spos); } else { @@ -4065,7 +4065,7 @@ bool BGVFAM::MoveIntermediateLines(PGLOBAL g, bool *b) } // endif Usetemp... - if (trace) + if (trace(1)) htrc("loop: Tpos=%d Spos=%d\n", Tpos, Spos); } // endfor n @@ -4201,7 +4201,7 @@ void BGVFAM::CloseTableFile(PGLOBAL g, bool abort) if (Hfile != INVALID_HANDLE_VALUE) rc = PlugCloseFile(g, To_Fb); - if (trace) + if (trace(1)) htrc("BGV CloseTableFile: closing %s wrc=%d rc=%d\n", To_File, wrc, rc); @@ -4247,7 +4247,7 @@ bool BGVFAM::ReadBlock(PGLOBAL g, PVCTCOL colp) pos = (BIGINT)Nrec * ((BIGINT)colp->Deplac + (BIGINT)Lrecl * (BIGINT)CurBlk); - if (trace) + if (trace(1)) htrc("RB: offset=%lld Nrec=%d Deplac=%d Lrecl=%d CurBlk=%d MaxBlk=%d\n", pos, Nrec, colp->Deplac, Lrecl, CurBlk, MaxBlk); @@ -4257,7 +4257,7 @@ bool BGVFAM::ReadBlock(PGLOBAL g, PVCTCOL colp) if (BigRead(g, Hfile, colp->Blk->GetValPointer(), colp->Clen * Nrec)) return true; - if (trace) + if (trace(1)) num_read++; return false; @@ -4284,7 +4284,7 @@ bool BGVFAM::WriteBlock(PGLOBAL g, PVCTCOL colp) pos = (BIGINT)Nrec * ((BIGINT)colp->Deplac + (BIGINT)Lrecl * (BIGINT)colp->ColBlk); - if (trace) + if (trace(1)) htrc("WB: offset=%lld Nrec=%d Deplac=%d Lrecl=%d ColBlk=%d\n", pos, Nrec, colp->Deplac, Lrecl, colp->ColBlk); diff --git a/storage/connect/filamzip.cpp b/storage/connect/filamzip.cpp index dfd9343af76..e76dc496246 100644 --- a/storage/connect/filamzip.cpp +++ b/storage/connect/filamzip.cpp @@ -699,7 +699,7 @@ bool UNZIPUTL::openEntry(PGLOBAL g) entryopen = true; } // endif rc - if (trace) + if (trace(1)) htrc("Openning entry%s %s\n", fn, (entryopen) ? "oked" : "failed"); return !entryopen; @@ -748,10 +748,10 @@ UNZFAM::UNZFAM(PUNZFAM txfp) : MAPFAM(txfp) /***********************************************************************/ int UNZFAM::GetFileLength(PGLOBAL g) { - int len = (zutp && zutp->entryopen) ? Top - Memory + int len = (zutp && zutp->entryopen) ? (int)(Top - Memory) : TXTFAM::GetFileLength(g) * 3; - if (trace) + if (trace(1)) htrc("Zipped file length=%d\n", len); return len; @@ -1088,7 +1088,7 @@ int ZIPFAM::WriteBuffer(PGLOBAL g) // Prepare to write the new line strcat(strcpy(To_Buf, Tdbp->GetLine()), (Bin) ? CrLf : "\n"); - len = strchr(To_Buf, '\n') - To_Buf + 1; + len = (int)(strchr(To_Buf, '\n') - To_Buf + 1); return zutp->writeEntry(g, To_Buf, len); } // end of WriteBuffer diff --git a/storage/connect/filter.cpp b/storage/connect/filter.cpp index 079128f9aa6..469cd90d1d7 100644 --- a/storage/connect/filter.cpp +++ b/storage/connect/filter.cpp @@ -87,7 +87,7 @@ BYTE OpBmp(PGLOBAL g, OPVAL opc) case OP_EXIST: bt = 0x00; break; default: sprintf(g->Message, MSG(BAD_FILTER_OP), opc); - throw (int)TYPE_ARRAY; + throw (int)TYPE_FILTER; } // endswitch opc return bt; @@ -301,7 +301,7 @@ PFIL FILTER::Link(PGLOBAL g, PFIL fil2) { PFIL fil1; - if (trace) + if (trace(1)) htrc("Linking filter %p with op=%d... to filter %p with op=%d\n", this, Opc, fil2, (fil2) ? fil2->Opc : 0); @@ -355,7 +355,7 @@ int FILTER::CheckColumn(PGLOBAL g, PSQL sqlp, PXOB &p, int &ag) char errmsg[MAX_STR] = ""; int agg, k, n = 0; - if (trace) + if (trace(1)) htrc("FILTER CheckColumn: sqlp=%p ag=%d\n", sqlp, ag); switch (Opc) { @@ -540,7 +540,7 @@ PFIL FILTER::SortJoin(PGLOBAL g) bool FILTER::FindJoinFilter(POPJOIN opj, PFIL fprec, bool teq, bool tek, bool tk2, bool tc2, bool tix, bool thx) { - if (trace) + if (trace(1)) htrc("FindJoinFilter: opj=%p fprec=%p tests=(%d,%d,%d,%d)\n", opj, fprec, teq, tek, tk2, tc2); @@ -867,7 +867,7 @@ bool FILTER::CheckLocal(PTDB tdbp) { bool local = TRUE; - if (trace) { + if (trace(1)) { if (tdbp) htrc("CheckLocal: filp=%p R%d\n", this, tdbp->GetTdb_No()); else @@ -877,7 +877,7 @@ bool FILTER::CheckLocal(PTDB tdbp) for (int i = 0; local && i < 2; i++) local = Arg(i)->CheckLocal(tdbp); - if (trace) + if (trace(1)) htrc("FCL: returning %d\n", local); return (local); @@ -983,7 +983,7 @@ bool FILTER::Convert(PGLOBAL g, bool having) { int i, comtype = TYPE_ERROR; - if (trace) + if (trace(1)) htrc("converting(?) %s %p opc=%d\n", (having) ? "having" : "filter", this, Opc); @@ -1014,7 +1014,7 @@ bool FILTER::Convert(PGLOBAL g, bool having) return TRUE; } // endswitch - if (trace) + if (trace(1)) htrc("Filter(%d): Arg type=%d\n", i, GetArgType(i)); // Set default values @@ -1059,7 +1059,7 @@ bool FILTER::Convert(PGLOBAL g, bool having) return TRUE; } // endif - if (trace) + if (trace(1)) htrc(" comtype=%d, B_T(%d)=%d Val(%d)=%p\n", comtype, i, Test[i].B_T, i, Val(i)); @@ -1067,7 +1067,7 @@ bool FILTER::Convert(PGLOBAL g, bool having) // Set or allocate the filter argument values and buffers for (i = 0; i < 2; i++) { - if (trace) + if (trace(1)) htrc(" conv type %d ? i=%d B_T=%d comtype=%d\n", GetArgType(i), i, Test[i].B_T, comtype); @@ -1144,7 +1144,7 @@ bool FILTER::Convert(PGLOBAL g, bool having) TEST: // Test for possible Eval optimization - if (trace) + if (trace(1)) htrc("Filp %p op=%d argtypes=(%d,%d)\n", this, Opc, GetArgType(0), GetArgType(1)); @@ -1233,7 +1233,7 @@ bool FILTER::Eval(PGLOBAL g) else if (Test[i].Conv) Val(i)->SetValue_pval(Arg(i)->GetValue()); - if (trace) + if (trace(1)) htrc(" Filter: op=%d type=%d %d B_T=%d %d val=%p %p\n", Opc, GetArgType(0), GetArgType(1), Test[0].B_T, Test[1].B_T, Val(0), Val(1)); @@ -1273,7 +1273,7 @@ bool FILTER::Eval(PGLOBAL g) goto FilterError; } // endswitch Type - if (trace) { + if (trace(1)) { htrc(" IN filtering: ap=%p\n", ap); if (ap) @@ -1363,7 +1363,7 @@ bool FILTER::Eval(PGLOBAL g) goto FilterError; } // endswitch Opc - if (trace) + if (trace(1)) htrc("Eval: filter %p Opc=%d result=%d\n", this, Opc, Value->GetIntValue()); @@ -1775,7 +1775,7 @@ PFIL PrepareFilter(PGLOBAL g, PFIL fp, bool having) { PFIL filp = NULL; - if (trace) + if (trace(1)) htrc("PrepareFilter: fp=%p having=%d\n", fp, having); while (fp) { @@ -1790,14 +1790,14 @@ PFIL PrepareFilter(PGLOBAL g, PFIL fp, bool having) break; // Remove eventual ending separator(s) // if (fp->Convert(g, having)) -// (int)throw TYPE_ARRAY; +// throw (int)TYPE_FILTER; filp = fp; fp = fp->Next; filp->Next = NULL; } // endwhile - if (trace) + if (trace(1)) htrc(" returning filp=%p\n", filp); return filp; @@ -1823,7 +1823,7 @@ DllExport bool ApplyFilter(PGLOBAL g, PFIL filp) if (filp->Eval(g)) throw (int)TYPE_FILTER; - if (trace > 1) + if (trace(2)) htrc("PlugFilter filp=%p result=%d\n", filp, filp->GetResult()); diff --git a/storage/connect/fmdlex.c b/storage/connect/fmdlex.c index ef4f7bfc65a..729b1b883c1 100644 --- a/storage/connect/fmdlex.c +++ b/storage/connect/fmdlex.c @@ -283,7 +283,7 @@ static void yy_fatal_error YY_PROTO(( const char msg[] )); */ #define YY_DO_BEFORE_ACTION \ yytext_ptr = yy_bp; \ - yyleng = yy_cp - yy_bp; \ + yyleng = (int)(yy_cp - yy_bp); \ yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ yy_c_buf_p = yy_cp; @@ -417,10 +417,10 @@ static PDTP pp; static void MakeParm(int n); static void MakeMMDD(int n); static void MakeAMPM(int n); -static void MakeIn(char *); -static void MakeOut(char *); -static void Quotin(char *); -static void Quotout(char *); +static void MakeIn(const char *); +static void MakeOut(const char *); +static void Quotin(const char *); +static void Quotout(const char *); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -695,7 +695,7 @@ case YY_STATE_EOF(dqt): case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = yy_cp - yytext_ptr - 1; + int yy_amount_of_matched_text = (int)(yy_cp - yytext_ptr - 1); /* Undo the effects of YY_DO_BEFORE_ACTION. */ *yy_cp = yy_hold_char; @@ -862,7 +862,7 @@ static int yy_get_next_buffer() /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = yy_c_buf_p - yytext_ptr; + number_to_move = (int)(yy_c_buf_p - yytext_ptr); for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -888,7 +888,7 @@ static int yy_get_next_buffer() /* just a shorter name for the current buffer */ YY_BUFFER_STATE b = yy_current_buffer; - int yy_c_buf_p_offset = yy_c_buf_p - b->yy_ch_buf; + int yy_c_buf_p_offset = (int)(yy_c_buf_p - b->yy_ch_buf); b->yy_buf_size *= 2; b->yy_ch_buf = (char *) @@ -1492,7 +1492,7 @@ void MakeAMPM(int n) } /* end of MakeAMPM */ -void MakeIn(char *text) +void MakeIn(const char *text) { if (!pp->InFmt) return; @@ -1500,14 +1500,14 @@ void MakeIn(char *text) strncat(pp->InFmt, text, (pp->Outsize - 1) - strlen(pp->InFmt)); } /* end of MakeIn */ -void MakeOut(char *text) +void MakeOut(const char *text) { if (!pp->OutFmt) return; strncat(pp->OutFmt, text, (pp->Outsize - 1) - strlen(pp->OutFmt)); } /* end of MakeOut */ -void Quotin(char *text) +void Quotin(const char *text) { if (!pp->InFmt) return; @@ -1516,7 +1516,7 @@ void Quotin(char *text) pp->InFmt[strlen(pp->InFmt)-1] = '\0'; } /* end of Quotin */ -void Quotout(char *text) +void Quotout(const char *text) { if (!pp->OutFmt) return; diff --git a/storage/connect/global.h b/storage/connect/global.h index e4b00786efa..472d09408c3 100644 --- a/storage/connect/global.h +++ b/storage/connect/global.h @@ -52,7 +52,7 @@ /***********************************************************************/ /* Define access to the thread based trace value. */ /***********************************************************************/ -#define trace GetTraceValue() +#define trace(T) (bool)(GetTraceValue() & (uint)T) /***********************************************************************/ /* Miscellaneous Constants */ @@ -220,14 +220,19 @@ DllExport BOOL PlugIsAbsolutePath(LPCSTR path); DllExport bool AllocSarea(PGLOBAL, uint); DllExport void FreeSarea(PGLOBAL); DllExport BOOL PlugSubSet(PGLOBAL, void *, uint); -DllExport void *PlugSubAlloc(PGLOBAL, void *, size_t); DllExport char *PlugDup(PGLOBAL g, const char *str); DllExport void *MakePtr(void *, OFFSET); DllExport void htrc(char const *fmt, ...); -DllExport int GetTraceValue(void); +//DllExport int GetTraceValue(void); +DllExport uint GetTraceValue(void); #if defined(__cplusplus) } // extern "C" #endif +/***********************************************************************/ +/* Non exported routine declarations. */ +/***********************************************************************/ +void *PlugSubAlloc(PGLOBAL, void *, size_t); // Does throw + /*-------------------------- End of Global.H --------------------------*/ diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 5964b1d049f..2b3db3753d5 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -98,8 +98,8 @@ rnd_next signals that it has reached the end of its data. Calls to ha_connect::extra() are hints as to what will be occuring to the request. - Author Olivier Bertrand -*/ + Author Olivier Bertrand + */ #ifdef USE_PRAGMA_IMPLEMENTATION #pragma implementation // gcc: Class implementation @@ -174,9 +174,9 @@ #define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[]= "Version 1.06.0005 October 14, 2017"; + char version[]= "Version 1.06.0007 March 11, 2018"; #if defined(__WIN__) - char compver[]= "Version 1.06.0005 " __DATE__ " " __TIME__; + char compver[]= "Version 1.06.0007 " __DATE__ " " __TIME__; char slash= '\\'; #else // !__WIN__ char slash= '/'; @@ -266,16 +266,38 @@ static char *strz(PGLOBAL g, LEX_STRING &ls) /***********************************************************************/ /* CONNECT session variables definitions. */ /***********************************************************************/ -// Tracing: 0 no, 1 yes, >1 more tracing -static MYSQL_THDVAR_INT(xtrace, - PLUGIN_VAR_RQCMDARG, "Console trace value.", - NULL, NULL, 0, 0, INT_MAX, 1); +// Tracing: 0 no, 1 yes, 2 more, 4 index... 511 all +const char *xtrace_names[] = +{ + "YES", "MORE", "INDEX", "MEMORY", "SUBALLOC", + "QUERY", "STMT", "HANDLER", "BLOCK", "MONGO", NullS +}; + +TYPELIB xtrace_typelib = +{ + array_elements(xtrace_names) - 1, "xtrace_typelib", + xtrace_names, NULL +}; + +static MYSQL_THDVAR_SET( + xtrace, // name + PLUGIN_VAR_RQCMDARG, // opt + "Trace values.", // comment + NULL, // check + NULL, // update function + 0, // def (NO) + &xtrace_typelib); // typelib // Getting exact info values static MYSQL_THDVAR_BOOL(exact_info, PLUGIN_VAR_RQCMDARG, "Getting exact info values", NULL, NULL, 0); +// Enabling cond_push +static MYSQL_THDVAR_BOOL(cond_push, PLUGIN_VAR_RQCMDARG, + "Enabling cond_push", + NULL, NULL, 1); // YES by default + /** Temporary file usage: no: Not using temporary file @@ -314,17 +336,18 @@ static MYSQL_THDVAR_UINT(work_size, static MYSQL_THDVAR_INT(conv_size, PLUGIN_VAR_RQCMDARG, // opt "Size used when converting TEXT columns.", - NULL, NULL, SZCONV, 0, 65500, 1); + NULL, NULL, SZCONV, 0, 65500, 8192); /** Type conversion: no: Unsupported types -> TYPE_ERROR yes: TEXT -> VARCHAR + force: Do it also for ODBC BINARY and BLOBs skip: skip unsupported type columns in Discovery */ const char *xconv_names[]= { - "NO", "YES", "SKIP", NullS + "NO", "YES", "FORCE", "SKIP", NullS }; TYPELIB xconv_typelib= @@ -339,7 +362,7 @@ static MYSQL_THDVAR_ENUM( "Unsupported types conversion.", // comment NULL, // check NULL, // update function - 0, // def (no) + 1, // def (yes) &xconv_typelib); // typelib // Null representation for JSON values @@ -364,12 +387,17 @@ static MYSQL_THDVAR_STR(java_wrapper, NULL, NULL, "wrappers/JdbcInterface"); #endif // JAVA_SUPPORT -#if 0 // This is apparently not acceptable for a plugin +// This is apparently not acceptable for a plugin so it is undocumented +#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) // Enabling MONGO table type +#if defined(MONGO_SUPPORT) || (MYSQL_VERSION_ID > 100200) static MYSQL_THDVAR_BOOL(enable_mongo, PLUGIN_VAR_RQCMDARG, - "Enabling the MongoDB access", - NULL, NULL, MONGO_ENABLED); -#endif // 0 + "Enabling the MongoDB access", NULL, NULL, 1); +#else // !version 2,3 +static MYSQL_THDVAR_BOOL(enable_mongo, PLUGIN_VAR_RQCMDARG, + "Enabling the MongoDB access", NULL, NULL, 0); +#endif // !version 2,3 +#endif // JAVA_SUPPORT || CMGO_SUPPORT #if defined(XMSG) || defined(NEWMSG) const char *language_names[]= @@ -401,9 +429,10 @@ handlerton *connect_hton= NULL; /***********************************************************************/ /* Function to export session variable values to other source files. */ /***********************************************************************/ -extern "C" int GetTraceValue(void) - {return connect_hton ? THDVAR(current_thd, xtrace) : 0;} +uint GetTraceValue(void) + {return (uint)(connect_hton ? THDVAR(current_thd, xtrace) : 0);} bool ExactInfo(void) {return THDVAR(current_thd, exact_info);} +bool CondPushEnabled(void) {return THDVAR(current_thd, cond_push);} USETEMP UseTemp(void) {return (USETEMP)THDVAR(current_thd, use_tempfile);} int GetConvSize(void) {return THDVAR(current_thd, conv_size);} TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);} @@ -419,22 +448,20 @@ void SetWorkSize(uint) push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, "Work size too big, try setting a smaller value"); } // end of SetWorkSize -#if defined(XMSG) || defined(NEWMSG) -extern "C" const char *msglang(void) -{ - return language_names[THDVAR(current_thd, msg_lang)]; -} // end of msglang -#else // !XMSG && !NEWMSG #if defined(JAVA_SUPPORT) char *GetJavaWrapper(void) {return connect_hton ? THDVAR(current_thd, java_wrapper) : (char*)"wrappers/JdbcInterface";} #endif // JAVA_SUPPORT -#if defined(JAVA_SUPPORT) -//bool MongoEnabled(void) { return THDVAR(current_thd, enable_mongo); } -#endif // JAVA_SUPPORT +#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) +bool MongoEnabled(void) {return THDVAR(current_thd, enable_mongo);} +#endif // JAVA_SUPPORT || CMGO_SUPPORT +#if defined(XMSG) || defined(NEWMSG) +extern "C" const char *msglang(void) + {return language_names[THDVAR(current_thd, msg_lang)];} +#else // !XMSG && !NEWMSG extern "C" const char *msglang(void) { #if defined(FRENCH) @@ -726,7 +753,7 @@ static int connect_init_func(void *p) connect_hton->tablefile_extensions= ha_connect_exts; connect_hton->discover_table_structure= connect_assisted_discovery; - if (trace) + if (trace(128)) sql_print_information("connect_init: hton=%p", p); DTVAL::SetTimeShift(); // Initialize time zone shift once for all @@ -818,7 +845,7 @@ static handler* connect_create_handler(handlerton *hton, { handler *h= new (mem_root) ha_connect(hton, table); - if (trace) + if (trace(128)) htrc("New CONNECT %p, table: %.*s\n", h, table ? table->table_name.length : 6, table ? table->table_name.str : ""); @@ -874,7 +901,7 @@ ha_connect::ha_connect(handlerton *hton, TABLE_SHARE *table_arg) /****************************************************************************/ ha_connect::~ha_connect(void) { - if (trace) + if (trace(128)) htrc("Delete CONNECT %p, table: %.*s, xp=%p count=%d\n", this, table ? table->s->table_name.length : 6, table ? table->s->table_name.str : "", @@ -1086,55 +1113,55 @@ PCSZ GetListOption(PGLOBAL g, PCSZ opname, PCSZ oplist, PCSZ def) if (!oplist) return (char*)def; - char key[16], val[256]; - char *pv, *pn, *pk= (char*)oplist; - PCSZ opval= def; - int n; + char key[16], val[256]; + char *pv, *pn, *pk = (char*)oplist; + PCSZ opval = def; + int n; while (*pk == ' ') pk++; - for (; pk; pk= pn) { - pn= strchr(pk, ','); - pv= strchr(pk, '='); + for (; pk; pk = pn) { + pn = strchr(pk, ','); + pv = strchr(pk, '='); - if (pv && (!pn || pv < pn)) { + if (pv && (!pn || pv < pn)) { n = MY_MIN(static_cast(pv - pk), sizeof(key) - 1); memcpy(key, pk, n); while (n && key[n - 1] == ' ') n--; - key[n]= 0; + key[n] = 0; - while(*(++pv) == ' ') ; + while (*(++pv) == ' '); - n= MY_MIN((pn ? pn - pv : strlen(pv)), sizeof(val) - 1); - memcpy(val, pv, n); + n = MY_MIN((pn ? pn - pv : strlen(pv)), sizeof(val) - 1); + memcpy(val, pv, n); while (n && val[n - 1] == ' ') n--; - val[n]= 0; - } else { - n= MY_MIN((pn ? pn - pk : strlen(pk)), sizeof(key) - 1); - memcpy(key, pk, n); + val[n] = 0; + } else { + n = MY_MIN((pn ? pn - pk : strlen(pk)), sizeof(key) - 1); + memcpy(key, pk, n); while (n && key[n - 1] == ' ') n--; - key[n]= 0; - val[0]= 0; - } // endif pv + key[n] = 0; + val[0] = 0; + } // endif pv - if (!stricmp(opname, key)) { - opval= PlugDup(g, val); - break; - } else if (!pn) - break; + if (!stricmp(opname, key)) { + opval = PlugDup(g, val); + break; + } else if (!pn) + break; - while (*(++pn) == ' ') ; - } // endfor pk + while (*(++pn) == ' '); + } // endfor pk return opval; } // end of GetListOption @@ -1658,7 +1685,7 @@ PIXDEF ha_connect::GetIndexInfo(TABLE_SHARE *s) s= table->s; for (int n= 0; (unsigned)n < s->keynames.count; n++) { - if (trace) + if (trace(1)) htrc("Getting created index %d info\n", n + 1); // Find the index to describe @@ -2004,7 +2031,7 @@ bool ha_connect::CheckColumnList(PGLOBAL g) } // endif } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); brc = true; } catch (const char *msg) { @@ -2061,7 +2088,7 @@ int ha_connect::MakeRecord(char *buf) PCOL colp= NULL; DBUG_ENTER("ha_connect::MakeRecord"); - if (trace > 1) + if (trace(2)) htrc("Maps: read=%08X write=%08X vcol=%08X defr=%08X defw=%08X\n", *table->read_set->bitmap, *table->write_set->bitmap, (table->vcol_set) ? *table->vcol_set->bitmap : 0, @@ -2585,14 +2612,14 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond) if (!cond) return NULL; - if (trace) + if (trace(1)) htrc("Cond type=%d\n", cond->type()); if (cond->type() == COND::COND_ITEM) { PFIL fp; Item_cond *cond_item= (Item_cond *)cond; - if (trace) + if (trace(1)) htrc("Cond: Ftype=%d name=%s\n", cond_item->functype(), cond_item->func_name()); @@ -2626,7 +2653,7 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond) Item_func *condf= (Item_func *)cond; Item* *args= condf->arguments(); - if (trace) + if (trace(1)) htrc("Func type=%d argnum=%d\n", condf->functype(), condf->argument_count()); @@ -2655,11 +2682,11 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond) return NULL; for (i= 0; i < condf->argument_count(); i++) { - if (trace) + if (trace(1)) htrc("Argtype(%d)=%d\n", i, args[i]->type()); if (i >= 2 && !ismul) { - if (trace) + if (trace(1)) htrc("Unexpected arg for vop=%d\n", vop); continue; @@ -2689,7 +2716,7 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond) break; } // endswitch type - if (trace) { + if (trace(1)) { htrc("Field index=%d\n", pField->field->field_index); htrc("Field name=%s\n", pField->field->field_name); } // endif trace @@ -2736,7 +2763,7 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond) return NULL; } // endswitch type - if (trace) + if (trace(1)) htrc("Value type=%hd\n", pp->Type); // Append the value to the argument list @@ -2754,7 +2781,7 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond) filp= MakeFilter(g, colp, pop, pfirst, neg); } else { - if (trace) + if (trace(1)) htrc("Unsupported condition\n"); return NULL; @@ -2780,7 +2807,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) if (!cond) return NULL; - if (trace) + if (trace(1)) htrc("Cond type=%d\n", cond->type()); if (cond->type() == COND::COND_ITEM) { @@ -2793,7 +2820,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) else pb0= pb1= pb2= ph0= ph1= ph2= NULL; - if (trace) + if (trace(1)) htrc("Cond: Ftype=%d name=%s\n", cond_item->functype(), cond_item->func_name()); @@ -2879,7 +2906,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) filp->Bd = filp->Hv = false; - if (trace) + if (trace(1)) htrc("Func type=%d argnum=%d\n", condf->functype(), condf->argument_count()); @@ -2916,11 +2943,11 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) return NULL; for (i= 0; i < condf->argument_count(); i++) { - if (trace) + if (trace(1)) htrc("Argtype(%d)=%d\n", i, args[i]->type()); if (i >= 2 && !ismul) { - if (trace) + if (trace(1)) htrc("Unexpected arg for vop=%d\n", vop); continue; @@ -2963,7 +2990,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) } // endif's - if (trace) { + if (trace(1)) { htrc("Field index=%d\n", pField->field->field_index); htrc("Field name=%s\n", pField->field->field_name); htrc("Field type=%d\n", pField->field->type()); @@ -3001,7 +3028,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) if ((res= pval->val_str(&tmp)) == NULL) return NULL; // To be clarified - if (trace) + if (trace(1)) htrc("Value=%.*s\n", res->length(), res->ptr()); // IN and BETWEEN clauses should be col VOP list @@ -3142,7 +3169,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) filp->Bd = true; } else { - if (trace) + if (trace(1)) htrc("Unsupported condition\n"); return NULL; @@ -3175,7 +3202,7 @@ const COND *ha_connect::cond_push(const COND *cond) { DBUG_ENTER("ha_connect::cond_push"); - if (tdbp) { + if (tdbp && CondPushEnabled()) { PGLOBAL& g= xp->g; AMT tty= tdbp->GetAmType(); bool x= (tty == TYPE_AM_MYX || tty == TYPE_AM_XDBC); @@ -3209,7 +3236,7 @@ const COND *ha_connect::cond_push(const COND *cond) if (filp->Having && strlen(filp->Having) > 255) goto fin; // Memory collapse - if (trace) + if (trace(1)) htrc("cond_push: %s\n", filp->Body); tdbp->SetCond(cond); @@ -3235,7 +3262,7 @@ const COND *ha_connect::cond_push(const COND *cond) } // endif tty } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); } catch (const char *msg) { strcpy(g->Message, msg); @@ -3288,7 +3315,7 @@ bool ha_connect::get_error_message(int error, String* buf) &my_charset_latin1, &dummy_errors); - if (trace) + if (trace(1)) htrc("GEM(%d): len=%u %s\n", error, len, g->Message); msg[len]= '\0'; @@ -3340,7 +3367,7 @@ int ha_connect::open(const char *name, int mode, uint test_if_locked) int rc= 0; DBUG_ENTER("ha_connect::open"); - if (trace) + if (trace(1)) htrc("open: name=%s mode=%d test=%u\n", name, mode, test_if_locked); if (!(share= get_share())) @@ -3415,7 +3442,7 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT*) rc = HA_ERR_INTERNAL_ERROR; } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); rc = HA_ERR_INTERNAL_ERROR; } catch (const char *msg) { @@ -3563,7 +3590,7 @@ int ha_connect::update_row(const uchar *old_data, uchar *new_data) PGLOBAL& g= xp->g; DBUG_ENTER("ha_connect::update_row"); - if (trace > 1) + if (trace(2)) htrc("update_row: old=%s new=%s\n", old_data, new_data); // Check values for possible change in indexed column @@ -3624,7 +3651,7 @@ int ha_connect::index_init(uint idx, bool sorted) PGLOBAL& g= xp->g; DBUG_ENTER("index_init"); - if (trace) + if (trace(1)) htrc("index_init: this=%p idx=%u sorted=%d\n", this, idx, sorted); if (GetIndexType(GetRealType()) == 2) { @@ -3677,7 +3704,7 @@ int ha_connect::index_init(uint idx, bool sorted) rc= 0; } // endif indexing - if (trace) + if (trace(1)) htrc("index_init: rc=%d indexing=%d active_index=%d\n", rc, indexing, active_index); @@ -3724,7 +3751,7 @@ int ha_connect::ReadIndexed(uchar *buf, OPVAL op, const key_range *kr) break; } // endswitch RC - if (trace > 1) + if (trace(2)) htrc("ReadIndexed: op=%d rc=%d\n", op, rc); table->status= (rc == RC_OK) ? 0 : STATUS_NOT_FOUND; @@ -3767,7 +3794,7 @@ int ha_connect::index_read(uchar * buf, const uchar * key, uint key_len, default: DBUG_RETURN(-1); break; } // endswitch find_flag - if (trace > 1) + if (trace(2)) htrc("%p index_read: op=%d\n", this, op); if (indexing > 0) { @@ -3931,7 +3958,7 @@ int ha_connect::rnd_init(bool scan) alter= 1; } // endif xmod - if (trace) + if (trace(1)) htrc("rnd_init: this=%p scan=%d xmod=%d alter=%d\n", this, scan, xmod, alter); @@ -4037,7 +4064,7 @@ int ha_connect::rnd_next(uchar *buf) break; } // endswitch RC - if (trace > 1 && (rc || !(xp->nrd++ % 16384))) { + if (trace(2) && (rc || !(xp->nrd++ % 16384))) { ulonglong tb2= my_interval_timer(); double elapsed= (double) (tb2 - xp->tb1) / 1000000000ULL; DBUG_PRINT("rnd_next", ("rc=%d nrd=%u fnd=%u nfd=%u sec=%.3lf\n", @@ -4081,7 +4108,7 @@ void ha_connect::position(const uchar *) DBUG_ENTER("ha_connect::position"); my_store_ptr(ref, ref_length, (my_off_t)tdbp->GetRecpos()); - if (trace > 1) + if (trace(2)) htrc("position: pos=%d\n", tdbp->GetRecpos()); DBUG_VOID_RETURN; @@ -4111,7 +4138,7 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos) DBUG_ENTER("ha_connect::rnd_pos"); if (!tdbp->SetRecpos(xp->g, (int)my_get_ptr(pos, ref_length))) { - if (trace) + if (trace(1)) htrc("rnd_pos: %d\n", tdbp->GetRecpos()); tdbp->SetFilter(NULL); @@ -4177,7 +4204,7 @@ int ha_connect::info(uint flag) DBUG_RETURN(HA_ERR_INTERNAL_ERROR); } // endif g - if (trace) + if (trace(1)) htrc("%p In info: flag=%u valid_info=%d\n", this, flag, valid_info); // tdbp must be available to get updated info @@ -4370,54 +4397,59 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn, bool quick) my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv"); return true; } // endif path - } + + } // endif !quick + } else return false; - // check FILE_ACL - // fall through - case TAB_ODBC: - case TAB_JDBC: + // Fall through case TAB_MYSQL: - case TAB_MONGO: case TAB_DIR: - case TAB_MAC: - case TAB_WMI: case TAB_ZIP: case TAB_OEM: #ifdef NO_EMBEDDED_ACCESS_CHECKS - return false; -#endif - /* - If table or table->mdl_ticket is NULL - it's a DLL, e.g. CREATE TABLE. - if the table has an MDL_EXCLUSIVE lock - it's a DDL too, e.g. the - insert step of CREATE ... SELECT. - - Otherwise it's a DML, the table was normally opened, locked, - privilege were already checked, and table->grant.privilege is set. - With SQL SECURITY DEFINER, table->grant.privilege has definer's privileges. - - Unless we're in prelocking mode, in this case table->grant.privilege - is only checked in start_stmt(), not in external_lock(). - */ - if (!table || !table->mdl_ticket || table->mdl_ticket->get_type() == MDL_EXCLUSIVE) - return check_access(thd, FILE_ACL, db, NULL, NULL, 0, 0); - if ((!quick && thd->lex->requires_prelocking()) || table->grant.privilege & FILE_ACL) - return false; - status_var_increment(thd->status_var.access_denied_errors); - my_error(access_denied_error_code(thd->password), MYF(0), - thd->security_ctx->priv_user, thd->security_ctx->priv_host, - (thd->password ? ER(ER_YES) : ER(ER_NO))); - return true; - - // This is temporary until a solution is found + return false; + #endif + + /* + Check FILE_ACL + If table or table->mdl_ticket is NULL - it's a DLL, e.g. CREATE TABLE. + if the table has an MDL_EXCLUSIVE lock - it's a DDL too, e.g. the + insert step of CREATE ... SELECT. + + Otherwise it's a DML, the table was normally opened, locked, + privilege were already checked, and table->grant.privilege is set. + With SQL SECURITY DEFINER, table->grant.privilege has definer's privileges. + + Unless we're in prelocking mode, in this case table->grant.privilege + is only checked in start_stmt(), not in external_lock(). + */ + if (!table || !table->mdl_ticket || table->mdl_ticket->get_type() == MDL_EXCLUSIVE) + return check_access(thd, FILE_ACL, db, NULL, NULL, 0, 0); + + if ((!quick && thd->lex->requires_prelocking()) || table->grant.privilege & FILE_ACL) + return false; + + status_var_increment(thd->status_var.access_denied_errors); + my_error(access_denied_error_code(thd->password), MYF(0), + thd->security_ctx->priv_user, thd->security_ctx->priv_host, + (thd->password ? ER(ER_YES) : ER(ER_NO))); + return true; + case TAB_ODBC: + case TAB_JDBC: + case TAB_MONGO: + case TAB_MAC: + case TAB_WMI: + return false; case TAB_TBL: case TAB_XCL: case TAB_PRX: case TAB_OCCUR: case TAB_PIVOT: case TAB_VIR: - return false; + // This is temporary until a solution is found + return false; } // endswitch type my_printf_error(ER_UNKNOWN_ERROR, "check_privileges failed", MYF(0)); @@ -4455,7 +4487,7 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, #if defined(DEVELOPMENT) if (true) { #else - if (trace) { + if (trace(65)) { #endif LEX_STRING *query_string= thd_query_string(thd); htrc("%p check_mode: cmdtype=%d\n", this, thd_sql_command(thd)); @@ -4576,7 +4608,7 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, } // endif's newmode - if (trace) + if (trace(1)) htrc("New mode=%d\n", newmode); return newmode; @@ -4654,7 +4686,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) DBUG_ASSERT(thd == current_thd); - if (trace) + if (trace(1)) htrc("external_lock: this=%p thd=%p xp=%p g=%p lock_type=%d\n", this, thd, xp, g, lock_type); @@ -4847,7 +4879,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) if (cras) g->Createas= 1; // To tell created table to ignore FLAG - if (trace) { + if (trace(1)) { #if 0 htrc("xcheck=%d cras=%d\n", xcheck, cras); @@ -4880,7 +4912,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) // Delay open until used fields are known } // endif tdbp - if (trace) + if (trace(1)) htrc("external_lock: rc=%d\n", rc); DBUG_RETURN(rc); @@ -5016,7 +5048,7 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to) THD *thd= current_thd; int sqlcom= thd_sql_command(thd); - if (trace) { + if (trace(1)) { if (to) htrc("rename_table: this=%p thd=%p sqlcom=%d from=%s to=%s\n", this, thd, sqlcom, name, to); @@ -5127,7 +5159,7 @@ ha_rows ha_connect::records_in_range(uint inx, key_range *min_key, if (index_init(inx, false)) DBUG_RETURN(HA_POS_ERROR); - if (trace) + if (trace(1)) htrc("records_in_range: inx=%d indexing=%d\n", inx, indexing); if (indexing > 0) { @@ -5156,7 +5188,7 @@ ha_rows ha_connect::records_in_range(uint inx, key_range *min_key, else rows= HA_POS_ERROR; - if (trace) + if (trace(1)) htrc("records_in_range: rows=%llu\n", rows); DBUG_RETURN(rows); @@ -5378,7 +5410,7 @@ static int init_table_share(THD* thd, } // endif charset - if (trace) + if (trace(1)) htrc("s_init: %.*s\n", sql->length(), sql->ptr()); return table_s->init_from_sql_statement_string(thd, true, @@ -5411,7 +5443,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #endif // __WIN__ //int hdr, mxe; int port = 0, mxr = 0, rc = 0, mul = 0, lrecl = 0; - PCSZ tabtyp = NULL; +//PCSZ tabtyp = NULL; #if defined(ODBC_SUPPORT) POPARM sop= NULL; PCSZ ucnc= NULL; @@ -5475,7 +5507,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #endif // __WIN__ port= atoi(GetListOption(g, "port", topt->oplist, "0")); #if defined(ODBC_SUPPORT) - tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL); +// tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL); mxr= atoi(GetListOption(g,"maxres", topt->oplist, "0")); cto= atoi(GetListOption(g,"ConnectTimeout", topt->oplist, "-1")); qto= atoi(GetListOption(g,"QueryTimeout", topt->oplist, "-1")); @@ -5609,7 +5641,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #endif // JAVA_SUPPORT case TAB_DBF: dbf = true; - // Passthru + // fall through case TAB_CSV: if (!fn && fnc != FNC_NO) sprintf(g->Message, "Missing %s file name", topt->type); @@ -5788,7 +5820,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd, break; case FNC_TABLE: - qrp = JDBCTables(g, shm, tab, tabtyp, mxr, true, sjp); +// qrp = JDBCTables(g, shm, tab, tabtyp, mxr, true, sjp); + qrp = JDBCTables(g, shm, tab, NULL, mxr, true, sjp); break; #if 0 case FNC_DSN: @@ -5843,12 +5876,12 @@ static int connect_assisted_discovery(handlerton *, THD* thd, case TAB_JSON: qrp = JSONColumns(g, db, dsn, topt, fnc == FNC_COL); break; -#if defined(MONGO_SUPPORT) +#if defined(JAVA_SUPPORT) case TAB_MONGO: url = strz(g, create_info->connect_string); qrp = MGOColumns(g, db, url, topt, fnc == FNC_COL); break; -#endif // MONGO_SUPPORT +#endif // JAVA_SUPPORT #if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT) case TAB_XML: qrp = XMLColumns(g, (char*)db, tab, topt, fnc == FNC_COL); @@ -6091,7 +6124,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, } // endif ok } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); rc = HA_ERR_INTERNAL_ERROR; } catch (const char *msg) { @@ -6185,7 +6218,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, table= table_arg; // Used by called functions - if (trace) + if (trace(1)) htrc("create: this=%p thd=%p xp=%p g=%p sqlcom=%d name=%s\n", this, thd, xp, g, sqlcom, GetTableName()); @@ -6574,7 +6607,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, } // endif sqlcom - if (trace) + if (trace(1)) htrc("xchk=%p createas=%d\n", g->Xchk, g->Createas); if (options->zipped) { @@ -6949,7 +6982,7 @@ ha_connect::check_if_supported_inplace_alter(TABLE *altered_table, xcp->newsep= xcp->SetName(g, GetStringOption("optname")); tshp= NULL; - if (trace && g->Xchk) + if (trace(1) && g->Xchk) htrc( "oldsep=%d newsep=%d oldopn=%s newopn=%s oldpix=%p newpix=%p\n", xcp->oldsep, xcp->newsep, @@ -7213,10 +7246,11 @@ static struct st_mysql_sys_var* connect_system_variables[]= { MYSQL_SYSVAR(class_path), MYSQL_SYSVAR(java_wrapper), #endif // JAVA_SUPPORT -#if defined(JAVA_SUPPORT) -//MYSQL_SYSVAR(enable_mongo), -#endif // JAVA_SUPPORT -NULL +#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) + MYSQL_SYSVAR(enable_mongo), +#endif // JAVA_SUPPORT || CMGO_SUPPORT + MYSQL_SYSVAR(cond_push), + NULL }; maria_declare_plugin(connect) @@ -7229,10 +7263,10 @@ maria_declare_plugin(connect) PLUGIN_LICENSE_GPL, connect_init_func, /* Plugin Init */ connect_done_func, /* Plugin Deinit */ - 0x0106, /* version number (1.05) */ + 0x0107, /* version number (1.05) */ NULL, /* status variables */ connect_system_variables, /* system variables */ - "1.06.0005", /* string version */ + "1.06.0007", /* string version */ MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ } maria_declare_plugin_end; diff --git a/storage/connect/inihandl.cpp b/storage/connect/inihandl.cpp index 96ae0a67a6b..c039a980bcb 100644 --- a/storage/connect/inihandl.cpp +++ b/storage/connect/inihandl.cpp @@ -293,7 +293,7 @@ static PROFILESECTION *PROFILE_Load( FILE *file ) next_key = §ion->key; prev_key = NULL; - if (trace > 1) + if (trace(2)) htrc("New section: '%s'\n",section->name); continue; @@ -336,7 +336,7 @@ static PROFILESECTION *PROFILE_Load( FILE *file ) next_key = &key->next; prev_key = key; - if (trace > 1) + if (trace(2)) htrc("New key: name='%s', value='%s'\n", key->name,key->value?key->value:"(none)"); @@ -359,7 +359,7 @@ static BOOL PROFILE_FlushFile(void) FILE *file = NULL; struct stat buf; - if (trace > 1) + if (trace(2)) htrc("PROFILE_FlushFile: CurProfile=%p\n", CurProfile); if (!CurProfile) { @@ -398,7 +398,7 @@ static BOOL PROFILE_FlushFile(void) return FALSE; } // endif !file - if (trace > 1) + if (trace(2)) htrc("Saving '%s'\n", CurProfile->filename); PROFILE_Save(file, CurProfile->section); @@ -447,7 +447,7 @@ static BOOL PROFILE_Open(LPCSTR filename) struct stat buf; PROFILE *tempProfile; - if (trace > 1) + if (trace(2)) htrc("PROFILE_Open: CurProfile=%p N=%d\n", CurProfile, N_CACHED_PROFILES); /* First time around */ @@ -468,7 +468,7 @@ static BOOL PROFILE_Open(LPCSTR filename) /* Check for a match */ for (i = 0; i < N_CACHED_PROFILES; i++) { - if (trace > 1) + if (trace(2)) htrc("MRU=%s i=%d\n", SVP(MRUProfile[i]->filename), i); if (MRUProfile[i]->filename && !strcmp(filename, MRUProfile[i]->filename)) { @@ -483,11 +483,11 @@ static BOOL PROFILE_Open(LPCSTR filename) } // endif i if (!stat(CurProfile->filename, &buf) && CurProfile->mtime == buf.st_mtime) { - if (trace > 1) + if (trace(2)) htrc("(%s): already opened (mru=%d)\n", filename, i); } else { - if (trace > 1) + if (trace(2)) htrc("(%s): already opened, needs refreshing (mru=%d)\n", filename, i); } // endif stat @@ -535,11 +535,11 @@ static BOOL PROFILE_Open(LPCSTR filename) // strcpy(p, filename); // _strlwr(p); - if (trace > 1) + if (trace(2)) htrc("Opening %s\n", filename); if ((file = fopen(filename, "r"))) { - if (trace > 1) + if (trace(2)) htrc("(%s): found it\n", filename); // CurProfile->unix_name = malloc(strlen(buffer)+1); @@ -574,12 +574,12 @@ void PROFILE_Close(LPCSTR filename) struct stat buf; PROFILE *tempProfile; - if (trace > 1) + if (trace(2)) htrc("PROFILE_Close: CurProfile=%p N=%d\n", CurProfile, N_CACHED_PROFILES); /* Check for a match */ for (i = 0; i < N_CACHED_PROFILES; i++) { - if (trace > 1) + if (trace(2)) htrc("MRU=%s i=%d\n", SVP(MRUProfile[i]->filename), i); if (MRUProfile[i]->filename && !strcmp(filename, MRUProfile[i]->filename)) { @@ -591,7 +591,7 @@ void PROFILE_Close(LPCSTR filename) CurProfile=tempProfile; } // endif i - if (trace > 1) { + if (trace(2)) { if (!stat(CurProfile->filename, &buf) && CurProfile->mtime == buf.st_mtime) htrc("(%s): already opened (mru=%d)\n", filename, i); else @@ -620,7 +620,7 @@ void PROFILE_End(void) { int i; - if (trace) + if (trace(3)) htrc("PROFILE_End: CurProfile=%p N=%d\n", CurProfile, N_CACHED_PROFILES); if (!CurProfile) // Sergey Vojtovich @@ -628,7 +628,7 @@ void PROFILE_End(void) /* Close all opened files and free the cache structure */ for (i = 0; i < N_CACHED_PROFILES; i++) { - if (trace) + if (trace(3)) htrc("MRU=%s i=%d\n", SVP(MRUProfile[i]->filename), i); // CurProfile = MRUProfile[i]; Sergey Vojtovich @@ -894,7 +894,7 @@ static int PROFILE_GetSectionNames(LPSTR buffer, uint len) uint f,l; PROFILESECTION *section; - if (trace > 1) + if (trace(2)) htrc("GetSectionNames: buffer=%p len=%u\n", buffer, len); if (!buffer || !len) @@ -909,17 +909,17 @@ static int PROFILE_GetSectionNames(LPSTR buffer, uint len) buf = buffer; section = CurProfile->section; - if (trace > 1) + if (trace(2)) htrc("GetSectionNames: section=%p\n", section); while (section != NULL) { - if (trace > 1) + if (trace(2)) htrc("section=%s\n", section->name); if (section->name[0]) { l = strlen(section->name) + 1; - if (trace > 1) + if (trace(2)) htrc("l=%u f=%u\n", l, f); if (l > f) { @@ -982,7 +982,7 @@ static int PROFILE_GetString(LPCSTR section, LPCSTR key_name, key = PROFILE_Find(&CurProfile->section, section, key_name, FALSE, FALSE); PROFILE_CopyEntry(buffer, (key && key->value) ? key->value : def_val, len, FALSE); - if (trace > 1) + if (trace(2)) htrc("('%s','%s','%s'): returning '%s'\n", section, key_name, def_val, buffer ); @@ -1010,7 +1010,7 @@ static BOOL PROFILE_SetString(LPCSTR section_name, LPCSTR key_name, LPCSTR value, BOOL create_always) { if (!key_name) { /* Delete a whole section */ - if (trace > 1) + if (trace(2)) htrc("Deleting('%s')\n", section_name); CurProfile->changed |= PROFILE_DeleteSection(&CurProfile->section, @@ -1018,7 +1018,7 @@ static BOOL PROFILE_SetString(LPCSTR section_name, LPCSTR key_name, return TRUE; /* Even if PROFILE_DeleteSection() has failed, this is not an error on application's level.*/ } else if (!value) { /* Delete a key */ - if (trace > 1) + if (trace(2)) htrc("Deleting('%s','%s')\n", section_name, key_name); CurProfile->changed |= PROFILE_DeleteKey(&CurProfile->section, @@ -1027,7 +1027,7 @@ static BOOL PROFILE_SetString(LPCSTR section_name, LPCSTR key_name, } else { /* Set the key value */ PROFILEKEY *key = PROFILE_Find(&CurProfile->section, section_name, key_name, TRUE, create_always); - if (trace > 1) + if (trace(2)) htrc("Setting('%s','%s','%s')\n", section_name, key_name, value); if (!key) @@ -1040,17 +1040,17 @@ static BOOL PROFILE_SetString(LPCSTR section_name, LPCSTR key_name, value++; if (!strcmp(key->value, value)) { - if (trace > 1) + if (trace(2)) htrc(" no change needed\n" ); return TRUE; /* No change needed */ } // endif value - if (trace > 1) + if (trace(2)) htrc(" replacing '%s'\n", key->value); free(key->value); - } else if (trace > 1) + } else if (trace(2)) htrc(" creating key\n" ); key->value = (char*)malloc(strlen(value) + 1); @@ -1345,7 +1345,7 @@ GetPrivateProfileSectionNames(LPSTR buffer, DWORD size, LPCSTR filename) { DWORD ret = 0; - if (trace > 1) + if (trace(2)) htrc("GPPSN: filename=%s\n", filename); EnterCriticalSection(&PROFILE_CritSect); diff --git a/storage/connect/javaconn.cpp b/storage/connect/javaconn.cpp index 90f834ef9a7..d1be0ca1848 100644 --- a/storage/connect/javaconn.cpp +++ b/storage/connect/javaconn.cpp @@ -363,7 +363,7 @@ bool JAVAConn::GetJVM(PGLOBAL g) bool JAVAConn::Open(PGLOBAL g) { bool brc = true, err = false; - jboolean jt = (trace > 0); + jboolean jt = (trace(1)); // Link or check whether jvm library was linked if (GetJVM(g)) @@ -430,7 +430,7 @@ bool JAVAConn::Open(PGLOBAL g) jpop->Append(cp); } // endif cp - if (trace) { + if (trace(1)) { htrc("ClassPath=%s\n", ClassPath); htrc("CLASSPATH=%s\n", cp); htrc("%s\n", jpop->GetStr()); @@ -486,7 +486,7 @@ bool JAVAConn::Open(PGLOBAL g) break; } // endswitch rc - if (trace) + if (trace(1)) htrc("%s\n", g->Message); if (brc) diff --git a/storage/connect/jdbconn.cpp b/storage/connect/jdbconn.cpp index 4c21c2c9681..ddbc3115f0b 100644 --- a/storage/connect/jdbconn.cpp +++ b/storage/connect/jdbconn.cpp @@ -1,7 +1,7 @@ /************ Jdbconn C++ Functions Source Code File (.CPP) ************/ -/* Name: JDBCONN.CPP Version 1.1 */ +/* Name: JDBCONN.CPP Version 1.2 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 2016-2017 */ +/* (C) Copyright to the author Olivier BERTRAND 2016-2018 */ /* */ /* This file contains the JDBC connection classes functions. */ /***********************************************************************/ @@ -116,10 +116,26 @@ int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v) return TYPE_ERROR; else len = MY_MIN(abs(len), GetConvSize()); + // Pass through case 12: // VARCHAR + if (tn && !stricmp(tn, "TEXT")) + // Postgresql returns 12 for TEXT + if (GetTypeConv() == TPC_NO) + return TYPE_ERROR; + + // Postgresql can return this + if (len == 0x7FFFFFFF) + len = GetConvSize(); + + // Pass through case -9: // NVARCHAR (unicode) + // Postgresql can return this when size is unknown + if (len == 0x7FFFFFFF) + len = GetConvSize(); + v = 'V'; + // Pass through case 1: // CHAR case -15: // NCHAR (unicode) case -8: // ROWID @@ -154,13 +170,13 @@ int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v) case 91: // DATE, YEAR type = TYPE_DATE; - if (!tn || toupper(tn[0]) != 'Y') { - len = 10; - v = 'D'; - } else { - len = 4; - v = 'Y'; - } // endif len + if (!tn || toupper(tn[0]) != 'Y') { + len = 10; + v = 'D'; + } else { + len = 4; + v = 'Y'; + } // endif len break; case 92: // TIME @@ -192,6 +208,104 @@ int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v) return type; } // end of TranslateJDBCType + /***********************************************************************/ + /* A helper class to split an optionally qualified table name into */ + /* components. */ + /* These formats are understood: */ + /* "CatalogName.SchemaName.TableName" */ + /* "SchemaName.TableName" */ + /* "TableName" */ + /***********************************************************************/ +class SQLQualifiedName { + static const uint max_parts = 3; // Catalog.Schema.Table + MYSQL_LEX_STRING m_part[max_parts]; + char m_buf[512]; + + void lex_string_set(MYSQL_LEX_STRING *S, char *str, size_t length) + { + S->str = str; + S->length = length; + } // end of lex_string_set + + void lex_string_shorten_down(MYSQL_LEX_STRING *S, size_t offs) + { + DBUG_ASSERT(offs <= S->length); + S->str += offs; + S->length -= offs; + } // end of lex_string_shorten_down + + /*********************************************************************/ + /* Find the rightmost '.' delimiter and return the length */ + /* of the qualifier, including the rightmost '.' delimier. */ + /* For example, for the string {"a.b.c",5} it will return 4, */ + /* which is the length of the qualifier "a.b." */ + /*********************************************************************/ + size_t lex_string_find_qualifier(MYSQL_LEX_STRING *S) + { + size_t i; + for (i = S->length; i > 0; i--) + { + if (S->str[i - 1] == '.') + { + S->str[i - 1] = '\0'; + return i; + } + } + return 0; + } // end of lex_string_find_qualifier + +public: + /*********************************************************************/ + /* Initialize to the given optionally qualified name. */ + /* NULL pointer in "name" is supported. */ + /* name qualifier has precedence over schema. */ + /*********************************************************************/ + SQLQualifiedName(JCATPARM *cap) + { + const char *name = (const char *)cap->Tab; + char *db = (char *)cap->DB; + size_t len, i; + + // Initialize the parts + for (i = 0; i < max_parts; i++) + lex_string_set(&m_part[i], NULL, 0); + + if (name) { + // Initialize the first (rightmost) part + lex_string_set(&m_part[0], m_buf, + strmake(m_buf, name, sizeof(m_buf) - 1) - m_buf); + + // Initialize the other parts, if exist. + for (i = 1; i < max_parts; i++) { + if (!(len = lex_string_find_qualifier(&m_part[i - 1]))) + break; + + lex_string_set(&m_part[i], m_part[i - 1].str, len - 1); + lex_string_shorten_down(&m_part[i - 1], len); + } // endfor i + + } // endif name + + // If it was not specified, set schema as the passed db name + if (db && !m_part[1].length) + lex_string_set(&m_part[1], db, strlen(db)); + + } // end of SQLQualifiedName + + char *ptr(uint i) + { + DBUG_ASSERT(i < max_parts); + return (char *)(m_part[i].length ? m_part[i].str : NULL); + } // end of ptr + + size_t length(uint i) + { + DBUG_ASSERT(i < max_parts); + return m_part[i].length; + } // end of length + +}; // end of class SQLQualifiedName + /***********************************************************************/ /* Allocate the structure used to refer to the result set. */ /***********************************************************************/ @@ -270,7 +384,7 @@ PQRYRES JDBCColumns(PGLOBAL g, PCSZ db, PCSZ table, PCSZ colpat, length[11] = 255; } // endif jcp - if (trace) + if (trace(1)) htrc("JDBCColumns: max=%d len=%d,%d,%d,%d\n", maxres, length[0], length[1], length[2], length[3]); @@ -287,7 +401,7 @@ PQRYRES JDBCColumns(PGLOBAL g, PCSZ db, PCSZ table, PCSZ colpat, if (info || !qrp) // Info table return qrp; - if (trace) + if (trace(1)) htrc("Getting col results ncol=%d\n", qrp->Nbcol); if (!(cap = AllocCatInfo(g, JCAT_COL, db, table, qrp))) @@ -303,7 +417,7 @@ PQRYRES JDBCColumns(PGLOBAL g, PCSZ db, PCSZ table, PCSZ colpat, qrp->Nblin = n; // ResetNullValues(cap); - if (trace) + if (trace(1)) htrc("Columns: NBCOL=%d NBLIN=%d\n", qrp->Nbcol, qrp->Nblin); } else @@ -394,7 +508,7 @@ PQRYRES JDBCTables(PGLOBAL g, PCSZ db, PCSZ tabpat, PCSZ tabtyp, length[4] = 255; } // endif info - if (trace) + if (trace(1)) htrc("JDBCTables: max=%d len=%d,%d\n", maxres, length[0], length[1]); /************************************************************************/ @@ -417,7 +531,7 @@ PQRYRES JDBCTables(PGLOBAL g, PCSZ db, PCSZ tabpat, PCSZ tabtyp, cap->Pat = tabtyp; - if (trace) + if (trace(1)) htrc("Getting table results ncol=%d\n", cap->Qrp->Nbcol); /************************************************************************/ @@ -427,7 +541,7 @@ PQRYRES JDBCTables(PGLOBAL g, PCSZ db, PCSZ tabpat, PCSZ tabtyp, qrp->Nblin = n; // ResetNullValues(cap); - if (trace) + if (trace(1)) htrc("Tables: NBCOL=%d NBLIN=%d\n", qrp->Nbcol, qrp->Nblin); } else @@ -475,7 +589,7 @@ PQRYRES JDBCDrivers(PGLOBAL g, int maxres, bool info) } else maxres = 0; - if (trace) + if (trace(1)) htrc("JDBCDrivers: max=%d len=%d\n", maxres, length[0]); /************************************************************************/ @@ -519,7 +633,7 @@ JDBConn::JDBConn(PGLOBAL g, PCSZ wrapper) : JAVAConn(g, wrapper) xqid = xuid = xid = grs = readid = fetchid = typid = errid = nullptr; prepid = xpid = pcid = nullptr; chrfldid = intfldid = dblfldid = fltfldid = bigfldid = nullptr; - objfldid = datfldid = timfldid = tspfldid = nullptr; + objfldid = datfldid = timfldid = tspfldid = uidfldid = nullptr; DiscFunc = "JdbcDisconnect"; m_Ncol = 0; m_Aff = 0; @@ -535,12 +649,84 @@ JDBConn::JDBConn(PGLOBAL g, PCSZ wrapper) : JAVAConn(g, wrapper) m_IDQuoteChar[1] = 0; } // end of JDBConn -//JDBConn::~JDBConn() -// { -//if (Connected()) -// EndCom(); +/***********************************************************************/ +/* Search for UUID columns. */ +/***********************************************************************/ +bool JDBConn::SetUUID(PGLOBAL g, PTDBJDBC tjp) +{ + int ncol, ctyp; + bool brc = true; + PCSZ fnc = "GetColumns"; + PCOL colp; + JCATPARM *cap; + //jint jtyp; + jboolean rc = false; + jobjectArray parms; + jmethodID catid = nullptr; + + if (gmID(g, catid, fnc, "([Ljava/lang/String;)I")) + return true; + else if (gmID(g, intfldid, "IntField", "(ILjava/lang/String;)I")) + return true; + else if (gmID(g, readid, "ReadNext", "()I")) + return true; + + cap = AllocCatInfo(g, JCAT_COL, tjp->Schema, tjp->TableName, NULL); + SQLQualifiedName name(cap); + + // Build the java string array + parms = env->NewObjectArray(4, env->FindClass("java/lang/String"), NULL); + env->SetObjectArrayElement(parms, 0, env->NewStringUTF(name.ptr(2))); + env->SetObjectArrayElement(parms, 1, env->NewStringUTF(name.ptr(1))); + env->SetObjectArrayElement(parms, 2, env->NewStringUTF(name.ptr(0))); + + for (colp = tjp->GetColumns(); colp; colp = colp->GetNext()) { + env->SetObjectArrayElement(parms, 3, env->NewStringUTF(colp->GetName())); + ncol = env->CallIntMethod(job, catid, parms); + + if (Check(ncol)) { + sprintf(g->Message, "%s: %s", fnc, Msg); + goto err; + } // endif Check + + rc = env->CallBooleanMethod(job, readid); + + if (Check(rc)) { + sprintf(g->Message, "ReadNext: %s", Msg); + goto err; + } else if (rc == 0) { + sprintf(g->Message, "table %s does not exist", tjp->TableName); + goto err; + } // endif rc -// } // end of ~JDBConn + // Returns 666 is case of error + //jtyp = env->CallIntMethod(job, typid, 5, nullptr); + + //if (Check((jtyp == 666) ? -1 : 1)) { + // sprintf(g->Message, "Getting jtyp: %s", Msg); + // goto err; + //} // endif ctyp + + ctyp = (int)env->CallIntMethod(job, intfldid, 5, nullptr); + + if (Check(ctyp)) { + sprintf(g->Message, "Getting ctyp: %s", Msg); + goto err; + } // endif ctyp + + if (ctyp == 1111) + ((PJDBCCOL)colp)->uuid = true; + + } // endfor colp + + // All is Ok + brc = false; + + err: + // Not used anymore + env->DeleteLocalRef(parms); + return brc; +} // end of SetUUID /***********************************************************************/ /* Utility routine. */ @@ -586,7 +772,7 @@ bool JDBConn::Connect(PJPARM sop) int irc = RC_FX; bool err = false; jint rc; - jboolean jt = (trace > 0); + jboolean jt = (trace(1)); PGLOBAL& g = m_G; /*******************************************************************/ @@ -770,6 +956,7 @@ int JDBConn::Rewind(PCSZ sql) /***********************************************************************/ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val) { + const char *field; PGLOBAL& g = m_G; jint ctyp; jstring cn, jn = nullptr; @@ -793,6 +980,11 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val) if (!gmID(g, objfldid, "ObjectField", "(ILjava/lang/String;)Ljava/lang/Object;")) { jb = env->CallObjectMethod(job, objfldid, (jint)rank, jn); + if (Check(0)) { + sprintf(g->Message, "Getting jp: %s", Msg); + throw (int)TYPE_AM_JDBC; + } // endif Check + if (jb == nullptr) { val->Reset(); val->SetNull(true); @@ -818,7 +1010,7 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val) cn = nullptr; if (cn) { - const char *field = env->GetStringUTFChars(cn, (jboolean)false); + field = env->GetStringUTFChars(cn, (jboolean)false); val->SetValue_psz((PSZ)field); } else val->Reset(); @@ -885,6 +1077,19 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val) break; case java.sql.Types.BOOLEAN: System.out.print(jdi.BooleanField(i)); */ + case 1111: // UUID + if (!gmID(g, uidfldid, "UuidField", "(ILjava/lang/String;)Ljava/lang/String;")) + cn = (jstring)env->CallObjectMethod(job, uidfldid, (jint)rank, jn); + else + cn = nullptr; + + if (cn) { + const char *field = env->GetStringUTFChars(cn, (jboolean)false); + val->SetValue_psz((PSZ)field); + } else + val->Reset(); + + break; case 0: // NULL val->SetNull(true); // passthru @@ -1055,7 +1260,14 @@ bool JDBConn::SetParam(JDBCCOL *colp) if (gmID(g, setid, "SetNullParm", "(II)I")) return true; - jrc = env->CallIntMethod(job, setid, i, (jint)GetJDBCType(val->GetType())); + jrc = env->CallIntMethod(job, setid, i, + (colp->uuid ? 1111 : (jint)GetJDBCType(val->GetType()))); + } else if (colp->uuid) { + if (gmID(g, setid, "SetUuidParm", "(ILjava/lang/String;)V")) + return true; + + jst = env->NewStringUTF(val->GetCharValue()); + env->CallVoidMethod(job, setid, i, jst); } else switch (val->GetType()) { case TYPE_STRING: if (gmID(g, setid, "SetStringParm", "(ILjava/lang/String;)V")) @@ -1274,105 +1486,6 @@ bool JDBConn::SetParam(JDBCCOL *colp) return qrp; } // end of GetMetaData - /***********************************************************************/ - /* A helper class to split an optionally qualified table name into */ - /* components. */ - /* These formats are understood: */ - /* "CatalogName.SchemaName.TableName" */ - /* "SchemaName.TableName" */ - /* "TableName" */ - /***********************************************************************/ - class SQLQualifiedName - { - static const uint max_parts= 3; // Catalog.Schema.Table - MYSQL_LEX_STRING m_part[max_parts]; - char m_buf[512]; - - void lex_string_set(MYSQL_LEX_STRING *S, char *str, size_t length) - { - S->str= str; - S->length= length; - } // end of lex_string_set - - void lex_string_shorten_down(MYSQL_LEX_STRING *S, size_t offs) - { - DBUG_ASSERT(offs <= S->length); - S->str+= offs; - S->length-= offs; - } // end of lex_string_shorten_down - - /*********************************************************************/ - /* Find the rightmost '.' delimiter and return the length */ - /* of the qualifier, including the rightmost '.' delimier. */ - /* For example, for the string {"a.b.c",5} it will return 4, */ - /* which is the length of the qualifier "a.b." */ - /*********************************************************************/ - size_t lex_string_find_qualifier(MYSQL_LEX_STRING *S) - { - size_t i; - for (i= S->length; i > 0; i--) - { - if (S->str[i - 1] == '.') - { - S->str[i - 1]= '\0'; - return i; - } - } - return 0; - } // end of lex_string_find_qualifier - - public: - /*********************************************************************/ - /* Initialize to the given optionally qualified name. */ - /* NULL pointer in "name" is supported. */ - /* name qualifier has precedence over schema. */ - /*********************************************************************/ - SQLQualifiedName(JCATPARM *cap) - { - const char *name = (const char *)cap->Tab; - char *db = (char *)cap->DB; - size_t len, i; - - // Initialize the parts - for (i = 0; i < max_parts; i++) - lex_string_set(&m_part[i], NULL, 0); - - if (name) { - // Initialize the first (rightmost) part - lex_string_set(&m_part[0], m_buf, - strmake(m_buf, name, sizeof(m_buf) - 1) - m_buf); - - // Initialize the other parts, if exist. - for (i= 1; i < max_parts; i++) { - if (!(len= lex_string_find_qualifier(&m_part[i - 1]))) - break; - - lex_string_set(&m_part[i], m_part[i - 1].str, len - 1); - lex_string_shorten_down(&m_part[i - 1], len); - } // endfor i - - } // endif name - - // If it was not specified, set schema as the passed db name - if (db && !m_part[1].length) - lex_string_set(&m_part[1], db, strlen(db)); - - } // end of SQLQualifiedName - - char *ptr(uint i) - { - DBUG_ASSERT(i < max_parts); - return (char *)(m_part[i].length ? m_part[i].str : NULL); - } // end of ptr - - size_t length(uint i) - { - DBUG_ASSERT(i < max_parts); - return m_part[i].length; - } // end of length - - }; // end of class SQLQualifiedName - /***********************************************************************/ /* Allocate recset and call SQLTables, SQLColumns or SQLPrimaryKeys. */ /***********************************************************************/ @@ -1443,7 +1556,7 @@ bool JDBConn::SetParam(JDBCCOL *colp) // Not used anymore env->DeleteLocalRef(parms); - if (trace) + if (trace(1)) htrc("Method %s returned %d columns\n", fnc, ncol); // n because we no more ignore the first column @@ -1488,7 +1601,7 @@ bool JDBConn::SetParam(JDBCCOL *colp) sprintf(g->Message, "Fetch: %s", Msg); return -1; } if (rc == 0) { - if (trace) + if (trace(1)) htrc("End of fetches i=%d\n", i); break; diff --git a/storage/connect/jdbconn.h b/storage/connect/jdbconn.h index 56f318d238b..0c36cccadcf 100644 --- a/storage/connect/jdbconn.h +++ b/storage/connect/jdbconn.h @@ -29,6 +29,7 @@ public: // Attributes public: char *GetQuoteChar(void) { return m_IDQuoteChar; } + bool SetUUID(PGLOBAL g, PTDBJDBC tjp); virtual int GetMaxValue(int infotype); public: @@ -58,13 +59,6 @@ public: protected: // Members -#if 0 - JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine) - JNIEnv *env; // Pointer to native interface - jclass jdi; // Pointer to the java wrapper class - jobject job; // The java wrapper class object - jmethodID errid; // The GetErrmsg method ID -#endif // 0 jmethodID xqid; // The ExecuteQuery method ID jmethodID xuid; // The ExecuteUpdate method ID jmethodID xid; // The Execute method ID @@ -84,8 +78,7 @@ protected: jmethodID timfldid; // The TimeField method ID jmethodID tspfldid; // The TimestampField method ID jmethodID bigfldid; // The BigintField method ID -// PCSZ Msg; -// PCSZ m_Wrap; + jmethodID uidfldid; // The UuidField method ID char m_IDQuoteChar[2]; PCSZ m_Pwd; int m_Ncol; diff --git a/storage/connect/jmgfam.cpp b/storage/connect/jmgfam.cpp index c7115cdd720..30f6279146d 100644 --- a/storage/connect/jmgfam.cpp +++ b/storage/connect/jmgfam.cpp @@ -298,7 +298,7 @@ int JMGFAM::ReadBuffer(PGLOBAL g) PSZ str = Jcp->GetDocument(); if (str) { - if (trace == 1) + if (trace(1)) htrc("%s\n", str); strncpy(Tdbp->GetLine(), str, Lrecl); diff --git a/storage/connect/jmgoconn.cpp b/storage/connect/jmgoconn.cpp index 4736641ef3f..1731ccbeb8c 100644 --- a/storage/connect/jmgoconn.cpp +++ b/storage/connect/jmgoconn.cpp @@ -254,7 +254,7 @@ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, all = true; if (pipe && Options) { - if (trace) + if (trace(1)) htrc("Pipeline: %s\n", Options); p = strrchr(Options, ']'); @@ -312,13 +312,13 @@ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, *(char*)p = ']'; // Restore Colist for discovery p = s->GetStr(); - if (trace) + if (trace(33)) htrc("New Pipeline: %s\n", p); return AggregateCollection(p); } else { if (filter || filp) { - if (trace) { + if (trace(1)) { if (filter) htrc("Filter: %s\n", filter); @@ -346,7 +346,7 @@ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, tdbp->SetFilter(NULL); // Not needed anymore } // endif To_Filter - if (trace) + if (trace(33)) htrc("selector: %s\n", s->GetStr()); s->Resize(s->GetLength() + 1); @@ -355,7 +355,7 @@ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, if (!all) { if (Options && *Options) { - if (trace) + if (trace(1)) htrc("options=%s\n", Options); op = Options; @@ -751,7 +751,7 @@ int JMgoConn::DocUpdate(PGLOBAL g, PTDB tdbp) jlong ar = env->CallLongMethod(job, updateid, upd); - if (trace) + if (trace(1)) htrc("DocUpdate: ar = %ld\n", ar); if (Check((int)ar)) { @@ -770,7 +770,7 @@ int JMgoConn::DocDelete(PGLOBAL g, bool all) int rc = RC_OK; jlong ar = env->CallLongMethod(job, deleteid, all); - if (trace) + if (trace(1)) htrc("DocDelete: ar = %ld\n", ar); if (Check((int)ar)) { diff --git a/storage/connect/json.cpp b/storage/connect/json.cpp index b86d2da21b7..98a4659cea8 100644 --- a/storage/connect/json.cpp +++ b/storage/connect/json.cpp @@ -97,7 +97,7 @@ PJSON ParseJson(PGLOBAL g, char *s, int len, int *ptyp, bool *comma) PJSON jsp = NULL; STRG src; - if (trace) + if (trace(1)) htrc("ParseJson: s=%.10s len=%d\n", s, len); if (!s || !len) { @@ -165,7 +165,7 @@ PJSON ParseJson(PGLOBAL g, char *s, int len, int *ptyp, bool *comma) }; // endswitch s[i] if (!jsp) - sprintf(g->Message, "Invalid Json string '%.*s'", 50, s); + sprintf(g->Message, "Invalid Json string '%.*s'", MY_MIN(len, 50), s); else if (ptyp && pretty == 3) { *ptyp = 3; // Not recognized pretty @@ -178,7 +178,7 @@ PJSON ParseJson(PGLOBAL g, char *s, int len, int *ptyp, bool *comma) } // endif ptyp } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); jsp = NULL; } catch (const char *msg) { @@ -652,7 +652,7 @@ PSZ Serialize(PGLOBAL g, PJSON jsp, char *fn, int pretty) } // endif's } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); str = NULL; } catch (const char *msg) { @@ -1015,6 +1015,20 @@ PJAR JOBJECT::GetKeyList(PGLOBAL g) return jarp; } // end of GetKeyList +/***********************************************************************/ +/* Return all values as an array. */ +/***********************************************************************/ +PJAR JOBJECT::GetValList(PGLOBAL g) +{ + PJAR jarp = new(g) JARRAY(); + + for (PJPR jpp = First; jpp; jpp = jpp->Next) + jarp->AddValue(g, jpp->GetVal()); + + jarp->InitArray(g); + return jarp; +} // end of GetValList + /***********************************************************************/ /* Get the value corresponding to the given key. */ /***********************************************************************/ @@ -1224,6 +1238,7 @@ PJVAL JARRAY::AddValue(PGLOBAL g, PJVAL jvp, int *x) Last->Next = jvp; Last = jvp; + Last->Next = NULL; } // endif x return jvp; @@ -1318,6 +1333,24 @@ bool JARRAY::IsNull(void) /* -------------------------- Class JVALUE- -------------------------- */ +/***********************************************************************/ +/* Constructor for a JSON. */ +/***********************************************************************/ +JVALUE::JVALUE(PJSON jsp) : JSON() +{ + if (jsp->GetType() == TYPE_JVAL) { + Jsp = jsp->GetJsp(); + Value = jsp->GetValue(); + } else { + Jsp = jsp; + Value = NULL; + } // endif Type + + Next = NULL; + Del = false; + Size = 1; +} // end of JVALUE constructor + /***********************************************************************/ /* Constructor for a Value with a given string or numeric value. */ /***********************************************************************/ diff --git a/storage/connect/json.h b/storage/connect/json.h index 375532212c4..dcc97287420 100644 --- a/storage/connect/json.h +++ b/storage/connect/json.h @@ -20,7 +20,8 @@ enum JTYP {TYPE_NULL = TYPE_VOID, TYPE_BINT = TYPE_BIGINT, TYPE_DTM = TYPE_DATE, TYPE_INTG = TYPE_INT, - TYPE_JSON = 12, + TYPE_VAL = 12, + TYPE_JSON, TYPE_JAR, TYPE_JOB, TYPE_JVAL}; @@ -157,6 +158,7 @@ class JSON : public BLOCK { //virtual PJVAL AddValue(PGLOBAL g, PJVAL jvp = NULL, int *x = NULL) {X return NULL;} virtual PJPR AddPair(PGLOBAL g, PCSZ key) {X return NULL;} virtual PJAR GetKeyList(PGLOBAL g) {X return NULL;} + virtual PJAR GetValList(PGLOBAL g) {X return NULL;} virtual PJVAL GetValue(const char *key) {X return NULL;} virtual PJOB GetObject(void) {return NULL;} virtual PJAR GetArray(void) {return NULL;} @@ -205,6 +207,7 @@ class JOBJECT : public JSON { virtual PJOB GetObject(void) {return this;} virtual PJVAL GetValue(const char* key); virtual PJAR GetKeyList(PGLOBAL g); + virtual PJAR GetValList(PGLOBAL g); virtual PSZ GetText(PGLOBAL g, PSZ text); virtual bool Merge(PGLOBAL g, PJSON jsp); virtual void SetValue(PGLOBAL g, PJVAL jvp, PCSZ key); @@ -258,8 +261,7 @@ class JVALUE : public JSON { friend bool SerializeValue(JOUT *, PJVAL); public: JVALUE(void) : JSON() {Clear();} - JVALUE(PJSON jsp) : JSON() - {Jsp = jsp; Value = NULL; Next = NULL; Del = false; Size = 1;} + JVALUE(PJSON jsp); JVALUE(PGLOBAL g, PVAL valp); JVALUE(PGLOBAL g, PCSZ strp); diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index eb783807190..e45846ea23b 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -1,6 +1,6 @@ /****************** jsonudf C++ Program Source Code File (.CPP) ******************/ -/* PROGRAM NAME: jsonudf Version 1.6 */ -/* (C) Copyright to the author Olivier BERTRAND 2015-2017 */ +/* PROGRAM NAME: jsonudf Version 1.7 */ +/* (C) Copyright to the author Olivier BERTRAND 2015-2018 */ /* This program are the JSON User Defined Functions . */ /*********************************************************************************/ @@ -31,16 +31,39 @@ bool IsNum(PSZ s); char *NextChr(PSZ s, char sep); char *GetJsonNull(void); uint GetJsonGrpSize(void); -static int IsJson(UDF_ARGS *args, uint i); +static int IsJson(UDF_ARGS *args, uint i, bool b = false); static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i); static char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error); static char *bin_handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error); +static PJSON JsonNew(PGLOBAL g, JTYP type); +static PJVAL JvalNew(PGLOBAL g, JTYP type, void *vp = NULL); +static PJSNX JsnxNew(PGLOBAL g, PJSON jsp, int type, int len = 64); static uint JsonGrpSize = 10; -/* ----------------------------------- JSNX ------------------------------------ */ +/*********************************************************************************/ +/* SubAlloc a new JSNX class with protection against memory exhaustion. */ +/*********************************************************************************/ +static PJSNX JsnxNew(PGLOBAL g, PJSON jsp, int type, int len) +{ + PJSNX jsx; + + try { + jsx = new(g) JSNX(g, jsp, type, len); + } catch (...) { + if (trace(1023)) + htrc("%s\n", g->Message); + + PUSH_WARNING(g->Message); + jsx = NULL; + } // end try/catch + + return jsx; +} /* end of JsnxNew */ + + /* ----------------------------------- JSNX ------------------------------------ */ /*********************************************************************************/ /* JSNX public constructor. */ @@ -81,21 +104,7 @@ my_bool JSNX::SetJpath(PGLOBAL g, char *path, my_bool jb) return true; Value->SetNullable(true); - -#if 0 - if (jb) { - // Path must return a Json item - size_t n = strlen(path); - - if (!n || path[n - 1] != '*') { - Jpath = (char*)PlugSubAlloc(g, NULL, n + 3); - strcat(strcpy(Jpath, path), (n) ? ":*" : "*"); - } else - Jpath = path; - - } else -#endif // 0 - Jpath = path; + Jpath = path; // Parse the json path Parsed = false; @@ -182,7 +191,7 @@ my_bool JSNX::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) // Set concat intermediate string p[n - 1] = 0; - if (trace) + if (trace(1)) htrc("Concat string=%s\n", p + 1); jnp->CncVal = AllocateValue(g, p + 1, TYPE_STRING); @@ -246,7 +255,7 @@ my_bool JSNX::ParseJpath(PGLOBAL g) // Jpath = Name; return true; - if (trace) + if (trace(1)) htrc("ParseJpath %s\n", SVP(Jpath)); if (!(pbuf = PlgDBDup(g, Jpath))) @@ -309,7 +318,7 @@ my_bool JSNX::ParseJpath(PGLOBAL g) Nod = i; MulVal = AllocateValue(g, Value); - if (trace) + if (trace(1)) for (i = 0; i < Nod; i++) htrc("Node(%d) Key=%s Op=%d Rank=%d\n", i, SVP(Nodes[i].Key), Nodes[i].Op, Nodes[i].Rank); @@ -506,13 +515,13 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) vp->Reset(); - if (trace) + if (trace(1)) htrc("CalculateArray size=%d op=%d\n", ars, op); - for (i = 0; i < arp->size(); i++) { + for (i = 0; i < ars; i++) { jvrp = arp->GetValue(i); - if (trace) + if (trace(1)) htrc("i=%d nv=%d\n", i, nv); if (!jvrp->IsNull() || (op == OP_CNC && GetJsonNull())) { @@ -525,7 +534,7 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) } else jvp = jvrp; - if (trace) + if (trace(1)) htrc("jvp=%s null=%d\n", jvp->GetString(g), jvp->IsNull() ? 1 : 0); @@ -561,7 +570,7 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n) if (err) vp->Reset(); - if (trace) { + if (trace(1)) { char buf(32); htrc("vp='%s' err=%d\n", @@ -753,6 +762,7 @@ my_bool JSNX::WriteValue(PGLOBAL g, PJVAL jvalp) /*********************************************************************************/ PSZ JSNX::Locate(PGLOBAL g, PJSON jsp, PJVAL jvp, int k) { + PSZ str = NULL; my_bool b = false, err = true; g->Message[0] = 0; @@ -762,37 +772,47 @@ PSZ JSNX::Locate(PGLOBAL g, PJSON jsp, PJVAL jvp, int k) return NULL; } // endif jsp - // Write to the path string - Jp = new(g) JOUTSTR(g); - Jp->WriteChr('$'); - Jvalp = jvp; - K = k; + try { + // Write to the path string + Jp = new(g) JOUTSTR(g); + Jp->WriteChr('$'); + Jvalp = jvp; + K = k; - switch (jsp->GetType()) { - case TYPE_JAR: - err = LocateArray((PJAR)jsp); - break; - case TYPE_JOB: - err = LocateObject((PJOB)jsp); - break; - case TYPE_JVAL: - err = LocateValue((PJVAL)jsp); - break; - default: - err = true; + switch (jsp->GetType()) { + case TYPE_JAR: + err = LocateArray((PJAR)jsp); + break; + case TYPE_JOB: + err = LocateObject((PJOB)jsp); + break; + case TYPE_JVAL: + err = LocateValue((PJVAL)jsp); + break; + default: + err = true; } // endswitch Type - if (err) { - if (!g->Message[0]) - strcpy(g->Message, "Invalid json tree"); + if (err) { + if (!g->Message[0]) + strcpy(g->Message, "Invalid json tree"); - } else if (Found) { - Jp->WriteChr('\0'); - PlugSubAlloc(g, NULL, Jp->N); - return Jp->Strp; - } // endif's + } else if (Found) { + Jp->WriteChr('\0'); + PlugSubAlloc(g, NULL, Jp->N); + str = Jp->Strp; + } // endif's - return NULL; + } catch (int n) { + if (trace(1)) + htrc("Exception %d: %s\n", n, g->Message); + + PUSH_WARNING(g->Message); + } catch (const char *msg) { + strcpy(g->Message, msg); + } // end catch + + return str; } // end of Locate /*********************************************************************************/ @@ -864,53 +884,62 @@ my_bool JSNX::LocateValue(PJVAL jvp) /*********************************************************************************/ PSZ JSNX::LocateAll(PGLOBAL g, PJSON jsp, PJVAL jvp, int mx) { + PSZ str = NULL; my_bool b = false, err = true; - PJPN jnp = (PJPN)PlugSubAlloc(g, NULL, sizeof(JPN) * mx); - - memset(jnp, 0, sizeof(JPN) * mx); - g->Message[0] = 0; - + PJPN jnp; + if (!jsp) { strcpy(g->Message, "Null json tree"); return NULL; } // endif jsp - // Write to the path string - Jp = new(g)JOUTSTR(g); - Jvalp = jvp; - Imax = mx - 1; - Jpnp = jnp; - Jp->WriteChr('['); + try { + jnp = (PJPN)PlugSubAlloc(g, NULL, sizeof(JPN) * mx); + memset(jnp, 0, sizeof(JPN) * mx); + g->Message[0] = 0; + + // Write to the path string + Jp = new(g)JOUTSTR(g); + Jvalp = jvp; + Imax = mx - 1; + Jpnp = jnp; + Jp->WriteChr('['); + + switch (jsp->GetType()) { + case TYPE_JAR: + err = LocateArrayAll((PJAR)jsp); + break; + case TYPE_JOB: + err = LocateObjectAll((PJOB)jsp); + break; + case TYPE_JVAL: + err = LocateValueAll((PJVAL)jsp); + break; + default: + err = true; + } // endswitch Type - switch (jsp->GetType()) { - case TYPE_JAR: - err = LocateArrayAll((PJAR)jsp); - break; - case TYPE_JOB: - err = LocateObjectAll((PJOB)jsp); - break; - case TYPE_JVAL: - err = LocateValueAll((PJVAL)jsp); - break; - default: - err = true; - } // endswitch Type + if (!err) { + if (Jp->N > 1) + Jp->N--; - if (err) { - if (!g->Message[0]) + Jp->WriteChr(']'); + Jp->WriteChr('\0'); + PlugSubAlloc(g, NULL, Jp->N); + str = Jp->Strp; + } else if (!g->Message[0]) strcpy(g->Message, "Invalid json tree"); - return NULL; - } else { - if (Jp->N > 1) - Jp->N--; + } catch (int n) { + if (trace(1)) + htrc("Exception %d: %s\n", n, g->Message); - Jp->WriteChr(']'); - Jp->WriteChr('\0'); - PlugSubAlloc(g, NULL, Jp->N); - return Jp->Strp; - } // endif's + PUSH_WARNING(g->Message); + } catch (const char *msg) { + strcpy(g->Message, msg); + } // end catch + return str; } // end of LocateAll /*********************************************************************************/ @@ -1137,6 +1166,72 @@ inline void JsonFreeMem(PGLOBAL g) PlugExit(g); } /* end of JsonFreeMem */ +/*********************************************************************************/ +/* SubAlloc a new JSON item with protection against memory exhaustion. */ +/*********************************************************************************/ +static PJSON JsonNew(PGLOBAL g, JTYP type) +{ + PJSON jsp = NULL; + + try { + switch (type) { + case TYPE_JAR: + jsp = new(g) JARRAY; + break; + case TYPE_JOB: + jsp = new(g) JOBJECT; + break; + default: + break; + } // endswitch type + + } catch (...) { + if (trace(1023)) + htrc("%s\n", g->Message); + + PUSH_WARNING(g->Message); + } // end try/catch + + return jsp; +} /* end of JsonNew */ + +/*********************************************************************************/ +/* SubAlloc a new JValue with protection against memory exhaustion. */ +/*********************************************************************************/ +static PJVAL JvalNew(PGLOBAL g, JTYP type, void *vp) +{ + PJVAL jvp = NULL; + + try { + if (!vp) + jvp = new (g) JVALUE; + else switch (type) { + case TYPE_JSON: + case TYPE_JVAL: + case TYPE_JAR: + case TYPE_JOB: + jvp = new(g) JVALUE((PJSON)vp); + break; + case TYPE_VAL: + jvp = new(g) JVALUE(g, (PVAL)vp); + break; + case TYPE_STRG: + jvp = new(g) JVALUE(g, (PCSZ)vp); + break; + default: + break; + } // endswitch type + + } catch (...) { + if (trace(1023)) + htrc("%s\n", g->Message); + + PUSH_WARNING(g->Message); + } // end try/catch + + return jvp; +} /* end of JsonNew */ + /*********************************************************************************/ /* Allocate and initialise the memory area. */ /*********************************************************************************/ @@ -1289,8 +1384,11 @@ static int *GetIntArgPtr(PGLOBAL g, UDF_ARGS *args, uint& n) for (uint i = n; i < args->arg_count; i++) if (args->arg_type[i] == INT_RESULT) { if (args->args[i]) { - x = (int*)PlugSubAlloc(g, NULL, sizeof(int)); - *x = (int)*(longlong*)args->args[i]; + if ((x = (int*)PlgDBSubAlloc(g, NULL, sizeof(int)))) + *x = (int)*(longlong*)args->args[i]; + else + PUSH_WARNING(g->Message); + } // endif args n = i + 1; @@ -1303,7 +1401,7 @@ static int *GetIntArgPtr(PGLOBAL g, UDF_ARGS *args, uint& n) /*********************************************************************************/ /* Returns not 0 if the argument is a JSON item or file name. */ /*********************************************************************************/ -static int IsJson(UDF_ARGS *args, uint i) +static int IsJson(UDF_ARGS *args, uint i, bool b) { int n = 0; @@ -1320,8 +1418,20 @@ static int IsJson(UDF_ARGS *args, uint i) else n = 2; // A file name may have been returned - } else if (!strnicmp(args->attributes[i], "Jfile_", 6)) + } else if (!strnicmp(args->attributes[i], "Jfile_", 6)) { n = 2; // arg is a json file name + } else if (b) { + char *sap; + PGLOBAL g = PlugInit(NULL, args->lengths[i] * M + 1024); + + JsonSubSet(g); + sap = MakePSZ(g, args, i); + + if (ParseJson(g, sap, strlen(sap))) + n = 4; + + JsonFreeMem(g); + } // endif's return n; } // end of IsJson @@ -1534,10 +1644,14 @@ static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i) { if (args->arg_count > (unsigned)i && args->args[i]) { int n = args->lengths[i]; - PSZ s = (PSZ)PlugSubAlloc(g, NULL, n + 1); + PSZ s = (PSZ)PlgDBSubAlloc(g, NULL, n + 1); + + if (s) { + memcpy(s, args->args[i], n); + s[n] = 0; + } else + PUSH_WARNING(g->Message); - memcpy(s, args->args[i], n); - s[n] = 0; return s; } else return NULL; @@ -1574,9 +1688,12 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) return "Key"; if (!b) { - p = (PSZ)PlugSubAlloc(g, NULL, n + 1); - memcpy(p, s, n); - p[n] = 0; + if ((p = (PSZ)PlgDBSubAlloc(g, NULL, n + 1))) { + memcpy(p, s, n); + p[n] = 0; + } else + PUSH_WARNING(g->Message); + s = p; } // endif b @@ -1665,15 +1782,16 @@ static char *GetJsonFile(PGLOBAL g, char *fn) return NULL; } // endif len - str = (char*)PlugSubAlloc(g, NULL, len + 1); - - if ((n = read(h, str, len)) < 0) { - sprintf(g->Message, "Error %d reading %d bytes from %s", errno, len, fn); - return NULL; - } // endif n + if ((str = (char*)PlgDBSubAlloc(g, NULL, len + 1))) { + if ((n = read(h, str, len)) < 0) { + sprintf(g->Message, "Error %d reading %d bytes from %s", errno, len, fn); + return NULL; + } // endif n - str[n] = 0; - close(h); + str[n] = 0; + close(h); + } // endif str + return str; } // end of GetJsonFile @@ -1759,6 +1877,41 @@ static PJVAL MakeValue(PGLOBAL g, UDF_ARGS *args, uint i, PJSON *top = NULL) return jvp; } // end of MakeValue +/*********************************************************************************/ +/* Try making a JSON value of the passed type from the passed argument. */ +/*********************************************************************************/ +static PJVAL MakeTypedValue(PGLOBAL g, UDF_ARGS *args, uint i, + JTYP type, PJSON *top = NULL) +{ + char *sap; + PJSON jsp; + PJVAL jvp = MakeValue(g, args, i, top); + + //if (type == TYPE_JSON) { + // if (jvp->GetValType() >= TYPE_JSON) + // return jvp; + + //} else if (jvp->GetValType() == type) + // return jvp; + + if (jvp->GetValType() == TYPE_STRG) { + sap = jvp->GetString(g); + + if ((jsp = ParseJson(g, sap, strlen(sap)))) { + if ((type == TYPE_JSON && jsp->GetType() != TYPE_JVAL) || jsp->GetType() == type) { + if (top) + *top = jsp; + + jvp->SetValue(jsp); + } // endif Type + + } // endif jsp + + } // endif Type + + return jvp; +} // end of MakeTypedValue + /*********************************************************************************/ /* Make a Json value containing the parameter. */ /*********************************************************************************/ @@ -1861,9 +2014,9 @@ my_bool json_array_add_values_init(UDF_INIT *initid, UDF_ARGS *args, char *messa if (args->arg_count < 2) { strcpy(message, "This function must have at least 2 arguments"); return true; - } else if (!IsJson(args, 0) && args->arg_type[0] != STRING_RESULT) { - strcpy(message, "First argument must be a json string or item"); - return true; + //} else if (!IsJson(args, 0, true)) { + // strcpy(message, "First argument must be a valid json string or item"); + // return true; } else CalcLen(args, false, reslen, memlen); @@ -1891,23 +2044,14 @@ char *json_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result, if (!g->Xchk) { if (!CheckMemory(g, initid, args, args->arg_count, true)) { - char *p; PJSON top; PJAR arp; - PJVAL jvp = MakeValue(g, args, 0, &top); + PJVAL jvp = MakeTypedValue(g, args, 0, TYPE_JAR, &top); - if ((p = jvp->GetString(g))) { - if (!(top = ParseJson(g, p, strlen(p)))) { - PUSH_WARNING(g->Message); - return NULL; - } // endif jsp - - jvp->SetValue(top); - } // endif p - if (jvp->GetValType() != TYPE_JAR) { arp = new(g)JARRAY; arp->AddValue(g, jvp); + top = arp; } else arp = jvp->GetArray(); @@ -1915,7 +2059,6 @@ char *json_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result, arp->AddValue(g, MakeValue(g, args, i)); arp->InitArray(g); -// str = Serialize(g, arp, NULL, 0); str = MakeResult(g, args, top, args->arg_count); } // endif CheckMemory @@ -1952,10 +2095,10 @@ my_bool json_array_add_init(UDF_INIT *initid, UDF_ARGS *args, char *message) if (args->arg_count < 2) { strcpy(message, "This function must have at least 2 arguments"); - return true; - } else if (!IsJson(args, 0)) { - strcpy(message, "First argument must be a json item"); - return true; + return true; + //} else if (!IsJson(args, 0, true)) { + // strcpy(message, "First argument is not a valid Json item"); + // return true; } else CalcLen(args, false, reslen, memlen, true); @@ -1994,22 +2137,38 @@ char *json_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result, PJVAL jvp; PJAR arp; - jvp = MakeValue(g, args, 0, &top); + jvp = MakeTypedValue(g, args, 0, TYPE_JSON, &top); jsp = jvp->GetJson(); x = GetIntArgPtr(g, args, n); if (CheckPath(g, args, jsp, jvp, 2)) PUSH_WARNING(g->Message); - else if (jvp && jvp->GetValType() == TYPE_JAR) { + else if (jvp) { PGLOBAL gb = GetMemPtr(g, args, 0); - arp = jvp->GetArray(); - arp->AddValue(gb, MakeValue(gb, args, 1), x); - arp->InitArray(gb); - str = MakeResult(g, args, top, n); + if (jvp->GetValType() != TYPE_JAR) { + if ((arp = (PJAR)JsonNew(gb, TYPE_JAR))) { + arp->AddValue(gb, JvalNew(gb, TYPE_JVAL, jvp)); + jvp->SetValue(arp); + + if (!top) + top = arp; + + } // endif arp + + } else + arp = jvp->GetArray(); + + if (arp) { + arp->AddValue(gb, MakeValue(gb, args, 1), x); + arp->InitArray(gb); + str = MakeResult(g, args, top, n); + } else + PUSH_WARNING(gb->Message); + } else { - PUSH_WARNING("First argument target is not an array"); -// if (g->Mrr) *error = 1; (only if no path) + PUSH_WARNING("Target is not an array"); + // if (g->Mrr) *error = 1; (only if no path) } // endif jvp } // endif CheckMemory @@ -2048,9 +2207,6 @@ my_bool json_array_delete_init(UDF_INIT *initid, UDF_ARGS *args, char *message) if (args->arg_count < 2) { strcpy(message, "This function must have at least 2 arguments"); return true; - } else if (!IsJson(args, 0)) { - strcpy(message, "First argument must be a json item"); - return true; } else CalcLen(args, false, reslen, memlen, true); @@ -2087,7 +2243,7 @@ char *json_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, uint n = 1; PJSON top; PJAR arp; - PJVAL jvp = MakeValue(g, args, 0, &top); + PJVAL jvp = MakeTypedValue(g, args, 0, TYPE_JSON, &top); if (!(x = GetIntArgPtr(g, args, n))) PUSH_WARNING("Missing or null array index"); @@ -2186,9 +2342,14 @@ long long jsonsum_int(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *err if (g->N) { // Keep result of constant function - long long *np = (long long*)PlugSubAlloc(g, NULL, sizeof(long long)); - *np = n; - g->Activityp = (PACTIVITY)np; + long long *np; + + if ((np = (long long*)PlgDBSubAlloc(g, NULL, sizeof(long long)))) { + *np = n; + g->Activityp = (PACTIVITY)np; + } else + PUSH_WARNING(g->Message); + } // endif const_item return n; @@ -2252,13 +2413,21 @@ double jsonsum_real(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error } else { *error = 1; n = -1.0; - } // end of CheckMemory + } // endif CheckMemory if (g->N) { // Keep result of constant function - double *np = (double*)PlugSubAlloc(g, NULL, sizeof(double)); - *np = n; - g->Activityp = (PACTIVITY)np; + double *np; + + if ((np = (double*)PlgDBSubAlloc(g, NULL, sizeof(double)))) { + *np = n; + g->Activityp = (PACTIVITY)np; + } else { + PUSH_WARNING(g->Message); + *error = 1; + n = -1.0; + } // endif np + } // endif const_item return n; @@ -2312,13 +2481,20 @@ double jsonavg_real(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error } else { *error = 1; n = -1.0; - } // end of CheckMemory + } // endif CheckMemory if (g->N) { // Keep result of constant function - double *np = (double*)PlugSubAlloc(g, NULL, sizeof(double)); - *np = n; - g->Activityp = (PACTIVITY)np; + double *np; + + if ((np = (double*)PlgDBSubAlloc(g, NULL, sizeof(double)))) { + *np = n; + g->Activityp = (PACTIVITY)np; + } else { + *error = 1; + n = -1.0; + } // endif np + } // endif const_item return n; @@ -2348,12 +2524,15 @@ char *json_make_object(UDF_INIT *initid, UDF_ARGS *args, char *result, if (!g->Xchk) { if (!CheckMemory(g, initid, args, args->arg_count, false, false, true)) { - PJOB objp = new(g)JOBJECT; + PJOB objp; + + if ((objp = (PJOB)JsonNew(g, TYPE_JOB))) { + for (uint i = 0; i < args->arg_count; i++) + objp->SetValue(g, MakeValue(g, args, i), MakeKey(g, args, i)); - for (uint i = 0; i < args->arg_count; i++) - objp->SetValue(g, MakeValue(g, args, i), MakeKey(g, args, i)); + str = Serialize(g, objp, NULL, 0); + } // endif objp - str = Serialize(g, objp, NULL, 0); } // endif CheckMemory if (!str) @@ -2394,13 +2573,16 @@ char *json_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result, if (!g->Xchk) { if (!CheckMemory(g, initid, args, args->arg_count, false, true)) { PJVAL jvp; - PJOB objp = new(g)JOBJECT; + PJOB objp; + + if ((objp = (PJOB)JsonNew(g, TYPE_JOB))) { + for (uint i = 0; i < args->arg_count; i++) + if (!(jvp = MakeValue(g, args, i))->IsNull()) + objp->SetValue(g, jvp, MakeKey(g, args, i)); - for (uint i = 0; i < args->arg_count; i++) - if (!(jvp = MakeValue(g, args, i))->IsNull()) - objp->SetValue(g, jvp, MakeKey(g, args, i)); + str = Serialize(g, objp, NULL, 0); + } // endif objp - str = Serialize(g, objp, NULL, 0); } // endif CheckMemory if (!str) @@ -2444,12 +2626,15 @@ char *json_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result, if (!g->Xchk) { if (!CheckMemory(g, initid, args, args->arg_count, false, true)) { - PJOB objp = new(g)JOBJECT; + PJOB objp; + + if ((objp = (PJOB)JsonNew(g, TYPE_JOB))) { + for (uint i = 0; i < args->arg_count; i += 2) + objp->SetValue(g, MakeValue(g, args, i + 1), MakePSZ(g, args, i)); - for (uint i = 0; i < args->arg_count; i += 2) - objp->SetValue(g, MakeValue(g, args, i+1), MakePSZ(g, args, i)); + str = Serialize(g, objp, NULL, 0); + } // endif objp - str = Serialize(g, objp, NULL, 0); } // endif CheckMemory if (!str) @@ -2731,6 +2916,82 @@ void json_object_list_deinit(UDF_INIT* initid) JsonFreeMem((PGLOBAL)initid->ptr); } // end of json_object_list_deinit +/*********************************************************************************/ +/* Returns an array of the Json object values. */ +/*********************************************************************************/ +my_bool json_object_values_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + unsigned long reslen, memlen; + + if (args->arg_count != 1) { + strcpy(message, "This function must have 1 argument"); + return true; + } else if (!IsJson(args, 0) && args->arg_type[0] != STRING_RESULT) { + strcpy(message, "Argument must be a json object"); + return true; + } else + CalcLen(args, false, reslen, memlen); + + return JsonInit(initid, args, message, true, reslen, memlen); +} // end of json_object_list_init + +char *json_object_values(UDF_INIT *initid, UDF_ARGS *args, char *result, + unsigned long *res_length, char *is_null, char *error) +{ + char *str = NULL; + PGLOBAL g = (PGLOBAL)initid->ptr; + + if (!g->N) { + if (!CheckMemory(g, initid, args, 1, true, true)) { + char *p; + PJSON jsp; + PJVAL jvp = MakeValue(g, args, 0); + + if ((p = jvp->GetString(g))) { + if (!(jsp = ParseJson(g, p, strlen(p)))) { + PUSH_WARNING(g->Message); + return NULL; + } // endif jsp + + } else + jsp = jvp->GetJson(); + + if (jsp->GetType() == TYPE_JOB) { + PJAR jarp = ((PJOB)jsp)->GetValList(g); + + if (!(str = Serialize(g, jarp, NULL, 0))) + PUSH_WARNING(g->Message); + + } else { + PUSH_WARNING("First argument is not an object"); + if (g->Mrr) *error = 1; + } // endif jvp + + } // endif CheckMemory + + if (initid->const_item) { + // Keep result of constant function + g->Xchk = str; + g->N = 1; // str can be NULL + } // endif const_item + + } else + str = (char*)g->Xchk; + + if (!str) { + *is_null = 1; + *res_length = 0; + } else + *res_length = strlen(str); + + return str; +} // end of json_object_values + +void json_object_values_deinit(UDF_INIT* initid) +{ + JsonFreeMem((PGLOBAL)initid->ptr); +} // end of json_object_values_deinit + /*********************************************************************************/ /* Set the value of JsonGrpSize. */ /*********************************************************************************/ @@ -2795,7 +3056,7 @@ my_bool json_array_grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message) PGLOBAL g = (PGLOBAL)initid->ptr; PlugSubSet(g, g->Sarea, g->Sarea_Size); - g->Activityp = (PACTIVITY)new(g) JARRAY; + g->Activityp = (PACTIVITY)JsonNew(g, TYPE_JAR); g->N = (int)n; return false; } // end of json_array_grp_init @@ -2805,7 +3066,7 @@ void json_array_grp_add(UDF_INIT *initid, UDF_ARGS *args, char*, char*) PGLOBAL g = (PGLOBAL)initid->ptr; PJAR arp = (PJAR)g->Activityp; - if (g->N-- > 0) + if (arp && g->N-- > 0) arp->AddValue(g, MakeValue(g, args, 0)); } // end of json_array_grp_add @@ -2820,12 +3081,16 @@ char *json_array_grp(UDF_INIT *initid, UDF_ARGS *, char *result, if (g->N < 0) PUSH_WARNING("Result truncated to json_grp_size values"); - arp->InitArray(g); + if (arp) { + arp->InitArray(g); + str = Serialize(g, arp, NULL, 0); + } else + str = NULL; - if (!(str = Serialize(g, arp, NULL, 0))) - str = strcpy(result, g->Message); + if (!str) + str = strcpy(result, g->Message); - *res_length = strlen(str); + *res_length = strlen(str); return str; } // end of json_array_grp @@ -2834,8 +3099,8 @@ void json_array_grp_clear(UDF_INIT *initid, char*, char*) PGLOBAL g = (PGLOBAL)initid->ptr; PlugSubSet(g, g->Sarea, g->Sarea_Size); - g->Activityp = (PACTIVITY)new(g) JARRAY; - g->N = GetJsonGroupSize(); + g->Activityp = (PACTIVITY)JsonNew(g, TYPE_JAR); + g->N = GetJsonGroupSize(); } // end of json_array_grp_clear void json_array_grp_deinit(UDF_INIT* initid) @@ -2868,7 +3133,7 @@ my_bool json_object_grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message) PGLOBAL g = (PGLOBAL)initid->ptr; PlugSubSet(g, g->Sarea, g->Sarea_Size); - g->Activityp = (PACTIVITY)new(g) JOBJECT; + g->Activityp = (PACTIVITY)JsonNew(g, TYPE_JOB); g->N = (int)n; return false; } // end of json_object_grp_init @@ -2893,7 +3158,7 @@ char *json_object_grp(UDF_INIT *initid, UDF_ARGS *, char *result, if (g->N < 0) PUSH_WARNING("Result truncated to json_grp_size values"); - if (!(str = Serialize(g, objp, NULL, 0))) + if (!objp || !(str = Serialize(g, objp, NULL, 0))) str = strcpy(result, g->Message); *res_length = strlen(str); @@ -2905,8 +3170,8 @@ void json_object_grp_clear(UDF_INIT *initid, char*, char*) PGLOBAL g = (PGLOBAL)initid->ptr; PlugSubSet(g, g->Sarea, g->Sarea_Size); - g->Activityp = (PACTIVITY)new(g) JOBJECT; - g->N = GetJsonGroupSize(); + g->Activityp = (PACTIVITY)JsonNew(g, TYPE_JOB); + g->N = GetJsonGroupSize(); } // end of json_object_grp_clear void json_object_grp_deinit(UDF_INIT* initid) @@ -3051,7 +3316,7 @@ my_bool json_get_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message) char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *) { - char *p, *path, *str = NULL; + char *path, *str = NULL; PJSON jsp; PJVAL jvp; PJSNX jsx; @@ -3067,17 +3332,10 @@ char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, if (CheckMemory(g, initid, args, 1, true, true)) { PUSH_WARNING("CheckMemory error"); goto fin; - } else - jvp = MakeValue(g, args, 0); - - if ((p = jvp->GetString(g))) { - if (!(jsp = ParseJson(g, p, strlen(p)))) { - PUSH_WARNING(g->Message); - return NULL; - } // endif jsp + } // endif CheckMemory - } else - jsp = jvp->GetJson(); + jvp = MakeTypedValue(g, args, 0, TYPE_JSON); + jsp = jvp->GetJson(); if (g->Mrr) { // First argument is a constant g->Xchk = jsp; @@ -3088,9 +3346,9 @@ char *json_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, jsp = (PJSON)g->Xchk; path = MakePSZ(g, args, 1); - jsx = new(g) JSNX(g, jsp, TYPE_STRING, initid->max_length); + jsx = JsnxNew(g, jsp, TYPE_STRING, initid->max_length); - if (jsx->SetJpath(g, path, true)) { + if (!jsx || jsx->SetJpath(g, path, true)) { PUSH_WARNING(g->Message); *is_null = 1; return NULL; @@ -3203,9 +3461,9 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, jsp = (PJSON)g->Xchk; path = MakePSZ(g, args, 1); - jsx = new(g) JSNX(g, jsp, TYPE_STRING, initid->max_length); + jsx = JsnxNew(g, jsp, TYPE_STRING, initid->max_length); - if (jsx->SetJpath(g, path)) { + if (!jsx || jsx->SetJpath(g, path)) { PUSH_WARNING(g->Message); goto err; } // endif SetJpath @@ -3220,7 +3478,7 @@ char *jsonget_string(UDF_INIT *initid, UDF_ARGS *args, char *result, g->Activityp = (PACTIVITY)str; } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); PUSH_WARNING(g->Message); @@ -3320,9 +3578,9 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args, jsp = (PJSON)g->Xchk; path = MakePSZ(g, args, 1); - jsx = new(g) JSNX(g, jsp, TYPE_BIGINT); + jsx = JsnxNew(g, jsp, TYPE_BIGINT); - if (jsx->SetJpath(g, path)) { + if (!jsx || jsx->SetJpath(g, path)) { PUSH_WARNING(g->Message); *is_null = 1; return 0; @@ -3339,9 +3597,14 @@ long long jsonget_int(UDF_INIT *initid, UDF_ARGS *args, if (initid->const_item) { // Keep result of constant function - long long *np = (long long*)PlugSubAlloc(g, NULL, sizeof(long long)); - *np = n; - g->Activityp = (PACTIVITY)np; + long long *np = (long long*)PlgDBSubAlloc(g, NULL, sizeof(long long)); + + if (np) { + *np = n; + g->Activityp = (PACTIVITY)np; + } else + PUSH_WARNING(g->Message); + } // endif const_item return n; @@ -3434,9 +3697,9 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args, jsp = (PJSON)g->Xchk; path = MakePSZ(g, args, 1); - jsx = new(g) JSNX(g, jsp, TYPE_DOUBLE); + jsx = JsnxNew(g, jsp, TYPE_DOUBLE); - if (jsx->SetJpath(g, path)) { + if (!jsx || jsx->SetJpath(g, path)) { PUSH_WARNING(g->Message); *is_null = 1; return 0.0; @@ -3453,9 +3716,17 @@ double jsonget_real(UDF_INIT *initid, UDF_ARGS *args, if (initid->const_item) { // Keep result of constant function - double *dp = (double*)PlugSubAlloc(g, NULL, sizeof(double)); - *dp = d; - g->Activityp = (PACTIVITY)dp; + double *dp; + + if ((dp = (double*)PlgDBSubAlloc(g, NULL, sizeof(double)))) { + *dp = d; + g->Activityp = (PACTIVITY)dp; + } else { + PUSH_WARNING(g->Message); + *is_null = 1; + return 0.0; + } // endif dp + } // endif const_item return d; @@ -3501,7 +3772,7 @@ my_bool jsonlocate_init(UDF_INIT *initid, UDF_ARGS *args, char *message) char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error) { - char *p, *path = NULL; + char *path = NULL; int k; PJVAL jvp, jvp2; PJSON jsp; @@ -3529,16 +3800,20 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, *error = 1; goto err; } else - jvp = MakeValue(g, args, 0); - - if ((p = jvp->GetString(g))) { - if (!(jsp = ParseJson(g, p, strlen(p)))) { - PUSH_WARNING(g->Message); - goto err; - } // endif jsp - - } else - jsp = jvp->GetJson(); + jvp = MakeTypedValue(g, args, 0, TYPE_JSON); + + //if ((p = jvp->GetString(g))) { + // if (!(jsp = ParseJson(g, p, strlen(p)))) { + // PUSH_WARNING(g->Message); + // goto err; + // } // endif jsp + //} else + // jsp = jvp->GetJson(); + + if (!(jsp = jvp->GetJson())) { + PUSH_WARNING("First argument is not a valid JSON item"); + goto err; + } // endif jsp if (g->Mrr) { // First argument is a constant g->Xchk = jsp; @@ -3561,7 +3836,7 @@ char *jsonlocate(UDF_INIT *initid, UDF_ARGS *args, char *result, g->Activityp = (PACTIVITY)path; } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); PUSH_WARNING(g->Message); @@ -3686,7 +3961,7 @@ char *json_locate_all(UDF_INIT *initid, UDF_ARGS *args, char *result, g->Activityp = (PACTIVITY)path; } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); PUSH_WARNING(g->Message); @@ -3845,9 +4120,9 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result, jsp = (PJSON)g->Xchk; path = MakePSZ(g, args, 1); - jsx = new(g)JSNX(g, jsp, TYPE_BIGINT); + jsx = JsnxNew(g, jsp, TYPE_BIGINT); - if (jsx->SetJpath(g, path)) { + if (!jsx || jsx->SetJpath(g, path)) { PUSH_WARNING(g->Message); goto err; } // endif SetJpath @@ -3856,9 +4131,14 @@ long long jsoncontains_path(UDF_INIT *initid, UDF_ARGS *args, char *result, if (initid->const_item) { // Keep result of constant function - long long *np = (long long*)PlugSubAlloc(g, NULL, sizeof(long long)); - *np = n; - g->Activityp = (PACTIVITY)np; + long long *np = (long long*)PlgDBSubAlloc(g, NULL, sizeof(long long)); + + if (np) { + *np = n; + g->Activityp = (PACTIVITY)np; + } else + PUSH_WARNING(g->Message); + } // endif const_item return n; @@ -3961,7 +4241,7 @@ char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, g->Activityp = (PACTIVITY)str; } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); PUSH_WARNING(g->Message); @@ -4335,18 +4615,23 @@ char *jbin_array(UDF_INIT *initid, UDF_ARGS *args, char *result, if (!bsp || bsp->Changed) { if (!CheckMemory(g, initid, args, args->arg_count, false)) { - PJAR arp = new(g) JARRAY; + PJAR arp; - bsp = JbinAlloc(g, args, initid->max_length, arp); - strcat(bsp->Msg, " array"); + if ((arp = (PJAR)JsonNew(g, TYPE_JAR)) && + (bsp = JbinAlloc(g, args, initid->max_length, arp))) { + strcat(bsp->Msg, " array"); - for (uint i = 0; i < args->arg_count; i++) - arp->AddValue(g, MakeValue(g, args, i)); + for (uint i = 0; i < args->arg_count; i++) + arp->AddValue(g, MakeValue(g, args, i)); + + arp->InitArray(g); + } // endif arp && bsp - arp->InitArray(g); } else - if ((bsp = JbinAlloc(g, args, initid->max_length, NULL))) - strncpy(bsp->Msg, g->Message, 139); + bsp = NULL; + + if (!bsp && (bsp = JbinAlloc(g, args, initid->max_length, NULL))) + strncpy(bsp->Msg, g->Message, 139); // Keep result of constant function g->Xchk = (initid->const_item) ? bsp : NULL; @@ -4377,9 +4662,6 @@ my_bool jbin_array_add_values_init(UDF_INIT *initid, UDF_ARGS *args, char *messa if (args->arg_count < 2) { strcpy(message, "This function must have at least 2 arguments"); return true; - } else if (!IsJson(args, 0) && args->arg_type[0] != STRING_RESULT) { - strcpy(message, "First argument must be a json string or item"); - return true; } else CalcLen(args, false, reslen, memlen); @@ -4394,24 +4676,17 @@ char *jbin_array_add_values(UDF_INIT *initid, UDF_ARGS *args, char *result, if (!bsp || bsp->Changed) { if (!CheckMemory(g, initid, args, args->arg_count, true)) { - char *p; PJSON top; PJAR arp; - PJVAL jvp = MakeValue(g, args, 0, &top); + PJVAL jvp = MakeTypedValue(g, args, 0, TYPE_JAR, &top); PGLOBAL gb = GetMemPtr(g, args, 0); - if ((p = jvp->GetString(g))) { - if (!(top = ParseJson(g, p, strlen(p)))) { - PUSH_WARNING(g->Message); - return NULL; - } // endif jsp - - jvp->SetValue(top); - } // endif p - if (jvp->GetValType() != TYPE_JAR) { - arp = new(gb)JARRAY; - arp->AddValue(gb, jvp); + if ((arp = (PJAR)JsonNew(gb, TYPE_JAR))) { + arp->AddValue(gb, jvp); + top = arp; + } // endif arp + } else arp = jvp->GetArray(); @@ -4458,9 +4733,9 @@ my_bool jbin_array_add_init(UDF_INIT *initid, UDF_ARGS *args, char *message) if (args->arg_count < 2) { strcpy(message, "This function must have at least 2 arguments"); return true; - } else if (!IsJson(args, 0)) { - strcpy(message, "First argument must be a json item"); - return true; + //} else if (!IsJson(args, 0)) { + // strcpy(message, "First argument must be a json item"); + // return true; } else CalcLen(args, false, reslen, memlen, true); @@ -4488,20 +4763,32 @@ char *jbin_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result, PJVAL jvp; PJAR arp; - jvp = MakeValue(g, args, 0, &top); -// jsp = jvp->GetJson(); + jvp = MakeTypedValue(g, args, 0, TYPE_JSON, &top); + // jsp = jvp->GetJson(); x = GetIntArgPtr(g, args, n); if (CheckPath(g, args, top, jvp, n)) PUSH_WARNING(g->Message); - else if (jvp && jvp->GetValType() == TYPE_JAR) { + else if (jvp) { PGLOBAL gb = GetMemPtr(g, args, 0); - arp = jvp->GetArray(); + if (jvp->GetValType() != TYPE_JAR) { + if ((arp = (PJAR)JsonNew(gb, TYPE_JAR))) { + arp->AddValue(gb, (PJVAL)JvalNew(gb, TYPE_JVAL, jvp)); + jvp->SetValue(arp); + + if (!top) + top = arp; + + } // endif arp + + } else + arp = jvp->GetArray(); + arp->AddValue(gb, MakeValue(gb, args, 1), x); arp->InitArray(gb); } else { - PUSH_WARNING("First argument is not an array"); + PUSH_WARNING("First argument target is not an array"); // if (g->Mrr) *error = 1; (only if no path) } // endif jvp @@ -4539,9 +4826,6 @@ my_bool jbin_array_delete_init(UDF_INIT *initid, UDF_ARGS *args, char *message) if (args->arg_count < 2) { strcpy(message, "This function must have at least 2 arguments"); return true; - } else if (!IsJson(args, 0)) { - strcpy(message, "First argument must be a json item"); - return true; } else CalcLen(args, false, reslen, memlen, true); @@ -4565,7 +4849,7 @@ char *jbin_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, int *x; uint n = 1; PJAR arp; - PJVAL jvp = MakeValue(g, args, 0, &top); + PJVAL jvp = MakeTypedValue(g, args, 0, TYPE_JSON, &top); if (CheckPath(g, args, top, jvp, 1)) PUSH_WARNING(g->Message); @@ -4578,8 +4862,8 @@ char *jbin_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, PUSH_WARNING("Missing or null array index"); } else { - PUSH_WARNING("First argument is not an array"); - if (g->Mrr) *error = 1; + PUSH_WARNING("First argument target is not an array"); +// if (g->Mrr) *error = 1; } // endif jvp } // endif CheckMemory @@ -4625,13 +4909,18 @@ char *jbin_object(UDF_INIT *initid, UDF_ARGS *args, char *result, if (!bsp || bsp->Changed) { if (!CheckMemory(g, initid, args, args->arg_count, true)) { - PJOB objp = new(g)JOBJECT; + PJOB objp; - for (uint i = 0; i < args->arg_count; i++) - objp->SetValue(g, MakeValue(g, args, i), MakeKey(g, args, i)); + if ((objp = (PJOB)JsonNew(g, TYPE_JOB))) { + for (uint i = 0; i < args->arg_count; i++) + objp->SetValue(g, MakeValue(g, args, i), MakeKey(g, args, i)); + + + if ((bsp = JbinAlloc(g, args, initid->max_length, objp))) + strcat(bsp->Msg, " object"); - if ((bsp = JbinAlloc(g, args, initid->max_length, objp))) - strcat(bsp->Msg, " object"); + } else + bsp = NULL; } else if ((bsp = JbinAlloc(g, args, initid->max_length, NULL))) @@ -4676,14 +4965,18 @@ char *jbin_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result, if (!bsp || bsp->Changed) { if (!CheckMemory(g, initid, args, args->arg_count, false, true)) { PJVAL jvp; - PJOB objp = new(g)JOBJECT; + PJOB objp; - for (uint i = 0; i < args->arg_count; i++) - if (!(jvp = MakeValue(g, args, i))->IsNull()) - objp->SetValue(g, jvp, MakeKey(g, args, i)); + if ((objp = (PJOB)JsonNew(g, TYPE_JOB))) { + for (uint i = 0; i < args->arg_count; i++) + if (!(jvp = MakeValue(g, args, i))->IsNull()) + objp->SetValue(g, jvp, MakeKey(g, args, i)); - if ((bsp = JbinAlloc(g, args, initid->max_length, objp))) - strcat(bsp->Msg, " object"); + if ((bsp = JbinAlloc(g, args, initid->max_length, objp))) + strcat(bsp->Msg, " object"); + + } else + bsp = NULL; } else if ((bsp = JbinAlloc(g, args, initid->max_length, NULL))) @@ -4732,13 +5025,17 @@ char *jbin_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result, if (!bsp || bsp->Changed) { if (!CheckMemory(g, initid, args, args->arg_count, false, true)) { - PJOB objp = new(g)JOBJECT; + PJOB objp; + + if ((objp = (PJOB)JsonNew(g, TYPE_JOB))) { + for (uint i = 0; i < args->arg_count; i += 2) + objp->SetValue(g, MakeValue(g, args, i + 1), MakePSZ(g, args, i)); - for (uint i = 0; i < args->arg_count; i += 2) - objp->SetValue(g, MakeValue(g, args, i+1), MakePSZ(g, args, i)); + if ((bsp = JbinAlloc(g, args, initid->max_length, objp))) + strcat(bsp->Msg, " object"); - if ((bsp = JbinAlloc(g, args, initid->max_length, objp))) - strcat(bsp->Msg, " object"); + } else + bsp = NULL; } else if ((bsp = JbinAlloc(g, args, initid->max_length, NULL))) @@ -4989,7 +5286,7 @@ my_bool jbin_get_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message) char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error) { - char *p, *path; + char *path; PJSON jsp; PJSNX jsx; PJVAL jvp; @@ -5006,17 +5303,10 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, if (CheckMemory(g, initid, args, 1, true, true)) { PUSH_WARNING("CheckMemory error"); goto fin; - } else - jvp = MakeValue(g, args, 0); - - if ((p = jvp->GetString(g))) { - if (!(jsp = ParseJson(g, p, strlen(p)))) { - PUSH_WARNING(g->Message); - goto fin; - } // endif jsp + } // endif CheckMemory - } else - jsp = jvp->GetJson(); + jvp = MakeTypedValue(g, args, 0, TYPE_JSON); + jsp = jvp->GetJson(); if (g->Mrr) { // First argument is a constant g->Xchk = jsp; @@ -5027,16 +5317,16 @@ char *jbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, jsp = (PJSON)g->Xchk; path = MakePSZ(g, args, 1); - jsx = new(g) JSNX(g, jsp, TYPE_STRING, initid->max_length); + jsx = JsnxNew(g, jsp, TYPE_STRING, initid->max_length); - if (jsx->SetJpath(g, path, false)) { + if (!jsx || jsx->SetJpath(g, path, false)) { PUSH_WARNING(g->Message); goto fin; } // endif SetJpath // Get the json tree if ((jvp = jsx->GetRowValue(g, jsp, 0, false))) { - jsp = (jvp->GetJsp()) ? jvp->GetJsp() : new(g) JVALUE(g, jvp->GetValue()); + jsp = (jvp->GetJsp()) ? jvp->GetJsp() : JvalNew(g, TYPE_VAL, jvp->GetValue()); if ((bsp = JbinAlloc(g, args, initid->max_length, jsp))) strcat(bsp->Msg, " item"); diff --git a/storage/connect/jsonudf.h b/storage/connect/jsonudf.h index cd3b9768f7a..23e8c0e1aed 100644 --- a/storage/connect/jsonudf.h +++ b/storage/connect/jsonudf.h @@ -89,6 +89,10 @@ extern "C" { DllExport char *json_object_list(UDF_EXEC_ARGS); DllExport void json_object_list_deinit(UDF_INIT*); + DllExport my_bool json_object_values_init(UDF_INIT*, UDF_ARGS*, char*); + DllExport char *json_object_values(UDF_EXEC_ARGS); + DllExport void json_object_values_deinit(UDF_INIT*); + DllExport my_bool jsonset_grp_size_init(UDF_INIT*, UDF_ARGS*, char*); DllExport long long jsonset_grp_size(UDF_INIT*, UDF_ARGS*, char*, char*); diff --git a/storage/connect/libdoc.cpp b/storage/connect/libdoc.cpp index 700d247da38..9b30b315441 100644 --- a/storage/connect/libdoc.cpp +++ b/storage/connect/libdoc.cpp @@ -194,7 +194,7 @@ void xtrc(char const *fmt, ...) { va_list ap; va_start (ap, fmt); - + ; //vfprintf(stderr, fmt, ap); vsprintf(s, fmt, ap); if (s[strlen(s)-1] == '\n') @@ -210,7 +210,7 @@ static xmlStrdupFunc Strdup; void xmlMyFree(void *mem) { - if (trace) { + if (trace(1)) { htrc("%.4d Freeing at %p %s\n", ++m, mem, s); *s = 0; } // endif trace @@ -220,7 +220,7 @@ void xmlMyFree(void *mem) void *xmlMyMalloc(size_t size) { void *p = Malloc(size); - if (trace) { + if (trace(1)) { htrc("%.4d Allocating %.5d at %p %s\n", ++m, size, p, s); *s = 0; } // endif trace @@ -230,7 +230,7 @@ void *xmlMyMalloc(size_t size) void *xmlMyMallocAtomic(size_t size) { void *p = MallocA(size); - if (trace) { + if (trace(1)) { htrc("%.4d Atom alloc %.5d at %p %s\n", ++m, size, p, s); *s = 0; } // endif trace @@ -240,7 +240,7 @@ void *xmlMyMallocAtomic(size_t size) void *xmlMyRealloc(void *mem, size_t size) { void *p = Realloc(mem, size); - if (trace) { + if (trace(1)) { htrc("%.4d ReAlloc %.5d to %p from %p %s\n", ++m, size, p, mem, s); *s = 0; } // endif trace @@ -250,7 +250,7 @@ void *xmlMyRealloc(void *mem, size_t size) char *xmlMyStrdup(const char *str) { char *p = Strdup(str); - if (trace) { + if (trace(1)) { htrc("%.4d Duplicating to %p from %p %s %s\n", ++m, p, str, str, s); *s = 0; } // endif trace @@ -339,7 +339,7 @@ void CloseXML2File(PGLOBAL g, PFBLOCK fp, bool all) { PX2BLOCK xp = (PX2BLOCK)fp; - if (trace) + if (trace(1)) htrc("CloseXML2File: xp=%p count=%d\n", xp, (xp) ? xp->Count : 0); if (xp && xp->Count > 1 && !all) { @@ -387,7 +387,7 @@ bool LIBXMLDOC::Initialize(PGLOBAL g, PCSZ entry, bool zipped) /******************************************************************/ bool LIBXMLDOC::ParseFile(PGLOBAL g, char *fn) { - if (trace) + if (trace(1)) htrc("ParseFile\n"); if (zip) { @@ -436,7 +436,7 @@ PFBLOCK LIBXMLDOC::LinkXblock(PGLOBAL g, MODE m, int rc, char *fn) /******************************************************************/ bool LIBXMLDOC::NewDoc(PGLOBAL g, PCSZ ver) { - if (trace) + if (trace(1)) htrc("NewDoc\n"); return ((Docp = xmlNewDoc(BAD_CAST ver)) == NULL); @@ -447,7 +447,7 @@ bool LIBXMLDOC::NewDoc(PGLOBAL g, PCSZ ver) /******************************************************************/ void LIBXMLDOC::AddComment(PGLOBAL g, char *txtp) { - if (trace) + if (trace(1)) htrc("AddComment: %s\n", txtp); xmlNodePtr cp = xmlNewDocComment(Docp, BAD_CAST txtp); @@ -459,7 +459,7 @@ void LIBXMLDOC::AddComment(PGLOBAL g, char *txtp) /******************************************************************/ PXNODE LIBXMLDOC::GetRoot(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("GetRoot\n"); xmlNodePtr root = xmlDocGetRootElement(Docp); @@ -475,7 +475,7 @@ PXNODE LIBXMLDOC::GetRoot(PGLOBAL g) /******************************************************************/ PXNODE LIBXMLDOC::NewRoot(PGLOBAL g, char *name) { - if (trace) + if (trace(1)) htrc("NewRoot: %s\n", name); xmlNodePtr root = xmlNewDocNode(Docp, NULL, BAD_CAST name, NULL); @@ -493,7 +493,7 @@ PXNODE LIBXMLDOC::NewRoot(PGLOBAL g, char *name) /******************************************************************/ PXNODE LIBXMLDOC::NewPnode(PGLOBAL g, char *name) { - if (trace) + if (trace(1)) htrc("NewNode: %s\n", name); xmlNodePtr nop; @@ -534,7 +534,7 @@ int LIBXMLDOC::DumpDoc(PGLOBAL g, char *ofn) int rc = 0; FILE *of; - if (trace) + if (trace(1)) htrc("DumpDoc: %s\n", ofn); if (!(of= global_fopen(g, MSGID_CANNOT_OPEN, ofn, "w"))) @@ -576,7 +576,7 @@ int LIBXMLDOC::DumpDoc(PGLOBAL g, char *ofn) /******************************************************************/ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp) { - if (trace) + if (trace(1)) htrc("CloseDoc: xp=%p count=%d\n", xp, (xp) ? xp->Count : 0); //if (xp && xp->Count == 1) { @@ -630,24 +630,24 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp) { xmlNodeSetPtr nl; - if (trace) + if (trace(1)) htrc("GetNodeList: %s np=%p\n", xp, np); if (!Ctxp) { // Init Xpath - if (trace) + if (trace(1)) htrc("Calling xmlPathInit\n"); xmlXPathInit(); - if (trace) + if (trace(1)) htrc("Calling xmlXPathNewContext Docp=%p\n", Docp); // Create xpath evaluation context if (!(Ctxp = xmlXPathNewContext(Docp))) { strcpy(g->Message, MSG(XPATH_CNTX_ERR)); - if (trace) + if (trace(1)) htrc("Context error: %s\n", g->Message); return NULL; @@ -655,7 +655,7 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp) // Register namespaces from list (if any) for (PNS nsp = Namespaces; nsp; nsp = nsp->Next) { - if (trace) + if (trace(1)) htrc("Calling xmlXPathRegisterNs Prefix=%s Uri=%s\n", nsp->Prefix, nsp->Uri); @@ -663,7 +663,7 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp) BAD_CAST nsp->Uri)) { sprintf(g->Message, MSG(REGISTER_ERR), nsp->Prefix, nsp->Uri); - if (trace) + if (trace(1)) htrc("Ns error: %s\n", g->Message); return NULL; @@ -674,7 +674,7 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp) } // endif Ctxp if (Xop) { - if (trace) + if (trace(1)) htrc("Calling xmlXPathFreeNodeSetList Xop=%p NOFREE=%d\n", Xop, Nofreelist); @@ -698,21 +698,21 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp) // Set the context to the calling node Ctxp->node = np; - if (trace) + if (trace(1)) htrc("Calling xmlXPathEval %s Ctxp=%p\n", xp, Ctxp); // Evaluate table xpath if (!(Xop = xmlXPathEval(BAD_CAST xp, Ctxp))) { sprintf(g->Message, MSG(XPATH_EVAL_ERR), xp); - if (trace) + if (trace(1)) htrc("Path error: %s\n", g->Message); return NULL; } else nl = Xop->nodesetval; - if (trace) + if (trace(1)) htrc("GetNodeList nl=%p n=%p\n", nl, (nl) ? nl->nodeNr : 0); return nl; @@ -811,7 +811,7 @@ XML2NODE::XML2NODE(PXDOC dp, xmlNodePtr np) : XMLNODE(dp) int XML2NODE::GetType(void) { - if (trace) + if (trace(1)) htrc("GetType type=%d\n", Nodep->type); return Nodep->type; @@ -822,7 +822,7 @@ int XML2NODE::GetType(void) /******************************************************************/ PXNODE XML2NODE::GetNext(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("GetNext\n"); if (!Nodep->next) @@ -838,7 +838,7 @@ PXNODE XML2NODE::GetNext(PGLOBAL g) /******************************************************************/ PXNODE XML2NODE::GetChild(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("GetChild\n"); if (!Nodep->children) @@ -856,7 +856,7 @@ RCODE XML2NODE::GetContent(PGLOBAL g, char *buf, int len) { RCODE rc = RC_OK; - if (trace) + if (trace(1)) htrc("GetContent\n"); if (Content) @@ -888,7 +888,7 @@ RCODE XML2NODE::GetContent(PGLOBAL g, char *buf, int len) *p2 = 0; - if (trace) + if (trace(1)) htrc("GetText buf='%s' len=%d\n", buf, len); xmlFree(Content); @@ -896,7 +896,7 @@ RCODE XML2NODE::GetContent(PGLOBAL g, char *buf, int len) } else *buf = '\0'; - if (trace) + if (trace(1)) htrc("GetContent: %s\n", buf); return rc; @@ -907,12 +907,12 @@ RCODE XML2NODE::GetContent(PGLOBAL g, char *buf, int len) /******************************************************************/ bool XML2NODE::SetContent(PGLOBAL g, char *txtp, int len) { - if (trace) + if (trace(1)) htrc("SetContent: %s\n", txtp); xmlChar *buf = xmlEncodeEntitiesReentrant(Docp, BAD_CAST txtp); - if (trace) + if (trace(1)) htrc("SetContent: %s -> %s\n", txtp, buf); xmlNodeSetContent(Nodep, buf); @@ -925,7 +925,7 @@ bool XML2NODE::SetContent(PGLOBAL g, char *txtp, int len) /******************************************************************/ PXNODE XML2NODE::Clone(PGLOBAL g, PXNODE np) { - if (trace) + if (trace(1)) htrc("Clone: np=%p\n", np); if (np) { @@ -941,7 +941,7 @@ PXNODE XML2NODE::Clone(PGLOBAL g, PXNODE np) /******************************************************************/ PXLIST XML2NODE::GetChildElements(PGLOBAL g, char *xp, PXLIST lp) { - if (trace) + if (trace(1)) htrc("GetChildElements: %s\n", xp); return SelectNodes(g, (xp) ? xp : (char*)"*", lp); @@ -952,7 +952,7 @@ PXLIST XML2NODE::GetChildElements(PGLOBAL g, char *xp, PXLIST lp) /******************************************************************/ PXLIST XML2NODE::SelectNodes(PGLOBAL g, char *xp, PXLIST lp) { - if (trace) + if (trace(1)) htrc("SelectNodes: %s\n", xp); xmlNodeSetPtr nl = ((PXDOC2)Doc)->GetNodeList(g, Nodep, xp); @@ -970,7 +970,7 @@ PXLIST XML2NODE::SelectNodes(PGLOBAL g, char *xp, PXLIST lp) /******************************************************************/ PXNODE XML2NODE::SelectSingleNode(PGLOBAL g, char *xp, PXNODE np) { - if (trace) + if (trace(1)) htrc("SelectSingleNode: %s\n", xp); xmlNodeSetPtr nl = ((PXDOC2)Doc)->GetNodeList(g, Nodep, xp); @@ -994,7 +994,7 @@ PXATTR XML2NODE::GetAttribute(PGLOBAL g, char *name, PXATTR ap) { xmlAttrPtr atp; - if (trace) + if (trace(1)) htrc("GetAttribute: %s\n", SVP(name)); if (name) @@ -1023,7 +1023,7 @@ PXNODE XML2NODE::AddChildNode(PGLOBAL g, PCSZ name, PXNODE np) { char *p, *pn, *pf = NULL, *nmp = PlugDup(g, name); - if (trace) + if (trace(1)) htrc("AddChildNode: %s\n", name); // Is a prefix specified @@ -1074,7 +1074,7 @@ PXNODE XML2NODE::AddChildNode(PGLOBAL g, PCSZ name, PXNODE np) /******************************************************************/ PXATTR XML2NODE::AddProperty(PGLOBAL g, char *name, PXATTR ap) { - if (trace) + if (trace(1)) htrc("AddProperty: %s\n", name); xmlAttrPtr atp = xmlNewProp(Nodep, BAD_CAST name, NULL); @@ -1097,7 +1097,7 @@ PXATTR XML2NODE::AddProperty(PGLOBAL g, char *name, PXATTR ap) /******************************************************************/ void XML2NODE::AddText(PGLOBAL g, PCSZ txtp) { - if (trace) + if (trace(1)) htrc("AddText: %s\n", txtp); // This is to avoid a blank line when inserting a new line @@ -1119,7 +1119,7 @@ void XML2NODE::DeleteChild(PGLOBAL g, PXNODE dnp) { xmlErrorPtr xerr; - if (trace) + if (trace(1)) htrc("DeleteChild: node=%p\n", dnp); xmlNodePtr np = ((PNODE2)dnp)->Nodep; @@ -1157,7 +1157,7 @@ void XML2NODE::DeleteChild(PGLOBAL g, PXNODE dnp) return; err: - if (trace) + if (trace(1)) htrc("DeleteChild: errmsg=%s\n", xerr->message); xmlResetError(xerr); @@ -1187,7 +1187,7 @@ int XML2NODELIST::GetLength(void) /******************************************************************/ PXNODE XML2NODELIST::GetItem(PGLOBAL g, int n, PXNODE np) { - if (trace) + if (trace(1)) htrc("GetItem: %d\n", n); if (!Listp || Listp->nodeNr <= n) @@ -1206,7 +1206,7 @@ PXNODE XML2NODELIST::GetItem(PGLOBAL g, int n, PXNODE np) /******************************************************************/ bool XML2NODELIST::DropItem(PGLOBAL g, int n) { - if (trace) + if (trace(1)) htrc("DropItem: n=%d\n", n); // We should do something here @@ -1234,7 +1234,7 @@ XML2ATTR::XML2ATTR(PXDOC dp, xmlAttrPtr ap, xmlNodePtr np) /******************************************************************/ PXATTR XML2ATTR::GetNext(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("Attr GetNext\n"); if (!Atrp->next) @@ -1252,7 +1252,7 @@ RCODE XML2ATTR::GetText(PGLOBAL g, char *buf, int len) RCODE rc = RC_OK; xmlChar *txt; - if (trace) + if (trace(1)) htrc("GetText\n"); if ((txt = xmlGetProp(Atrp->parent, Atrp->name))) { @@ -1269,7 +1269,7 @@ RCODE XML2ATTR::GetText(PGLOBAL g, char *buf, int len) } else *buf = '\0'; - if (trace) + if (trace(1)) htrc("GetText: %s\n", buf); return rc; @@ -1280,7 +1280,7 @@ RCODE XML2ATTR::GetText(PGLOBAL g, char *buf, int len) /******************************************************************/ bool XML2ATTR::SetText(PGLOBAL g, char *txtp, int len) { - if (trace) + if (trace(1)) htrc("SetText: %s %d\n", txtp, len); xmlSetProp(Parent, Atrp->name, BAD_CAST txtp); diff --git a/storage/connect/macutil.cpp b/storage/connect/macutil.cpp index b9600bdac2e..f95f3adcc6e 100644 --- a/storage/connect/macutil.cpp +++ b/storage/connect/macutil.cpp @@ -230,13 +230,13 @@ bool MACINFO::GetOneInfo(PGLOBAL g, int flag, void *v, int lv) case 11: // Description if ((p = strstr(Curp->Description, " - Packet Scheduler Miniport"))) { strncpy(buf, Curp->Description, p - Curp->Description); - i = p - Curp->Description; + i = (int)(p - Curp->Description); strncpy(buf, Curp->Description, i); buf[i] = 0; p = buf; } else if ((p = strstr(Curp->Description, " - Miniport d'ordonnancement de paquets"))) { - i = p - Curp->Description; + i = (int)(p - Curp->Description); strncpy(buf, Curp->Description, i); buf[i] = 0; p = buf; diff --git a/storage/connect/mongo.cpp b/storage/connect/mongo.cpp index 088dc2d29d1..53e2bf377c4 100644 --- a/storage/connect/mongo.cpp +++ b/storage/connect/mongo.cpp @@ -172,7 +172,7 @@ PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt, bool info) goto err; skipit: - if (trace) + if (trace(1)) htrc("MGOColumns: n=%d len=%d\n", n, length[0]); /*********************************************************************/ @@ -276,7 +276,7 @@ int MGODISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt) tdp->Wrapname = (PSZ)GetStringTableOption(g, topt, "Wrapper", (tdp->Version == 2) ? "Mongo2Interface" : "Mongo3Interface"); - if (trace) + if (trace(1)) htrc("Uri %s coll=%s db=%s colist=%s filter=%s lvl=%d\n", tdp->Uri, tdp->Tabname, tdp->Tabschema, tdp->Colist, tdp->Filter, lvl); diff --git a/storage/connect/mycat.cc b/storage/connect/mycat.cc index bb77512be62..cc8f75b2976 100644 --- a/storage/connect/mycat.cc +++ b/storage/connect/mycat.cc @@ -94,9 +94,9 @@ #if defined(XML_SUPPORT) #include "tabxml.h" #endif // XML_SUPPORT -#if defined(JAVA_SUPPORT) +#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) #include "mongo.h" -#endif // JAVA_SUPPORT +#endif // JAVA_SUPPORT || CMGO_SUPPORT #if defined(ZIP_SUPPORT) #include "tabzip.h" #endif // ZIP_SUPPORT @@ -109,9 +109,10 @@ extern "C" HINSTANCE s_hModule; // Saved module handle #endif // !__WIN__ -#if defined(JAVA_SUPPORT) -//bool MongoEnabled(void); -#endif // JAVA_SUPPORT +#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) +bool MongoEnabled(void); +#endif // JAVA_SUPPORT || CMGO_SUPPORT + PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info); /***********************************************************************/ @@ -145,6 +146,9 @@ TABTYPE GetTypeID(const char *type) #if defined(JAVA_SUPPORT) : (!stricmp(type, "JDBC")) ? TAB_JDBC : (!stricmp(type, "MONGO")) ? TAB_MONGO +#endif +#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) + : (!stricmp(type, "MONGO") && MongoEnabled()) ? TAB_MONGO #endif : (!stricmp(type, "MYSQL")) ? TAB_MYSQL : (!stricmp(type, "MYPRX")) ? TAB_MYSQL @@ -488,7 +492,7 @@ void MYCAT::Reset(void) PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR type, PRELDEF *) { - if (trace) + if (trace(1)) printf("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type)); // If not specified get the type of this table @@ -509,7 +513,7 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) LPCSTR schema = (PSZ)PlugDup(g, tablep->GetSchema()); PRELDEF tdp= NULL; - if (trace) + if (trace(1)) printf("MakeTableDesc: name=%s schema=%s am=%s\n", name, SVP(schema), SVP(am)); @@ -562,8 +566,16 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) break; #endif // MONGO_SUPPORT #if defined(ZIP_SUPPORT) - case TAB_ZIP: tdp= new(g) ZIPDEF; break; + case TAB_ZIP: tdp = new(g) ZIPDEF; break; #endif // ZIP_SUPPORT +#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) + case TAB_MONGO: + if (MongoEnabled()) { + tdp = new(g) MGODEF; + break; + } // endif enabled + // fall through +#endif // JAVA_SUPPORT || CMGO_SUPPORT default: sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name); } // endswitch @@ -584,14 +596,14 @@ PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type) PTDB tdbp= NULL; // LPCSTR name= tablep->GetName(); - if (trace) + if (trace(1)) printf("GetTableDB: name=%s\n", tablep->GetName()); // Look for the description of the requested table tdp= GetTableDesc(g, tablep, type); if (tdp) { - if (trace) + if (trace(1)) printf("tdb=%p type=%s\n", tdp, tdp->GetType()); if (tablep->GetSchema()) @@ -601,7 +613,7 @@ PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type) } // endif tdp if (tdbp) { - if (trace) + if (trace(1)) printf("tdbp=%p name=%s amtype=%d\n", tdbp, tdbp->GetName(), tdbp->GetAmType()); tablep->SetTo_Tdb(tdbp); diff --git a/storage/connect/myconn.cpp b/storage/connect/myconn.cpp index fe00f6a1eab..253c42bb002 100644 --- a/storage/connect/myconn.cpp +++ b/storage/connect/myconn.cpp @@ -177,7 +177,7 @@ PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db, return NULL; } // endif b - if (trace) + if (trace(1)) htrc("MyColumns: cmd='%s'\n", cmd.GetStr()); if ((n = myc.GetResultSize(g, cmd.GetStr())) < 0) { @@ -248,7 +248,7 @@ PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db, while (true) { p2 = strchr(p1, '\''); - len = MY_MAX(len, p2 - p1); + len = MY_MAX(len, (int)(p2 - p1)); if (*++p2 != ',') break; p1 = p2 + 2; } // endwhile @@ -482,7 +482,7 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db, return RC_FX; } // endif m_DB - if (trace) + if (trace(1)) htrc("MYSQLC Open: m_DB=%.4X size=%d\n", m_DB, (int)sizeof(*m_DB)); // Removed to do like FEDERATED do @@ -744,7 +744,7 @@ int MYSQLC::ExecSQL(PGLOBAL g, const char *query, int *w) m_Fields = mysql_num_fields(m_Res); m_Rows = (!m_Use) ? (int)mysql_num_rows(m_Res) : 0; - if (trace) + if (trace(1)) htrc("ExecSQL: m_Res=%.4X size=%d m_Fields=%d m_Rows=%d\n", m_Res, sizeof(*m_Res), m_Fields, m_Rows); @@ -1068,7 +1068,7 @@ void MYSQLC::Close(void) { FreeResult(); - if (trace) + if (trace(1)) htrc("MYSQLC Close: m_DB=%.4X\n", m_DB); mysql_close(m_DB); diff --git a/storage/connect/mysql-test/connect/r/jdbc_postgresql.result b/storage/connect/mysql-test/connect/r/jdbc_postgresql.result index 6d77d79d5d3..7969672dd66 100644 --- a/storage/connect/mysql-test/connect/r/jdbc_postgresql.result +++ b/storage/connect/mysql-test/connect/r/jdbc_postgresql.result @@ -1,9 +1,11 @@ +SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/JavaWrappers.jar;C:/Jconnectors/postgresql-42.2.1.jar'; CREATE TABLE t2 ( command varchar(128) not null, number int(5) not null flag=1, message varchar(255) flag=2) -ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:postgresql://localhost/mtr' -OPTION_LIST='User=mtr,Password=mtr,Schema=public,Execsrc=1'; +ENGINE=CONNECT TABLE_TYPE=JDBC +CONNECTION='jdbc:postgresql://localhost/test?user=postgres&password=tinono' +OPTION_LIST='Execsrc=1'; SELECT * FROM t2 WHERE command='drop table employee'; command number message drop table employee 0 Execute: org.postgresql.util.PSQLException: ERREUR: la table « employee » n'existe pas @@ -14,17 +16,18 @@ SELECT * FROM t2 WHERE command = "insert into employee values(4567,'Johnson', 'E command number message insert into employee values(4567,'Johnson', 'Engineer', 12560.50) 1 Affected rows CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables -CONNECTION='jdbc:postgresql://localhost/mtr' -OPTION_LIST='User=mtr,Password=mtr,Schema=public,Tabtype=TABLE,Maxres=10'; +CONNECTION='jdbc:postgresql://localhost/test?user=postgres&password=tinono' +OPTION_LIST='Tabtype=TABLE,Maxres=10'; SELECT * FROM t1; Table_Cat Table_Schema Table_Name Table_Type Remark - public employee TABLE NULL - public t1 TABLE NULL - public t2 TABLE NULL +NULL public employee TABLE NULL +NULL public t1 TABLE NULL +NULL public t2 TABLE NULL +NULL public tchar TABLE NULL +NULL public testuuid TABLE NULL DROP TABLE t1; -CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=columns -CONNECTION='jdbc:postgresql://localhost/mtr' tabname=employee -OPTION_LIST='User=mtr,Password=mtr,Maxres=10'; +CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC tabname=employee CATFUNC=columns +CONNECTION='jdbc:postgresql://localhost/test?user=postgres&password=tinono'; SELECT * FROM t1; Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks NULL public employee id 4 int4 10 0 0 10 0 NULL @@ -34,13 +37,14 @@ NULL public employee salary 2 numeric 8 0 2 10 1 NULL DROP TABLE t1; CREATE SERVER 'postgresql' FOREIGN DATA WRAPPER 'postgresql' OPTIONS ( HOST 'localhost', -DATABASE 'mtr', -USER 'mtr', -PASSWORD 'mtr', +DATABASE 'test', +USER 'postgres', +PASSWORD 'tinono', PORT 0, SOCKET '', OWNER 'root'); -CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='postgresql/public.employee'; +CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC +CONNECTION='postgresql/public.employee'; SELECT * FROM t1; id name title salary 4567 Johnson Engineer 12560.50 @@ -60,6 +64,3 @@ SELECT * FROM t2 WHERE command='drop table employee'; command number message drop table employee 0 Affected rows DROP TABLE t2; -SET GLOBAL connect_jvm_path=NULL; -SET GLOBAL connect_class_path=NULL; -SET GLOBAL time_zone = SYSTEM; diff --git a/storage/connect/mysql-test/connect/r/json_java_2.result b/storage/connect/mysql-test/connect/r/json_java_2.result index 783d86e6595..1a90132dede 100644 --- a/storage/connect/mysql-test/connect/r/json_java_2.result +++ b/storage/connect/mysql-test/connect/r/json_java_2.result @@ -1,4 +1,5 @@ -SET GLOBAL connect_class_path='C:/MariaDB-10.1/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar'; +SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar'; +set connect_enable_mongo=1; # # Test the MONGO table type # @@ -381,3 +382,7 @@ planner 167 41.75 postcard 23 5.75 DROP TABLE t1; true +<<<<<<< HEAD +======= +set connect_enable_mongo=0; +>>>>>>> connect/10.0 diff --git a/storage/connect/mysql-test/connect/r/json_java_3.result b/storage/connect/mysql-test/connect/r/json_java_3.result index a301e0273d5..4c5fc94fca6 100644 --- a/storage/connect/mysql-test/connect/r/json_java_3.result +++ b/storage/connect/mysql-test/connect/r/json_java_3.result @@ -1,4 +1,5 @@ -SET GLOBAL connect_class_path='C:/MariaDB-10.1/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo3.jar'; +SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo3.jar'; +set connect_enable_mongo=1; # # Test the MONGO table type # @@ -381,3 +382,4 @@ planner 167 41.75 postcard 23 5.75 DROP TABLE t1; true +set connect_enable_mongo=0; diff --git a/storage/connect/mysql-test/connect/r/json_mongo_c.result b/storage/connect/mysql-test/connect/r/json_mongo_c.result index 8adc006a51b..550e94f286e 100644 --- a/storage/connect/mysql-test/connect/r/json_mongo_c.result +++ b/storage/connect/mysql-test/connect/r/json_mongo_c.result @@ -1,3 +1,4 @@ +set connect_enable_mongo=1; # # Test the MONGO table type # @@ -380,3 +381,4 @@ planner 167 41.75 postcard 23 5.75 DROP TABLE t1; true +set connect_enable_mongo=0; diff --git a/storage/connect/mysql-test/connect/r/json_udf.result b/storage/connect/mysql-test/connect/r/json_udf.result index 7d81ca5e73d..09544bb1ecb 100644 --- a/storage/connect/mysql-test/connect/r/json_udf.result +++ b/storage/connect/mysql-test/connect/r/json_udf.result @@ -50,17 +50,19 @@ SELECT Json_Array_Add(Json_Make_Array(56, 3.1416, 'foo', NULL), 'One more') Arra Array [56,3.141600,"foo",null,"One more"] SELECT Json_Array_Add(JsonValue('one value'), 'One more'); -ERROR HY000: Can't initialize function 'json_array_add'; First argument must be a json item +Json_Array_Add(JsonValue('one value'), 'One more') +["\"one value\"","One more"] SELECT Json_Array_Add('one value', 'One more'); -ERROR HY000: Can't initialize function 'json_array_add'; First argument must be a json item +Json_Array_Add('one value', 'One more') +["one value","One more"] SELECT Json_Array_Add('one value' json_, 'One more'); Json_Array_Add('one value' json_, 'One more') one value Warnings: Warning 1105 Error 2 opening one value -Warning 1105 First argument target is not an array SELECT Json_Array_Add(5 json_, 'One more'); -ERROR HY000: Can't initialize function 'json_array_add'; First argument must be a json item +Json_Array_Add(5 json_, 'One more') +[5,"One more"] SELECT Json_Array_Add('[5,3,8,7,9]' json_, 4, 0); Json_Array_Add('[5,3,8,7,9]' json_, 4, 0) [4,5,3,8,7,9] diff --git a/storage/connect/mysql-test/connect/r/json_udf_bin.result b/storage/connect/mysql-test/connect/r/json_udf_bin.result index 0c009d612fe..d0819619c33 100644 --- a/storage/connect/mysql-test/connect/r/json_udf_bin.result +++ b/storage/connect/mysql-test/connect/r/json_udf_bin.result @@ -272,10 +272,9 @@ Json_Serialize(Jbin_Array('a','b','c')) ["a","b","c"] SELECT Json_Serialize(Jbin_Array_Add(Jbin_File('not_exist.json'), 'd')); Json_Serialize(Jbin_Array_Add(Jbin_File('not_exist.json'), 'd')) -Null json tree +[null,"d"] Warnings: Warning 1105 Open(map) error 2 on not_exist.json -Warning 1105 First argument is not an array # This does not modify the file SELECT Json_Serialize(Jbin_Array_Add(Jbin_File('bt1.json'), 'd')); Json_Serialize(Jbin_Array_Add(Jbin_File('bt1.json'), 'd')) diff --git a/storage/connect/mysql-test/connect/r/mongo_c.result b/storage/connect/mysql-test/connect/r/mongo_c.result index c7aadcf1165..132bb34ce64 100644 --- a/storage/connect/mysql-test/connect/r/mongo_c.result +++ b/storage/connect/mysql-test/connect/r/mongo_c.result @@ -1,3 +1,4 @@ +set connect_enable_mongo=1; # # Test the MONGO table type # @@ -376,3 +377,4 @@ planner 167 41.750000 postcard 23 5.750000 DROP TABLE t1; true +set connect_enable_mongo=0; diff --git a/storage/connect/mysql-test/connect/r/mongo_java_2.result b/storage/connect/mysql-test/connect/r/mongo_java_2.result index 708b6f1cc7c..67c67653e88 100644 --- a/storage/connect/mysql-test/connect/r/mongo_java_2.result +++ b/storage/connect/mysql-test/connect/r/mongo_java_2.result @@ -1,4 +1,5 @@ -SET GLOBAL connect_class_path='C:/MariaDB-10.1/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar'; +SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar'; +set connect_enable_mongo=1; # # Test the MONGO table type # @@ -377,3 +378,4 @@ planner 167 41.75 postcard 23 5.75 DROP TABLE t1; true +set connect_enable_mongo=0; diff --git a/storage/connect/mysql-test/connect/r/mongo_java_3.result b/storage/connect/mysql-test/connect/r/mongo_java_3.result index 672d9f15b80..665178bd3ea 100644 --- a/storage/connect/mysql-test/connect/r/mongo_java_3.result +++ b/storage/connect/mysql-test/connect/r/mongo_java_3.result @@ -1,4 +1,5 @@ -SET GLOBAL connect_class_path='C:/MariaDB-10.1/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo3.jar'; +SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo3.jar'; +set connect_enable_mongo=1; # # Test the MONGO table type # @@ -377,3 +378,4 @@ planner 167 41.75 postcard 23 5.75 DROP TABLE t1; true +set connect_enable_mongo=0; diff --git a/storage/connect/mysql-test/connect/r/tbl_thread.result b/storage/connect/mysql-test/connect/r/tbl_thread.result index e07fc0988fd..9633f358c97 100644 --- a/storage/connect/mysql-test/connect/r/tbl_thread.result +++ b/storage/connect/mysql-test/connect/r/tbl_thread.result @@ -79,7 +79,7 @@ a b CREATE TABLE total (a int, b char(10)) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2,t3,t4,t5' OPTION_LIST='thread=yes,port=PORT'; -set connect_xtrace=1; +set connect_xtrace=96; SELECT * FROM total order by a desc; a b 19 test19 @@ -118,7 +118,7 @@ SELECT * FROM t2; v 22 CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=PORT';; -set connect_xtrace=1; +set connect_xtrace=96; SELECT * FROM total order by v desc; v 22 @@ -137,7 +137,7 @@ SELECT * FROM t2; v 22 CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=PORT';; -set connect_xtrace=1; +set connect_xtrace=96; SELECT * FROM total order by v desc; v 22 diff --git a/storage/connect/mysql-test/connect/r/vcol.result b/storage/connect/mysql-test/connect/r/vcol.result new file mode 100644 index 00000000000..4c59a3b06d8 --- /dev/null +++ b/storage/connect/mysql-test/connect/r/vcol.result @@ -0,0 +1,29 @@ +create table t1 ( +#linenum int(6) not null default 0 special=rowid, +name char(12) not null, +city char(11) not null, +birth date not null date_format='DD/MM/YYYY', +hired date not null date_format='DD/MM/YYYY' flag=36, +agehired int(3) as (floor(datediff(hired,birth)/365.25)) +) +engine=CONNECT table_type=FIX file_name='boys.txt' mapped=YES lrecl=47 ending=1; +select * from t1; +name city birth hired agehired +John Boston 1986-01-25 2010-06-02 24 +Henry Boston 1987-06-07 2008-04-01 20 +George San Jose 1981-08-10 2010-06-02 28 +Sam Chicago 1979-11-22 2007-10-10 27 +James Dallas 1992-05-13 2009-12-14 17 +Bill Boston 1986-09-11 2008-02-10 21 +drop table t1; +create table t1 ( +#linenum int(6) not null default 0 special=rowid, +name char(12) not null, +city char(11) not null, +birth date not null date_format='DD/MM/YYYY', +hired date not null date_format='DD/MM/YYYY' flag=36, +agehired int(3) as (floor(datediff(hired,birth)/365.25)), +index (agehired) +) +engine=CONNECT table_type=FIX file_name='boys.txt' mapped=YES lrecl=47 ending=1; +ERROR HY000: Key/Index cannot be defined on a non-stored computed column diff --git a/storage/connect/mysql-test/connect/std_data/JavaWrappers.jar b/storage/connect/mysql-test/connect/std_data/JavaWrappers.jar new file mode 100644 index 00000000000..33b29e7685b Binary files /dev/null and b/storage/connect/mysql-test/connect/std_data/JavaWrappers.jar differ diff --git a/storage/connect/mysql-test/connect/std_data/Mongo2.jar b/storage/connect/mysql-test/connect/std_data/Mongo2.jar index d019bf6906b..9be654bd4c8 100644 Binary files a/storage/connect/mysql-test/connect/std_data/Mongo2.jar and b/storage/connect/mysql-test/connect/std_data/Mongo2.jar differ diff --git a/storage/connect/mysql-test/connect/std_data/Mongo3.jar b/storage/connect/mysql-test/connect/std_data/Mongo3.jar index 21c6c2d10bd..2850177a668 100644 Binary files a/storage/connect/mysql-test/connect/std_data/Mongo3.jar and b/storage/connect/mysql-test/connect/std_data/Mongo3.jar differ diff --git a/storage/connect/mysql-test/connect/t/jdbc_postgresql.test b/storage/connect/mysql-test/connect/t/jdbc_postgresql.test index 1041ef468d7..8036f71020d 100644 --- a/storage/connect/mysql-test/connect/t/jdbc_postgresql.test +++ b/storage/connect/mysql-test/connect/t/jdbc_postgresql.test @@ -3,25 +3,32 @@ # # This test is run against Postgresql driver # +eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/JavaWrappers.jar;C:/Jconnectors/postgresql-42.2.1.jar'; CREATE TABLE t2 ( command varchar(128) not null, number int(5) not null flag=1, message varchar(255) flag=2) -ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:postgresql://localhost/mtr' -OPTION_LIST='User=mtr,Password=mtr,Schema=public,Execsrc=1'; +ENGINE=CONNECT TABLE_TYPE=JDBC +CONNECTION='jdbc:postgresql://localhost/test?user=postgres&password=tinono' +OPTION_LIST='Execsrc=1'; +#CONNECTION='jdbc:postgresql://localhost/mtr' +#OPTION_LIST='User=mtr,Password=mtr,Schema=public,Execsrc=1'; SELECT * FROM t2 WHERE command='drop table employee'; SELECT * FROM t2 WHERE command = 'create table employee (id int not null, name varchar(32), title char(16), salary decimal(8,2))'; SELECT * FROM t2 WHERE command = "insert into employee values(4567,'Johnson', 'Engineer', 12560.50)"; CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables -CONNECTION='jdbc:postgresql://localhost/mtr' -OPTION_LIST='User=mtr,Password=mtr,Schema=public,Tabtype=TABLE,Maxres=10'; +CONNECTION='jdbc:postgresql://localhost/test?user=postgres&password=tinono' +OPTION_LIST='Tabtype=TABLE,Maxres=10'; +#CONNECTION='jdbc:postgresql://localhost/mtr' +#OPTION_LIST='User=mtr,Password=mtr,Schema=public,Tabtype=TABLE,Maxres=10'; SELECT * FROM t1; DROP TABLE t1; -CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=columns -CONNECTION='jdbc:postgresql://localhost/mtr' tabname=employee -OPTION_LIST='User=mtr,Password=mtr,Maxres=10'; +CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC tabname=employee CATFUNC=columns +CONNECTION='jdbc:postgresql://localhost/test?user=postgres&password=tinono'; +#CONNECTION='jdbc:postgresql://localhost/mtr' tabname=employee; +#OPTION_LIST='User=mtr,Password=mtr,Maxres=10'; SELECT * FROM t1; DROP TABLE t1; @@ -30,14 +37,18 @@ DROP TABLE t1; # CREATE SERVER 'postgresql' FOREIGN DATA WRAPPER 'postgresql' OPTIONS ( HOST 'localhost', -DATABASE 'mtr', -USER 'mtr', -PASSWORD 'mtr', +DATABASE 'test', +USER 'postgres', +PASSWORD 'tinono', PORT 0, SOCKET '', OWNER 'root'); +#DATABASE 'mtr', +#USER 'mtr', +#PASSWORD 'mtr', -CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='postgresql/public.employee'; +CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC +CONNECTION='postgresql/public.employee'; SELECT * FROM t1; INSERT INTO t1 VALUES(3126,'Smith', 'Clerk', 5230.00); UPDATE t1 SET salary = salary + 100.00; diff --git a/storage/connect/mysql-test/connect/t/jdbconn.inc b/storage/connect/mysql-test/connect/t/jdbconn.inc index 05122f51924..81ec80c13d6 100644 --- a/storage/connect/mysql-test/connect/t/jdbconn.inc +++ b/storage/connect/mysql-test/connect/t/jdbconn.inc @@ -22,10 +22,11 @@ DROP TABLE t1; # 1 - The current directory. # 2 - The paths of the connect_class_path global variable. # 3 - The paths of the CLASSPATH environment variable. -# In this test we use an executable jar file that contains all what is needed. -eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/JdbcMariaDB.jar'; +# In this test we use an executable jar file that contains all the eisting wrappers. +#eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/JdbcMariaDB.jar'; +eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/JavaWrappers.jar'; -# Paths to the JDK classes and to the MySQL and MariaDB drivers can be defined in the CLASSPATH environment variable +# Paths to the JDK classes and to the JDBC drivers should be defined in the CLASSPATH environment variable #CREATE FUNCTION envar RETURNS STRING SONAME 'ha_connect.dll'; #SELECT envar('CLASSPATH'); diff --git a/storage/connect/mysql-test/connect/t/json_udf.test b/storage/connect/mysql-test/connect/t/json_udf.test index 35dbbfed706..d45131f32ba 100644 --- a/storage/connect/mysql-test/connect/t/json_udf.test +++ b/storage/connect/mysql-test/connect/t/json_udf.test @@ -29,12 +29,12 @@ SELECT Json_Make_Array(Json_Make_Array(56, 3.1416, 'foo'), TRUE); --error ER_CANT_INITIALIZE_UDF SELECT Json_Array_Add(Json_Make_Array(56, 3.1416, 'foo', NULL)) Array; SELECT Json_Array_Add(Json_Make_Array(56, 3.1416, 'foo', NULL), 'One more') Array; ---error ER_CANT_INITIALIZE_UDF +#--error ER_CANT_INITIALIZE_UDF SELECT Json_Array_Add(JsonValue('one value'), 'One more'); ---error ER_CANT_INITIALIZE_UDF +#--error ER_CANT_INITIALIZE_UDF SELECT Json_Array_Add('one value', 'One more'); SELECT Json_Array_Add('one value' json_, 'One more'); ---error ER_CANT_INITIALIZE_UDF +#--error ER_CANT_INITIALIZE_UDF SELECT Json_Array_Add(5 json_, 'One more'); SELECT Json_Array_Add('[5,3,8,7,9]' json_, 4, 0); SELECT Json_Array_Add('[5,3,8,7,9]' json_, 4, 2) Array; diff --git a/storage/connect/mysql-test/connect/t/mongo.inc b/storage/connect/mysql-test/connect/t/mongo.inc index 2d7cbcfa8bd..fab2ca84139 100644 --- a/storage/connect/mysql-test/connect/t/mongo.inc +++ b/storage/connect/mysql-test/connect/t/mongo.inc @@ -1,3 +1,3 @@ -let $MONGO= C:/PROGRA~1/MongoDB/Server/3.4/bin/mongo; -let $MONGOIMPORT= C:/PROGRA~1/MongoDB/Server/3.4/bin/mongoimport; +let $MONGO= C:/Applic/MongoDB/Server/3.6/bin/mongo; +let $MONGOIMPORT= C:/Applic/MongoDB/Server/3.6/bin/mongoimport; diff --git a/storage/connect/mysql-test/connect/t/mongo_test.inc b/storage/connect/mysql-test/connect/t/mongo_test.inc index dfc223e9074..357fa55240b 100644 --- a/storage/connect/mysql-test/connect/t/mongo_test.inc +++ b/storage/connect/mysql-test/connect/t/mongo_test.inc @@ -1,4 +1,4 @@ -#set connect_enable_mongo=1; +set connect_enable_mongo=1; --echo # --echo # Test the MONGO table type @@ -130,7 +130,9 @@ DROP TABLE t1; --echo # --echo # try CRUD operations --echo # +--disable_query_log --exec $MONGO --eval "db.testcoll.drop()" --quiet +--enable_query_log eval CREATE TABLE t1 (_id INT(4) NOT NULL, msg CHAR(64)) ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME='testcoll' OPTION_LIST='Driver=$DRV,Version=$VERS' $CONN; @@ -147,7 +149,9 @@ DROP TABLE t1; --echo # --echo # List states whose population is equal or more than 10 millions --echo # +--disable_query_log --exec $MONGO --eval "db.cities.drop()" --quiet +--enable_query_log --exec $MONGOIMPORT --quiet $MTR_SUITE_DIR/std_data/cities.json eval CREATE TABLE t1 ( _id char(5) NOT NULL, @@ -204,4 +208,4 @@ SELECT * FROM t1; DROP TABLE t1; --exec $MONGO --eval "db.testcoll.drop()" --quiet -#set connect_enable_mongo=0; +set connect_enable_mongo=0; diff --git a/storage/connect/mysql-test/connect/t/tbl_thread.test b/storage/connect/mysql-test/connect/t/tbl_thread.test index 68a0ebcd44d..05409c695fb 100644 --- a/storage/connect/mysql-test/connect/t/tbl_thread.test +++ b/storage/connect/mysql-test/connect/t/tbl_thread.test @@ -56,7 +56,7 @@ SELECT * FROM t5; eval CREATE TABLE total (a int, b char(10)) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2,t3,t4,t5' OPTION_LIST='thread=yes,port=$PORT'; -set connect_xtrace=1; +set connect_xtrace=96; SELECT * FROM total order by a desc; set connect_xtrace=0; @@ -85,7 +85,7 @@ SELECT * FROM t2; --replace_result $PORT PORT --eval CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=$PORT'; -set connect_xtrace=1; +set connect_xtrace=96; SELECT * FROM total order by v desc; set connect_xtrace=0; DROP TABLE t1,t2,total; @@ -101,7 +101,7 @@ SELECT * FROM t2; --replace_result $PORT PORT --eval CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=$PORT'; -set connect_xtrace=1; +set connect_xtrace=96; SELECT * FROM total order by v desc; set connect_xtrace=0; diff --git a/storage/connect/mysql-test/connect/t/vcol.test b/storage/connect/mysql-test/connect/t/vcol.test new file mode 100644 index 00000000000..88b822102d0 --- /dev/null +++ b/storage/connect/mysql-test/connect/t/vcol.test @@ -0,0 +1,31 @@ +let datadir= `select @@datadir`; +--copy_file $MTR_SUITE_DIR/std_data/boys.txt $datadir/test/boys.txt + +create table t1 ( + #linenum int(6) not null default 0 special=rowid, + name char(12) not null, + city char(11) not null, + birth date not null date_format='DD/MM/YYYY', + hired date not null date_format='DD/MM/YYYY' flag=36, + agehired int(3) as (floor(datediff(hired,birth)/365.25)) + ) +engine=CONNECT table_type=FIX file_name='boys.txt' mapped=YES lrecl=47 ending=1; +select * from t1; +drop table t1; + +--error ER_KEY_BASED_ON_GENERATED_VIRTUAL_COLUMN +create table t1 ( + #linenum int(6) not null default 0 special=rowid, + name char(12) not null, + city char(11) not null, + birth date not null date_format='DD/MM/YYYY', + hired date not null date_format='DD/MM/YYYY' flag=36, + agehired int(3) as (floor(datediff(hired,birth)/365.25)), + index (agehired) + ) +engine=CONNECT table_type=FIX file_name='boys.txt' mapped=YES lrecl=47 ending=1; + +# +# Clean up +# +--remove_file $datadir/test/boys.txt diff --git a/storage/connect/odbconn.cpp b/storage/connect/odbconn.cpp index 70a0a6a1450..f7b1a43a95d 100644 --- a/storage/connect/odbconn.cpp +++ b/storage/connect/odbconn.cpp @@ -137,10 +137,10 @@ int TranslateSQLType(int stp, int prec, int& len, char& v, bool& w) case SQL_WLONGVARCHAR: // (-10) w = true; case SQL_LONGVARCHAR: // (-1) - if (GetTypeConv() == TPC_YES) { + if (GetTypeConv() == TPC_YES || GetTypeConv() == TPC_FORCE) { v = 'V'; type = TYPE_STRING; - len = MY_MIN(abs(len), GetConvSize()); + len = (len) ? MY_MIN(abs(len), GetConvSize()) : GetConvSize(); } else type = TYPE_ERROR; @@ -190,12 +190,23 @@ int TranslateSQLType(int stp, int prec, int& len, char& v, bool& w) case SQL_BIGINT: // (-5) type = TYPE_BIGINT; break; - case SQL_UNKNOWN_TYPE: // 0 case SQL_BINARY: // (-2) case SQL_VARBINARY: // (-3) case SQL_LONGVARBINARY: // (-4) - case SQL_GUID: // (-11) - default: + if (GetTypeConv() == TPC_FORCE) { + v = 'V'; + type = TYPE_STRING; + len = (len) ? MY_MIN(abs(len), GetConvSize()) : GetConvSize(); + } else + type = TYPE_ERROR; + + break; + case SQL_GUID: // (-11) + type = TYPE_STRING; + len = 36; + break; + case SQL_UNKNOWN_TYPE: // 0 + default: type = TYPE_ERROR; len = 0; } // endswitch type @@ -364,7 +375,7 @@ PQRYRES ODBCColumns(PGLOBAL g, PCSZ dsn, PCSZ db, PCSZ table, length[11] = 255; } // endif ocp - if (trace) + if (trace(1)) htrc("ODBCColumns: max=%d len=%d,%d,%d,%d\n", maxres, length[0], length[1], length[2], length[3]); @@ -381,7 +392,7 @@ PQRYRES ODBCColumns(PGLOBAL g, PCSZ dsn, PCSZ db, PCSZ table, if (info || !qrp) // Info table return qrp; - if (trace) + if (trace(1)) htrc("Getting col results ncol=%d\n", qrp->Nbcol); if (!(cap = AllocCatInfo(g, CAT_COL, db, table, qrp))) @@ -396,7 +407,7 @@ PQRYRES ODBCColumns(PGLOBAL g, PCSZ dsn, PCSZ db, PCSZ table, qrp->Nblin = n; // ResetNullValues(cap); - if (trace) + if (trace(1)) htrc("Columns: NBCOL=%d NBLIN=%d\n", qrp->Nbcol, qrp->Nblin); } else @@ -536,7 +547,7 @@ PQRYRES ODBCDrivers(PGLOBAL g, int maxres, bool info) } else maxres = 0; - if (trace) + if (trace(1)) htrc("ODBCDrivers: max=%d len=%d\n", maxres, length[0]); /************************************************************************/ @@ -593,7 +604,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, int maxres, bool info) maxres = 0; } // endif info - if (trace) + if (trace(1)) htrc("ODBCDataSources: max=%d len=%d\n", maxres, length[0]); /************************************************************************/ @@ -666,7 +677,7 @@ PQRYRES ODBCTables(PGLOBAL g, PCSZ dsn, PCSZ db, PCSZ tabpat, PCSZ tabtyp, length[4] = 255; } // endif info - if (trace) + if (trace(1)) htrc("ODBCTables: max=%d len=%d,%d\n", maxres, length[0], length[1]); /************************************************************************/ @@ -687,7 +698,7 @@ PQRYRES ODBCTables(PGLOBAL g, PCSZ dsn, PCSZ db, PCSZ tabpat, PCSZ tabtyp, cap->Pat = tabtyp; - if (trace) + if (trace(1)) htrc("Getting table results ncol=%d\n", cap->Qrp->Nbcol); /************************************************************************/ @@ -697,7 +708,7 @@ PQRYRES ODBCTables(PGLOBAL g, PCSZ dsn, PCSZ db, PCSZ tabpat, PCSZ tabtyp, qrp->Nblin = n; // ResetNullValues(cap); - if (trace) + if (trace(1)) htrc("Tables: NBCOL=%d NBLIN=%d\n", qrp->Nbcol, qrp->Nblin); } else @@ -755,7 +766,7 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table) n = ocp->GetMaxValue(SQL_MAX_COLUMN_NAME_LEN); length[3] = (n) ? (n + 1) : 128; - if (trace) + if (trace(1)) htrc("ODBCPrimaryKeys: max=%d len=%d,%d,%d\n", maxres, length[0], length[1], length[2]); @@ -765,7 +776,7 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table) qrp = PlgAllocResult(g, ncol, maxres, IDS_PKEY, buftyp, NULL, length, false, true); - if (trace) + if (trace(1)) htrc("Getting pkey results ncol=%d\n", qrp->Nbcol); cap = AllocCatInfo(g, CAT_KEY, NULL, table, qrp); @@ -777,7 +788,7 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table) qrp->Nblin = n; // ResetNullValues(cap); - if (trace) + if (trace(1)) htrc("PrimaryKeys: NBCOL=%d NBLIN=%d\n", qrp->Nbcol, qrp->Nblin); } else @@ -838,7 +849,7 @@ PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat, n = ocp->GetMaxValue(SQL_MAX_COLUMN_NAME_LEN); length[7] = (n) ? (n + 1) : 128; - if (trace) + if (trace(1)) htrc("SemStatistics: max=%d pat=%s\n", maxres, SVP(pat)); /************************************************************************/ @@ -847,7 +858,7 @@ PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat, qrp = PlgAllocResult(g, ncol, maxres, IDS_STAT, buftyp, NULL, length, false, true); - if (trace) + if (trace(1)) htrc("Getting stat results ncol=%d\n", qrp->Nbcol); cap = AllocCatInfo(g, CAT_STAT, NULL, pat, qrp); @@ -861,7 +872,7 @@ PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat, qrp->Nblin = n; // ResetNullValues(cap); - if (trace) + if (trace(1)) htrc("Statistics: NBCOL=%d NBLIN=%d\n", qrp->Nbcol, qrp->Nblin); } else @@ -918,7 +929,7 @@ bool DBX::BuildErrorMessage(ODBConn* pdb, HSTMT hstmt) && strcmp((char*)state, "00000"); i++) { m_ErrMsg[i] = (PSZ)PlugDup(g, (char*)msg); - if (trace) + if (trace(1)) htrc("%s: %s, Native=%d\n", state, msg, native); rc = SQLError(pdb->m_henv, pdb->m_hdbc, hstmt, state, @@ -932,7 +943,7 @@ bool DBX::BuildErrorMessage(ODBConn* pdb, HSTMT hstmt) MSG(BAD_HANDLE_VAL)); m_ErrMsg[0] = (PSZ)PlugDup(g, (char*)msg); - if (trace) + if (trace(1)) htrc("%s: rc=%hd\n", SVP(m_ErrMsg[0]), m_RC); return true; @@ -941,7 +952,7 @@ bool DBX::BuildErrorMessage(ODBConn* pdb, HSTMT hstmt) } else m_ErrMsg[0] = "No connexion address provided"; - if (trace) + if (trace(1)) htrc("%s: rc=%hd (%s)\n", SVP(m_Msg), m_RC, SVP(m_ErrMsg[0])); return true; @@ -1004,7 +1015,7 @@ bool ODBConn::Check(RETCODE rc) { switch (rc) { case SQL_SUCCESS_WITH_INFO: - if (trace) { + if (trace(1)) { DBX x(rc); if (x.BuildErrorMessage(this, m_hstmt)) @@ -1223,7 +1234,7 @@ void ODBConn::AllocConnect(DWORD Options) if ((signed)m_LoginTimeout >= 0) { rc = SQLSetConnectOption(m_hdbc, SQL_LOGIN_TIMEOUT, m_LoginTimeout); - if (trace && rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) + if (trace(1) && rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) htrc("Warning: Failure setting login timeout\n"); } // endif Timeout @@ -1231,7 +1242,7 @@ void ODBConn::AllocConnect(DWORD Options) if (!m_Updatable) { rc = SQLSetConnectOption(m_hdbc, SQL_ACCESS_MODE, SQL_MODE_READ_ONLY); - if (trace && rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) + if (trace(1) && rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) htrc("Warning: Failure setting read only access mode\n"); } // endif @@ -1385,7 +1396,7 @@ void ODBConn::GetConnectInfo() else m_Updatable = false; - if (trace) + if (trace(1)) htrc("Warning: data source is readonly\n"); } else // Make data source is !Updatable @@ -1397,7 +1408,7 @@ void ODBConn::GetConnectInfo() rc = SQLGetInfo(m_hdbc, SQL_IDENTIFIER_QUOTE_CHAR, m_IDQuoteChar, sizeof(m_IDQuoteChar), &nResult); - if (trace) + if (trace(1)) htrc("DBMS: %s, Version: %s, rc=%d\n", GetStringInfo(SQL_DBMS_NAME), GetStringInfo(SQL_DBMS_VER), rc); @@ -1447,7 +1458,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols) OnSetOptions(hstmt); b = true; - if (trace) + if (trace(1)) htrc("ExecDirect hstmt=%p %.256s\n", hstmt, sql); if (m_Tdb->Srcdef) { @@ -1510,7 +1521,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols) ThrowDBX(m_G->Message); } // endif tp - if (trace) + if (trace(1)) htrc("Binding col=%u type=%d buf=%p len=%d slen=%p\n", n, tp, buffer, len, colp->GetStrLen()); @@ -1523,7 +1534,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols) } // endif pcol } catch(DBX *x) { - if (trace) + if (trace(1)) for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++) htrc(x->m_ErrMsg[i]); @@ -1569,7 +1580,7 @@ int ODBConn::GetResultSize(char *sql, ODBCCOL *colp) } catch(DBX *x) { strcpy(m_G->Message, x->GetErrorMessage(0)); - if (trace) + if (trace(1)) for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++) htrc(x->m_ErrMsg[i]); @@ -1610,7 +1621,7 @@ int ODBConn::Fetch(int pos) } // endif m_RowsetSize // } while (rc == SQL_STILL_EXECUTING); - if (trace > 1) + if (trace(2)) htrc("Fetch: hstmt=%p RowseSize=%d rc=%d\n", m_hstmt, m_RowsetSize, rc); @@ -1626,7 +1637,7 @@ int ODBConn::Fetch(int pos) m_Fetch++; m_Rows += irc; } catch(DBX *x) { - if (trace) + if (trace(1)) for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++) htrc(x->m_ErrMsg[i]); @@ -1662,7 +1673,7 @@ int ODBConn::PrepareSQL(char *sql) m_Transact = true; } catch(DBX *x) { - if (trace) + if (trace(1)) for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++) htrc(x->m_ErrMsg[i]); @@ -1693,7 +1704,7 @@ int ODBConn::PrepareSQL(char *sql) OnSetOptions(hstmt); b = true; - if (trace) + if (trace(1)) htrc("Prepare hstmt=%p %.64s\n", hstmt, sql); do { @@ -1708,7 +1719,7 @@ int ODBConn::PrepareSQL(char *sql) } while (rc == SQL_STILL_EXECUTING); } catch(DBX *x) { - if (trace) + if (trace(1)) for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++) htrc(x->m_ErrMsg[i]); @@ -1881,7 +1892,7 @@ bool ODBConn::ExecSQLcommand(char *sql) OnSetOptions(hstmt); b = true; - if (trace) + if (trace(1)) htrc("ExecSQLcommand hstmt=%p %.64s\n", hstmt, sql); // Proceed with command execution @@ -1908,7 +1919,7 @@ bool ODBConn::ExecSQLcommand(char *sql) } // endif ncol } catch(DBX *x) { - if (trace) + if (trace(1)) for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++) htrc(x->m_ErrMsg[i]); @@ -2250,10 +2261,10 @@ public: return (SQLCHAR *) (m_part[i].length ? m_part[i].str : NULL); } // end of ptr - size_t length(uint i) + SQLSMALLINT length(uint i) { DBUG_ASSERT(i < max_parts); - return m_part[i].length; + return (SQLSMALLINT)m_part[i].length; } // end of length }; // end of class SQLQualifiedName @@ -2394,7 +2405,7 @@ int ODBConn::GetCatInfo(CATPARM *cap) if ((rc = SQLFetch(hstmt)) == SQL_NO_DATA_FOUND) break; else if (rc != SQL_SUCCESS) { - if (trace > 1 || (trace && rc != SQL_SUCCESS_WITH_INFO)) { + if (trace(2) || (trace(1) && rc != SQL_SUCCESS_WITH_INFO)) { UCHAR msg[SQL_MAX_MESSAGE_LENGTH + 1]; UCHAR state[SQL_SQLSTATE_SIZE + 1]; RETCODE erc; @@ -2427,7 +2438,7 @@ int ODBConn::GetCatInfo(CATPARM *cap) else if (vlen[n] == SQL_NULL_DATA) pval[n]->SetNull(true); else if (crp->Type == TYPE_STRING/* && vlen[n] != SQL_NULL_DATA*/) - pval[n]->SetValue_char(pbuf[n], vlen[n]); + pval[n]->SetValue_char(pbuf[n], (int)vlen[n]); else pval[n]->SetNull(false); @@ -2466,7 +2477,7 @@ int ODBConn::GetCatInfo(CATPARM *cap) irc = (int)crow; } catch(DBX *x) { - if (trace) + if (trace(1)) for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++) htrc(x->m_ErrMsg[i]); @@ -2605,12 +2616,12 @@ void ODBConn::Close() rc = SQLDisconnect(m_hdbc); - if (trace && rc != SQL_SUCCESS) + if (trace(1) && rc != SQL_SUCCESS) htrc("Error: SQLDisconnect rc=%d\n", rc); rc = SQLFreeConnect(m_hdbc); - if (trace && rc != SQL_SUCCESS) + if (trace(1) && rc != SQL_SUCCESS) htrc("Error: SQLFreeConnect rc=%d\n", rc); m_hdbc = SQL_NULL_HDBC; @@ -2619,7 +2630,7 @@ void ODBConn::Close() if (m_henv != SQL_NULL_HENV) { rc = SQLFreeEnv(m_henv); - if (trace && rc != SQL_SUCCESS) // Nothing we can do + if (trace(1) && rc != SQL_SUCCESS) // Nothing we can do htrc("Error: SQLFreeEnv failure ignored in Close\n"); m_henv = SQL_NULL_HENV; diff --git a/storage/connect/plgdbsem.h b/storage/connect/plgdbsem.h index 6a0a8be8ff8..5446e0d2a07 100644 --- a/storage/connect/plgdbsem.h +++ b/storage/connect/plgdbsem.h @@ -362,7 +362,8 @@ enum COLUSE {U_P = 0x01, /* the projection list. */ U_IS_NULL = 0x80, /* The column has a null value */ U_SPECIAL = 0x100, /* The column is special */ U_UNSIGNED = 0x200, /* The column type is unsigned */ - U_ZEROFILL = 0x400}; /* The column is zero filled */ + U_ZEROFILL = 0x400, /* The column is zero filled */ + U_UUID = 0x800}; /* The column is a UUID */ /***********************************************************************/ /* DB description class and block pointer definitions. */ diff --git a/storage/connect/plgdbutl.cpp b/storage/connect/plgdbutl.cpp index f669d644637..e296553d8e2 100644 --- a/storage/connect/plgdbutl.cpp +++ b/storage/connect/plgdbutl.cpp @@ -1,11 +1,11 @@ /********** PlgDBUtl Fpe C++ Program Source Code File (.CPP) ***********/ /* PROGRAM NAME: PLGDBUTL */ /* ------------- */ -/* Version 4.0 */ +/* Version 4.1 */ /* */ /* COPYRIGHT: */ /* ---------- */ -/* (C) Copyright to the author Olivier BERTRAND 1998-2017 */ +/* (C) Copyright to the author Olivier BERTRAND 1998-2018 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ @@ -215,35 +215,13 @@ int global_open(GLOBAL *g, int msgid, const char *path, int flags, int mode) } DllExport void SetTrc(void) - { +{ // If tracing is on, debug must be initialized. debug = pfile; - } // end of SetTrc - -#if 0 -/**************************************************************************/ -/* Tracing output function. */ -/**************************************************************************/ -void ptrc(char const *fmt, ...) - { - va_list ap; - va_start (ap, fmt); - -// if (trace == 0 || (trace == 1 && !pfile) || !fmt) -// printf("In %s wrong trace=%d pfile=%p fmt=%p\n", -// __FILE__, trace, pfile, fmt); - - if (trace == 1) - vfprintf(pfile, fmt, ap); - else - vprintf(fmt, ap); - - va_end (ap); - } // end of ptrc -#endif // 0 +} // end of SetTrc /**************************************************************************/ -/* Allocate the result structure that will contain result data. */ +/* SubAllocate the result structure that will contain result data. */ /**************************************************************************/ PQRYRES PlgAllocResult(PGLOBAL g, int ncol, int maxres, int ids, int *buftyp, XFLD *fldtyp, @@ -307,7 +285,7 @@ PQRYRES PlgAllocResult(PGLOBAL g, int ncol, int maxres, int ids, else crp->Kdata = NULL; - if (trace) + if (trace(1)) htrc("Column(%d) %s type=%d len=%d value=%p\n", crp->Ncol, crp->Name, crp->Type, crp->Length, crp->Kdata); @@ -475,7 +453,7 @@ bool PlugEvalLike(PGLOBAL g, LPCSTR strg, LPCSTR pat, bool ci) char *tp, *sp; bool b; - if (trace) + if (trace(2)) htrc("LIKE: strg='%s' pattern='%s'\n", strg, pat); if (ci) { /* Case insensitive test */ @@ -541,10 +519,10 @@ bool EvalLikePattern(LPCSTR sp, LPCSTR tp) { LPSTR p; char c; - int n; + ssize_t n; bool b, t = false; - if (trace) + if (trace(2)) htrc("Eval Like: sp=%s tp=%s\n", (sp) ? sp : "Null", (tp) ? tp : "Null"); @@ -582,7 +560,7 @@ bool EvalLikePattern(LPCSTR sp, LPCSTR tp) else n = strlen(tp); /* Get length of pattern head */ - if (trace) + if (trace(2)) htrc(" testing: t=%d sp=%s tp=%s p=%p\n", t, sp, tp, p); if (n > (signed)strlen(sp)) /* If head is longer than strg */ @@ -628,7 +606,7 @@ bool EvalLikePattern(LPCSTR sp, LPCSTR tp) b = !strcmp(sp, tp); } /* endif p */ - if (trace) + if (trace(2)) htrc(" done: b=%d n=%d sp=%s tp=%s\n", b, n, (sp) ? sp : "Null", tp); @@ -668,7 +646,7 @@ char *MakeEscape(PGLOBAL g, char* str, char q) /***********************************************************************/ void PlugConvertConstant(PGLOBAL g, void* & value, short& type) { - if (trace) + if (trace(1)) htrc("PlugConvertConstant: value=%p type=%hd\n", value, type); if (type != TYPE_XOBJECT) { @@ -688,7 +666,7 @@ PDTP MakeDateFormat(PGLOBAL g, PCSZ dfmt, bool in, bool out, int flag) int rc; PDTP pdp = (PDTP)PlugSubAlloc(g, NULL, sizeof(DATPAR)); - if (trace) + if (trace(1)) htrc("MakeDateFormat: dfmt=%s\n", dfmt); memset(pdp, 0, sizeof(DATPAR)); @@ -711,7 +689,7 @@ PDTP MakeDateFormat(PGLOBAL g, PCSZ dfmt, bool in, bool out, int flag) rc = fmdflex(pdp); pthread_mutex_unlock(&parmut); - if (trace) + if (trace(1)) htrc("Done: in=%s out=%s rc=%d\n", SVP(pdp->InFmt), SVP(pdp->OutFmt), rc); return pdp; @@ -733,7 +711,7 @@ int ExtractDate(char *dts, PDTP pdp, int defy, int val[6]) else // assume standard MySQL date format fmt = "%4d-%2d-%2d %2d:%2d:%2d"; - if (trace > 1) + if (trace(2)) htrc("ExtractDate: dts=%s fmt=%s defy=%d\n", dts, fmt, defy); // Set default values for time only use @@ -816,7 +794,7 @@ int ExtractDate(char *dts, PDTP pdp, int defy, int val[6]) } // endfor i - if (trace > 1) + if (trace(2)) htrc("numval=%d val=(%d,%d,%d,%d,%d,%d)\n", numval, val[0], val[1], val[2], val[3], val[4], val[5]); @@ -833,18 +811,18 @@ FILE *PlugOpenFile(PGLOBAL g, LPCSTR fname, LPCSTR ftype) PFBLOCK fp; PDBUSER dbuserp = (PDBUSER)g->Activityp->Aptr; - if (trace) { + if (trace(1)) { htrc("PlugOpenFile: fname=%s ftype=%s\n", fname, ftype); htrc("dbuserp=%p\n", dbuserp); } // endif trace if ((fop= global_fopen(g, MSGID_OPEN_MODE_STRERROR, fname, ftype)) != NULL) { - if (trace) + if (trace(1)) htrc(" fop=%p\n", fop); fp = (PFBLOCK)PlugSubAlloc(g, NULL, sizeof(FBLOCK)); - if (trace) + if (trace(1)) htrc(" fp=%p\n", fp); // fname may be in volatile memory such as stack @@ -857,7 +835,7 @@ FILE *PlugOpenFile(PGLOBAL g, LPCSTR fname, LPCSTR ftype) dbuserp->Openlist = fp; } /* endif fop */ - if (trace) + if (trace(1)) htrc(" returning fop=%p\n", fop); return (fop); @@ -888,7 +866,7 @@ int PlugCloseFile(PGLOBAL g, PFBLOCK fp, bool all) { int rc = 0; - if (trace) + if (trace(1)) htrc("PlugCloseFile: fp=%p count=%hd type=%hd\n", fp, ((fp) ? fp->Count : 0), ((fp) ? fp->Type : 0)); @@ -1050,7 +1028,7 @@ int GetIniSize(char *section, char *key, char *def, char *ini) n *= 1024; } // endswitch c - if (trace) + if (trace(1)) htrc("GetIniSize: key=%s buff=%s i=%d n=%d\n", key, buff, i, n); return n; @@ -1086,7 +1064,7 @@ DllExport PSZ GetIniString(PGLOBAL g, void *mp, LPCSTR sec, LPCSTR key, p = (PSZ)PlugSubAlloc(g, mp, n + 1); - if (trace) + if (trace(1)) htrc("GetIniString: sec=%s key=%s buf=%s\n", sec, key, buf); strcpy(p, buf); @@ -1237,7 +1215,7 @@ char *GetExceptionDesc(PGLOBAL g, unsigned int e) /* so it can be freed at the normal or error query completion. */ /***********************************************************************/ void *PlgDBalloc(PGLOBAL g, void *area, MBLOCK& mp) - { +{ //bool b; size_t maxsub, minsub; void *arp = (area) ? area : g->Sarea; @@ -1253,7 +1231,7 @@ void *PlgDBalloc(PGLOBAL g, void *area, MBLOCK& mp) // done to check whether the block is already there. // b = mp.Sub; mp.Sub = false; // Restrict suballocation to one quarter - } // endif Memp + } // endif Memp // Suballoc when possible if mp.Sub is initially true, but leaving // a minimum amount of storage for future operations such as the @@ -1263,35 +1241,40 @@ void *PlgDBalloc(PGLOBAL g, void *area, MBLOCK& mp) maxsub = (pph->FreeBlk < minsub) ? 0 : pph->FreeBlk - minsub; mp.Sub = mp.Size <= ((mp.Sub) ? maxsub : (maxsub >> 2)); - if (trace > 1) - htrc("PlgDBalloc: in %p size=%d used=%d free=%d sub=%d\n", - arp, mp.Size, pph->To_Free, pph->FreeBlk, mp.Sub); + if (trace(2)) + htrc("PlgDBalloc: in %p size=%d used=%d free=%d sub=%d\n", + arp, mp.Size, pph->To_Free, pph->FreeBlk, mp.Sub); - if (!mp.Sub) { + if (!mp.Sub) { // For allocations greater than one fourth of remaining storage // in the area, do allocate from virtual storage. + const char*v = "malloc"; #if defined(__WIN__) - if (mp.Size >= BIGMEM) - mp.Memp = VirtualAlloc(NULL, mp.Size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); - else + if (mp.Size >= BIGMEM) { + v = "VirtualAlloc"; + mp.Memp = VirtualAlloc(NULL, mp.Size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); + } else #endif mp.Memp = malloc(mp.Size); - if (!mp.Inlist && mp.Memp) { + if (trace(8)) + htrc("PlgDBalloc: %s(%d) at %p\n", v, mp.Size, mp.Memp); + + if (!mp.Inlist && mp.Memp) { // New allocated block, put it in the memory block chain. PDBUSER dbuserp = (PDBUSER)g->Activityp->Aptr; mp.Next = dbuserp->Memlist; dbuserp->Memlist = ∓ mp.Inlist = true; - } // endif mp + } // endif mp } else // Suballocating is Ok. mp.Memp = PlugSubAlloc(g, area, mp.Size); return mp.Memp; - } // end of PlgDBalloc +} // end of PlgDBalloc /***********************************************************************/ /* PlgDBrealloc: reallocates memory conditionally. */ @@ -1306,7 +1289,7 @@ void *PlgDBrealloc(PGLOBAL g, void *area, MBLOCK& mp, size_t newsize) // assert (mp.Memp != NULL); #endif - if (trace > 1) + if (trace(2)) htrc("PlgDBrealloc: %p size=%d sub=%d\n", mp.Memp, mp.Size, mp.Sub); if (newsize == mp.Size) @@ -1326,10 +1309,14 @@ void *PlgDBrealloc(PGLOBAL g, void *area, MBLOCK& mp, size_t newsize) mp.Memp = PlugSubAlloc(g, area, newsize); memcpy(mp.Memp, m.Memp, MY_MIN(m.Size, newsize)); PlgDBfree(m); // Free the old block - } else if (!(mp.Memp = realloc(mp.Memp, newsize))) { - mp = m; // Possible only if newsize > Size - return NULL; // Failed - } // endif's + } else { + if (!(mp.Memp = realloc(mp.Memp, newsize))) { + mp = m; // Possible only if newsize > Size + return NULL; // Failed + } else if (trace(8)) + htrc("PlgDBrealloc: realloc(%ld) at %p\n", newsize, mp.Memp); + + } // endif's mp.Size = newsize; } else if (!mp.Sub || newsize > mp.Size) { @@ -1352,7 +1339,7 @@ void *PlgDBrealloc(PGLOBAL g, void *area, MBLOCK& mp, size_t newsize) } // endif's - if (trace) + if (trace(8)) htrc(" newsize=%d newp=%p sub=%d\n", mp.Size, mp.Memp, mp.Sub); return mp.Memp; @@ -1363,16 +1350,20 @@ void *PlgDBrealloc(PGLOBAL g, void *area, MBLOCK& mp, size_t newsize) /***********************************************************************/ void PlgDBfree(MBLOCK& mp) { - if (trace > 1) - htrc("PlgDBfree: %p sub=%d size=%d\n", mp.Memp, mp.Sub, mp.Size); - - if (!mp.Sub && mp.Memp) + if (!mp.Sub && mp.Memp) { + const char*v = "free"; #if defined(__WIN__) - if (mp.Size >= BIGMEM) - VirtualFree(mp.Memp, 0, MEM_RELEASE); - else + if (mp.Size >= BIGMEM) { + v = "VirtualFree"; + VirtualFree(mp.Memp, 0, MEM_RELEASE); + } else #endif - free(mp.Memp); + free(mp.Memp); + + if (trace(8)) + htrc("PlgDBfree: %s(%p) size=%d\n", v, mp.Memp, mp.Size); + + } // endif mp // Do not reset Next to avoid cutting the Mblock chain mp.Memp = NULL; @@ -1384,7 +1375,7 @@ void PlgDBfree(MBLOCK& mp) /* Program for sub-allocating one item in a storage area. */ /* Note: This function is equivalent to PlugSubAlloc except that in */ /* case of insufficient memory, it returns NULL instead of doing a */ -/* long jump. The caller must test the return value for error. */ +/* throw. The caller must test the return value for error. */ /***********************************************************************/ void *PlgDBSubAlloc(PGLOBAL g, void *memp, size_t size) { @@ -1400,7 +1391,7 @@ void *PlgDBSubAlloc(PGLOBAL g, void *memp, size_t size) size = ((size + 7) / 8) * 8; /* Round up size to multiple of 8 */ pph = (PPOOLHEADER)memp; - if (trace > 1) + if (trace(16)) htrc("PlgDBSubAlloc: memp=%p size=%d used=%d free=%d\n", memp, size, pph->To_Free, pph->FreeBlk); @@ -1409,7 +1400,7 @@ void *PlgDBSubAlloc(PGLOBAL g, void *memp, size_t size) "Not enough memory in Work area for request of %d (used=%d free=%d)", (int) size, pph->To_Free, pph->FreeBlk); - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return NULL; @@ -1422,7 +1413,7 @@ void *PlgDBSubAlloc(PGLOBAL g, void *memp, size_t size) pph->To_Free += size; // New offset of pool free block pph->FreeBlk -= size; // New size of pool free block - if (trace > 1) + if (trace(16)) htrc("Done memp=%p used=%d free=%d\n", memp, pph->To_Free, pph->FreeBlk); @@ -1453,7 +1444,7 @@ void PlugPutOut(PGLOBAL g, FILE *f, short t, void *v, uint n) { char m[64]; - if (trace) + if (trace(1)) htrc("PUTOUT: f=%p t=%d v=%p n=%d\n", f, t, v, n); if (!v) diff --git a/storage/connect/plugutil.cpp b/storage/connect/plugutil.cpp index e9ba1682e69..887527e38ab 100644 --- a/storage/connect/plugutil.cpp +++ b/storage/connect/plugutil.cpp @@ -136,7 +136,7 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize) { PGLOBAL g; - if (trace > 1) + if (trace(2)) htrc("PlugInit: Language='%s'\n", ((!Language) ? "Null" : (char*)Language)); @@ -162,7 +162,7 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize) /*******************************************************************/ if (worksize && AllocSarea(g, worksize)) { char errmsg[MAX_STR]; - sprintf(errmsg, MSG(WORK_AREA), g->Message); + snprintf(errmsg, sizeof(errmsg) - 1, MSG(WORK_AREA), g->Message); strcpy(g->Message, errmsg); } // endif Sarea @@ -205,7 +205,7 @@ LPSTR PlugRemoveType(LPSTR pBuff, LPCSTR FileName) _splitpath(FileName, drive, direc, fname, ftype); - if (trace > 1) { + if (trace(2)) { htrc("after _splitpath: FileName=%s\n", FileName); htrc("drive=%s dir=%s fname=%s ext=%s\n", SVP(drive), direc, fname, ftype); @@ -213,7 +213,7 @@ LPSTR PlugRemoveType(LPSTR pBuff, LPCSTR FileName) _makepath(pBuff, drive, direc, fname, ""); - if (trace > 1) + if (trace(2)) htrc("buff='%s'\n", pBuff); return pBuff; @@ -246,7 +246,7 @@ LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath) char *drive = NULL, *defdrv = NULL; #endif - if (trace > 1) + if (trace(2)) htrc("prefix=%s fn=%s path=%s\n", prefix, FileName, defpath); if (!strncmp(FileName, "//", 2) || !strncmp(FileName, "\\\\", 2)) { @@ -263,7 +263,7 @@ LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath) #if !defined(__WIN__) if (*FileName == '~') { if (_fullpath(pBuff, FileName, _MAX_PATH)) { - if (trace > 1) + if (trace(2)) htrc("pbuff='%s'\n", pBuff); return pBuff; @@ -298,7 +298,7 @@ LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath) _splitpath(tmpdir, defdrv, defdir, NULL, NULL); - if (trace > 1) { + if (trace(2)) { htrc("after _splitpath: FileName=%s\n", FileName); #if defined(__WIN__) htrc("drive=%s dir=%s fname=%s ext=%s\n", drive, direc, fname, ftype); @@ -325,11 +325,11 @@ LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath) _makepath(newname, drive, direc, fname, ftype); - if (trace > 1) + if (trace(2)) htrc("newname='%s'\n", newname); if (_fullpath(pBuff, newname, _MAX_PATH)) { - if (trace > 1) + if (trace(2)) htrc("pbuff='%s'\n", pBuff); return pBuff; @@ -470,7 +470,7 @@ bool AllocSarea(PGLOBAL g, uint size) #if defined(DEVELOPMENT) if (true) { #else - if (trace) { + if (trace(8)) { #endif if (g->Sarea) htrc("Work area of %u allocated at %p\n", size, g->Sarea); @@ -498,7 +498,7 @@ void FreeSarea(PGLOBAL g) #if defined(DEVELOPMENT) if (true) #else - if (trace) + if (trace(8)) #endif htrc("Freeing Sarea at %p size = %d\n", g->Sarea, g->Sarea_Size); @@ -545,7 +545,7 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size) size = ((size + 7) / 8) * 8; /* Round up size to multiple of 8 */ pph = (PPOOLHEADER)memp; - if (trace > 3) + if (trace(16)) htrc("SubAlloc in %p size=%d used=%d free=%d\n", memp, size, pph->To_Free, pph->FreeBlk); @@ -556,10 +556,10 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size) "Not enough memory in %s area for request of %u (used=%d free=%d)", pname, (uint)size, pph->To_Free, pph->FreeBlk); - if (trace) + if (trace(1)) htrc("PlugSubAlloc: %s\n", g->Message); - throw 1234; + throw 1234; } /* endif size OS32 code */ /*********************************************************************/ @@ -569,7 +569,7 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size) pph->To_Free += (OFFSET)size; /* New offset of pool free block */ pph->FreeBlk -= (uint)size; /* New size of pool free block */ - if (trace > 3) + if (trace(16)) htrc("Done memp=%p used=%d free=%d\n", memp, pph->To_Free, pph->FreeBlk); diff --git a/storage/connect/preparse.h b/storage/connect/preparse.h index f16624548fb..3db7a2af1cd 100644 --- a/storage/connect/preparse.h +++ b/storage/connect/preparse.h @@ -8,7 +8,7 @@ /***********************************************************************/ typedef struct _datpar { const char *Format; // Points to format to decode - char *Curp; // Points to current parsing position + const char *Curp; // Points to current parsing position char *InFmt; // Start of input format char *OutFmt; // Start of output format int Index[8]; // Indexes of date values diff --git a/storage/connect/rcmsg.c b/storage/connect/rcmsg.c index 75759e03314..895f8f5862b 100644 --- a/storage/connect/rcmsg.c +++ b/storage/connect/rcmsg.c @@ -27,9 +27,9 @@ char *msglang(void); -char *GetMsgid(int id) +const char *GetMsgid(int id) { - char *p = NULL; + const char *p = NULL; // This conditional until a real fix is found for MDEV-7304 #if defined(FRENCH) @@ -55,7 +55,8 @@ char *GetMsgid(int id) int GetRcString(int id, char *buf, int bufsize) { - char *p = NULL, msg[32]; + const char *p = NULL; + char msg[32]; if (!(p = GetMsgid(id))) { sprintf(msg, "ID=%d unknown", id); diff --git a/storage/connect/rcmsg.h b/storage/connect/rcmsg.h index b22e77f5175..499ca3b2dd4 100644 --- a/storage/connect/rcmsg.h +++ b/storage/connect/rcmsg.h @@ -5,7 +5,7 @@ extern "C" { #endif -char *GetMsgid(int id); +const char *GetMsgid(int id); int GetRcString(int id, char *buf, int bufsize); #ifdef __cplusplus diff --git a/storage/connect/reldef.cpp b/storage/connect/reldef.cpp index 031fdebe650..e4f169575f8 100644 --- a/storage/connect/reldef.cpp +++ b/storage/connect/reldef.cpp @@ -450,7 +450,7 @@ int TABDEF::GetColCatInfo(PGLOBAL g) } // endswitch tc // lrecl must be at least recln to avoid buffer overflow - if (trace) + if (trace(1)) htrc("Lrecl: Calculated=%d defined=%d\n", recln, Hc->GetIntegerOption("Lrecl")); @@ -547,14 +547,12 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) } // endif dladdr #endif // 0 - // Is the library already loaded? - if (!Hdll && !(Hdll = dlopen(soname, RTLD_NOLOAD))) - // Load the desired shared library - if (!(Hdll = dlopen(soname, RTLD_LAZY))) { - error = dlerror(); - sprintf(g->Message, MSG(SHARED_LIB_ERR), soname, SVP(error)); - return NULL; - } // endif Hdll + // Load the desired shared library + if (!Hdll && !(Hdll = dlopen(soname, RTLD_LAZY))) { + error = dlerror(); + sprintf(g->Message, MSG(SHARED_LIB_ERR), soname, SVP(error)); + return NULL; + } // endif Hdll // The exported name is always in uppercase for (int i = 0; ; i++) { diff --git a/storage/connect/tabcol.cpp b/storage/connect/tabcol.cpp index 5065d86ce6a..93de0598fe8 100644 --- a/storage/connect/tabcol.cpp +++ b/storage/connect/tabcol.cpp @@ -33,7 +33,7 @@ XTAB::XTAB(LPCSTR name, LPCSTR srcdef) : Name(name) Schema = NULL; Qualifier = NULL; - if (trace) + if (trace(1)) htrc("XTAB: making new TABLE %s %s\n", Name, Srcdef); } // end of XTAB constructor @@ -49,7 +49,7 @@ XTAB::XTAB(PTABLE tp) : Name(tp->Name) Schema = tp->Schema; Qualifier = tp->Qualifier; - if (trace) + if (trace(1)) htrc(" making copy TABLE %s %s\n", Name, SVP(Srcdef)); } // end of XTAB constructor @@ -61,7 +61,7 @@ PTABLE XTAB::Link(PTABLE tab2) { PTABLE tabp; - if (trace) + if (trace(1)) htrc("Linking tables %s... to %s\n", Name, tab2->Name); for (tabp = this; tabp->Next; tabp = tabp->Next) ; @@ -117,7 +117,7 @@ COLUMN::COLUMN(LPCSTR name) : Name(name) To_Col = NULL; Qualifier = NULL; - if (trace) + if (trace(1)) htrc(" making new COLUMN %s\n", Name); } // end of COLUMN constructor diff --git a/storage/connect/tabdos.cpp b/storage/connect/tabdos.cpp index 5b9667a6c84..29cbbb35765 100644 --- a/storage/connect/tabdos.cpp +++ b/storage/connect/tabdos.cpp @@ -704,7 +704,7 @@ int TDBDOS::MakeBlockValues(PGLOBAL g) // savmin = cdp->GetBmap(); // cdp->SetBmap(PlugSubAlloc(g, NULL, block * sizeof(int))); - if (trace) + if (trace(1)) htrc("Dval(%p) Bmap(%p) col(%d) %s Block=%d lg=%d\n", cdp->GetDval(), cdp->GetBmap(), i, cdp->GetName(), block, lg); @@ -729,7 +729,7 @@ int TDBDOS::MakeBlockValues(PGLOBAL g) memset(cdp->GetMax(), 0, block * lg); } // endif Type - if (trace) + if (trace(1)) htrc("min(%p) max(%p) col(%d) %s Block=%d lg=%d\n", cdp->GetMin(), cdp->GetMax(), i, cdp->GetName(), block, lg); @@ -901,7 +901,7 @@ bool TDBDOS::SaveBlockValues(PGLOBAL g) "wb", (int)errno, filename); strcat(strcat(g->Message, ": "), strerror(errno)); - if (trace) + if (trace(1)) htrc("%s\n", g->Message); return true; @@ -1634,7 +1634,7 @@ int TDBDOS::TestBlock(PGLOBAL g) To_Filter = NULL; // So remove filter } // endswitch Beval - if (trace) + if (trace(1)) htrc("BF Eval Beval=%d\n", Beval); } // endif To_BlkFil @@ -1647,8 +1647,8 @@ int TDBDOS::TestBlock(PGLOBAL g) /***********************************************************************/ int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add) { - int k, n, rc = RC_OK; - bool fixed, doit, sep, b = (pxdf != NULL); + int k, n, rc = RC_OK; + bool fixed, doit, sep, b = (pxdf != NULL); PCOL *keycols, colp; PIXDEF xdp, sxp = NULL; PKPDEF kdp; @@ -1694,8 +1694,8 @@ int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add) try { // Allocate all columns that will be used by indexes. - // This must be done before opening the table so specific - // column initialization can be done (in particular by TDBVCT) + // This must be done before opening the table so specific + // column initialization can be done (in particular by TDBVCT) for (n = 0, xdp = pxdf; xdp; xdp = xdp->GetNext()) for (kdp = xdp->GetToKeyParts(); kdp; kdp = kdp->GetNext()) { if (!(colp = ColDB(g, kdp->GetName(), 0))) { @@ -1779,7 +1779,7 @@ int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add) return RC_INFO; // Error or Physical table does not exist } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); rc = RC_FX; } catch (const char *msg) { @@ -1902,7 +1902,7 @@ bool TDBDOS::InitialyzeIndex(PGLOBAL g, volatile PIXDEF xdp, bool sorted) } // endif brc } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); brc = true; } catch (const char *msg) { @@ -2001,7 +2001,7 @@ int TDBDOS::Cardinality(PGLOBAL g) if (len >= 0) { int rec; - if (trace) + if (trace(1)) htrc("Estimating lines len=%d ending=%d/n", len, ((PDOSDEF)To_Def)->Ending); @@ -2018,7 +2018,7 @@ int TDBDOS::Cardinality(PGLOBAL g) Cardinal = (len + rec - 1) / rec; - if (trace) + if (trace(1)) htrc("avglen=%d MaxSize%d\n", rec, Cardinal); } // endif len @@ -2048,7 +2048,7 @@ int TDBDOS::GetMaxSize(PGLOBAL g) if (len >= 0) { int rec; - if (trace) + if (trace(1)) htrc("Estimating lines len=%d ending=%d/n", len, ((PDOSDEF)To_Def)->Ending); @@ -2059,7 +2059,7 @@ int TDBDOS::GetMaxSize(PGLOBAL g) rec = EstimatedLength() + ((PDOSDEF)To_Def)->Ending; MaxSize = (len + rec - 1) / rec; - if (trace) + if (trace(1)) htrc("avglen=%d MaxSize%d\n", rec, MaxSize); } // endif len @@ -2108,7 +2108,7 @@ bool TDBDOS::IsUsingTemp(PGLOBAL) /***********************************************************************/ bool TDBDOS::OpenDB(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("DOS OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n", this, Tdb_No, Use, Mode); @@ -2184,7 +2184,7 @@ bool TDBDOS::OpenDB(PGLOBAL g) } else memset(To_Line, 0, linelen); - if (trace) + if (trace(1)) htrc("OpenDos: R%hd mode=%d To_Line=%p\n", Tdb_No, Mode, To_Line); if (SkipHeader(g)) // When called from CSV/FMT files @@ -2202,7 +2202,7 @@ bool TDBDOS::OpenDB(PGLOBAL g) /***********************************************************************/ int TDBDOS::ReadDB(PGLOBAL g) { - if (trace > 1) + if (trace(2)) htrc("DOS ReadDB: R%d Mode=%d key=%p link=%p Kindex=%p To_Line=%p\n", GetTdb_No(), Mode, To_Key_Col, To_Link, To_Kindex, To_Line); @@ -2227,7 +2227,7 @@ int TDBDOS::ReadDB(PGLOBAL g) if (SetRecpos(g, recpos)) return RC_FX; - if (trace > 1) + if (trace(2)) htrc("File position is now %d\n", GetRecpos()); if (Mode == MODE_READ) @@ -2243,7 +2243,7 @@ int TDBDOS::ReadDB(PGLOBAL g) } // endif To_Kindex - if (trace > 1) + if (trace(2)) htrc(" ReadDB: this=%p To_Line=%p\n", this, To_Line); /*********************************************************************/ @@ -2279,14 +2279,14 @@ bool TDBDOS::PrepareWriting(PGLOBAL) /***********************************************************************/ int TDBDOS::WriteDB(PGLOBAL g) { - if (trace > 1) + if (trace(2)) htrc("DOS WriteDB: R%d Mode=%d \n", Tdb_No, Mode); // Make the line to write if (PrepareWriting(g)) return RC_FX; - if (trace > 1) + if (trace(2)) htrc("Write: line is='%s'\n", To_Line); // Now start the writing process @@ -2403,7 +2403,7 @@ DOSCOL::DOSCOL(PGLOBAL g, PCOLDEF cdp, PTDB tp, PCOL cp, int i, PCSZ am) Dcm = (*p) ? atoi(p) : GetScale(); } // endif fmt - if (trace) + if (trace(1)) htrc(" making new %sCOL C%d %s at %p\n", am, Index, Name, this); } // end of DOSCOL constructor @@ -2518,7 +2518,7 @@ void DOSCOL::ReadColumn(PGLOBAL g) double dval; PTDBDOS tdbp = (PTDBDOS)To_Tdb; - if (trace > 1) + if (trace(2)) htrc( "DOS ReadColumn: col %s R%d coluse=%.4X status=%.4X buf_type=%d\n", Name, tdbp->GetTdb_No(), ColUse, Status, Buf_Type); @@ -2607,13 +2607,13 @@ void DOSCOL::WriteColumn(PGLOBAL g) int i, k, len, field; PTDBDOS tdbp = (PTDBDOS)To_Tdb; - if (trace > 1) + if (trace(2)) htrc("DOS WriteColumn: col %s R%d coluse=%.4X status=%.4X\n", Name, tdbp->GetTdb_No(), ColUse, Status); p = tdbp->To_Line + Deplac; - if (trace > 1) + if (trace(2)) htrc("Lrecl=%d deplac=%d int=%d\n", tdbp->Lrecl, Deplac, Long); field = Long; @@ -2630,7 +2630,7 @@ void DOSCOL::WriteColumn(PGLOBAL g) } // endif Ftype - if (trace > 1) + if (trace(2)) htrc("Long=%d field=%d coltype=%d colval=%p\n", Long, field, Buf_Type, Value); @@ -2703,7 +2703,7 @@ void DOSCOL::WriteColumn(PGLOBAL g) } else // Standard CONNECT format p2 = Value->ShowValue(Buf, field); - if (trace) + if (trace(1)) htrc("new length(%p)=%d\n", p2, strlen(p2)); if ((len = strlen(p2)) > field) { @@ -2714,7 +2714,7 @@ void DOSCOL::WriteColumn(PGLOBAL g) if (p2[i] == '.') p2[i] = Dsp; - if (trace > 1) + if (trace(2)) htrc("buffer=%s\n", p2); /*******************************************************************/ @@ -2724,7 +2724,7 @@ void DOSCOL::WriteColumn(PGLOBAL g) memset(p, ' ', field); memcpy(p, p2, len); - if (trace > 1) + if (trace(2)) htrc(" col write: '%.*s'\n", len, p); } // endif Use @@ -2881,4 +2881,3 @@ bool DOSCOL::AddDistinctValue(PGLOBAL g) } // end of AddDistinctValue /* ------------------------------------------------------------------- */ - diff --git a/storage/connect/tabdos.h b/storage/connect/tabdos.h index 948b357dc1f..bdde37adaad 100644 --- a/storage/connect/tabdos.h +++ b/storage/connect/tabdos.h @@ -29,6 +29,7 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */ friend class TXTFAM; friend class DBFBASE; friend class UNZIPUTL; + friend class JSONCOL; public: // Constructor DOSDEF(void); diff --git a/storage/connect/tabext.cpp b/storage/connect/tabext.cpp index a75b373b564..64d401bef15 100644 --- a/storage/connect/tabext.cpp +++ b/storage/connect/tabext.cpp @@ -433,7 +433,7 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) } else Query->Resize(len); - if (trace) + if (trace(33)) htrc("Query=%s\n", Query->GetStr()); return false; @@ -527,7 +527,7 @@ bool TDBEXT::MakeCommand(PGLOBAL g) return true; } // endif p - if (trace) + if (trace(33)) htrc("Command=%s\n", stmt); Query = new(g)STRING(g, 0, stmt); @@ -585,7 +585,7 @@ EXTCOL::EXTCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am) tdbp->SetColumns(this); } // endif cprec - if (trace) + if (trace(1)) htrc(" making new %sCOL C%d %s at %p\n", am, Index, Name, this); // Set additional remote access method information for column. diff --git a/storage/connect/tabfix.cpp b/storage/connect/tabfix.cpp index a78d5861e53..1969fd4465f 100644 --- a/storage/connect/tabfix.cpp +++ b/storage/connect/tabfix.cpp @@ -291,7 +291,7 @@ bool TDBFIX::IsUsingTemp(PGLOBAL) /***********************************************************************/ bool TDBFIX::OpenDB(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("FIX OpenDB: tdbp=%p tdb=R%d use=%d key=%p mode=%d Ftype=%d\n", this, Tdb_No, Use, To_Key_Col, Mode, Ftype); @@ -345,7 +345,7 @@ bool TDBFIX::OpenDB(PGLOBAL g) /*********************************************************************/ To_BlkFil = InitBlockFilter(g, To_Filter); - if (trace) + if (trace(1)) htrc("OpenFix: R%hd mode=%d BlkFil=%p\n", Tdb_No, Mode, To_BlkFil); /*********************************************************************/ @@ -474,7 +474,7 @@ void BINCOL::ReadColumn(PGLOBAL g) int rc; PTDBFIX tdbp = (PTDBFIX)To_Tdb; - if (trace > 1) + if (trace(2)) htrc("BIN ReadColumn: col %s R%d coluse=%.4X status=%.4X buf_type=%d\n", Name, tdbp->GetTdb_No(), ColUse, Status, Buf_Type); @@ -565,7 +565,7 @@ void BINCOL::WriteColumn(PGLOBAL g) longlong n; PTDBFIX tdbp = (PTDBFIX)To_Tdb; - if (trace) { + if (trace(1)) { htrc("BIN WriteColumn: col %s R%d coluse=%.4X status=%.4X", Name, tdbp->GetTdb_No(), ColUse, Status); htrc(" Lrecl=%d\n", tdbp->Lrecl); diff --git a/storage/connect/tabfmt.cpp b/storage/connect/tabfmt.cpp index 516601a5eb4..63fa2a63668 100644 --- a/storage/connect/tabfmt.cpp +++ b/storage/connect/tabfmt.cpp @@ -185,7 +185,7 @@ PQRYRES CSVColumns(PGLOBAL g, PCSZ dp, PTOS topt, bool info) mxr = MY_MAX(0, tdp->Maxerr); - if (trace) + if (trace(1)) htrc("File %s Sep=%c Qot=%c Header=%d maxerr=%d\n", SVP(tdp->Fn), tdp->Sep, tdp->Qot, tdp->Header, tdp->Maxerr); @@ -379,7 +379,7 @@ PQRYRES CSVColumns(PGLOBAL g, PCSZ dp, PTOS topt, bool info) skip: ; // Skip erroneous line } // endfor num_read - if (trace) { + if (trace(1)) { htrc("imax=%d Lengths:", imax); for (i = 0; i < imax; i++) @@ -391,7 +391,7 @@ PQRYRES CSVColumns(PGLOBAL g, PCSZ dp, PTOS topt, bool info) tdbp->CloseDB(g); skipit: - if (trace) + if (trace(1)) htrc("CSVColumns: imax=%d hmax=%d len=%d\n", imax, hmax, length[0]); @@ -701,7 +701,7 @@ int TDBCSV::EstimatedLength(void) int n = 0; PCOLDEF cdp; - if (trace) + if (trace(1)) htrc("EstimatedLength: Fields=%d Columns=%p\n", Fields, Columns); for (cdp = To_Def->GetCols(); cdp; cdp = cdp->GetNext()) @@ -906,7 +906,7 @@ int TDBCSV::ReadBuffer(PGLOBAL g) int i, n, len, rc = Txfp->ReadBuffer(g); bool bad = false; - if (trace > 1) + if (trace(2)) htrc("CSV: Row is '%s' rc=%d\n", To_Line, rc); if (rc != RC_OK || !Fields) @@ -934,7 +934,7 @@ int TDBCSV::ReadBuffer(PGLOBAL g) if (p) { //len = p++ - p2; - len = p - p2 - 1;; + len = (int)(p - p2 - 1); // if (Sep != ' ') // for (; *p == ' '; p++) ; // Skip blanks @@ -978,7 +978,7 @@ int TDBCSV::ReadBuffer(PGLOBAL g) return RC_NF; } else if ((p = strchr(p2, Sep))) - len = p - p2; + len = (int)(p - p2); else if (i == Fields - 1) len = strlen(p2); else if (Accept && Maxerr == 0) { @@ -996,7 +996,7 @@ int TDBCSV::ReadBuffer(PGLOBAL g) } else len = 0; - Offset[i] = p2 - To_Line; + Offset[i] = (int)(p2 - To_Line); if (Mode != MODE_UPDATE) Fldlen[i] = len; @@ -1024,7 +1024,7 @@ bool TDBCSV::PrepareWriting(PGLOBAL g) char sep[2], qot[2]; int i, nlen, oldlen = strlen(To_Line); - if (trace > 1) + if (trace(2)) htrc("CSV WriteDB: R%d Mode=%d key=%p link=%p\n", Tdb_No, Mode, To_Key_Col, To_Link); @@ -1090,7 +1090,7 @@ bool TDBCSV::PrepareWriting(PGLOBAL g) To_Line[nlen] = '\0'; } // endif - if (trace > 1) + if (trace(2)) htrc("Write: line is=%s", To_Line); return false; @@ -1118,7 +1118,7 @@ int TDBCSV::CheckWrite(PGLOBAL g) { int maxlen, n, nlen = (Fields - 1); - if (trace > 1) + if (trace(2)) htrc("CheckWrite: R%d Mode=%d\n", Tdb_No, Mode); // Before writing the line we must check its length @@ -1290,7 +1290,7 @@ int TDBFMT::ReadBuffer(PGLOBAL g) else ++Linenum; - if (trace > 1) + if (trace(2)) htrc("FMT: Row %d is '%s' rc=%d\n", Linenum, To_Line, rc); // Find the offsets and lengths of the columns for this row @@ -1445,7 +1445,7 @@ void CSVCOL::ReadColumn(PGLOBAL g) Deplac = tdbp->Offset[Fldnum]; // Field offset Long = tdbp->Fldlen[Fldnum]; // Field length - if (trace > 1) + if (trace(2)) htrc("CSV ReadColumn %s Fldnum=%d offset=%d fldlen=%d\n", Name, Fldnum, Deplac, Long); @@ -1489,13 +1489,13 @@ void CSVCOL::WriteColumn(PGLOBAL g) int flen; PTDBCSV tdbp = (PTDBCSV)To_Tdb; - if (trace > 1) + if (trace(2)) htrc("CSV WriteColumn: col %s R%d coluse=%.4X status=%.4X\n", Name, tdbp->GetTdb_No(), ColUse, Status); flen = GetLength(); - if (trace > 1) + if (trace(2)) htrc("Lrecl=%d Long=%d field=%d coltype=%d colval=%p\n", tdbp->Lrecl, Long, flen, Buf_Type, Value); @@ -1510,7 +1510,7 @@ void CSVCOL::WriteColumn(PGLOBAL g) /*********************************************************************/ p = Value->ShowValue(buf); - if (trace > 1) + if (trace(2)) htrc("new length(%p)=%d\n", p, strlen(p)); if ((signed)strlen(p) > flen) { @@ -1522,7 +1522,7 @@ void CSVCOL::WriteColumn(PGLOBAL g) if (p[i] == '.') p[i] = Dsp; - if (trace > 1) + if (trace(2)) htrc("buffer=%s\n", p); /*********************************************************************/ @@ -1536,7 +1536,7 @@ void CSVCOL::WriteColumn(PGLOBAL g) } else strncpy(tdbp->Field[Fldnum], p, flen); - if (trace > 1) + if (trace(2)) htrc(" col written: '%s'\n", p); } // end of WriteColumn diff --git a/storage/connect/tabjdbc.cpp b/storage/connect/tabjdbc.cpp index b6a1487955b..275b5edaeae 100644 --- a/storage/connect/tabjdbc.cpp +++ b/storage/connect/tabjdbc.cpp @@ -153,7 +153,7 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b) // Tabname = GetStringCatInfo(g, "Tabname", Tabname); } // endif - if (trace) + if (trace(1)) htrc("server: %s Tabname: %s", url, Tabname); // Now make the required URL @@ -470,7 +470,7 @@ bool TDBJDBC::MakeInsert(PGLOBAL g) else Prepared = true; - if (trace) + if (trace(33)) htrc("Insert=%s\n", Query->GetStr()); return false; @@ -553,7 +553,7 @@ bool TDBJDBC::OpenDB(PGLOBAL g) { bool rc = true; - if (trace) + if (trace(1)) htrc("JDBC OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n", this, Tdb_No, Use, Mode); @@ -572,7 +572,7 @@ bool TDBJDBC::OpenDB(PGLOBAL g) if (Memory < 3) { // Method will depend on cursor type - if ((Rbuf = Jcp->Rewind(Query->GetStr())) < 0) + if ((Rbuf = Query ? Jcp->Rewind(Query->GetStr()) : 0) < 0) if (Mode != MODE_READX) { Jcp->Close(); return true; @@ -605,6 +605,10 @@ bool TDBJDBC::OpenDB(PGLOBAL g) else if (Quoted) Quote = Jcp->GetQuoteChar(); + if (Mode != MODE_READ && Mode != MODE_READX) + if (Jcp->SetUUID(g, this)) + PushWarning(g, this, 1); + Use = USE_OPEN; // Do it now in case we are recursively called /*********************************************************************/ @@ -767,7 +771,7 @@ bool TDBJDBC::ReadKey(PGLOBAL g, OPVAL op, const key_range *kr) Mode = MODE_READ; } // endif's op - if (trace) + if (trace(33)) htrc("JDBC ReadKey: Query=%s\n", Query->GetStr()); rc = Jcp->ExecuteQuery((char*)Query->GetStr()); @@ -783,7 +787,7 @@ int TDBJDBC::ReadDB(PGLOBAL g) { int rc; - if (trace > 1) + if (trace(2)) htrc("JDBC ReadDB: R%d Mode=%d\n", GetTdb_No(), Mode); if (Mode == MODE_UPDATE || Mode == MODE_DELETE) { @@ -836,7 +840,7 @@ int TDBJDBC::ReadDB(PGLOBAL g) } // endif placed - if (trace > 1) + if (trace(2)) htrc(" Read: Rbuf=%d rc=%d\n", Rbuf, rc); return rc; @@ -897,7 +901,7 @@ int TDBJDBC::WriteDB(PGLOBAL g) Query->RepLast(')'); - if (trace > 1) + if (trace(2)) htrc("Inserting: %s\n", Query->GetStr()); rc = Jcp->ExecuteUpdate(Query->GetStr()); @@ -925,7 +929,7 @@ int TDBJDBC::DeleteDB(PGLOBAL g, int irc) AftRows = Jcp->m_Aff; sprintf(g->Message, "%s: %d affected rows", TableName, AftRows); - if (trace) + if (trace(1)) htrc("%s\n", g->Message); PushWarning(g, this, 0); // 0 means a Note @@ -946,14 +950,14 @@ void TDBJDBC::CloseDB(PGLOBAL g) if (Jcp) Jcp->Close(); - if (trace) + if (trace(1)) htrc("JDBC CloseDB: closing %s\n", Name); if (!Werr && (Mode == MODE_INSERT || Mode == MODE_UPDATE || Mode == MODE_DELETE)) { sprintf(g->Message, "%s: %d affected rows", TableName, AftRows); - if (trace) + if (trace(1)) htrc("%s\n", g->Message); PushWarning(g, this, 0); // 0 means a Note @@ -970,6 +974,7 @@ void TDBJDBC::CloseDB(PGLOBAL g) JDBCCOL::JDBCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am) : EXTCOL(cdp, tdbp, cprec, i, am) { + uuid = false; } // end of JDBCCOL constructor /***********************************************************************/ @@ -977,6 +982,7 @@ JDBCCOL::JDBCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am) /***********************************************************************/ JDBCCOL::JDBCCOL(void) : EXTCOL() { + uuid = false; } // end of JDBCCOL constructor /***********************************************************************/ @@ -985,12 +991,11 @@ JDBCCOL::JDBCCOL(void) : EXTCOL() /***********************************************************************/ JDBCCOL::JDBCCOL(JDBCCOL *col1, PTDB tdbp) : EXTCOL(col1, tdbp) { + uuid = col1->uuid; } // end of JDBCCOL copy constructor /***********************************************************************/ -/* ReadColumn: when SQLFetch is used there is nothing to do as the */ -/* column buffer was bind to the record set. This is also the case */ -/* when calculating MaxSize (Bufp is NULL even when Rows is not). */ +/* ReadColumn: retrieve the column value via the JDBC driver. */ /***********************************************************************/ void JDBCCOL::ReadColumn(PGLOBAL g) { @@ -1117,7 +1122,7 @@ bool TDBXJDC::OpenDB(PGLOBAL g) { bool rc = false; - if (trace) + if (trace(1)) htrc("JDBC OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n", this, Tdb_No, Use, Mode); diff --git a/storage/connect/tabjdbc.h b/storage/connect/tabjdbc.h index d422ed26ef2..078129a14e3 100644 --- a/storage/connect/tabjdbc.h +++ b/storage/connect/tabjdbc.h @@ -101,6 +101,7 @@ protected: /***********************************************************************/ class JDBCCOL : public EXTCOL { friend class TDBJDBC; + friend class JDBConn; public: // Constructors JDBCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am = "JDBC"); @@ -119,6 +120,7 @@ protected: JDBCCOL(void); // Members + bool uuid; // For PostgreSQL }; // end of class JDBCCOL /***********************************************************************/ diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index 8778b7d4b47..b66682e0190 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -54,16 +54,16 @@ USETEMP UseTemp(void); char *GetJsonNull(void); -typedef struct _jncol { - struct _jncol *Next; - char *Name; - char *Fmt; - int Type; - int Len; - int Scale; - bool Cbn; - bool Found; -} JCOL, *PJCL; +//typedef struct _jncol { +// struct _jncol *Next; +// char *Name; +// char *Fmt; +// int Type; +// int Len; +// int Scale; +// bool Cbn; +// bool Found; +//} JCOL, *PJCL; /***********************************************************************/ /* JSONColumns: construct the result blocks containing the description */ @@ -76,26 +76,13 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, FLD_LENGTH, FLD_SCALE, FLD_NULL, FLD_FORMAT}; static unsigned int length[] = {0, 6, 8, 10, 10, 6, 6, 0}; - char *p, colname[65], fmt[129]; - int i, j, lvl, n = 0; + int i, n = 0; int ncol = sizeof(buftyp) / sizeof(int); - bool mgo = (GetTypeID(topt->type) == TAB_MONGO); - PCSZ sep, level; - PVAL valp; - JCOL jcol; - PJCL jcp, fjcp = NULL, pjcp = NULL; - PJPR *jrp, jpp; - PJSON jsp; - PJVAL jvp; - PJOB row; - PJDEF tdp; - TDBJSN *tjnp = NULL; - PJTDB tjsp = NULL; + PJCL jcp; + JSONDISC *pjdc = NULL; PQRYRES qrp; PCOLRES crp; - jcol.Name = jcol.Fmt = NULL; - if (info) { length[0] = 128; length[7] = 256; @@ -107,20 +94,100 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) return NULL; } // endif Multiple - /*********************************************************************/ - /* Open the input file. */ + pjdc = new(g) JSONDISC(g, length); + + if (!(n = pjdc->GetColumns(g, db, dsn, topt))) + return NULL; + + skipit: + if (trace(1)) + htrc("JSONColumns: n=%d len=%d\n", n, length[0]); + + /*********************************************************************/ + /* Allocate the structures used to refer to the result set. */ + /*********************************************************************/ + qrp = PlgAllocResult(g, ncol, n, IDS_COLUMNS + 3, + buftyp, fldtyp, length, false, false); + + crp = qrp->Colresp->Next->Next->Next->Next->Next->Next; + crp->Name = "Nullable"; + crp->Next->Name = "Jpath"; + + if (info || !qrp) + return qrp; + + qrp->Nblin = n; + + /*********************************************************************/ + /* Now get the results into blocks. */ + /*********************************************************************/ + for (i = 0, jcp = pjdc->fjcp; jcp; i++, jcp = jcp->Next) { + if (jcp->Type == TYPE_UNKNOWN) + jcp->Type = TYPE_STRING; // Void column + + crp = qrp->Colresp; // Column Name + crp->Kdata->SetValue(jcp->Name, i); + crp = crp->Next; // Data Type + crp->Kdata->SetValue(jcp->Type, i); + crp = crp->Next; // Type Name + crp->Kdata->SetValue(GetTypeName(jcp->Type), i); + crp = crp->Next; // Precision + crp->Kdata->SetValue(jcp->Len, i); + crp = crp->Next; // Length + crp->Kdata->SetValue(jcp->Len, i); + crp = crp->Next; // Scale (precision) + crp->Kdata->SetValue(jcp->Scale, i); + crp = crp->Next; // Nullable + crp->Kdata->SetValue(jcp->Cbn ? 1 : 0, i); + crp = crp->Next; // Field format + + if (crp->Kdata) + crp->Kdata->SetValue(jcp->Fmt, i); + + } // endfor i + /*********************************************************************/ - level = GetStringTableOption(g, topt, "Level", NULL); + /* Return the result pointer. */ + /*********************************************************************/ + return qrp; + } // end of JSONColumns + +/* -------------------------- Class JSONDISC ------------------------- */ + +/***********************************************************************/ +/* Class used to get the columns of a JSON table. */ +/***********************************************************************/ +JSONDISC::JSONDISC(PGLOBAL g, uint *lg) +{ + length = lg; + jcp = fjcp = pjcp = NULL; + tjnp = NULL; + jpp = NULL; + tjsp = NULL; + jsp = NULL; + row = NULL; + sep = NULL; + i = n = bf = ncol = lvl = 0; + all = false; +} // end of JSONDISC constructor + +int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) +{ + bool mgo = (GetTypeID(topt->type) == TAB_MONGO); + PCSZ level = GetStringTableOption(g, topt, "Level", NULL); if (level) { lvl = atoi(level); lvl = (lvl > 16) ? 16 : lvl; - } else + } else lvl = 0; sep = GetStringTableOption(g, topt, "Separator", "."); - tdp = new(g) JSONDEF; + /*********************************************************************/ + /* Open the input file. */ + /*********************************************************************/ + tdp = new(g) JSONDEF; #if defined(ZIP_SUPPORT) tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL); tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false); @@ -130,21 +197,21 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) if (!(tdp->Database = SetPath(g, db))) return NULL; - tdp->Objname = GetStringTableOption(g, topt, "Object", NULL); - tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0; - tdp->Pretty = GetIntegerTableOption(g, topt, "Pretty", 2); + tdp->Objname = GetStringTableOption(g, topt, "Object", NULL); + tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0; + tdp->Pretty = GetIntegerTableOption(g, topt, "Pretty", 2); tdp->Xcol = GetStringTableOption(g, topt, "Expand", NULL); tdp->Accept = GetBooleanTableOption(g, topt, "Accept", false); tdp->Uri = (dsn && *dsn ? dsn : NULL); if (!tdp->Fn && !tdp->Uri) { strcpy(g->Message, MSG(MISSING_FNAME)); - return NULL; + return 0; } // endif Fn - if (trace) - htrc("File %s objname=%s pretty=%d lvl=%d\n", - tdp->Fn, tdp->Objname, tdp->Pretty, lvl); + if (trace(1)) + htrc("File %s objname=%s pretty=%d lvl=%d\n", + tdp->Fn, tdp->Objname, tdp->Pretty, lvl); if (tdp->Uri) { #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) @@ -160,34 +227,34 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) tdp->Pretty = 0; #else // !MONGO_SUPPORT sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); - return NULL; + return 0; #endif // !MONGO_SUPPORT } // endif Uri - if (tdp->Pretty == 2) { + if (tdp->Pretty == 2) { if (tdp->Zipped) { #if defined(ZIP_SUPPORT) tjsp = new(g) TDBJSON(tdp, new(g) UNZFAM(tdp)); #else // !ZIP_SUPPORT sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); - return NULL; + return 0; #endif // !ZIP_SUPPORT - } else - tjsp = new(g) TDBJSON(tdp, new(g) MAPFAM(tdp)); + } else + tjsp = new(g) TDBJSON(tdp, new(g) MAPFAM(tdp)); - if (tjsp->MakeDocument(g)) - return NULL; + if (tjsp->MakeDocument(g)) + return NULL; - jsp = (tjsp->GetDoc()) ? tjsp->GetDoc()->GetValue(0) : NULL; - } else { - if (!(tdp->Lrecl = GetIntegerTableOption(g, topt, "Lrecl", 0))) + jsp = (tjsp->GetDoc()) ? tjsp->GetDoc()->GetValue(0) : NULL; + } else { + if (!(tdp->Lrecl = GetIntegerTableOption(g, topt, "Lrecl", 0))) if (!mgo) { sprintf(g->Message, "LRECL must be specified for pretty=%d", tdp->Pretty); return NULL; - } else + } else tdp->Lrecl = 8192; // Should be enough - tdp->Ending = GetIntegerTableOption(g, topt, "Ending", CRLF); + tdp->Ending = GetIntegerTableOption(g, topt, "Ending", CRLF); if (tdp->Zipped) { #if defined(ZIP_SUPPORT) @@ -196,7 +263,7 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); return NULL; #endif // !ZIP_SUPPORT - } else if (tdp->Uri) { + } else if (tdp->Uri) { if (tdp->Driver && toupper(*tdp->Driver) == 'C') { #if defined(CMGO_SUPPORT) tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp)); @@ -204,14 +271,14 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) sprintf(g->Message, "Mongo %s Driver not available", "C"); return NULL; #endif - } else if (tdp->Driver && toupper(*tdp->Driver) == 'J') { + } else if (tdp->Driver && toupper(*tdp->Driver) == 'J') { #if defined(JAVA_SUPPORT) tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); #else sprintf(g->Message, "Mongo %s Driver not available", "Java"); return NULL; #endif - } else { // Driver not specified + } else { // Driver not specified #if defined(CMGO_SUPPORT) tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp)); #elif defined(JAVA_SUPPORT) @@ -222,10 +289,10 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) #endif } // endif Driver - } else + } else tjnp = new(g) TDBJSN(tdp, new(g) DOSFAM(tdp)); - tjnp->SetMode(MODE_READ); + tjnp->SetMode(MODE_READ); // Allocate the parse work memory PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL)); @@ -237,248 +304,227 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) tjnp->SetG(G); if (tjnp->OpenDB(g)) - return NULL; + return NULL; - switch (tjnp->ReadDB(g)) { - case RC_EF: - strcpy(g->Message, "Void json table"); - case RC_FX: - goto err; - default: - jsp = tjnp->GetRow(); - } // endswitch ReadDB + switch (tjnp->ReadDB(g)) { + case RC_EF: + strcpy(g->Message, "Void json table"); + case RC_FX: + goto err; + default: + jsp = tjnp->GetRow(); + } // endswitch ReadDB - } // endif pretty + } // endif pretty - if (!(row = (jsp) ? jsp->GetObject() : NULL)) { - strcpy(g->Message, "Can only retrieve columns from object rows"); - goto err; - } // endif row + if (!(row = (jsp) ? jsp->GetObject() : NULL)) { + strcpy(g->Message, "Can only retrieve columns from object rows"); + goto err; + } // endif row - jcol.Next = NULL; - jcol.Found = true; - colname[64] = 0; - fmt[128] = 0; + all = GetBooleanTableOption(g, topt, "Fullarray", false); + jcol.Name = jcol.Fmt = NULL; + jcol.Next = NULL; + jcol.Found = true; + colname[0] = 0; if (!tdp->Uri) { - *fmt = '$'; + fmt[0] = '$'; fmt[1] = '.'; - p = fmt + 2; - } else - p = fmt; - - jrp = (PJPR*)PlugSubAlloc(g, NULL, sizeof(PJPR) * MY_MAX(lvl, 0)); - - /*********************************************************************/ - /* Analyse the JSON tree and define columns. */ - /*********************************************************************/ - for (i = 1; ; i++) { - for (jpp = row->GetFirst(); jpp; jpp = jpp->GetNext()) { - for (j = 0; j < lvl; j++) - jrp[j] = NULL; - - more: - strncpy(colname, jpp->GetKey(), 64); - *p = 0; - j = 0; - jvp = jpp->GetVal(); - - retry: - if ((valp = jvp ? jvp->GetValue() : NULL)) { - jcol.Type = valp->GetType(); - jcol.Len = valp->GetValLen(); - jcol.Scale = valp->GetValPrec(); - jcol.Cbn = valp->IsNull(); - } else if (!jvp || jvp->IsNull()) { - jcol.Type = TYPE_UNKNOWN; - jcol.Len = jcol.Scale = 0; - jcol.Cbn = true; - } else if (j < lvl) { - if (!*p) - strcat(fmt, colname); - - jsp = jvp->GetJson(); - - switch (jsp->GetType()) { - case TYPE_JOB: - if (!jrp[j]) - jrp[j] = jsp->GetFirst(); - - if (*jrp[j]->GetKey() != '$') { - strncat(strncat(fmt, sep, 128), jrp[j]->GetKey(), 128); - strncat(strncat(colname, "_", 64), jrp[j]->GetKey(), 64); - } // endif Key - - jvp = jrp[j]->GetVal(); - j++; - break; - case TYPE_JAR: - if (!tdp->Xcol || stricmp(tdp->Xcol, colname)) { - if (tdp->Uri) - strncat(strncat(fmt, sep, 128), "0", 128); - else - strncat(fmt, "[0]", 128); - - } else - strncat(fmt, (tdp->Uri ? sep : "[]"), 128); - - jvp = jsp->GetValue(0); - break; - default: - sprintf(g->Message, "Logical error after %s", fmt); - goto err; - } // endswitch jsp - - goto retry; - } else if (lvl >= 0) { - jcol.Type = TYPE_STRING; - jcol.Len = 256; - jcol.Scale = 0; - jcol.Cbn = true; - } else - continue; + bf = 2; + } // endif Uri - // Check whether this column was already found - for (jcp = fjcp; jcp; jcp = jcp->Next) - if (!strcmp(colname, jcp->Name)) - break; - - if (jcp) { - if (jcp->Type != jcol.Type) { - if (jcp->Type == TYPE_UNKNOWN) - jcp->Type = jcol.Type; - else if (jcol.Type != TYPE_UNKNOWN) - jcp->Type = TYPE_STRING; + /*********************************************************************/ + /* Analyse the JSON tree and define columns. */ + /*********************************************************************/ + for (i = 1; ; i++) { + for (jpp = row->GetFirst(); jpp; jpp = jpp->GetNext()) { + strncpy(colname, jpp->GetKey(), 64); + fmt[bf] = 0; + + if (Find(g, jpp->GetVal(), MY_MIN(lvl, 0))) + goto err; + + } // endfor jpp + + // Missing column can be null + for (jcp = fjcp; jcp; jcp = jcp->Next) { + jcp->Cbn |= !jcp->Found; + jcp->Found = false; + } // endfor jcp + + if (tdp->Pretty != 2) { + // Read next record + switch (tjnp->ReadDB(g)) { + case RC_EF: + jsp = NULL; + break; + case RC_FX: + goto err; + default: + jsp = tjnp->GetRow(); + } // endswitch ReadDB - } // endif Type + } else + jsp = tjsp->GetDoc()->GetValue(i); - if (*p && (!jcp->Fmt || strlen(jcp->Fmt) < strlen(fmt))) { - jcp->Fmt = PlugDup(g, fmt); - length[7] = MY_MAX(length[7], strlen(fmt)); - } // endif fmt - - jcp->Len = MY_MAX(jcp->Len, jcol.Len); - jcp->Scale = MY_MAX(jcp->Scale, jcol.Scale); - jcp->Cbn |= jcol.Cbn; - jcp->Found = true; - } else if (jcol.Type != TYPE_UNKNOWN || tdp->Accept) { - // New column - jcp = (PJCL)PlugSubAlloc(g, NULL, sizeof(JCOL)); - *jcp = jcol; - jcp->Cbn |= (i > 1); - jcp->Name = PlugDup(g, colname); - length[0] = MY_MAX(length[0], strlen(colname)); - - if (*p) { - jcp->Fmt = PlugDup(g, fmt); - length[7] = MY_MAX(length[7], strlen(fmt)); - } else - jcp->Fmt = NULL; - - if (pjcp) { - jcp->Next = pjcp->Next; - pjcp->Next = jcp; - } else - fjcp = jcp; + if (!(row = (jsp) ? jsp->GetObject() : NULL)) + break; - n++; - } // endif jcp + } // endfor i - pjcp = jcp; + if (tdp->Pretty != 2) + tjnp->CloseDB(g); - for (j = lvl - 1; j >= 0; j--) - if (jrp[j] && (jrp[j] = jrp[j]->GetNext())) - goto more; + return n; - } // endfor jpp +err: + if (tdp->Pretty != 2) + tjnp->CloseDB(g); - // Missing column can be null - for (jcp = fjcp; jcp; jcp = jcp->Next) { - jcp->Cbn |= !jcp->Found; - jcp->Found = false; - } // endfor jcp + return 0; +} // end of GetColumns - if (tdp->Pretty != 2) { - // Read next record - switch (tjnp->ReadDB(g)) { - case RC_EF: - jsp = NULL; - break; - case RC_FX: - goto err; - default: - jsp = tjnp->GetRow(); - } // endswitch ReadDB +bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j) +{ + char *p, *pc = colname + strlen(colname); + int ars; + PJOB job; + PJAR jar; + + if ((valp = jvp ? jvp->GetValue() : NULL)) { + jcol.Type = valp->GetType(); + jcol.Len = valp->GetValLen(); + jcol.Scale = valp->GetValPrec(); + jcol.Cbn = valp->IsNull(); + } else if (!jvp || jvp->IsNull()) { + jcol.Type = TYPE_UNKNOWN; + jcol.Len = jcol.Scale = 0; + jcol.Cbn = true; + } else if (j < lvl) { + if (!fmt[bf]) + strcat(fmt, colname); + + p = fmt + strlen(fmt); + jsp = jvp->GetJson(); + + switch (jsp->GetType()) { + case TYPE_JOB: + job = (PJOB)jsp; + + for (PJPR jrp = job->GetFirst(); jrp; jrp = jrp->GetNext()) { + if (*jrp->GetKey() != '$') { + strncat(strncat(fmt, sep, 128), jrp->GetKey(), 128); + strncat(strncat(colname, "_", 64), jrp->GetKey(), 64); + } // endif Key + + if (Find(g, jrp->GetVal(), j + 1)) + return true; + + *p = *pc = 0; + } // endfor jrp + + return false; + case TYPE_JAR: + jar = (PJAR)jsp; + + if (all || (tdp->Xcol && !stricmp(tdp->Xcol, colname))) + ars = jar->GetSize(false); + else + ars = MY_MIN(jar->GetSize(false), 1); - } else - jsp = tjsp->GetDoc()->GetValue(i); + for (int k = 0; k < ars; k++) { + if (!tdp->Xcol || stricmp(tdp->Xcol, colname)) { + sprintf(buf, "%d", k); - if (!(row = (jsp) ? jsp->GetObject() : NULL)) - break; + if (tdp->Uri) + strncat(strncat(fmt, sep, 128), buf, 128); + else + strncat(strncat(strncat(fmt, "[", 128), buf, 128), "]", 128); - } // endor i + if (all) + strncat(strncat(colname, "_", 64), buf, 64); - if (tdp->Pretty != 2) - tjnp->CloseDB(g); + } else + strncat(fmt, (tdp->Uri ? sep : "[*]"), 128); - skipit: - if (trace) - htrc("JSONColumns: n=%d len=%d\n", n, length[0]); + if (Find(g, jar->GetValue(k), j)) + return true; - /*********************************************************************/ - /* Allocate the structures used to refer to the result set. */ - /*********************************************************************/ - qrp = PlgAllocResult(g, ncol, n, IDS_COLUMNS + 3, - buftyp, fldtyp, length, false, false); + *p = *pc = 0; + } // endfor k - crp = qrp->Colresp->Next->Next->Next->Next->Next->Next; - crp->Name = "Nullable"; - crp->Next->Name = "Jpath"; + return false; + default: + sprintf(g->Message, "Logical error after %s", fmt); + return true; + } // endswitch Type - if (info || !qrp) - return qrp; + } else if (lvl >= 0) { + jcol.Type = TYPE_STRING; + jcol.Len = 256; + jcol.Scale = 0; + jcol.Cbn = true; + } else + return false; - qrp->Nblin = n; + AddColumn(g); + return false; +} // end of Find - /*********************************************************************/ - /* Now get the results into blocks. */ - /*********************************************************************/ - for (i = 0, jcp = fjcp; jcp; i++, jcp = jcp->Next) { - if (jcp->Type == TYPE_UNKNOWN) - jcp->Type = TYPE_STRING; // Void column +void JSONDISC::AddColumn(PGLOBAL g) +{ + bool b = fmt[bf] != 0; // True if formatted - crp = qrp->Colresp; // Column Name - crp->Kdata->SetValue(jcp->Name, i); - crp = crp->Next; // Data Type - crp->Kdata->SetValue(jcp->Type, i); - crp = crp->Next; // Type Name - crp->Kdata->SetValue(GetTypeName(jcp->Type), i); - crp = crp->Next; // Precision - crp->Kdata->SetValue(jcp->Len, i); - crp = crp->Next; // Length - crp->Kdata->SetValue(jcp->Len, i); - crp = crp->Next; // Scale (precision) - crp->Kdata->SetValue(jcp->Scale, i); - crp = crp->Next; // Nullable - crp->Kdata->SetValue(jcp->Cbn ? 1 : 0, i); - crp = crp->Next; // Field format + // Check whether this column was already found + for (jcp = fjcp; jcp; jcp = jcp->Next) + if (!strcmp(colname, jcp->Name)) + break; - if (crp->Kdata) - crp->Kdata->SetValue(jcp->Fmt, i); + if (jcp) { + if (jcp->Type != jcol.Type) { + if (jcp->Type == TYPE_UNKNOWN) + jcp->Type = jcol.Type; + else if (jcol.Type != TYPE_UNKNOWN) + jcp->Type = TYPE_STRING; + + } // endif Type + + if (b && (!jcp->Fmt || strlen(jcp->Fmt) < strlen(fmt))) { + jcp->Fmt = PlugDup(g, fmt); + length[7] = MY_MAX(length[7], strlen(fmt)); + } // endif fmt + + jcp->Len = MY_MAX(jcp->Len, jcol.Len); + jcp->Scale = MY_MAX(jcp->Scale, jcol.Scale); + jcp->Cbn |= jcol.Cbn; + jcp->Found = true; + } else if (jcol.Type != TYPE_UNKNOWN || tdp->Accept) { + // New column + jcp = (PJCL)PlugSubAlloc(g, NULL, sizeof(JCOL)); + *jcp = jcol; + jcp->Cbn |= (i > 1); + jcp->Name = PlugDup(g, colname); + length[0] = MY_MAX(length[0], strlen(colname)); + + if (b) { + jcp->Fmt = PlugDup(g, fmt); + length[7] = MY_MAX(length[7], strlen(fmt)); + } else + jcp->Fmt = NULL; - } // endfor i + if (pjcp) { + jcp->Next = pjcp->Next; + pjcp->Next = jcp; + } else + fjcp = jcp; - /*********************************************************************/ - /* Return the result pointer. */ - /*********************************************************************/ - return qrp; + n++; + } // endif jcp -err: - if (tdp->Pretty != 2) - tjnp->CloseDB(g); + pjcp = jcp; +} // end of AddColumn - return NULL; - } // end of JSONColumns /* -------------------------- Class JSONDEF -------------------------- */ @@ -513,6 +559,7 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff) Limit = GetIntCatInfo("Limit", 10); Base = GetIntCatInfo("Base", 0) ? 1 : 0; Sep = *GetStringCatInfo(g, "Separator", "."); + Accept = GetBoolCatInfo("Accept", false); if (Uri = GetStringCatInfo(g, "Connect", NULL)) { #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) @@ -1471,6 +1518,9 @@ void JSONCOL::ReadColumn(PGLOBAL g) if (!Tjp->SameRow || Xnod >= Tjp->SameRow) Value->SetValue_pval(GetColumnValue(g, Tjp->Row, 0)); + if (Xpd && Value->IsNull() && !((PJDEF)Tjp->To_Def)->Accept) + throw("Null expandable JSON value"); + // Set null when applicable if (!Nullable) Value->SetNull(false); @@ -1546,11 +1596,16 @@ PVAL JSONCOL::GetColumnValue(PGLOBAL g, PJSON row, int i) /***********************************************************************/ PVAL JSONCOL::ExpandArray(PGLOBAL g, PJAR arp, int n) { - int ars; + int ars = MY_MIN(Tjp->Limit, arp->size()); PJVAL jvp; JVALUE jval; - ars = MY_MIN(Tjp->Limit, arp->size()); + if (!ars) { + Value->Reset(); + Value->SetNull(true); + Tjp->NextSame = 0; + return Value; + } // endif ars if (!(jvp = arp->GetValue((Nodes[n].Rx = Nodes[n].Nx)))) { strcpy(g->Message, "Logical error expanding array"); @@ -1591,14 +1646,14 @@ PVAL JSONCOL::CalculateArray(PGLOBAL g, PJAR arp, int n) vp->Reset(); ars = MY_MIN(Tjp->Limit, arp->size()); - if (trace) + if (trace(1)) htrc("CalculateArray: size=%d op=%d nextsame=%d\n", ars, op, nextsame); for (i = 0; i < ars; i++) { jvrp = arp->GetValue(i); - if (trace) + if (trace(1)) htrc("i=%d nv=%d\n", i, nv); if (!jvrp->IsNull() || (op == OP_CNC && GetJsonNull())) do { @@ -1612,7 +1667,7 @@ PVAL JSONCOL::CalculateArray(PGLOBAL g, PJAR arp, int n) } else jvp = jvrp; - if (trace) + if (trace(1)) htrc("jvp=%s null=%d\n", jvp->GetString(g), jvp->IsNull() ? 1 : 0); @@ -1648,7 +1703,7 @@ PVAL JSONCOL::CalculateArray(PGLOBAL g, PJAR arp, int n) if (err) vp->Reset(); - if (trace) { + if (trace(1)) { char buf(32); htrc("vp='%s' err=%d\n", diff --git a/storage/connect/tabjson.h b/storage/connect/tabjson.h index 17583cba333..0341c0f8aa0 100644 --- a/storage/connect/tabjson.h +++ b/storage/connect/tabjson.h @@ -15,6 +15,7 @@ enum JMODE {MODE_OBJECT, MODE_ARRAY, MODE_VALUE}; typedef class JSONDEF *PJDEF; typedef class TDBJSON *PJTDB; typedef class JSONCOL *PJCOL; +class TDBJSN; /***********************************************************************/ /* The JSON tree node. Can be an Object or an Array. */ @@ -29,6 +30,47 @@ typedef struct _jnode { int Nx; // Next to read row number } JNODE, *PJNODE; +typedef struct _jncol { + struct _jncol *Next; + char *Name; + char *Fmt; + int Type; + int Len; + int Scale; + bool Cbn; + bool Found; +} JCOL, *PJCL; + +/***********************************************************************/ +/* Class used to get the columns of a mongo collection. */ +/***********************************************************************/ +class JSONDISC : public BLOCK { +public: + // Constructor + JSONDISC(PGLOBAL g, uint *lg); + + // Functions + int GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt); + bool Find(PGLOBAL g, PJVAL jvp, int j); + void AddColumn(PGLOBAL g); + + // Members + JCOL jcol; + PJCL jcp, fjcp, pjcp; + PVAL valp; + PJDEF tdp; + TDBJSN *tjnp; + PJTDB tjsp; + PJPR jpp; + PJSON jsp; + PJOB row; + PCSZ sep; + char colname[65], fmt[129], buf[16]; + uint *length; + int i, n, bf, ncol, lvl; + bool all; +}; // end of JSONDISC + /***********************************************************************/ /* JSON table. */ /***********************************************************************/ @@ -36,13 +78,13 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */ friend class TDBJSON; friend class TDBJSN; friend class TDBJCL; + friend class JSONDISC; #if defined(CMGO_SUPPORT) friend class CMGFAM; #endif // CMGO_SUPPORT #if defined(JAVA_SUPPORT) friend class JMGFAM; #endif // JAVA_SUPPORT - friend PQRYRES JSONColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool); public: // Constructor JSONDEF(void); diff --git a/storage/connect/table.cpp b/storage/connect/table.cpp index 61aefc93082..d4d3a34d67e 100644 --- a/storage/connect/table.cpp +++ b/storage/connect/table.cpp @@ -128,7 +128,7 @@ PCOL TDB::ColDB(PGLOBAL g, PSZ name, int num) PCOLDEF cdp; PCOL cp, colp = NULL, cprec = NULL; - if (trace) + if (trace(1)) htrc("ColDB: am=%d colname=%s tabname=%s num=%d\n", GetAmType(), SVP(name), Name, num); @@ -146,7 +146,7 @@ PCOL TDB::ColDB(PGLOBAL g, PSZ name, int num) else if (cp->GetIndex() < i) cprec = cp; - if (trace) + if (trace(1)) htrc("cdp(%d).Name=%s cp=%p\n", i, cdp->GetName(), cp); /*****************************************************************/ @@ -159,7 +159,7 @@ PCOL TDB::ColDB(PGLOBAL g, PSZ name, int num) else if (Mode != MODE_INSERT) colp = InsertSpcBlk(g, cdp); - if (trace) + if (trace(1)) htrc("colp=%p\n", colp); if (name || num) @@ -256,7 +256,7 @@ PCOL TDB::InsertSpcBlk(PGLOBAL g, PCOLDEF cdp) /***********************************************************************/ void TDB::MarkDB(PGLOBAL, PTDB tdb2) { - if (trace) + if (trace(1)) htrc("DOS MarkDB: tdbp=%p tdb2=%p\n", this, tdb2); } // end of MarkDB @@ -416,7 +416,7 @@ PCOL TDBASE::ColDB(PGLOBAL g, PSZ name, int num) PCOLDEF cdp; PCOL cp, colp = NULL, cprec = NULL; - if (trace) + if (trace(1)) htrc("ColDB: am=%d colname=%s tabname=%s num=%d\n", GetAmType(), SVP(name), Name, num); @@ -434,7 +434,7 @@ PCOL TDBASE::ColDB(PGLOBAL g, PSZ name, int num) else if (cp->GetIndex() < i) cprec = cp; - if (trace) + if (trace(1)) htrc("cdp(%d).Name=%s cp=%p\n", i, cdp->GetName(), cp); /*****************************************************************/ @@ -447,7 +447,7 @@ PCOL TDBASE::ColDB(PGLOBAL g, PSZ name, int num) else if (Mode != MODE_INSERT) colp = InsertSpcBlk(g, cdp); - if (trace) + if (trace(1)) htrc("colp=%p\n", colp); if (name || num) @@ -592,7 +592,7 @@ void TDBASE::PrintAM(FILE *f, char *m) /***********************************************************************/ void TDBASE::MarkDB(PGLOBAL, PTDB tdb2) { - if (trace) + if (trace(1)) htrc("DOS MarkDB: tdbp=%p tdb2=%p\n", this, tdb2); } // end of MarkDB diff --git a/storage/connect/tabmac.cpp b/storage/connect/tabmac.cpp index a28b5d7108c..8260ab65391 100644 --- a/storage/connect/tabmac.cpp +++ b/storage/connect/tabmac.cpp @@ -367,13 +367,13 @@ void MACCOL::ReadColumn(PGLOBAL g) case 11: // Description if ((p = strstr(adp->Description, " - Packet Scheduler Miniport"))) { strncpy(buf, adp->Description, p - adp->Description); - i = p - adp->Description; + i = (int)(p - adp->Description); strncpy(buf, adp->Description, i); buf[i] = 0; p = buf; } else if ((p = strstr(adp->Description, " - Miniport d'ordonnancement de paquets"))) { - i = p - adp->Description; + i = (int)(p - adp->Description); strncpy(buf, adp->Description, i); buf[i] = 0; p = buf; diff --git a/storage/connect/tabmul.cpp b/storage/connect/tabmul.cpp index 5c41f9094ac..649fc6706c6 100644 --- a/storage/connect/tabmul.cpp +++ b/storage/connect/tabmul.cpp @@ -134,7 +134,7 @@ bool TDBMUL::InitFileNames(PGLOBAL g) PSZ filename; int rc, n = 0; - if (trace) + if (trace(1)) htrc("in InitFileName: fn[]=%d\n", FNSZ); filename = (char*)PlugSubAlloc(g, NULL, FNSZ); @@ -144,7 +144,7 @@ bool TDBMUL::InitFileNames(PGLOBAL g) PlugSetPath(filename, Tdbp->GetFile(g), Tdbp->GetPath()); - if (trace) + if (trace(1)) htrc("InitFileName: fn='%s'\n", filename); if (Mul != 2) { @@ -159,7 +159,7 @@ bool TDBMUL::InitFileNames(PGLOBAL g) if (dirp->OpenDB(g)) return true; - if (trace && Mul == 3) { + if (trace(1) && Mul == 3) { int nf = ((PTDBSDR)dirp)->FindInDir(g); htrc("Number of files = %d\n", nf); } // endif trace @@ -203,12 +203,12 @@ bool TDBMUL::InitFileNames(PGLOBAL g) // Data files can be imported from Windows (having CRLF) if (*p == '\n' || *p == '\r') { // is this enough for Unix ??? - *p--; // Eliminate ending CR or LF character + p--; // Eliminate ending CR or LF character if (p >= filename) // is this enough for Unix ??? if (*p == '\n' || *p == '\r') - *p--; // Eliminate ending CR or LF character + p--; // Eliminate ending CR or LF character } // endif p @@ -319,7 +319,7 @@ int TDBMUL::GetMaxSize(PGLOBAL g) int i; int mxsz; - if (trace) + if (trace(1)) htrc("TDBMUL::GetMaxSize: Filenames=%p\n", Filenames); if (!Filenames && InitFileNames(g)) @@ -375,7 +375,7 @@ int TDBMUL::RowNumber(PGLOBAL g, bool b) /***********************************************************************/ bool TDBMUL::OpenDB(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("MUL OpenDB: tdbp=%p tdb=R%d use=%d key=%p mode=%d\n", this, Tdb_No, Use, To_Key_Col, Mode); @@ -546,7 +546,7 @@ bool TDBMSD::InitFileNames(PGLOBAL g) PSZ filename; int rc, n = 0; - if (trace) + if (trace(1)) htrc("in InitFileName: fn[]=%d\n", FNSZ); filename = (char*)PlugSubAlloc(g, NULL, FNSZ); @@ -556,7 +556,7 @@ bool TDBMSD::InitFileNames(PGLOBAL g) PlugSetPath(filename, Tdbp->GetFile(g), Tdbp->GetPath()); - if (trace) + if (trace(1)) htrc("InitFileName: fn='%s'\n", filename); dirp = new(g) TDBSDR(filename); @@ -787,7 +787,7 @@ int TDBDIR::GetMaxSize(PGLOBAL g) /***********************************************************************/ bool TDBDIR::OpenDB(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("DIR OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n", this, Tdb_No, Use, Mode); @@ -985,7 +985,7 @@ void DIRCOL::SetTimeValue(PGLOBAL g, FILETIME& ftime) /***********************************************************************/ void DIRCOL::ReadColumn(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("DIR ReadColumn: col %s R%d use=%.4X status=%.4X type=%d N=%d\n", Name, Tdbp->GetTdb_No(), ColUse, Status, Buf_Type, N); @@ -1452,7 +1452,7 @@ int TDBDHR::GetMaxSize(PGLOBAL g) /***********************************************************************/ bool TDBDHR::OpenDB(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("DHR OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n", this, Tdb_No, Use, Mode); @@ -1589,7 +1589,7 @@ void DHRCOL::ReadColumn(PGLOBAL g) int rc; PTDBDHR tdbp = (PTDBDHR)To_Tdb; - if (trace) + if (trace(1)) htrc("DHR ReadColumn: col %s R%d use=%.4X status=%.4X type=%d N=%d\n", Name, tdbp->GetTdb_No(), ColUse, Status, Buf_Type, N); diff --git a/storage/connect/tabmysql.cpp b/storage/connect/tabmysql.cpp index d1e2ae69608..605b3822430 100644 --- a/storage/connect/tabmysql.cpp +++ b/storage/connect/tabmysql.cpp @@ -124,8 +124,8 @@ bool MYSQLDEF::GetServerInfo(PGLOBAL g, const char *server_name) DBUG_RETURN(true); } // endif server - DBUG_PRINT("info", ("get_server_by_name returned server at %lx", - (size_t) server)); + DBUG_PRINT("info", ("get_server_by_name returned server at %p", + server)); // TODO: We need to examine which of these can really be NULL Hostname = PlugDup(g, server->host); @@ -203,7 +203,7 @@ bool MYSQLDEF::ParseURL(PGLOBAL g, char *url, bool b) // Otherwise, straight server name, Tabname = (b) ? GetStringCatInfo(g, "Tabname", Name) : NULL; - if (trace) + if (trace(1)) htrc("server: %s TableName: %s", url, Tabname); Server = url; @@ -567,7 +567,7 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx) return true; } // endif Query - if (trace) + if (trace(33)) htrc("Query=%s\n", Query->GetStr()); return false; @@ -681,7 +681,7 @@ bool TDBMYSQL::MakeCommand(PGLOBAL g) strlwr(strcpy(name, Name)); // Not a keyword if ((p = strstr(qrystr, name))) { - Query->Set(Qrystr, p - qrystr); + Query->Set(Qrystr, (uint)(p - qrystr)); if (qtd && *(p-1) == ' ') { Query->Append('`'); @@ -1042,7 +1042,7 @@ int TDBMYSQL::SendCommand(PGLOBAL g) sprintf(g->Message, "%s: %d affected rows", TableName, AftRows); PushWarning(g, this, 0); // 0 means a Note - if (trace) + if (trace(1)) htrc("%s\n", g->Message); if (w && Myc.ExecSQL(g, "SHOW WARNINGS") == RC_OK) { @@ -1109,7 +1109,7 @@ bool TDBMYSQL::ReadKey(PGLOBAL g, OPVAL op, const key_range *kr) Mode = MODE_READ; } // endif's op - if (trace) + if (trace(33)) htrc("MYSQL ReadKey: Query=%s\n", Query->GetStr()); m_Rc = Myc.ExecSQL(g, Query->GetStr()); @@ -1124,7 +1124,7 @@ int TDBMYSQL::ReadDB(PGLOBAL g) { int rc; - if (trace > 1) + if (trace(2)) htrc("MySQL ReadDB: R%d Mode=%d\n", GetTdb_No(), Mode); if (Mode == MODE_UPDATE || Mode == MODE_DELETE) @@ -1137,7 +1137,7 @@ int TDBMYSQL::ReadDB(PGLOBAL g) N++; Fetched = ((rc = Myc.Fetch(g, -1)) == RC_OK); - if (trace > 1) + if (trace(2)) htrc(" Read: rc=%d\n", rc); return rc; @@ -1220,7 +1220,7 @@ void TDBMYSQL::CloseDB(PGLOBAL g) Myc.Close(); } // endif Myc - if (trace) + if (trace(1)) htrc("MySQL CloseDB: closing %s rc=%d\n", Name, m_Rc); } // end of CloseDB @@ -1248,7 +1248,7 @@ MYSQLCOL::MYSQLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am) Slen = 0; Rank = -1; // Not known yet - if (trace) + if (trace(1)) htrc(" making new %sCOL C%d %s at %p\n", am, Index, Name, this); } // end of MYSQLCOL constructor @@ -1279,7 +1279,7 @@ MYSQLCOL::MYSQLCOL(MYSQL_FIELD *fld, PTDB tdbp, int i, PCSZ am) Slen = 0; Rank = i; - if (trace) + if (trace(1)) htrc(" making new %sCOL C%d %s at %p\n", am, Index, Name, this); } // end of MYSQLCOL constructor @@ -1409,7 +1409,7 @@ void MYSQLCOL::ReadColumn(PGLOBAL g) tdbp->Fetched = true; if ((buf = ((PTDBMY)To_Tdb)->Myc.GetCharField(Rank))) { - if (trace > 1) + if (trace(2)) htrc("MySQL ReadColumn: name=%s buf=%s\n", Name, buf); // TODO: have a true way to differenciate temporal values @@ -1679,7 +1679,7 @@ MYXCOL::MYXCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am) MYXCOL::MYXCOL(MYSQL_FIELD *fld, PTDB tdbp, int i, PCSZ am) : MYSQLCOL(fld, tdbp, i, am) { - if (trace) + if (trace(1)) htrc(" making new %sCOL C%d %s at %p\n", am, Index, Name, this); } // end of MYSQLCOL constructor diff --git a/storage/connect/tabodbc.cpp b/storage/connect/tabodbc.cpp index 56e5e72efd6..f7bc3934fbd 100644 --- a/storage/connect/tabodbc.cpp +++ b/storage/connect/tabodbc.cpp @@ -289,7 +289,7 @@ void TDBODBC::SetFile(PGLOBAL g, PCSZ fn) sprintf(Connect, MulConn, fn); } // endif MultConn - DBQ = (PSZ)fn; + DBQ = PlugDup(g, fn); } // end of SetFile /***********************************************************************/ @@ -538,7 +538,7 @@ bool TDBODBC::OpenDB(PGLOBAL g) { bool rc = true; - if (trace) + if (trace(1)) htrc("ODBC OpenDB: tdbp=%p tdb=R%d use=%dmode=%d\n", this, Tdb_No, Use, Mode); @@ -750,7 +750,7 @@ bool TDBODBC::ReadKey(PGLOBAL g, OPVAL op, const key_range *kr) Mode = MODE_READ; } // endif's op - if (trace) + if (trace(33)) htrc("ODBC ReadKey: Query=%s\n", Query->GetStr()); Rows = Ocp->ExecDirectSQL((char*)Query->GetStr(), (PODBCCOL)Columns); @@ -765,7 +765,7 @@ int TDBODBC::ReadDB(PGLOBAL g) { int rc; - if (trace > 1) + if (trace(2)) htrc("ODBC ReadDB: R%d Mode=%d\n", GetTdb_No(), Mode); if (Mode == MODE_UPDATE || Mode == MODE_DELETE) { @@ -776,7 +776,7 @@ int TDBODBC::ReadDB(PGLOBAL g) if (!Ocp->ExecSQLcommand(Query->GetStr())) { sprintf(g->Message, "%s: %d affected rows", TableName, AftRows); - if (trace) + if (trace(1)) htrc("%s\n", g->Message); PushWarning(g, this, 0); // 0 means a Note @@ -817,7 +817,7 @@ int TDBODBC::ReadDB(PGLOBAL g) } // endif Placed - if (trace > 1) + if (trace(2)) htrc(" Read: Rbuf=%d rc=%d\n", Rbuf, rc); return rc; @@ -852,7 +852,7 @@ int TDBODBC::DeleteDB(PGLOBAL g, int irc) if (!Ocp->ExecSQLcommand(Query->GetStr())) { sprintf(g->Message, "%s: %d affected rows", TableName, AftRows); - if (trace) + if (trace(1)) htrc("%s\n", g->Message); PushWarning(g, this, 0); // 0 means a Note @@ -874,7 +874,7 @@ void TDBODBC::CloseDB(PGLOBAL g) Ocp->Close(); - if (trace) + if (trace(1)) htrc("ODBC CloseDB: closing %s\n", Name); } // end of CloseDB @@ -975,7 +975,7 @@ void ODBCCOL::ReadColumn(PGLOBAL g) } // endif Buf_Type - if (trace > 1) { + if (trace(2)) { char buf[64]; htrc("ODBC Column %s: rows=%d buf=%p type=%d value=%s\n", @@ -1214,7 +1214,7 @@ bool TDBXDBC::OpenDB(PGLOBAL g) { bool rc = false; - if (trace) + if (trace(1)) htrc("ODBC OpenDB: tdbp=%p tdb=R%d use=%dmode=%d\n", this, Tdb_No, Use, Mode); diff --git a/storage/connect/tabpivot.cpp b/storage/connect/tabpivot.cpp index 76a46e6899b..da5d134f347 100644 --- a/storage/connect/tabpivot.cpp +++ b/storage/connect/tabpivot.cpp @@ -299,7 +299,7 @@ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g) Qryp->Nbcol += (ndif - 2); return Qryp; } catch (int n) { - if (trace) + if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); } catch (const char *msg) { strcpy(g->Message, msg); diff --git a/storage/connect/tabsys.cpp b/storage/connect/tabsys.cpp index 7f0d9881298..f73a2b6578d 100644 --- a/storage/connect/tabsys.cpp +++ b/storage/connect/tabsys.cpp @@ -180,7 +180,7 @@ PTDB TDBINI::Clone(PTABS t) /***********************************************************************/ char *TDBINI::GetSeclist(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("GetSeclist: Seclist=%p\n", Seclist); if (!Seclist) { @@ -267,7 +267,7 @@ bool TDBINI::OpenDB(PGLOBAL g) if (!colp->IsSpecial()) // Not a pseudo column colp->AllocBuf(g); - if (trace) + if (trace(1)) htrc("INI OpenDB: seclist=%s seclen=%d ifile=%s\n", Seclist, Seclen, Ifile); @@ -287,7 +287,7 @@ int TDBINI::ReadDB(PGLOBAL) else Section += (strlen(Section) + 1); - if (trace > 1) + if (trace(2)) htrc("INI ReadDB: section=%s N=%d\n", Section, N); N++; @@ -453,7 +453,7 @@ void INICOL::ReadColumn(PGLOBAL) { PTDBINI tdbp = (PTDBINI)To_Tdb; - if (trace > 1) + if (trace(2)) htrc("INI ReadColumn: col %s R%d flag=%d\n", Name, tdbp->GetTdb_No(), Flag); @@ -493,7 +493,7 @@ void INICOL::WriteColumn(PGLOBAL g) bool rc; PTDBINI tdbp = (PTDBINI)To_Tdb; - if (trace > 1) + if (trace(2)) htrc("INI WriteColumn: col %s R%d coluse=%.4X status=%.4X\n", Name, tdbp->GetTdb_No(), ColUse, Status); @@ -823,7 +823,7 @@ void XINCOL::WriteColumn(PGLOBAL g) bool rc; PTDBXIN tdbp = (PTDBXIN)To_Tdb; - if (trace > 1) + if (trace(2)) htrc("XIN WriteColumn: col %s R%d coluse=%.4X status=%.4X\n", Name, tdbp->GetTdb_No(), ColUse, Status); diff --git a/storage/connect/tabtbl.cpp b/storage/connect/tabtbl.cpp index 7925e8f29a8..e194568ccf8 100644 --- a/storage/connect/tabtbl.cpp +++ b/storage/connect/tabtbl.cpp @@ -132,7 +132,7 @@ bool TBLDEF::DefineAM(PGLOBAL g, LPCSTR, int) tbl = new(g) XTAB(pn, def); tbl->SetSchema(pdb); - if (trace) + if (trace(1)) htrc("TBL: Name=%s db=%s\n", tbl->GetName(), tbl->GetSchema()); // Link the blocks @@ -436,7 +436,7 @@ int TDBTBL::RowNumber(PGLOBAL g, bool b) /***********************************************************************/ bool TDBTBL::OpenDB(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("TBL OpenDB: tdbp=%p tdb=R%d use=%d key=%p mode=%d\n", this, Tdb_No, Use, To_Key_Col, Mode); @@ -475,7 +475,7 @@ bool TDBTBL::OpenDB(PGLOBAL g) else if (((PPRXCOL)cp)->Init(g, NULL) && !Accept) return TRUE; - if (trace) + if (trace(1)) htrc("Opening subtable %s\n", Tdbp->GetName()); // Now we can safely open the table @@ -530,7 +530,7 @@ int TDBTBL::ReadDB(PGLOBAL g) else if (((PPRXCOL)cp)->Init(g, NULL) && !Accept) return RC_FX; - if (trace) + if (trace(1)) htrc("Opening subtable %s\n", Tdbp->GetName()); // Now we can safely open the table @@ -555,7 +555,7 @@ int TDBTBL::ReadDB(PGLOBAL g) /***********************************************************************/ void TBTBLK::ReadColumn(PGLOBAL) { - if (trace) + if (trace(1)) htrc("TBT ReadColumn: name=%s\n", Name); Value->SetValue_psz((char*)((PTDBTBL)To_Tdb)->Tdbp->GetName()); @@ -575,27 +575,30 @@ pthread_handler_t ThreadOpen(void *p) if (!my_thread_init()) { set_current_thd(cmp->Thd); - if (trace) + if (trace(1)) htrc("ThreadOpen: Thd=%d\n", cmp->Thd); // Try to open the connection - if (!cmp->Tap->GetTo_Tdb()->OpenDB(cmp->G)) { - pthread_mutex_lock(&tblmut); - if (trace) + pthread_mutex_lock(&tblmut); + + if (!cmp->Tap->GetTo_Tdb()->OpenDB(cmp->G)) { +// pthread_mutex_lock(&tblmut); + if (trace(1)) htrc("Table %s ready\n", cmp->Tap->GetName()); cmp->Ready = true; - pthread_mutex_unlock(&tblmut); +// pthread_mutex_unlock(&tblmut); } else { - pthread_mutex_lock(&tblmut); - if (trace) +// pthread_mutex_lock(&tblmut); + if (trace(1)) htrc("Opening %s failed\n", cmp->Tap->GetName()); cmp->Rc = RC_FX; - pthread_mutex_unlock(&tblmut); +// pthread_mutex_unlock(&tblmut); } // endif OpenDB - my_thread_end(); + pthread_mutex_unlock(&tblmut); + my_thread_end(); } else cmp->Rc = RC_FX; @@ -672,7 +675,7 @@ bool TDBTBM::OpenTables(PGLOBAL g) // Remove remote table from the local list *ptabp = tabp->Next; - if (trace) + if (trace(1)) htrc("=====> New remote table %s\n", tabp->GetName()); // Make the remote table block @@ -698,7 +701,7 @@ bool TDBTBM::OpenTables(PGLOBAL g) ptp = &tp->Next; Nrc++; // Number of remote connections } else { - if (trace) + if (trace(1)) htrc("=====> Local table %s\n", tabp->GetName()); ptabp = &tabp->Next; @@ -714,7 +717,7 @@ bool TDBTBM::OpenTables(PGLOBAL g) /***********************************************************************/ bool TDBTBM::OpenDB(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("TBM OpenDB: tdbp=%p tdb=R%d use=%d key=%p mode=%d\n", this, Tdb_No, Use, To_Key_Col, Mode); @@ -762,7 +765,7 @@ bool TDBTBM::OpenDB(PGLOBAL g) else if (((PPRXCOL)cp)->Init(g, NULL) && !Accept) return TRUE; - if (trace) + if (trace(1)) htrc("Opening subtable %s\n", Tdbp->GetName()); // Now we can safely open the table @@ -863,7 +866,7 @@ int TDBTBM::ReadNextRemote(PGLOBAL g) else if (((PPRXCOL)cp)->Init(g, NULL) && !Accept) return RC_FX; - if (trace) + if (trace(1)) htrc("Reading subtable %s\n", Tdbp->GetName()); return RC_OK; diff --git a/storage/connect/tabutil.cpp b/storage/connect/tabutil.cpp index 5d8d7c1b9f8..68b66aec31f 100644 --- a/storage/connect/tabutil.cpp +++ b/storage/connect/tabutil.cpp @@ -457,7 +457,7 @@ PTDB TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b) hc->get_table()->s->option_struct->srcdef = sp; } // endif s - if (trace && tdbp) + if (trace(1) && tdbp) htrc("Subtable %s in %s\n", name, SVP(tdbp->GetDef()->GetDB())); @@ -647,7 +647,7 @@ PRXCOL::PRXCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am) Pseudo = false; Colnum = cdp->GetOffset(); // If columns are retrieved by number - if (trace) + if (trace(1)) htrc(" making new %sCOL C%d %s at %p\n", am, Index, Name, this); } // end of PRXCOL constructor @@ -732,7 +732,7 @@ void PRXCOL::Reset(void) /***********************************************************************/ void PRXCOL::ReadColumn(PGLOBAL g) { - if (trace > 1) + if (trace(2)) htrc("PRX ReadColumn: name=%s\n", Name); if (Colp) { @@ -759,7 +759,7 @@ void PRXCOL::ReadColumn(PGLOBAL g) /***********************************************************************/ void PRXCOL::WriteColumn(PGLOBAL g) { - if (trace > 1) + if (trace(2)) htrc("PRX WriteColumn: name=%s\n", Name); if (Colp) { diff --git a/storage/connect/tabvct.cpp b/storage/connect/tabvct.cpp index 533986e44da..11b344ef652 100644 --- a/storage/connect/tabvct.cpp +++ b/storage/connect/tabvct.cpp @@ -304,7 +304,7 @@ bool TDBVCT::IsUsingTemp(PGLOBAL) /***********************************************************************/ bool TDBVCT::OpenDB(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("VCT OpenDB: tdbp=%p tdb=R%d use=%d key=%p mode=%d\n", this, Tdb_No, Use, To_Key_Col, Mode); @@ -364,7 +364,7 @@ bool TDBVCT::OpenDB(PGLOBAL g) /***********************************************************************/ int TDBVCT::ReadDB(PGLOBAL g) { - if (trace) + if (trace(1)) htrc("VCT ReadDB: R%d Mode=%d CurBlk=%d CurNum=%d key=%p link=%p Kindex=%p\n", GetTdb_No(), Mode, Txfp->CurBlk, Txfp->CurNum, To_Key_Col, To_Link, To_Kindex); @@ -546,7 +546,7 @@ void VCTCOL::ReadColumn(PGLOBAL g) assert (!To_Kcol); #endif - if (trace > 1) + if (trace(2)) htrc("VCT ReadColumn: col %s R%d coluse=%.4X status=%.4X buf_type=%d\n", Name, To_Tdb->GetTdb_No(), ColUse, Status, Buf_Type); @@ -574,7 +574,7 @@ void VCTCOL::WriteColumn(PGLOBAL) { PTXF txfp = ((PTDBVCT)To_Tdb)->Txfp;; - if (trace > 1) + if (trace(2)) htrc("VCT WriteColumn: col %s R%d coluse=%.4X status=%.4X buf_type=%d\n", Name, To_Tdb->GetTdb_No(), ColUse, Status, Buf_Type); diff --git a/storage/connect/tabwmi.cpp b/storage/connect/tabwmi.cpp index 335ffce5d7f..8a8e1bcbcb6 100644 --- a/storage/connect/tabwmi.cpp +++ b/storage/connect/tabwmi.cpp @@ -34,7 +34,7 @@ PWMIUT InitWMI(PGLOBAL g, PCSZ nsp, PCSZ classname) HRESULT res; PWMIUT wp = (PWMIUT)PlugSubAlloc(g, NULL, sizeof(WMIUTIL)); - if (trace) + if (trace(1)) htrc("WMIColumns class %s space %s\n", SVP(classname), SVP(nsp)); /*********************************************************************/ @@ -103,7 +103,7 @@ PWMIUT InitWMI(PGLOBAL g, PCSZ nsp, PCSZ classname) loc->Release(); - if (trace) + if (trace(1)) htrc("Successfully connected to namespace.\n"); /*********************************************************************/ diff --git a/storage/connect/tabxml.cpp b/storage/connect/tabxml.cpp index 6402f48e090..c96e0844497 100644 --- a/storage/connect/tabxml.cpp +++ b/storage/connect/tabxml.cpp @@ -153,7 +153,7 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) lvl = (lvl < 0) ? 0 : (lvl > 16) ? 16 : lvl; } // endif fn - if (trace) + if (trace(1)) htrc("File %s lvl=%d\n", topt->filename, lvl); tdp = new(g) XMLDEF; @@ -362,7 +362,7 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) txmp->CloseDB(g); skipit: - if (trace) + if (trace(1)) htrc("XMLColumns: n=%d len=%d\n", n, length[0]); /*********************************************************************/ @@ -686,7 +686,7 @@ PTDB TDBXML::Clone(PTABS t) /***********************************************************************/ PCOL TDBXML::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) { - if (trace) + if (trace(1)) htrc("TDBXML: MakeCol %s n=%d\n", (cdp) ? cdp->GetName() : "", n); return new(g) XMLCOL(cdp, this, cprec, n); @@ -720,7 +720,7 @@ int TDBXML::LoadTableFile(PGLOBAL g, char *filename) if (Docp) return rc; // Already done - if (trace) + if (trace(1)) htrc("TDBXML: loading %s\n", filename); /*********************************************************************/ @@ -753,7 +753,7 @@ int TDBXML::LoadTableFile(PGLOBAL g, char *filename) return RC_FX; } // endif init - if (trace) + if (trace(1)) htrc("TDBXML: parsing %s rc=%d\n", filename, rc); // Parse the XML file @@ -1182,7 +1182,7 @@ int TDBXML::ReadDB(PGLOBAL g) } // endswitch recpos } else { - if (trace) + if (trace(1)) htrc("TDBXML ReadDB: Irow=%d Nrow=%d\n", Irow, Nrow); // This is to force the table to be expanded when constructing @@ -1209,7 +1209,7 @@ int TDBXML::ReadDB(PGLOBAL g) } // endif To_Kindex if (!same) { - if (trace > 1) + if (trace(2)) htrc("TDBXML ReadDB: Irow=%d RowNode=%p\n", Irow, RowNode); // Get the new row node @@ -1319,7 +1319,7 @@ void TDBXML::CloseDB(PGLOBAL g) Docp->CloseDoc(g, To_Xb); // This causes a crash in Diagnostics_area::set_error_status -// throw (int)TYPE_AM_XML; +// throw (int)TYPE_AM_XML; } // endif DumpDoc } // endif Changed @@ -1472,7 +1472,7 @@ bool XMLCOL::ParseXpath(PGLOBAL g, bool mode) } else strcat(pbuf, Xname); - if (trace) + if (trace(1)) htrc("XMLCOL: pbuf=%s\n", pbuf); // For Update or Insert the Xpath must be analyzed @@ -1555,7 +1555,7 @@ bool XMLCOL::ParseXpath(PGLOBAL g, bool mode) if (Type || Nod) Tdbp->Hasnod = true; - if (trace) + if (trace(1)) htrc("XMLCOL: Xname=%s\n", pbuf); // Save the calculated Xpath @@ -1679,7 +1679,7 @@ void XMLCOL::WriteColumn(PGLOBAL g) int i, n, k = 0; PXNODE TopNode = NULL; - if (trace > 1) + if (trace(2)) htrc("XML WriteColumn: col %s R%d coluse=%.4X status=%.4X\n", Name, Tdbp->GetTdb_No(), ColUse, Status); @@ -1913,7 +1913,7 @@ void XMULCOL::WriteColumn(PGLOBAL g) int i, n, len, k = 0; PXNODE TopNode = NULL; - if (trace) + if (trace(1)) htrc("XML WriteColumn: col %s R%d coluse=%.4X status=%.4X\n", Name, Tdbp->GetTdb_No(), ColUse, Status); @@ -2129,7 +2129,7 @@ void XPOSCOL::WriteColumn(PGLOBAL g) char *p, buf[16]; int i, k, n; - if (trace) + if (trace(1)) htrc("XML WriteColumn: col %s R%d coluse=%.4X status=%.4X\n", Name, Tdbp->GetTdb_No(), ColUse, Status); diff --git a/storage/connect/user_connect.cc b/storage/connect/user_connect.cc index cb62667c0fe..9532d7c2a8d 100644 --- a/storage/connect/user_connect.cc +++ b/storage/connect/user_connect.cc @@ -178,7 +178,7 @@ bool user_connect::CheckCleanup(bool force) g->Mrr = 0; last_query_id= thdp->query_id; - if (trace && !force) + if (trace(65) && !force) printf("=====> Begin new query %llu\n", last_query_id); return true; diff --git a/storage/connect/valblk.cpp b/storage/connect/valblk.cpp index 018c7ee3fe1..73ca135691c 100644 --- a/storage/connect/valblk.cpp +++ b/storage/connect/valblk.cpp @@ -53,7 +53,7 @@ PVBLK AllocValBlock(PGLOBAL g, void *mp, int type, int nval, int len, { PVBLK blkp; - if (trace) + if (trace(1)) htrc("AVB: mp=%p type=%d nval=%d len=%d check=%u blank=%u\n", mp, type, nval, len, check, blank); diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 7af70ea1349..e159efaa989 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -337,7 +337,7 @@ PVAL AllocateValue(PGLOBAL g, void *value, short type, short prec) { PVAL valp; - if (trace) + if (trace(1)) htrc("AllocateConstant: value=%p type=%hd\n", value, type); switch (type) { @@ -727,7 +727,7 @@ bool TYPVAL::SetValue_char(const char *p, int n) else Tval = (TYPE)val; - if (trace > 1) { + if (trace(2)) { char buf[64]; htrc(strcat(strcat(strcpy(buf, " setting %s to: "), Fmt), "\n"), GetTypeName(Type), Tval); @@ -750,7 +750,7 @@ bool TYPVAL::SetValue_char(const char *p, int n) buf[n] = '\0'; Tval = atof(buf); - if (trace > 1) + if (trace(2)) htrc(" setting double: '%s' -> %lf\n", buf, Tval); Null = false; @@ -996,7 +996,7 @@ int TYPVAL::CompareValue(PVAL vp) // Process filtering on numeric values. TYPE n = GetTypedValue(vp); -//if (trace) +//if (trace(1)) // htrc(" Comparing: val=%d,%d\n", Tval, n); return (Tval > n) ? 1 : (Tval < n) ? (-1) : 0; @@ -1374,7 +1374,7 @@ bool TYPVAL::SetValue_char(const char *cp, int n) } else if (cp != Strp) { const char *p = cp + n - 1; - for (p; p >= cp; p--, n--) + for (; p >= cp; p--, n--) if (*p && *p != ' ') break; @@ -1384,7 +1384,7 @@ bool TYPVAL::SetValue_char(const char *cp, int n) strncpy(Strp, cp, n); Strp[n] = '\0'; - if (trace > 1) + if (trace(2)) htrc(" Setting string to: '%s'\n", Strp); } else @@ -1631,7 +1631,7 @@ int TYPVAL::CompareValue(PVAL vp) int n; //assert(vp->GetType() == Type); - if (trace) + if (trace(1)) htrc(" Comparing: val='%s','%s'\n", Strp, vp->GetCharValue()); // Process filtering on character strings. @@ -1656,14 +1656,14 @@ bool TYPVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) char *p[2], val[2][32]; int i; - if (trace) + if (trace(1)) htrc("Compute: np=%d op=%d\n", np, op); for (i = 0; i < np; i++) if (!vp[i]->IsNull()) { p[i] = vp[i]->GetCharString(val[i]); - if (trace) + if (trace(1)) htrc("p[%d]=%s\n", i, p[i]); } else @@ -1679,7 +1679,7 @@ bool TYPVAL::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op) if ((i = Len - (signed)strlen(Strp)) > 0) strncat(Strp, p[np - 1], i); - if (trace) + if (trace(1)) htrc("Strp=%s\n", Strp); break; @@ -1747,7 +1747,7 @@ DECVAL::DECVAL(PSZ s) : TYPVAL(s) if (s) { char *p = strchr(Strp, '.'); - Prec = (p) ? Len - (p - Strp) : 0; + Prec = (p) ? (int)(Len - (p - Strp)) : 0; } // endif s Type = TYPE_DECIM; @@ -1854,7 +1854,7 @@ int DECVAL::CompareValue(PVAL vp) // Process filtering on numeric values. double f = atof(Strp), n = vp->GetFloatValue(); -//if (trace) +//if (trace(1)) // htrc(" Comparing: val=%d,%d\n", f, n); return (f > n) ? 1 : (f < n) ? (-1) : 0; @@ -2410,7 +2410,7 @@ void DTVAL::SetTimeShift(void) Shift = (int)mktime(&dtm) - 86400; - if (trace) + if (trace(1)) htrc("DTVAL Shift=%d\n", Shift); } // end of SetTimeShift @@ -2485,7 +2485,7 @@ bool DTVAL::MakeTime(struct tm *ptm) int n, y = ptm->tm_year; time_t t = mktime_mysql(ptm); - if (trace > 1) + if (trace(2)) htrc("MakeTime from (%d,%d,%d,%d,%d,%d)\n", ptm->tm_year, ptm->tm_mon, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); @@ -2508,7 +2508,7 @@ bool DTVAL::MakeTime(struct tm *ptm) } Tval= (int) t; - if (trace > 1) + if (trace(2)) htrc("MakeTime Ival=%d\n", Tval); return false; @@ -2528,14 +2528,14 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) datm.tm_mon=0; datm.tm_year=70; - if (trace > 1) + if (trace(2)) htrc("MakeDate from(%d,%d,%d,%d,%d,%d) nval=%d\n", val[0], val[1], val[2], val[3], val[4], val[5], nval); for (i = 0; i < nval; i++) { n = val[i]; -// if (trace > 1) +// if (trace(2)) // htrc("i=%d n=%d\n", i, n); switch (i) { @@ -2545,7 +2545,7 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) datm.tm_year = n; -// if (trace > 1) +// if (trace(2)) // htrc("n=%d tm_year=%d\n", n, datm.tm_year); break; @@ -2564,7 +2564,7 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) datm.tm_mon = m; datm.tm_year += n; -// if (trace > 1) +// if (trace(2)) // htrc("n=%d m=%d tm_year=%d tm_mon=%d\n", n, m, datm.tm_year, datm.tm_mon); break; @@ -2581,7 +2581,7 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) datm.tm_mday = m; datm.tm_year += n; -// if (trace > 1) +// if (trace(2)) // htrc("n=%d m=%d tm_year=%d tm_mon=%d\n", n, m, datm.tm_year, datm.tm_mon); break; @@ -2592,7 +2592,7 @@ bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval) } // endfor i - if (trace > 1) + if (trace(2)) htrc("MakeDate datm=(%d,%d,%d,%d,%d,%d)\n", datm.tm_year, datm.tm_mon, datm.tm_mday, datm.tm_hour, datm.tm_min, datm.tm_sec); @@ -2656,7 +2656,7 @@ bool DTVAL::SetValue_char(const char *p, int n) // Trim trailing blanks for (p2 = p + n -1; p < p2 && *p2 == ' '; p2--); - if ((rc = (n = p2 - p + 1) > Len)) + if ((rc = (n = (int)(p2 - p + 1)) > Len)) n = Len; memcpy(Sdate, p, n); @@ -2667,7 +2667,7 @@ bool DTVAL::SetValue_char(const char *p, int n) ndv = ExtractDate(Sdate, Pdtp, DefYear, dval); MakeDate(NULL, dval, ndv); - if (trace > 1) + if (trace(2)) htrc(" setting date: '%s' -> %d\n", Sdate, Tval); Null = (Nullable && ndv == 0); @@ -2694,7 +2694,7 @@ void DTVAL::SetValue_psz(PCSZ p) ndv = ExtractDate(Sdate, Pdtp, DefYear, dval); MakeDate(NULL, dval, ndv); - if (trace > 1) + if (trace(2)) htrc(" setting date: '%s' -> %d\n", Sdate, Tval); Null = (Nullable && ndv == 0); @@ -2849,13 +2849,13 @@ bool DTVAL::FormatValue(PVAL vp, PCSZ fmt) char *buf = (char*)vp->GetTo_Val(); // Should be big enough struct tm tm, *ptm = GetGmTime(&tm); - if (trace > 1) + if (trace(2)) htrc("FormatValue: ptm=%p len=%d\n", ptm, vp->GetValLen()); if (ptm) { size_t n = strftime(buf, vp->GetValLen(), fmt, ptm); - if (trace > 1) + if (trace(2)) htrc("strftime: n=%d buf=%s\n", n, (n) ? buf : "???"); return (n == 0); diff --git a/storage/connect/xindex.cpp b/storage/connect/xindex.cpp index 30dce3b7fef..efefc17b5f5 100755 --- a/storage/connect/xindex.cpp +++ b/storage/connect/xindex.cpp @@ -344,7 +344,7 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp) } // endif n - if (trace) + if (trace(1)) htrc("XINDEX Make: n=%d\n", n); // File position must be stored @@ -417,7 +417,7 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp) if (kcp->Init(g, colp, n, true, 0)) return true; - if (trace) + if (trace(1)) htrc("Adding colp=%p Buf_Type=%d size=%d\n", colp, colp->GetResultType(), n); @@ -484,7 +484,7 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp) } else To_Rec[nkey] = Tdbp->GetRecpos(); - if (trace > 1) + if (trace(2)) htrc("Make: To_Rec[%d]=%d\n", nkey, To_Rec[nkey]); /*******************************************************************/ @@ -553,7 +553,7 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp) if ((Ndif = Qsort(g, Num_K)) < 0) goto err; // Error during sort - if (trace) + if (trace(1)) htrc("Make: Nk=%d n=%d Num_K=%d Ndif=%d addcolp=%p BlkFil=%p X=%p\n", Nk, n, Num_K, Ndif, addcolp, Tdbp->To_BlkFil, X); @@ -883,7 +883,7 @@ bool XINDEX::SaveIndex(PGLOBAL g, PIXDEF sxp) n[5] = Nblk; n[6] = Sblk; n[7] = Srtd ? 1 : 0; // Values are sorted in the file - if (trace) { + if (trace(1)) { htrc("Saving index %s\n", Xdp->GetName()); htrc("ID=%d Nk=%d nof=%d Num_K=%d Incr=%d Nblk=%d Sblk=%d Srtd=%d\n", ID, Nk, nof, Num_K, Incr, Nblk, Sblk, Srtd); @@ -926,7 +926,7 @@ bool XINDEX::SaveIndex(PGLOBAL g, PIXDEF sxp) // dup->ProgCur += 5; } // endfor kcp - if (trace) + if (trace(1)) htrc("Index %s saved, Size=%d\n", Xdp->GetName(), size); end: @@ -1016,7 +1016,7 @@ bool XINDEX::Init(PGLOBAL g) PlugSetPath(fn, fn, Tdbp->GetPath()); - if (trace) + if (trace(1)) htrc("Index %s file: %s\n", Xdp->GetName(), fn); /*********************************************************************/ @@ -1039,7 +1039,7 @@ bool XINDEX::Init(PGLOBAL g) } else Srtd = false; - if (trace) + if (trace(1)) htrc("nv=%d %d %d %d %d %d %d (%d)\n", nv[0], nv[1], nv[2], nv[3], nv[4], nv[5], nv[6], Srtd); @@ -1048,7 +1048,7 @@ bool XINDEX::Init(PGLOBAL g) if (/*nv[0] != ID ||*/ nv[1] != Nk) { sprintf(g->Message, MSG(BAD_INDEX_FILE), fn); - if (trace) + if (trace(1)) htrc("nv[0]=%d ID=%d nv[1]=%d Nk=%d\n", nv[0], ID, nv[1], Nk); goto err; @@ -1269,7 +1269,7 @@ bool XINDEX::MapInit(PGLOBAL g) PlugSetPath(fn, fn, Tdbp->GetPath()); - if (trace) + if (trace(1)) htrc("Index %s file: %s\n", Xdp->GetName(), fn); /*********************************************************************/ @@ -1300,7 +1300,7 @@ bool XINDEX::MapInit(PGLOBAL g) nv0 = nv[0]; } // endif nv - if (trace) + if (trace(1)) htrc("nv=%d %d %d %d %d %d %d %d\n", nv0, nv[1], nv[2], nv[3], nv[4], nv[5], nv[6], Srtd); @@ -1310,7 +1310,7 @@ bool XINDEX::MapInit(PGLOBAL g) // Not this index sprintf(g->Message, MSG(BAD_INDEX_FILE), fn); - if (trace) + if (trace(1)) htrc("nv0=%d ID=%d nv[1]=%d Nk=%d\n", nv0, ID, nv[1], Nk); goto err; @@ -1483,7 +1483,7 @@ bool XINDEX::GetAllSizes(PGLOBAL g,/* int &ndif,*/ int &numk) PlugSetPath(fn, fn, Tdbp->GetPath()); - if (trace) + if (trace(1)) htrc("Index %s file: %s\n", Xdp->GetName(), fn); /*********************************************************************/ @@ -1500,7 +1500,7 @@ bool XINDEX::GetAllSizes(PGLOBAL g,/* int &ndif,*/ int &numk) if (X->Read(g, nv, NZ, sizeof(int))) goto err; - if (trace) + if (trace(1)) htrc("nv=%d %d %d %d\n", nv[0], nv[1], nv[2], nv[3]); // The test on ID was suppressed because MariaDB can change an index ID @@ -1508,7 +1508,7 @@ bool XINDEX::GetAllSizes(PGLOBAL g,/* int &ndif,*/ int &numk) if (/*nv[0] != ID ||*/ nv[1] != Nk) { sprintf(g->Message, MSG(BAD_INDEX_FILE), fn); - if (trace) + if (trace(1)) htrc("nv[0]=%d ID=%d nv[1]=%d Nk=%d\n", nv[0], ID, nv[1], Nk); goto err; @@ -1770,7 +1770,7 @@ int XINDEX::Fetch(PGLOBAL g) if (Num_K == 0) return -1; // means end of file - if (trace > 1) + if (trace(2)) htrc("XINDEX Fetch: Op=%d\n", Op); /*********************************************************************/ @@ -1834,7 +1834,7 @@ int XINDEX::Fetch(PGLOBAL g) Nth++; - if (trace > 1) + if (trace(2)) htrc("Fetch: Looking for new value Nth=%d\n", Nth); Cur_K = FastFind(); @@ -1907,7 +1907,7 @@ int XINDEX::FastFind(void) sup = To_KeyCol->Ndf; } // endif Nblk - if (trace > 2) + if (trace(4)) htrc("XINDEX FastFind: Nblk=%d Op=%d inf=%d sup=%d\n", Nblk, Op, inf, sup); @@ -1985,7 +1985,7 @@ int XINDEX::FastFind(void) curk = (kcp->Kof) ? kcp->Kof[kcp->Val_K] : kcp->Val_K; } // endfor kcp - if (trace > 2) + if (trace(4)) htrc("XINDEX FastFind: curk=%d\n", curk); return curk; @@ -2123,7 +2123,7 @@ int XINDXS::Fetch(PGLOBAL g) if (Num_K == 0) return -1; // means end of file - if (trace > 1) + if (trace(2)) htrc("XINDXS Fetch: Op=%d\n", Op); /*********************************************************************/ @@ -2176,7 +2176,7 @@ int XINDXS::Fetch(PGLOBAL g) else Nth++; - if (trace > 1) + if (trace(2)) htrc("Fetch: Looking for new value Nth=%d\n", Nth); Cur_K = FastFind(); @@ -2243,7 +2243,7 @@ int XINDXS::FastFind(void) sup = Ndif; } // endif Nblk - if (trace > 2) + if (trace(4)) htrc("XINDXS FastFind: Nblk=%d Op=%d inf=%d sup=%d\n", Nblk, Op, inf, sup); @@ -2269,7 +2269,7 @@ int XINDXS::FastFind(void) n = 0; } // endif sup - if (trace > 2) + if (trace(4)) htrc("XINDXS FastFind: n=%d i=%d\n", n, i); // Loop on kcp because of dynamic indexing @@ -2337,7 +2337,7 @@ bool XFILE::Open(PGLOBAL g, char *filename, int id, MODE mode) } // endswitch mode if (!(Xfile= global_fopen(g, MSGID_OPEN_ERROR_AND_STRERROR, filename, pmod))) { - if (trace) + if (trace(1)) htrc("Open: %s\n", g->Message); return true; @@ -2354,7 +2354,7 @@ bool XFILE::Open(PGLOBAL g, char *filename, int id, MODE mode) NewOff.v.Low = (int)ftell(Xfile); - if (trace) + if (trace(1)) htrc("XFILE Open: NewOff.v.Low=%d\n", NewOff.v.Low); } else if (mode == MODE_WRITE) { @@ -2365,7 +2365,7 @@ bool XFILE::Open(PGLOBAL g, char *filename, int id, MODE mode) fseek(Xfile, 0, SEEK_END); NewOff.v.Low = (int)ftell(Xfile); - if (trace) + if (trace(1)) htrc("XFILE Open: NewOff.v.Low=%d\n", NewOff.v.Low); } // endif id @@ -2377,7 +2377,7 @@ bool XFILE::Open(PGLOBAL g, char *filename, int id, MODE mode) return true; } // endif MAX_INDX - if (trace) + if (trace(1)) htrc("XFILE Open: noff[%d].v.Low=%d\n", id, noff[id].v.Low); // Position the cursor at the offset of this index @@ -2510,7 +2510,7 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode) return true; } // endif - if (trace) + if (trace(1)) htrc(" Xopen: filename=%s id=%d mode=%d\n", filename, id, mode); #if defined(__WIN__) @@ -2554,7 +2554,7 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode) return true; } // endif Hfile - if (trace) + if (trace(1)) htrc(" access=%p share=%p creation=%d handle=%p fn=%s\n", access, share, creation, Hfile, filename); @@ -2628,13 +2628,13 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode) if (Hfile == INVALID_HANDLE_VALUE) { /*rc = errno;*/ - if (trace) + if (trace(1)) htrc("Open: %s\n", g->Message); return true; } // endif Hfile - if (trace) + if (trace(1)) htrc(" oflag=%p mode=%d handle=%d fn=%s\n", oflag, mode, Hfile, filename); @@ -2647,7 +2647,7 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode) return true; } // endif - if (trace) + if (trace(1)) htrc("INSERT: NewOff=%lld\n", NewOff.Val); } else if (mode == MODE_WRITE) { @@ -2657,7 +2657,7 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode) NewOff.v.Low = write(Hfile, &noff, sizeof(noff)); } // endif id - if (trace) + if (trace(1)) htrc("WRITE: NewOff=%lld\n", NewOff.Val); } else if (mode == MODE_READ && id >= 0) { @@ -2667,7 +2667,7 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode) return true; } // endif read - if (trace) + if (trace(1)) htrc("noff[%d]=%lld\n", id, noff[id].Val); // Position the cursor at the offset of this index @@ -2705,13 +2705,13 @@ bool XHUGE::Seek(PGLOBAL g, int low, int high, int origin) if (lseek64(Hfile, pos, origin) < 0) { sprintf(g->Message, MSG(ERROR_IN_LSK), errno); - if (trace) + if (trace(1)) htrc("lseek64 error %d\n", errno); return true; } // endif lseek64 - if (trace) + if (trace(1)) htrc("Seek: low=%d high=%d\n", low, high); #endif // UNIX @@ -2750,13 +2750,13 @@ bool XHUGE::Read(PGLOBAL g, void *buf, int n, int size) #else // UNIX ssize_t count = (ssize_t)(n * size); - if (trace) + if (trace(1)) htrc("Hfile=%d n=%d size=%d count=%d\n", Hfile, n, size, count); if (read(Hfile, buf, count) != count) { sprintf(g->Message, MSG(READ_ERROR), "Index file", strerror(errno)); - if (trace) + if (trace(1)) htrc("read error %d\n", errno); rc = true; @@ -2810,7 +2810,7 @@ int XHUGE::Write(PGLOBAL g, void *buf, int n, int size, bool& rc) /***********************************************************************/ void XHUGE::Close(char *fn, int id) { - if (trace) + if (trace(1)) htrc("XHUGE::Close: fn=%s id=%d NewOff=%lld\n", fn, id, NewOff.Val); #if defined(__WIN__) @@ -3022,7 +3022,7 @@ bool KXYCOL::Init(PGLOBAL g, PCOL colp, int n, bool sm, int kln) Prefix = true; } // endif kln - if (trace) + if (trace(1)) htrc("KCOL(%p) Init: col=%s n=%d type=%d sm=%d\n", this, colp->GetName(), n, colp->GetResultType(), sm); @@ -3076,7 +3076,7 @@ BYTE* KXYCOL::MapInit(PGLOBAL g, PCOL colp, int *n, BYTE *m) Type = colp->GetResultType(); - if (trace) + if (trace(1)) htrc("MapInit(%p): colp=%p type=%d n=%d len=%d m=%p\n", this, colp, Type, n[0], len, m); @@ -3196,7 +3196,7 @@ bool KXYCOL::InitFind(PGLOBAL g, PXOB xp) Valp->SetValue_pval(xp->GetValue(), false); } // endif Type - if (trace > 1) { + if (trace(2)) { char buf[32]; htrc("KCOL InitFind: value=%s\n", Valp->GetCharString(buf)); @@ -3237,7 +3237,7 @@ int KXYCOL::Compare(int i1, int i2) // Do the actual comparison between values. register int k = Kblp->CompVal(i1, i2); - if (trace > 2) + if (trace(4)) htrc("Compare done result=%d\n", k); return (Asc) ? k : -k; @@ -3249,7 +3249,7 @@ int KXYCOL::Compare(int i1, int i2) int KXYCOL::CompVal(int i) { // Do the actual comparison between numerical values. - if (trace > 2) { + if (trace(4)) { register int k = (int)Kblp->CompVal(Valp, (int)i); htrc("Compare done result=%d\n", k); diff --git a/storage/connect/xobject.cpp b/storage/connect/xobject.cpp index 02d3e974dcc..c595ce5d6c4 100644 --- a/storage/connect/xobject.cpp +++ b/storage/connect/xobject.cpp @@ -204,7 +204,7 @@ STRING::STRING(PGLOBAL g, uint n, PCSZ str) *Strp = 0; Next = GetNext(); - Size = Next - Strp; + Size = (int)(Next - Strp); Trc = false; } else { // This should normally never happen @@ -239,7 +239,7 @@ char *STRING::Realloc(uint len) p = Strp; Next = GetNext(); - Size = Next - p; + Size = (int)(Next - p); return p; } // end of Realloc @@ -439,4 +439,3 @@ bool STRING::Resize(uint newsize) return newsize > Size; } // end of Resize - -- cgit v1.2.1 From d6dbe8e2071bf9fdc21b5530abce88ff01b40e25 Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Thu, 26 Apr 2018 22:42:42 +0300 Subject: List of unstable tests for 10.0.35 release --- mysql-test/unstable-tests | 137 +++++++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 67 deletions(-) diff --git a/mysql-test/unstable-tests b/mysql-test/unstable-tests index 4f74a7d744d..d50a9acc92e 100644 --- a/mysql-test/unstable-tests +++ b/mysql-test/unstable-tests @@ -23,59 +23,59 @@ # ############################################################################## +# Based on 10.0 48636f09720af45454e5db1183b62a1991db8faf + main.count_distinct2 : MDEV-11768 - timeout -main.create : Modified in 10.0.34 main.create_delayed : MDEV-10605 - failed with timeout -main.ctype_utf8 : Modified in 10.0.34 -main.ctype_utf8mb4 : Modified in 10.0.34 +main.ctype_ucs : Modified in 10.0.35 +main.ctype_utf8mb4 : Modified in 10.0.35 main.debug_sync : MDEV-10607 - internal error -main.derived : Modified in 10.0.34 main.derived_opt : MDEV-11768 - timeout -main.dyncol : Modified in 10.0.34 +main.dyncol : Modified in 10.0.35 main.events_slowlog : MDEV-12821 - wrong result -main.fulltext : Modified in 10.0.34 -main.func_isnull : Modified in 10.0.34 -main.func_misc : Modified in 10.0.34 -main.func_set : Modified in 10.0.34 -main.func_str : Modified in 10.0.34 +main.func_concat : Modified in 10.0.35 +main.func_misc : Modified in 10.0.35 +main.func_str : Modified in 10.0.35 +main.func_time : Modified in 10.0.35 +main.having : Modified in 10.0.35 main.gis : MDEV-13411 - wrong result on P8 -main.group_by : Modified in 10.0.34 -main.having : Modified in 10.0.34 main.host_cache_size_functionality : MDEV-10606 - sporadic failure on shutdown main.index_intersect_innodb : MDEV-10643 - failed with timeout main.index_merge_innodb : MDEV-7142 - wrong result main.innodb_mysql_lock : MDEV-7861 - sporadic lock detection failure -main.join_cache : Modified in 10.0.34 -main.join_outer : Modified in 10.0.34 +main.join_outer : Modified in 10.0.35 main.kill_processlist-6619 : MDEV-10793 - wrong result main.log_tables-big : MDEV-13408 - wrong result -main.mdev_14586 : Added in 10.0.34 main.mdev-504 : MDEV-10607 - sporadic "can't connect" main.mdev375 : MDEV-10607 - sporadic "can't connect" -main.merge : MDEV-10607 - sporadic "can't connect"; modified in 10.0.34 -main.myisam_optimize : Modified in 10.0.34 -main.mysqlbinlog : Modified in 10.0.34 -main.mysqldump-nl : Modified in 10.0.34 +main.merge : MDEV-10607 - sporadic "can't connect" main.mysqlhotcopy_myisam : MDEV-10995 - test hangs on debug build main.mysqltest : MDEV-9269 - fails on Alpha main.mysql_client_test_nonblock : MDEV-15096 - exec failed -main.order_by : Modified in 10.0.34 -main.ps : MDEV-11017 - sporadic wrong Prepared_stmt_count; modified in 10.0.34 -main.query_cache_debug : Modified in 10.0.34 -main.repair : Modified in 10.0.34 +main.parser : Modified in 10.0.35 +main.partition : Modified in 10.0.35 +main.ps : MDEV-11017 - sporadic wrong Prepared_stmt_count +main.ps_qc_innodb : Added in 10.0.35 +main.query_cache_debug : MDEV-15281 - resize or similar command in progress +main.read_only_innodb : Modified in 10.0.35 main.show_explain : MDEV-10674 - wrong result +main.sp-destruct : Modified in 10.0.35 main.sp_notembedded : MDEV-10607 - internal error main.sp-security : MDEV-10607 - sporadic "can't connect" main.stat_tables_par_innodb : MDEV-14155 - wrong rounding -main.subselect : Modified in 10.0.34 -main.subselect_exists2in : Modified in 10.0.34 +main.statistics : Modified in 10.0.35 main.subselect_innodb : MDEV-10614 - sporadic wrong results +main.subselect_mat : Modified in 10.0.35 +main.subselect4 : Modified in 10.0.35 main.symlink-aria-11902 : MDEV-15098 - error 40 from storage engine main.symlink-myisam-11902 : MDEV-15098 - error 40 from storage engine +main.tc_heuristic_recover : MDEV-15200 - wrong error on mysqld_stub_cmd main.type_datetime : MDEV-14322 - wrong result -main.union : Modified in 10.0.34 -main.view : Modified in 10.0.34 -main.xa : MDEV-11769 - lock wait timeout; modified in 10.0.34 +main.type_time_6065 : Modified in 10.0.35 +main.update_innodb : Modified in 10.0.35 +main.view : Modified in 10.0.35 +main.xa : MDEV-11769 - lock wait timeout +main.xml : Modified in 10.0.35 #---------------------------------------------------------------- @@ -91,8 +91,21 @@ binlog.binlog_xa_recover : MDEV-8517 - Extra checkpoint #---------------------------------------------------------------- -connect.json : Sporadic wrong result -connect.zip : Sporadic wrong result +connect.jdbc : Included file modified in 10.0.35 +connect.jdbc_new : Included file modified in 10.0.35 +connect.jdbc_oracle : Included file modified in 10.0.35 +connect.jdbc_postgresql : Modified in 10.0.35 +connect.json_java_2 : Included file modified in 10.0.35 +connect.json_java_3 : Included file modified in 10.0.35 +connect.json_mongo_c : Included file modified in 10.0.35 +connect.json_udf : Modified in 10.0.35 +connect.mongo_c : Included file modified in 10.0.35 +connect.mongo_java_2 : Included file modified in 10.0.35 +connect.mongo_java_3 : Included file modified in 10.0.35 +connect.mongo_test : Modified in 10.0.35 +connect.tbl_thread : Modified in 10.0.35 +connect.vcol : Added in 10.0.35 +connect.zip : MDEV-13884 - wrong result #---------------------------------------------------------------- @@ -119,28 +132,31 @@ funcs_2/charset.* : MDEV-10999 - test not maintained innodb.binlog_consistent : MDEV-10618 - Server fails to start innodb.group_commit_crash : MDEV-11770 - checksum mismatch innodb.group_commit_crash_no_optimize_thread : MDEV-11770 - checksum mismatch -innodb.innodb : Modified in 10.0.34 +innodb.innodb-alter-nullable : Modified in 10.0.35 innodb.innodb-alter-table : MDEV-10619 - Testcase timeout -innodb.innodb-autoinc : Modified in 10.0.34 +innodb.innodb_bug11754376 : Modified in 10.0.35 +innodb.innodb_bug27216817 : Added in 10.0.35 innodb.innodb_bug30423 : MDEV-7311 - Wrong number of rows in the plan innodb.innodb_bug48024 : MDEV-14352 - Assertion failure -innodb.innodb-index-debug : Modified in 10.0.34 -innodb.innodb-index-online : Modified in 10.0.34 +innodb.innodb_bug56947 : Modified in 10.0.35 +innodb.innodb_corrupt_bit : Modified in 10.0.35 innodb.innodb_monitor : MDEV-10939 - Testcase timeout -innodb.innodb-replace-debug : Added in 10.0.34 -innodb.innodb-wl5522-debug : Modified in 10.0.34 -innodb.recovery_shutdown : Added in 10.0.34 - +innodb.innodb-replace-debug : Modified in 10.0.35 +innodb.log_file_size : MDEV-15668 - Not found pattern; modified in 10.0.35 +innodb.mvcc : Added in 10.0.35 +innodb.read_only_recover_committed : Added in 10.0.35 +innodb.recovery_shutdown : MDEV-15671 - Warning: database page corruption; modified in 10.0.35 +innodb.xa_recovery : MDEV-15279 - mysqld got exception + +innodb_fts.innobase_drop_fts_index_table : Modified in 10.0.35 innodb_fts.innodb-fts-fic : MDEV-14154 - Assertion failure -innodb_fts.innodb_fts_misc_debug : MDEV-14156 - Unexpected warning - -innodb_zip.wl5522_debug_zip : Added in 10.0.34 +innodb_fts.innodb_fts_misc_debug : MDEV-14156 - Unexpected warning; modified in 10.0.35 +innodb_fts.innodb_fts_result_cache_limit : Modified in 10.0.35 #---------------------------------------------------------------- -maria.lock : Modified in 10.0.34 -maria.maria : MDEV-14430 - Wrong result; modified in 10.0.34 -maria.repair : Added in 10.0.34 +maria.dynamic : Added in 10.0.35 +maria.maria : MDEV-14430 - Wrong result #---------------------------------------------------------------- @@ -162,9 +178,9 @@ multi_source.status_vars : MDEV-4632 - failed while waiting for Slave_received_h #---------------------------------------------------------------- -parts.partition_alter_innodb : Added in 10.0.34 -parts.partition_alter_maria : Modified in 10.0.34 -parts.partition_alter_myisam : Added in 10.0.34 +parts.partition_alter_innodb : Include file modified in 10.0.35 +parts.partition_alter_maria : Modified in 10.0.35 +parts.partition_alter_myisam : Include file modified in 10.0.35 parts.partition_auto_increment_maria : MDEV-14430 - wrong result parts.partition_debug_innodb : MDEV-15095 - table does not exist parts.partition_exch_qa_10 : MDEV-11765 - wrong result @@ -182,14 +198,12 @@ perfschema_stress.* : MDEV-10996 - tests not maintained #---------------------------------------------------------------- plugins.feedback_plugin_send : MDEV-7932 - ssl failed for url, MDEV-11118 - wrong result -plugins.server_audit : MDEV-9562 - crashes on sol10-sparc; modified in 10.0.34 -plugins.thread_pool_server_audit : MDEV-9562 - crashes on sol10-sparc, MDEV-14295 - wrong result; modified in 10.0.34 +plugins.server_audit : MDEV-9562 - crashes on sol10-sparc; modified in 10.0.35 +plugins.thread_pool_server_audit : MDEV-9562 - crashes on sol10-sparc, MDEV-14295 - wrong result #---------------------------------------------------------------- roles.create_and_grant_role : MDEV-11772 - wrong result -roles.flush_roles-12366 : Added in 10.0.34 -roles.set_role-13655 : Added in 10.0.34 #---------------------------------------------------------------- @@ -233,7 +247,7 @@ spider/bg.direct_aggregate : MDEV-7098 - Trying to unlock mutex that wasn't spider/bg.direct_aggregate_part : MDEV-7098 - Trying to unlock mutex that wasn't locked spider/bg.spider3_fixes : MDEV-7098 - Trying to unlock mutex that wasn't locked spider/bg.spider_fixes_part : MDEV-7098 - Trying to unlock mutex that wasn't locked -spider/bg.ha : MDEV-7914, MDEV-9329 - Crash, failures on s390x +spider/bg.ha : MDEV-7914 (fixed in 10.3), MDEV-9329 - Crash, failures on s390x spider/bg.ha_part : MDEV-9329 - Fails on Ubuntu/s390x spider/bg.spider_fixes : MDEV-7098, MDEV-9329 - Mutex problem, failures on s390x spider/bg.vp_fixes : MDEV-9329 - Fails on Ubuntu/s390x @@ -253,15 +267,11 @@ stress.ddl_innodb : MDEV-10635 - Testcase timeout #---------------------------------------------------------------- sys_vars.autocommit_func2 : MDEV-9329 - Fails on Ubuntu/s390x -sys_vars.innodb_buffer_pool_dump_now_basic : Modified in 10.0.34 -sys_vars.innodb_buffer_pool_dump_pct_basic : Modified in 10.0.34 -sys_vars.innodb_buffer_pool_load_now_basic : Modified in 10.0.34 -sys_vars.innodb_print_lock_wait_timeout_info_basic : Added in 10.0.34 +sys_vars.max_prepared_stmt_count_basic : Modified in 10.0.35 sys_vars.thread_cache_size_func : MDEV-11775 - wrong result #---------------------------------------------------------------- -tokudb.card_scale_percent : Modified in 10.0.34 tokudb.change_column_all_1000_10 : MDEV-12640 - Lost connection during query tokudb.change_column_bin : MDEV-12640 - Lost connection during query tokudb.change_column_char : MDEV-12822 - Lost connection during query @@ -269,14 +279,12 @@ tokudb.cluster_filter_unpack_varchar : MDEV-10636 - Wrong execution plan tokudb.dir_per_db : MDEV-11537 - wrong result tokudb.dir_per_db_rename_to_nonexisting_schema : MDEV-12823 - Valgrind tokudb.hotindex-insert-bigchar : MDEV-13870 - ASAN failures +tokudb.hotindex-update-0 : MDEV-15198 - Timeout tokudb.hotindex-update-1 : MDEV-12640 - Lost connection during query -tokudb.locking-read-repeatable-read-1 : Added in 10.0.34 -tokudb.locking-read-repeatable-read-2 : Added in 10.0.34 tokudb.locks-select-update-1 : MDEV-13406 - Lock wait timeout -tokudb.nonflushing_analyze_debug : Added in 10.0.34 tokudb.rows-32m-rand-insert : MDEV-12640 - Lost connection during query tokudb.rows-32m-seq-insert : MDEV-12640 - Lost connection during query -tokudb.row_format : Modified in 10.0.34 +tokudb.savepoint-5 : MDEV-15280 - wrong result tokudb_backup.* : MDEV-11001 - tests don't work @@ -287,11 +295,6 @@ tokudb_bugs.frm_store2 : MDEV-12823 - Valgrind tokudb_bugs.frm_store3 : MDEV-12823 - Valgrind tokudb_bugs.xa : MDEV-11804 - Lock wait timeout -tokudb_parts.nonflushing_analyze_debug : Added in 10.0.34 - -tokudb_perfschema.crash_tokudb : Added in 10.0.34 -tokudb_perfschema.start_server_tokudb : Added in 10.0.34 - tokudb_rpl.* : MDEV-11001 - tests don't work tokudb_sys_vars.* : MDEV-11001 - tests don't work @@ -301,7 +304,7 @@ rpl-tokudb.* : MDEV-14354 - Tests fail with tcmalloc unit.lf : MDEV-12897 - Unexpected return code unit.ma_test_loghandler : MDEV-10638 - record read not ok -unit.pfs : MySQL:84457 - unittest pft-t failing +unit.my_atomic : MDEV-15670 - Signal 11 thrown #---------------------------------------------------------------- -- cgit v1.2.1 From 5cfe52314e29386e1867fad1b44eace2b9d0be7e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 27 Apr 2018 11:21:55 +0200 Subject: Bug#25471090: MYSQL USE AFTER FREE fix another similar line followup for 7828ba0df488 --- sql-common/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-common/client.c b/sql-common/client.c index bb7bdb1ff7d..9cb3311d2e1 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1636,7 +1636,7 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, else { cur->data[field] = to; - if (len > (ulong) (end_to - to)) + if (to + len > end_to) { free_rows(result); set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate); -- cgit v1.2.1 From a52c46e06935b09ff9219ae7684b5a29394e992b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 30 Apr 2018 13:50:59 +0200 Subject: Bug#25471090: MYSQL USE AFTER FREE a better fix --- sql-common/client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql-common/client.c b/sql-common/client.c index 9cb3311d2e1..b485ebf4f60 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1636,7 +1636,7 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, else { cur->data[field] = to; - if (to + len > end_to) + if (unlikely(len > (ulong)(end_to-to) || to > end_to)) { free_rows(result); set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate); @@ -1708,7 +1708,7 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths) } else { - if (pos + len > end_pos) + if (unlikely(len > (ulong)(end_pos - pos) || pos > end_pos)) { set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate); return -1; -- cgit v1.2.1 From fab383aac0a713b48765d0464428199470ae8c0a Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 30 Apr 2018 23:06:09 +0200 Subject: Use after free in authentication --- mysql-test/r/connect_debug.result | 5 +++++ mysql-test/t/connect_debug.test | 12 ++++++++++++ sql-common/client.c | 4 ++-- sql/sql_acl.cc | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 mysql-test/r/connect_debug.result create mode 100644 mysql-test/t/connect_debug.test diff --git a/mysql-test/r/connect_debug.result b/mysql-test/r/connect_debug.result new file mode 100644 index 00000000000..0452b238db9 --- /dev/null +++ b/mysql-test/r/connect_debug.result @@ -0,0 +1,5 @@ +set @old_dbug=@@global.debug_dbug; +set global debug_dbug='+d,auth_disconnect'; +create user 'bad' identified by 'worse'; +set global debug_dbug=@old_dbug; +drop user bad; diff --git a/mysql-test/t/connect_debug.test b/mysql-test/t/connect_debug.test new file mode 100644 index 00000000000..299b605b2cd --- /dev/null +++ b/mysql-test/t/connect_debug.test @@ -0,0 +1,12 @@ +source include/have_debug.inc; +set @old_dbug=@@global.debug_dbug; + +# +# use after free if need plugin change and auth aborted +# +set global debug_dbug='+d,auth_disconnect'; +create user 'bad' identified by 'worse'; +--error 1 +--exec $MYSQL --default-auth=mysql_old_password --user=bad --password=worse +set global debug_dbug=@old_dbug; +drop user bad; diff --git a/sql-common/client.c b/sql-common/client.c index b485ebf4f60..00e2877bedb 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -2742,7 +2742,7 @@ static int client_mpvio_read_packet(struct st_plugin_vio *mpv, uchar **buf) *buf= mysql->net.read_pos; /* was it a request to change plugins ? */ - if (**buf == 254) + if (pkt_len == packet_error || **buf == 254) return (int)packet_error; /* if yes, this plugin shan't continue */ /* @@ -2927,7 +2927,7 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, compile_time_assert(CR_OK == -1); compile_time_assert(CR_ERROR == 0); - if (res > CR_OK && mysql->net.read_pos[0] != 254) + if (res > CR_OK && (mysql->net.last_errno || mysql->net.read_pos[0] != 254)) { /* the plugin returned an error. write it down in mysql, diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 16358409124..14f34db6ccc 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -8217,6 +8217,7 @@ static bool send_plugin_request_packet(MPVIO_EXT *mpvio, const char *client_auth_plugin= ((st_mysql_auth *) (plugin_decl(mpvio->plugin)->info))->client_auth_plugin; + DBUG_EXECUTE_IF("auth_disconnect", { vio_close(net->vio); DBUG_RETURN(1); }); DBUG_ASSERT(client_auth_plugin); /* -- cgit v1.2.1 From f47eac2882b8635b8de252cdca8e46200b1ff724 Mon Sep 17 00:00:00 2001 From: Mayank Prasad Date: Wed, 10 Jan 2018 20:54:09 +0530 Subject: Bug #25928471: ONLINE ALTER AND CONCURRENT DELETE ON TABLE WITH MANY TEXT COLUMNS CAUSES CRASH Issue: ------ Prefix for externally stored columns were being stored in online_log when a table is altered and alter causes table to be rebuilt. Space in online_log is limited and if length of prefix of externally stored columns is very big, then it is being written to online log without making sure if it fits. This leads to memory corruption. Fix: ---- After fix for Bug#16544143, there is no need to store prefixes of externally stored columnd in online_log. Thus remove the code which stores column prefixes for externally stored columns. Also, before writing anything on online_log, make sure it fits to available memory to avoid memory corruption. Read RB page for more details. Reviewed-by: Annamalai Gurusami RB: 18239 --- storage/innobase/row/row0log.cc | 126 ++++++---------------------------------- storage/xtradb/row/row0log.cc | 126 ++++++---------------------------------- 2 files changed, 36 insertions(+), 216 deletions(-) diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc index 62ca32b712c..1383c91f41f 100644 --- a/storage/innobase/row/row0log.cc +++ b/storage/innobase/row/row0log.cc @@ -435,6 +435,8 @@ err_exit: *avail = srv_sort_buf_size - log->tail.bytes; if (size > *avail) { + /* Make sure log->tail.buf is large enough */ + ut_ad(size <= sizeof log->tail.buf); return(log->tail.buf); } else { return(log->tail.block + log->tail.bytes); @@ -528,12 +530,10 @@ row_log_table_delete( { ulint old_pk_extra_size; ulint old_pk_size; - ulint ext_size = 0; ulint mrec_size; ulint avail_size; mem_heap_t* heap = NULL; const dtuple_t* old_pk; - row_ext_t* ext; ut_ad(dict_index_is_clust(index)); ut_ad(rec_offs_validate(rec, index, offsets)); @@ -614,72 +614,20 @@ row_log_table_delete( &old_pk_extra_size); ut_ad(old_pk_extra_size < 0x100); - mrec_size = 6 + old_pk_size; - - /* Log enough prefix of the BLOB unless both the - old and new table are in COMPACT or REDUNDANT format, - which store the prefix in the clustered index record. */ - if (rec_offs_any_extern(offsets) - && (dict_table_get_format(index->table) >= UNIV_FORMAT_B - || dict_table_get_format(new_table) >= UNIV_FORMAT_B)) { - - /* Build a cache of those off-page column prefixes - that are referenced by secondary indexes. It can be - that none of the off-page columns are needed. */ - row_build(ROW_COPY_DATA, index, rec, - offsets, NULL, NULL, NULL, &ext, heap); - if (ext) { - /* Log the row_ext_t, ext->ext and ext->buf */ - ext_size = ext->n_ext * ext->max_len - + sizeof(*ext) - + ext->n_ext * sizeof(ulint) - + (ext->n_ext - 1) * sizeof ext->len; - mrec_size += ext_size; - } - } + /* 2 = 1 (extra_size) + at least 1 byte payload */ + mrec_size = 2 + old_pk_size; if (byte* b = row_log_table_open(index->online_log, mrec_size, &avail_size)) { *b++ = ROW_T_DELETE; *b++ = static_cast(old_pk_extra_size); - /* Log the size of external prefix we saved */ - mach_write_to_4(b, ext_size); - b += 4; - rec_convert_dtuple_to_temp( b + old_pk_extra_size, new_index, old_pk->fields, old_pk->n_fields); b += old_pk_size; - if (ext_size) { - ulint cur_ext_size = sizeof(*ext) - + (ext->n_ext - 1) * sizeof ext->len; - - memcpy(b, ext, cur_ext_size); - b += cur_ext_size; - - /* Check if we need to col_map to adjust the column - number. If columns were added/removed/reordered, - adjust the column number. */ - if (const ulint* col_map = - index->online_log->col_map) { - for (ulint i = 0; i < ext->n_ext; i++) { - const_cast(ext->ext[i]) = - col_map[ext->ext[i]]; - } - } - - memcpy(b, ext->ext, ext->n_ext * sizeof(*ext->ext)); - b += ext->n_ext * sizeof(*ext->ext); - - ext_size -= cur_ext_size - + ext->n_ext * sizeof(*ext->ext); - memcpy(b, ext->buf, ext_size); - b += ext_size; - } - row_log_table_close( index->online_log, b, mrec_size, avail_size); } @@ -1601,15 +1549,13 @@ row_log_table_apply_insert( /******************************************************//** Deletes a record from a table that is being rebuilt. @return DB_SUCCESS or error code */ -static MY_ATTRIBUTE((nonnull(1, 2, 4, 5), warn_unused_result)) +static MY_ATTRIBUTE((nonnull, warn_unused_result)) dberr_t row_log_table_apply_delete_low( /*===========================*/ btr_pcur_t* pcur, /*!< in/out: B-tree cursor, will be trashed */ const ulint* offsets, /*!< in: offsets on pcur */ - const row_ext_t* save_ext, /*!< in: saved external field - info, or NULL */ mem_heap_t* heap, /*!< in/out: memory heap */ mtr_t* mtr) /*!< in/out: mini-transaction, will be committed */ @@ -1633,11 +1579,7 @@ row_log_table_apply_delete_low( /* Build a row template for purging secondary index entries. */ row = row_build( ROW_COPY_DATA, index, btr_pcur_get_rec(pcur), - offsets, NULL, NULL, NULL, - save_ext ? NULL : &ext, heap); - if (!save_ext) { - save_ext = ext; - } + offsets, NULL, NULL, NULL, &ext, heap); } else { row = NULL; } @@ -1656,7 +1598,7 @@ row_log_table_apply_delete_low( } const dtuple_t* entry = row_build_index_entry( - row, save_ext, index, heap); + row, ext, index, heap); mtr_start(mtr); btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_TREE, pcur, mtr); @@ -1699,11 +1641,10 @@ flag_ok: /******************************************************//** Replays a delete operation on a table that was rebuilt. @return DB_SUCCESS or error code */ -static MY_ATTRIBUTE((nonnull(1, 3, 4, 5, 6, 7), warn_unused_result)) +static MY_ATTRIBUTE((nonnull, warn_unused_result)) dberr_t row_log_table_apply_delete( /*=======================*/ - que_thr_t* thr, /*!< in: query graph */ ulint trx_id_col, /*!< in: position of DB_TRX_ID in the new clustered index */ @@ -1712,9 +1653,7 @@ row_log_table_apply_delete( mem_heap_t* offsets_heap, /*!< in/out: memory heap that can be emptied */ mem_heap_t* heap, /*!< in/out: memory heap */ - const row_log_t* log, /*!< in: online log */ - const row_ext_t* save_ext) /*!< in: saved external field - info, or NULL */ + const row_log_t* log) /*!< in: online log */ { dict_table_t* new_table = log->table; dict_index_t* index = dict_table_get_first_index(new_table); @@ -1814,8 +1753,7 @@ all_done: } } - return(row_log_table_apply_delete_low(&pcur, offsets, save_ext, - heap, &mtr)); + return row_log_table_apply_delete_low(&pcur, offsets, heap, &mtr); } /******************************************************//** @@ -2026,7 +1964,7 @@ func_exit_committed: /* Some BLOBs are missing, so we are interpreting this ROW_T_UPDATE as ROW_T_DELETE (see *1). */ error = row_log_table_apply_delete_low( - &pcur, cur_offsets, NULL, heap, &mtr); + &pcur, cur_offsets, heap, &mtr); goto func_exit_committed; } @@ -2064,7 +2002,7 @@ func_exit_committed: } error = row_log_table_apply_delete_low( - &pcur, cur_offsets, NULL, heap, &mtr); + &pcur, cur_offsets, heap, &mtr); ut_ad(mtr.state == MTR_COMMITTED); if (error == DB_SUCCESS) { @@ -2210,8 +2148,6 @@ row_log_table_apply_op( ulint extra_size; const mrec_t* next_mrec; dtuple_t* old_pk; - row_ext_t* ext; - ulint ext_size; ut_ad(dict_index_is_clust(dup->index)); ut_ad(dup->index->table != log->table); @@ -2219,7 +2155,7 @@ row_log_table_apply_op( *error = DB_SUCCESS; - /* 3 = 1 (op type) + 1 (ext_size) + at least 1 byte payload */ + /* 3 = 1 (op type) + 1 (extra_size) + at least 1 byte payload */ if (mrec + 3 >= mrec_end) { return(NULL); } @@ -2269,14 +2205,12 @@ row_log_table_apply_op( break; case ROW_T_DELETE: - /* 1 (extra_size) + 4 (ext_size) + at least 1 (payload) */ - if (mrec + 6 >= mrec_end) { + /* 1 (extra_size) + at least 1 (payload) */ + if (mrec + 2 >= mrec_end) { return(NULL); } extra_size = *mrec++; - ext_size = mach_read_from_4(mrec); - mrec += 4; ut_ad(mrec < mrec_end); /* We assume extra_size < 0x100 for the PRIMARY KEY prefix. @@ -2285,40 +2219,16 @@ row_log_table_apply_op( rec_offs_set_n_fields(offsets, new_index->n_uniq + 2); rec_init_offsets_temp(mrec, new_index, offsets); - next_mrec = mrec + rec_offs_data_size(offsets) + ext_size; + next_mrec = mrec + rec_offs_data_size(offsets); if (next_mrec > mrec_end) { return(NULL); } log->head.total += next_mrec - mrec_start; - /* If there are external fields, retrieve those logged - prefix info and reconstruct the row_ext_t */ - if (ext_size) { - /* We use memcpy to avoid unaligned - access on some non-x86 platforms.*/ - ext = static_cast( - mem_heap_dup(heap, - mrec + rec_offs_data_size(offsets), - ext_size)); - - byte* ext_start = reinterpret_cast(ext); - - ulint ext_len = sizeof(*ext) - + (ext->n_ext - 1) * sizeof ext->len; - - ext->ext = reinterpret_cast(ext_start + ext_len); - ext_len += ext->n_ext * sizeof(*ext->ext); - - ext->buf = static_cast(ext_start + ext_len); - } else { - ext = NULL; - } - *error = row_log_table_apply_delete( - thr, new_trx_id_col, - mrec, offsets, offsets_heap, heap, - log, ext); + new_trx_id_col, + mrec, offsets, offsets_heap, heap, log); break; case ROW_T_UPDATE: diff --git a/storage/xtradb/row/row0log.cc b/storage/xtradb/row/row0log.cc index 52f6a963ec6..c239722e4f7 100644 --- a/storage/xtradb/row/row0log.cc +++ b/storage/xtradb/row/row0log.cc @@ -435,6 +435,8 @@ err_exit: *avail = srv_sort_buf_size - log->tail.bytes; if (size > *avail) { + /* Make sure log->tail.buf is large enough */ + ut_ad(size <= sizeof log->tail.buf); return(log->tail.buf); } else { return(log->tail.block + log->tail.bytes); @@ -528,12 +530,10 @@ row_log_table_delete( { ulint old_pk_extra_size; ulint old_pk_size; - ulint ext_size = 0; ulint mrec_size; ulint avail_size; mem_heap_t* heap = NULL; const dtuple_t* old_pk; - row_ext_t* ext; ut_ad(dict_index_is_clust(index)); ut_ad(rec_offs_validate(rec, index, offsets)); @@ -614,72 +614,20 @@ row_log_table_delete( &old_pk_extra_size); ut_ad(old_pk_extra_size < 0x100); - mrec_size = 6 + old_pk_size; - - /* Log enough prefix of the BLOB unless both the - old and new table are in COMPACT or REDUNDANT format, - which store the prefix in the clustered index record. */ - if (rec_offs_any_extern(offsets) - && (dict_table_get_format(index->table) >= UNIV_FORMAT_B - || dict_table_get_format(new_table) >= UNIV_FORMAT_B)) { - - /* Build a cache of those off-page column prefixes - that are referenced by secondary indexes. It can be - that none of the off-page columns are needed. */ - row_build(ROW_COPY_DATA, index, rec, - offsets, NULL, NULL, NULL, &ext, heap); - if (ext) { - /* Log the row_ext_t, ext->ext and ext->buf */ - ext_size = ext->n_ext * ext->max_len - + sizeof(*ext) - + ext->n_ext * sizeof(ulint) - + (ext->n_ext - 1) * sizeof ext->len; - mrec_size += ext_size; - } - } + /* 2 = 1 (extra_size) + at least 1 byte payload */ + mrec_size = 2 + old_pk_size; if (byte* b = row_log_table_open(index->online_log, mrec_size, &avail_size)) { *b++ = ROW_T_DELETE; *b++ = static_cast(old_pk_extra_size); - /* Log the size of external prefix we saved */ - mach_write_to_4(b, ext_size); - b += 4; - rec_convert_dtuple_to_temp( b + old_pk_extra_size, new_index, old_pk->fields, old_pk->n_fields); b += old_pk_size; - if (ext_size) { - ulint cur_ext_size = sizeof(*ext) - + (ext->n_ext - 1) * sizeof ext->len; - - memcpy(b, ext, cur_ext_size); - b += cur_ext_size; - - /* Check if we need to col_map to adjust the column - number. If columns were added/removed/reordered, - adjust the column number. */ - if (const ulint* col_map = - index->online_log->col_map) { - for (ulint i = 0; i < ext->n_ext; i++) { - const_cast(ext->ext[i]) = - col_map[ext->ext[i]]; - } - } - - memcpy(b, ext->ext, ext->n_ext * sizeof(*ext->ext)); - b += ext->n_ext * sizeof(*ext->ext); - - ext_size -= cur_ext_size - + ext->n_ext * sizeof(*ext->ext); - memcpy(b, ext->buf, ext_size); - b += ext_size; - } - row_log_table_close( index->online_log, b, mrec_size, avail_size); } @@ -1601,15 +1549,13 @@ row_log_table_apply_insert( /******************************************************//** Deletes a record from a table that is being rebuilt. @return DB_SUCCESS or error code */ -static MY_ATTRIBUTE((nonnull(1, 2, 4, 5), warn_unused_result)) +static MY_ATTRIBUTE((nonnull, warn_unused_result)) dberr_t row_log_table_apply_delete_low( /*===========================*/ btr_pcur_t* pcur, /*!< in/out: B-tree cursor, will be trashed */ const ulint* offsets, /*!< in: offsets on pcur */ - const row_ext_t* save_ext, /*!< in: saved external field - info, or NULL */ mem_heap_t* heap, /*!< in/out: memory heap */ mtr_t* mtr) /*!< in/out: mini-transaction, will be committed */ @@ -1633,11 +1579,7 @@ row_log_table_apply_delete_low( /* Build a row template for purging secondary index entries. */ row = row_build( ROW_COPY_DATA, index, btr_pcur_get_rec(pcur), - offsets, NULL, NULL, NULL, - save_ext ? NULL : &ext, heap); - if (!save_ext) { - save_ext = ext; - } + offsets, NULL, NULL, NULL, &ext, heap); } else { row = NULL; } @@ -1656,7 +1598,7 @@ row_log_table_apply_delete_low( } const dtuple_t* entry = row_build_index_entry( - row, save_ext, index, heap); + row, ext, index, heap); mtr_start(mtr); btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_TREE, pcur, mtr); @@ -1699,11 +1641,10 @@ flag_ok: /******************************************************//** Replays a delete operation on a table that was rebuilt. @return DB_SUCCESS or error code */ -static MY_ATTRIBUTE((nonnull(1, 3, 4, 5, 6, 7), warn_unused_result)) +static MY_ATTRIBUTE((nonnull, warn_unused_result)) dberr_t row_log_table_apply_delete( /*=======================*/ - que_thr_t* thr, /*!< in: query graph */ ulint trx_id_col, /*!< in: position of DB_TRX_ID in the new clustered index */ @@ -1712,9 +1653,7 @@ row_log_table_apply_delete( mem_heap_t* offsets_heap, /*!< in/out: memory heap that can be emptied */ mem_heap_t* heap, /*!< in/out: memory heap */ - const row_log_t* log, /*!< in: online log */ - const row_ext_t* save_ext) /*!< in: saved external field - info, or NULL */ + const row_log_t* log) /*!< in: online log */ { dict_table_t* new_table = log->table; dict_index_t* index = dict_table_get_first_index(new_table); @@ -1814,8 +1753,7 @@ all_done: } } - return(row_log_table_apply_delete_low(&pcur, offsets, save_ext, - heap, &mtr)); + return row_log_table_apply_delete_low(&pcur, offsets, heap, &mtr); } /******************************************************//** @@ -2026,7 +1964,7 @@ func_exit_committed: /* Some BLOBs are missing, so we are interpreting this ROW_T_UPDATE as ROW_T_DELETE (see *1). */ error = row_log_table_apply_delete_low( - &pcur, cur_offsets, NULL, heap, &mtr); + &pcur, cur_offsets, heap, &mtr); goto func_exit_committed; } @@ -2064,7 +2002,7 @@ func_exit_committed: } error = row_log_table_apply_delete_low( - &pcur, cur_offsets, NULL, heap, &mtr); + &pcur, cur_offsets, heap, &mtr); ut_ad(mtr.state == MTR_COMMITTED); if (error == DB_SUCCESS) { @@ -2210,8 +2148,6 @@ row_log_table_apply_op( ulint extra_size; const mrec_t* next_mrec; dtuple_t* old_pk; - row_ext_t* ext; - ulint ext_size; ut_ad(dict_index_is_clust(dup->index)); ut_ad(dup->index->table != log->table); @@ -2219,7 +2155,7 @@ row_log_table_apply_op( *error = DB_SUCCESS; - /* 3 = 1 (op type) + 1 (ext_size) + at least 1 byte payload */ + /* 3 = 1 (op type) + 1 (extra_size) + at least 1 byte payload */ if (mrec + 3 >= mrec_end) { return(NULL); } @@ -2269,14 +2205,12 @@ row_log_table_apply_op( break; case ROW_T_DELETE: - /* 1 (extra_size) + 4 (ext_size) + at least 1 (payload) */ - if (mrec + 6 >= mrec_end) { + /* 1 (extra_size) + at least 1 (payload) */ + if (mrec + 2 >= mrec_end) { return(NULL); } extra_size = *mrec++; - ext_size = mach_read_from_4(mrec); - mrec += 4; ut_ad(mrec < mrec_end); /* We assume extra_size < 0x100 for the PRIMARY KEY prefix. @@ -2285,40 +2219,16 @@ row_log_table_apply_op( rec_offs_set_n_fields(offsets, new_index->n_uniq + 2); rec_init_offsets_temp(mrec, new_index, offsets); - next_mrec = mrec + rec_offs_data_size(offsets) + ext_size; + next_mrec = mrec + rec_offs_data_size(offsets); if (next_mrec > mrec_end) { return(NULL); } log->head.total += next_mrec - mrec_start; - /* If there are external fields, retrieve those logged - prefix info and reconstruct the row_ext_t */ - if (ext_size) { - /* We use memcpy to avoid unaligned - access on some non-x86 platforms.*/ - ext = static_cast( - mem_heap_dup(heap, - mrec + rec_offs_data_size(offsets), - ext_size)); - - byte* ext_start = reinterpret_cast(ext); - - ulint ext_len = sizeof(*ext) - + (ext->n_ext - 1) * sizeof ext->len; - - ext->ext = reinterpret_cast(ext_start + ext_len); - ext_len += ext->n_ext * sizeof(*ext->ext); - - ext->buf = static_cast(ext_start + ext_len); - } else { - ext = NULL; - } - *error = row_log_table_apply_delete( - thr, new_trx_id_col, - mrec, offsets, offsets_heap, heap, - log, ext); + new_trx_id_col, + mrec, offsets, offsets_heap, heap, log); break; case ROW_T_UPDATE: -- cgit v1.2.1 From a411910dd677f161b301c095f36373f4f5da5555 Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Thu, 3 May 2018 10:26:00 -0400 Subject: bump the VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 75daccdd9d4..59a439d4152 100644 --- a/VERSION +++ b/VERSION @@ -1,3 +1,3 @@ MYSQL_VERSION_MAJOR=10 MYSQL_VERSION_MINOR=0 -MYSQL_VERSION_PATCH=35 +MYSQL_VERSION_PATCH=36 -- cgit v1.2.1 From 1cb7c4bfc05b85f4384f4a719568d29b83abf1da Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 3 May 2018 16:14:54 +0100 Subject: MDEV-16084 Calling exit() from a signal handler is unsafe. Call _exit() from signal handler. main() can just do return. --- mysql-test/lib/My/SafeProcess/safe_process.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mysql-test/lib/My/SafeProcess/safe_process.cc b/mysql-test/lib/My/SafeProcess/safe_process.cc index feb3eb4df66..5f6544414e2 100644 --- a/mysql-test/lib/My/SafeProcess/safe_process.cc +++ b/mysql-test/lib/My/SafeProcess/safe_process.cc @@ -89,7 +89,7 @@ static void die(const char* fmt, ...) } -static void kill_child(bool was_killed) +static int kill_child(bool was_killed) { int status= 0; @@ -108,15 +108,15 @@ static void kill_child(bool was_killed) exit_code= WEXITSTATUS(status); message("Child exit: %d", exit_code); // Exit with exit status of the child - exit(exit_code); + return exit_code; } if (WIFSIGNALED(status)) message("Child killed by signal: %d", WTERMSIG(status)); - exit(exit_code); + return exit_code; } - exit(5); + return 5; } @@ -136,7 +136,7 @@ extern "C" void handle_signal(int sig) terminated= 1; if (child_pid > 0) - kill_child(sig == SIGCHLD); + _exit(kill_child(sig == SIGCHLD)); // Ignore further signals signal(SIGTERM, SIG_IGN); @@ -292,8 +292,6 @@ int main(int argc, char* const argv[] ) /* Wait for parent or child to die */ sleep(1); } - kill_child(0); - - return 4; + return kill_child(0); } -- cgit v1.2.1 From 1d58d184c2c4ddd8a3b2be6f86d76c4e57bbe14f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 4 May 2018 00:09:45 +0200 Subject: protocol: verify that number of rows is correct --- sql-common/client.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/sql-common/client.c b/sql-common/client.c index 00e2877bedb..6321e64bc75 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1483,7 +1483,9 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, { uchar *pos; /* fields count may be wrong */ - DBUG_ASSERT((uint) (field - result) < fields); + if (field - result >= fields) + goto err; + cli_fetch_lengths(&lengths[0], row->data, default_value ? 8 : 7); field->catalog= strmake_root(alloc,(char*) row->data[0], lengths[0]); field->db= strmake_root(alloc,(char*) row->data[1], lengths[1]); @@ -1501,12 +1503,7 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, /* Unpack fixed length parts */ if (lengths[6] != 12) - { - /* malformed packet. signal an error. */ - free_rows(data); /* Free old data */ - set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate); - DBUG_RETURN(0); - } + goto err; pos= (uchar*) row->data[6]; field->charsetnr= uint2korr(pos); @@ -1533,6 +1530,8 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, /* old protocol, for backward compatibility */ for (row=data->data; row ; row = row->next,field++) { + if (field - result >= fields) + goto err; cli_fetch_lengths(&lengths[0], row->data, default_value ? 6 : 5); field->org_table= field->table= strdup_root(alloc,(char*) row->data[0]); field->name= strdup_root(alloc,(char*) row->data[1]); @@ -1569,8 +1568,17 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, } } #endif /* DELETE_SUPPORT_OF_4_0_PROTOCOL */ + if (field - result < fields) + goto err; free_rows(data); /* Free old data */ DBUG_RETURN(result); + +err: + /* malformed packet. signal an error. */ + free_rows(data); + free_root(alloc, MYF(0)); + set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate); + DBUG_RETURN(0); } /* Read all rows (fields or data) from server */ -- cgit v1.2.1 From 04b1e61d69ebfdeab196c28ef19316b27f8588bc Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 4 May 2018 15:51:13 +0200 Subject: compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit storage/connect/tabjson.cpp:198:10: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null] return NULL; --- storage/connect/tabjson.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index b66682e0190..9e4f5ab987d 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -195,7 +195,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL); if (!(tdp->Database = SetPath(g, db))) - return NULL; + return 0; tdp->Objname = GetStringTableOption(g, topt, "Object", NULL); tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0; @@ -243,14 +243,14 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) tjsp = new(g) TDBJSON(tdp, new(g) MAPFAM(tdp)); if (tjsp->MakeDocument(g)) - return NULL; + return 0; jsp = (tjsp->GetDoc()) ? tjsp->GetDoc()->GetValue(0) : NULL; } else { if (!(tdp->Lrecl = GetIntegerTableOption(g, topt, "Lrecl", 0))) if (!mgo) { sprintf(g->Message, "LRECL must be specified for pretty=%d", tdp->Pretty); - return NULL; + return 0; } else tdp->Lrecl = 8192; // Should be enough @@ -269,14 +269,14 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp)); #else sprintf(g->Message, "Mongo %s Driver not available", "C"); - return NULL; + return 0; #endif } else if (tdp->Driver && toupper(*tdp->Driver) == 'J') { #if defined(JAVA_SUPPORT) tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); #else sprintf(g->Message, "Mongo %s Driver not available", "Java"); - return NULL; + return 0; #endif } else { // Driver not specified #if defined(CMGO_SUPPORT) @@ -285,7 +285,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); #else sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); - return NULL; + return 0; #endif } // endif Driver @@ -304,7 +304,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) tjnp->SetG(G); if (tjnp->OpenDB(g)) - return NULL; + return 0; switch (tjnp->ReadDB(g)) { case RC_EF: -- cgit v1.2.1