Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

(272) Added the wide string entry message functions #376

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c9feb64
Made changes to header files for documentation
rmknan Sep 15, 2023
c58b5ff
Redid the changes to files
rmknan Sep 15, 2023
13bffe3
removed the commented lines
rmknan Sep 15, 2023
53f7fe9
Made changes to target and stumpless_private and new header file
rmknan Sep 15, 2023
8f93327
Made changes to wrapper.h
rmknan Sep 15, 2023
900fb5d
Made changes to target and stumpless.yml
rmknan Sep 15, 2023
b640144
Made changes to new header
rmknan Sep 16, 2023
fc39738
Made changes to stumpless.yml
rmknan Sep 16, 2023
c2a9be6
Working- All changes done
rmknan Sep 16, 2023
2f0de9d
Merge branch 'latest' of github.com:goatshriek/stumpless into 293
rmknan Sep 16, 2023
c986a92
made the requested changes
rmknan Sep 16, 2023
f335d4f
Made changes to element.c format
rmknan Sep 16, 2023
c67c883
Merge branch 'latest' of github.com:goatshriek/stumpless into 367
rmknan Sep 17, 2023
13a1824
Edited the format len offset at line 221 and 224
rmknan Sep 19, 2023
845c9b2
Edited the format len offset at line 221 and 224
rmknan Sep 21, 2023
48f5ec1
Edited the format len offset at line 221
rmknan Sep 21, 2023
e89a1c9
Valgrind test passing locally
rmknan Sep 25, 2023
359b3fe
Added the wide string entry message functions
rmknan Sep 28, 2023
67572e7
Merge branch 'latest' of github.com:rmknan/stumpless into 272
rmknan Sep 28, 2023
35ee4d8
Changes to entry.cpp and wcsrtomb files
rmknan Oct 6, 2023
dc7e079
changes to nowcsrtomb and entry.cpp
rmknan Oct 7, 2023
b3a0974
All errors resolved, Build Successful
rmknan Oct 10, 2023
5861497
Valgrind passed and changed stumpless def
rmknan Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions include/stumpless/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,39 @@ struct stumpless_entry *
stumpless_set_entry_message_str( struct stumpless_entry *entry,
const char *message );

/**
* Sets the message of a given entry.
*
* **Thread Safety: MT-Safe**
* This function is thread safe. A mutex is used to coordinate changes to the
* entry while it is being modified.
*
* **Async Signal Safety: AS-Unsafe lock heap**
* This function is not safe to call from signal handlers due to the use of a
* non-reentrant lock to coordinate changes and the use of memory management
* functions to create the new message and free the old one.
*
* **Async Cancel Safety: AC-Unsafe lock heap**
* This function is not safe to call from threads that may be asynchronously
* cancelled, due to the use of a lock that could be left locked as well as
* memory management functions.
*
* @since release v2.1.0
Copy link
Owner

Choose a reason for hiding this comment

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

change this to the next release, v2.2.0

*
* @param entry The entry to modify.
*
* @param message The new message to set on the entry. If this is NULL, then it
* will be blank in the entry (no characters). This must be a valid UTF-16 string
* in shortest form.
*
* @return The modified entry if no error is encountered. If an error is
* encountered, then NULL is returned and an error code is set appropriately.
*/
STUMPLESS_PUBLIC_FUNCTION
struct stumpless_entry *
stumpless_set_entry_message_str_w( struct stumpless_entry *entry,
const wchar_t *message );

/**
* Puts the param in the element at the given index of an entry.
*
Expand Down
33 changes: 33 additions & 0 deletions src/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "private/config.h"
#include "private/config/locale/wrapper.h"
#include "private/config/wrapper/format_string.h"
#include "private/config/wrapper/wstring.h"
#include "private/config/wrapper/gethostname.h"
#include "private/config/wrapper/getpid.h"
#include "private/config/wrapper/thread_safety.h"
Expand Down Expand Up @@ -868,6 +869,38 @@
return entry;
}


struct stumpless_entry *
stumpless_set_entry_message_str_w( struct stumpless_entry *entry,
const wchar_t *message ) {
char *new_message;
size_t new_message_length;
const char *old_message;

VALIDATE_ARG_NOT_NULL( entry );

if( message ) {
new_message = config_copy_wstring_to_cstring( message, &new_message_length );
if( !new_message ) {
return NULL;
}
} else {

Check warning on line 887 in src/entry.c

View check run for this annotation

Codecov / codecov/patch

src/entry.c#L887

Added line #L887 was not covered by tests
new_message = NULL;
new_message_length = 0;
}

lock_entry( entry );
old_message = entry->message;
entry->message = new_message;
entry->message_length = new_message_length;
unlock_entry( entry );

free_mem( old_message );
clear_error( );

return entry;
}

struct stumpless_entry *
stumpless_set_entry_param_by_index( struct stumpless_entry *entry,
size_t element_index,
Expand Down
158 changes: 158 additions & 0 deletions test/function/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,164 @@ namespace {
stumpless_free_all( );
}








// TEST( SetMessageWideStrTest, AsciiMessage ) {
// struct stumpless_entry *entry;
// const char *ascii_message;
// const struct stumpless_entry *result;
// const char *new_message;

// entry = create_empty_entry( );
// ASSERT_NOT_NULL( entry );

// ascii_message = load_corpus( "cstring/ascii" );
goatshriek marked this conversation as resolved.
Show resolved Hide resolved
// ASSERT_NOT_NULL( ascii_message );

// result = stumpless_set_entry_message_str_w( entry, ascii_message );
// EXPECT_EQ( entry, result );
// EXPECT_NO_ERROR;

// new_message = stumpless_get_entry_message( entry );
// EXPECT_NOT_NULL( new_message );
// EXPECT_NO_ERROR;
// EXPECT_STREQ( ascii_message, new_message );

// delete[] ascii_message;
// free( ( void * ) new_message );
// stumpless_destroy_entry_and_contents( entry );
// stumpless_free_all( );
// }

// TEST( SetMessageWideStrTest, LongAsciiMessage ) {
// struct stumpless_entry *entry;
// const char *long_message;
// const struct stumpless_entry *result;
// const char *new_message;

// entry = create_empty_entry( );
// ASSERT_NOT_NULL( entry );

// long_message = load_corpus( "cstring/lorem" );
rmknan marked this conversation as resolved.
Show resolved Hide resolved
// ASSERT_NOT_NULL( long_message );

// result = stumpless_set_entry_message_str_w( entry, long_message );
// EXPECT_EQ( entry, result );
// EXPECT_NO_ERROR;

// new_message = stumpless_get_entry_message( entry );
// EXPECT_NOT_NULL( new_message );
// EXPECT_NO_ERROR;
// EXPECT_STREQ( long_message, new_message );

// delete[] long_message;
// free( ( void * ) new_message );
// stumpless_destroy_entry_and_contents( entry );
// stumpless_free_all( );
// }

TEST( SetMessageWideStrTest, MallocFailureOnMessage ) {
void * (*set_malloc_result)(size_t);
struct stumpless_entry *entry;
const wchar_t *new_message = L"nice and long to make sure it beats the first";
const struct stumpless_entry *result;
const struct stumpless_error *error;

entry = create_empty_entry( );
ASSERT_NOT_NULL( entry );

set_malloc_result = stumpless_set_malloc( MALLOC_FAIL_ON_SIZE( 46 ) );
ASSERT_NOT_NULL( set_malloc_result );

result = stumpless_set_entry_message_str_w( entry, new_message );
EXPECT_ERROR_ID_EQ( STUMPLESS_MEMORY_ALLOCATION_FAILURE );
EXPECT_NULL( result );

set_malloc_result = stumpless_set_malloc( malloc );
EXPECT_TRUE( set_malloc_result == malloc );

stumpless_destroy_entry_and_contents( entry );
stumpless_free_all( );
}

TEST( SetMessageWideStrTest, NullEntry ) {
const struct stumpless_entry *result;
const struct stumpless_error *error;

result = stumpless_set_entry_message_str_w( NULL, L"test-message" );
EXPECT_ERROR_ID_EQ( STUMPLESS_ARGUMENT_EMPTY );
EXPECT_NULL( result );

stumpless_free_all( );
}

TEST( SetMessageWideStrTest, NullMessage ) {
struct stumpless_entry *entry;
const struct stumpless_entry *result;

entry = create_empty_entry( );
EXPECT_NO_ERROR;
EXPECT_NOT_NULL( entry );

result = stumpless_set_entry_message_str_w( entry, NULL );
EXPECT_NO_ERROR;
EXPECT_EQ( entry, result );

EXPECT_NULL( entry->message );
EXPECT_EQ( 0, entry->message_length );

stumpless_destroy_entry_and_contents( entry );

stumpless_free_all( );
}

// TEST( SetMessageWideStrTest, Utf16Message ) {
// struct stumpless_entry *entry;
// const char *utf16_message;
// const struct stumpless_entry *result;
// const char *new_message;

// entry = create_empty_entry( );
// ASSERT_NOT_NULL( entry );

// utf16_message = load_corpus( "cstring/zh-cn" );
rmknan marked this conversation as resolved.
Show resolved Hide resolved
// ASSERT_NOT_NULL( utf16_message );

// result = stumpless_set_entry_message_str_w( entry, utf16_message );
// EXPECT_EQ( entry, result );
// EXPECT_NO_ERROR;

// new_message = stumpless_get_entry_message( entry );
// EXPECT_NOT_NULL( new_message );
// EXPECT_NO_ERROR;
// EXPECT_STREQ( utf16_message, new_message );

// delete[] utf16_message;
// free( ( void * ) new_message );
// stumpless_destroy_entry_and_contents( entry );
// stumpless_free_all( );
// }
















TEST( SetParam, NullEntry ) {
struct stumpless_param *param;
const struct stumpless_entry *result;
Expand Down
1 change: 1 addition & 0 deletions tools/check_headers/stumpless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,4 @@
"stumpless_get_target_type_string" : "stumpless/target.h"
"STUMPLESS_FOREACH_TARGET_TYPE" : "stumpless/target.h"
"STUMPLESS_FOREACH_SEVERITY" : "stumpless/severity.h"
"stumpless_set_entry_message_str_w" : "stumpless/entry.h"
Loading