Skip to content

Commit f5619a1

Browse files
committed
Updates after Seb's feedback#3
1 parent 2001847 commit f5619a1

6 files changed

Lines changed: 123 additions & 100 deletions

File tree

engine/src/customprinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,10 +1120,11 @@ static bool convert_options_array(void *p_context, MCArrayRef p_array, MCNameRef
11201120
convert_options_array_t *ctxt;
11211121
ctxt = (convert_options_array_t *)p_context;
11221122

1123-
//MCExecPoint ep(nil, nil, nil);
11241123
if (!MCCStringClone(MCStringGetCString(MCNameGetString(p_key)), ctxt -> option_keys[ctxt -> index]))
11251124
return false;
11261125
MCStringRef t_value;
1126+
if (MCValueGetTypeCode(p_value) != kMCValueTypeCodeString)
1127+
return false;
11271128
t_value = (MCStringRef) MCValueRetain(p_value);
11281129

11291130
ctxt -> option_values[ctxt -> index] = strdup(MCStringGetCString(t_value));

engine/src/deploy_windows.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,24 +1083,30 @@ static uint64_t MCWindowsVersionInfoParseVersion(MCStringRef p_string)
10831083
static bool add_version_info_entry(void *p_context, MCArrayRef p_array, MCNameRef p_key, MCValueRef p_value)
10841084
{
10851085
MCWindowsVersionInfo *t_string;
1086-
char *t_value;
1087-
t_value = strdup(MCStringGetCString((MCStringRef)p_value));
1088-
uint4 t_value_len = strlen(t_value);
1089-
1090-
if (t_value[t_value_len - 1] != '\0')
1091-
t_value[t_value_len - 1] = '\0';
1092-
1093-
unsigned short *t_value_utf16;
1094-
uint4 t_value_utf16_length;
1095-
MCS_nativetoutf16(t_value, strlen(t_value), t_value_utf16, t_value_utf16_length);
1096-
1097-
swap_uint16s(t_value_utf16, t_value_utf16_length / 2);
1098-
return MCWindowsVersionInfoAdd((MCWindowsVersionInfo *)p_context, MCStringGetCString(MCNameGetString(p_key)), true, t_value_utf16, t_value_utf16_length, t_string);
1086+
MCExecPoint ep(NULL, NULL, NULL);
1087+
MCExecContext ctxt(ep);
1088+
MCAutoStringRef t_value;
1089+
/* UNCHECKED */ ctxt . ConvertToString(p_value, &t_value);
1090+
byte_t *t_bytes;
1091+
uindex_t t_byte_count;
1092+
/* UNCHECKED */ MCStringConvertToBytes(*t_value, kMCStringEncodingUTF16LE, false, t_bytes, t_byte_count);
1093+
if (t_bytes[t_byte_count - 1] != '\0' || t_bytes[t_byte_count - 2] != '\0')
1094+
{
1095+
byte_t* temp = t_bytes;
1096+
t_bytes = new byte_t[t_byte_count + 2];
1097+
memcpy(t_bytes, temp, t_byte_count);
1098+
t_byte_count +=2;
1099+
delete temp;
1100+
t_bytes[t_byte_count - 2] = '\0';
1101+
t_bytes[t_byte_count - 1] = '\0';
1102+
}
1103+
return MCWindowsVersionInfoAdd((MCWindowsVersionInfo *)p_context, MCStringGetCString(MCNameGetString(p_key)), true, t_bytes, t_byte_count, t_string);
10991104
}
11001105

11011106
static bool MCWindowsResourcesAddVersionInfo(MCWindowsResources& self, MCArrayRef p_info)
11021107
{
11031108
MCExecPoint ep(NULL, NULL, NULL);
1109+
MCExecContext ctxt(ep);
11041110

11051111
bool t_success;
11061112
t_success = true;
@@ -1109,16 +1115,20 @@ static bool MCWindowsResourcesAddVersionInfo(MCWindowsResources& self, MCArrayRe
11091115
t_file_version = t_product_version = 0;
11101116
if (t_success)
11111117
{
1112-
MCNewAutoNameRef t_key1, t_key2;
1113-
/* UNCHECKED */ MCNameCreateWithCString("FileVersion", &t_key1);
1114-
/* UNCHECKED */ MCNameCreateWithCString("ProductVersion", &t_key2);
1115-
11161118
MCValueRef t_value1, t_value2;
11171119

1118-
if (MCArrayFetchValue(p_info, false, *t_key1, t_value1))
1119-
t_file_version = MCWindowsVersionInfoParseVersion((MCStringRef)t_value1);
1120-
if (MCArrayFetchValue(p_info, false, *t_key2, t_value2))
1121-
t_product_version = MCWindowsVersionInfoParseVersion((MCStringRef)t_value2);
1120+
if (MCArrayFetchValue(p_info, false, MCNAME("FileVersion"), t_value1))
1121+
{
1122+
MCAutoStringRef t_string1;
1123+
/* UNCHECKED */ ctxt . ConvertToString(t_value1, &t_string1);
1124+
t_file_version = MCWindowsVersionInfoParseVersion(*t_string1);
1125+
}
1126+
if (MCArrayFetchValue(p_info, false, MCNAME("ProductVersion"), t_value2))
1127+
{
1128+
MCAutoStringRef t_string2;
1129+
/* UNCHECKED */ ctxt . ConvertToString(t_value2, &t_string2);
1130+
t_product_version = MCWindowsVersionInfoParseVersion(*t_string2);
1131+
}
11221132
MCValueRelease(t_value1);
11231133
MCValueRelease(t_value2);
11241134
}

engine/src/exec.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -631,33 +631,6 @@ class MCExecContext
631631
m_ep.sethlist(p_list);
632632
}
633633

634-
//////////
635-
636-
void Clear()
637-
{
638-
m_ep.clear();
639-
}
640-
641-
bool IsEmpty()
642-
{
643-
return m_ep.isempty();
644-
}
645-
646-
bool IsString()
647-
{
648-
return m_ep.isstring();
649-
}
650-
651-
bool IsArray()
652-
{
653-
return m_ep.isarray();
654-
}
655-
656-
bool IsNumber()
657-
{
658-
return m_ep.isnumber();
659-
}
660-
661634
//////////
662635

663636
// Convert the given valueref to a string. If the type is not convertable

engine/src/fieldstyledtext.cpp

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2727
#include "cdata.h"
2828
#include "mcerror.h"
2929
#include "execpt.h"
30+
#include "exec.h"
3031
#include "util.h"
3132
#include "block.h"
3233

@@ -459,8 +460,35 @@ MCParagraph *MCField::parsestyledtextappendparagraph(MCArrayRef p_style, MCNameR
459460
return t_new_paragraph;
460461
}
461462

463+
static bool convert_array_value_to_number_if_non_empty(MCExecContext& ctxt, MCArrayRef p_array, MCNameRef p_key, MCNumberRef &r_value)
464+
{
465+
MCValueRef t_value;
466+
if (!MCArrayFetchValue(p_array, false, p_key, t_value))
467+
return false;
468+
if (MCValueIsEmpty(t_value))
469+
return false;
470+
if (!ctxt . ConvertToNumber(t_value, r_value))
471+
return false;
472+
return true;
473+
}
474+
475+
static bool copy_element_as_color_if_non_empty(MCExecContext& ctxt, MCArrayRef array, MCNameRef key, MCColor& r_value)
476+
{
477+
MCValueRef t_value;
478+
if (!MCArrayFetchValue(array, false, key, t_value))
479+
return false;
480+
if (MCValueIsEmpty(t_value))
481+
return false;
482+
MCAutoStringRef t_string;
483+
if (!ctxt . ConvertToString(t_value, &t_string))
484+
return false;
485+
return MCscreen -> parsecolor(*t_string, r_value, nil);
486+
}
487+
462488
void MCField::parsestyledtextappendblock(MCParagraph *p_paragraph, MCArrayRef p_style, const char *p_initial, const char *p_final, MCStringRef p_metadata, bool p_is_unicode)
463489
{
490+
MCExecPoint ep(NULL, NULL, NULL);
491+
MCExecContext ctxt(ep);
464492
// Make sure we don't try and append any more than 64K worth of bytes.
465493
uint32_t t_text_length;
466494
t_text_length = MCMin(p_final - p_initial, 65534 - p_paragraph -> textsize);
@@ -523,95 +551,93 @@ void MCField::parsestyledtextappendblock(MCParagraph *p_paragraph, MCArrayRef p_
523551
MCValueRef t_valueref;
524552

525553
// Set foreground
526-
if (MCArrayFetchValue(p_style, false, MCNAME("textColor"), t_valueref))
527554
{
528555
MCColor t_color;
529-
if (MCscreen -> parsecolor((MCStringRef)t_valueref, t_color, nil))
556+
if (copy_element_as_color_if_non_empty(ctxt, p_style, MCNAME("textColor"), t_color))
530557
t_block -> setcolor(&t_color);
531-
MCValueRelease(t_valueref);
532558
}
533559

534560
// Set background
535-
if (MCArrayFetchValue(p_style, false, MCNAME("backgroundColor"), t_valueref))
536561
{
537562
MCColor t_color;
538-
if (MCscreen -> parsecolor((MCStringRef)t_valueref, t_color, nil))
563+
if (copy_element_as_color_if_non_empty(ctxt, p_style, MCNAME("backgroundColor"), t_color))
539564
t_block -> setbackcolor(&t_color);
540-
MCValueRelease(t_valueref);
541565
}
542-
543566
// Set textshift
544-
if (MCArrayFetchValue(p_style, false, MCNAME("textShift"), t_valueref))
545567
{
546-
t_block -> setshift(MCNumberFetchAsInteger((MCNumberRef)t_valueref));
547-
MCValueRelease(t_valueref);
568+
MCAutoNumberRef t_number;
569+
convert_array_value_to_number_if_non_empty(ctxt, p_style, MCNAME("textShift"), &t_number);
570+
t_block -> setshift(MCNumberFetchAsInteger(*t_number));
548571
}
549-
572+
550573
// If the block is unicode then we always have to set textFont. In either
551574
// case if there is a textFont key, strip any ,unicode tag first.
552-
if (MCArrayFetchValue(p_style, false, MCNAME("textFont"), t_valueref))
575+
if (MCArrayFetchValue(p_style, false, MCNAME("textFont"), t_valueref) && !MCValueIsEmpty(t_valueref))
553576
{
577+
MCAutoStringRef t_string;
578+
/* UNCHECKED */ ctxt . ConvertToString(t_valueref, &t_string);
554579
uindex_t t_comma;
555-
if (MCStringFirstIndexOfChar((MCStringRef)t_valueref, ',', 0, kMCCompareExact, t_comma))
580+
if (MCStringFirstIndexOfChar(*t_string, ',', 0, kMCCompareExact, t_comma))
556581
{
557582
MCAutoStringRef t_substring;
558-
MCStringCopySubstringAndRelease((MCStringRef)t_valueref, MCRangeMake(0, t_comma), &t_substring);
583+
MCStringCopySubstringAndRelease(*t_string, MCRangeMake(0, t_comma), &t_substring);
559584
t_valueref = MCValueRetain(*t_substring);
560585
}
561-
else
562-
MCValueRelease(t_valueref);
563586
}
564587

565588
// Now if we have unicode, or a textFont style set it.
566-
if (!MCStringIsEmpty((MCStringRef)t_valueref))
589+
if (!MCValueIsEmpty(t_valueref))
567590
{
568-
t_block -> setatts(P_TEXT_FONT, (void *)MCStringGetCString((MCStringRef)t_valueref));
591+
MCAutoStringRef t_string;
592+
/* UNCHECKED */ ctxt . ConvertToString(t_valueref, &t_string);
593+
t_block -> setatts(P_TEXT_FONT, (void *)MCStringGetCString(*t_string));
569594
MCValueRelease(t_valueref);
570595
}
571596

572597
// Set textsize
573-
if (MCArrayFetchValue(p_style, false, MCNAME("textSize"), t_valueref))
574598
{
575-
t_block -> setatts(P_TEXT_SIZE, (void *)MCNumberFetchAsInteger((MCNumberRef)t_valueref));
576-
MCValueRelease(t_valueref);
599+
MCAutoNumberRef t_number;
600+
convert_array_value_to_number_if_non_empty(ctxt, p_style, MCNAME("textSize"), &t_number);
601+
t_block -> setatts(P_TEXT_SIZE, (void *)MCNumberFetchAsInteger(*t_number));
577602
}
578603

579604
// Set textstyle
580-
if (MCArrayFetchValue(p_style, false, MCNAME("textStyle"), t_valueref))
605+
if (MCArrayFetchValue(p_style, false, MCNAME("textStyle"), t_valueref) && !MCValueIsEmpty(t_valueref))
581606
{
607+
MCAutoStringRef t_string;
608+
/* UNCHECKED */ ctxt . ConvertToString(t_valueref, &t_string);
582609
uint4 flags;
583610
MCAutoStringRef fname;
584611
uint2 height;
585612
uint2 size;
586613
uint2 style;
587614

588-
MCF_parsetextatts(P_TEXT_STYLE, (MCStringRef)t_valueref, flags, &fname, height, size, style);
615+
MCF_parsetextatts(P_TEXT_STYLE, *t_string, flags, &fname, height, size, style);
589616

590617
t_block -> setatts(P_TEXT_STYLE, (void *)style);
591-
MCValueRelease(t_valueref);
592618
}
593619

594620
// Set linktext
595621
if (MCArrayFetchValue(p_style, false, MCNAME("linkText"), t_valueref))
596622
{
597623
t_block -> setatts(P_LINK_TEXT, (void *)t_valueref);
598-
MCValueRelease(t_valueref);
599624
}
600625

601626
// Set imagesource
602627
if (MCArrayFetchValue(p_style, false, MCNAME("imageSource"), t_valueref))
603628
{
604629
t_block -> setatts(P_IMAGE_SOURCE, (void *)t_valueref);
605-
MCValueRelease(t_valueref);
606630
}
607631

608-
if (!MCStringIsEmpty((MCStringRef)t_valueref))
632+
if (!MCValueIsEmpty(t_valueref))
609633
MCValueRelease(t_valueref);
610634

611635
}
612636

613637
void MCField::parsestyledtextblockarray(MCArrayRef p_block_value, MCParagraph*& x_paragraphs)
614638
{
639+
MCExecPoint ep(NULL, NULL, NULL);
640+
MCExecContext ctxt(ep);
615641
// If the value is a sequence, recurse for each element.
616642
if (MCArrayIsSequence(p_block_value))
617643
{
@@ -622,28 +648,32 @@ void MCField::parsestyledtextblockarray(MCArrayRef p_block_value, MCParagraph*&
622648
continue;
623649

624650
if (!MCValueIsArray(t_block_entry))
625-
continue;
651+
{
652+
MCArrayRef t_array;
653+
/* UNCHECKED */ ctxt . ConvertToArray(t_block_entry, &t_array);
626654

627-
parsestyledtextblockarray((MCArrayRef)t_block_entry, x_paragraphs);
655+
parsestyledtextblockarray(*t_array, x_paragraphs);
628656
}
629-
630657
return;
631658
}
632659

633660
MCValueRef t_valueref;
634-
MCAutoArrayRef t_style_entry;
661+
MCAutoArrayRef t_style_entry;
635662

636663
// Set foreground
637-
if (MCArrayFetchValue(p_block_value, false, MCNAME("style"), t_valueref))
664+
if (MCArrayFetchValue(p_block_value, false, MCNAME("style"), t_valueref) && !MCValueIsEmpty(t_valueref))
638665
{
639-
/* UNCHECKED */ MCArrayCopyAndRelease((MCArrayRef)t_valueref, &t_style_entry);
666+
MCArrayRef t_array;
667+
/* UNCHECKED */ ctxt . ConvertToArray(t_valueref, t_array);
668+
/* UNCHECKED */ MCArrayCopyAndRelease(t_array, &t_style_entry);
640669
}
641670
// Get the metadata (if any)
642671
MCStringRef t_metadata;
643-
if (MCArrayFetchValue(p_block_value, false, MCNAME("metadata"), t_valueref))
672+
if (MCArrayFetchValue(p_block_value, false, MCNAME("metadata"), t_valueref) && !MCValueIsEmpty(t_valueref))
644673
{
645-
t_metadata = (MCStringRef)MCValueRetain(t_valueref);
646-
MCValueRelease(t_valueref);
674+
MCAutoStringRef t_string;
675+
/* UNCHECKED */ ctxt . ConvertToString(t_valueref, &t_string);
676+
t_metadata = MCValueRetain(*t_string);
647677
}
648678
// If there are no paragraphs yet, create one.
649679
MCParagraph *t_paragraph;
@@ -658,16 +688,18 @@ void MCField::parsestyledtextblockarray(MCArrayRef p_block_value, MCParagraph*&
658688
bool t_is_unicode;
659689
t_is_unicode = false;
660690

661-
if (!MCArrayFetchValue(p_block_value, false, MCNAME("text"), t_valueref))
691+
if (!MCArrayFetchValue(p_block_value, false, MCNAME("text"), t_valueref) || MCValueIsEmpty(t_valueref))
662692
{
663693
/* UNCKECKED */ MCArrayFetchValue(p_block_value, false, MCNAME("unicodeText"), t_valueref);
664694
t_is_unicode = true;
665695
}
666-
if (MCStringIsEmpty((MCStringRef)t_valueref) || MCValueGetTypeCode(t_valueref) == kMCValueTypeCodeArray)
696+
if (MCValueIsEmpty(t_valueref) || MCValueGetTypeCode(t_valueref) == kMCValueTypeCodeArray)
667697
return;
668698

669-
t_text_ptr = MCStringGetCString((MCStringRef)t_valueref);
670-
t_text_length = MCStringGetLength((MCStringRef)t_valueref);
699+
MCAutoStringRef t_temp;
700+
/* UNCHECKED */ ctxt . ConvertToString(t_valueref, &t_temp);
701+
t_text_ptr = MCStringGetCString(*t_temp);
702+
t_text_length = MCStringGetLength(*t_temp);
671703
while(t_text_length != 0)
672704
{
673705
bool t_add_paragraph;
@@ -696,7 +728,7 @@ void MCField::parsestyledtextblockarray(MCArrayRef p_block_value, MCParagraph*&
696728
parsestyledtextappendblock(t_paragraph, *t_style_entry, t_text_initial_ptr, t_text_final_ptr, t_metadata, t_is_unicode);
697729

698730
MCValueRelease(t_metadata);
699-
if (!MCStringIsEmpty((MCStringRef)t_valueref))
731+
if (!MCValueIsEmpty(t_valueref))
700732
MCValueRelease(t_valueref);
701733

702734
// And, if we need a new paragraph, add it.

engine/src/mbliphonedc.mm

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ void MCIPhoneRunBlockOnMainFiber(void (^block)(void))
12711271

12721272
// MW-2012-08-06: [[ Fibers ]] Updated entry point for didBecomeActive.
12731273
static void MCIPhoneDoDidBecomeActive(void *)
1274-
{
1274+
{
12751275
extern char **environ;
12761276
char **env;
12771277
env = environ;
@@ -1302,12 +1302,15 @@ static void MCIPhoneDoDidBecomeActive(void *)
13021302

13031303
if (!t_init_success)
13041304
{
1305-
MCStringRef t_value;
1306-
t_value = (MCStringRef) MCValueRetain(MCresult -> getvalueref());
1307-
NSLog(@"Startup error: %s\n", MCStringGetCString(t_value));
1308-
MCValueRelease(t_value);
1309-
abort();
1310-
return;
1305+
1306+
if (MCValueGetTypeCode(MCresult -> getvalueref()) == kMCValueTypeCodeString)
1307+
{
1308+
MCStringRef t_value;
1309+
t_value = (MCStringRef) MCValueRetain(MCresult -> getvalueref());
1310+
NSLog(@"Startup error: %s\n", MCStringGetCString(t_value));
1311+
abort();
1312+
return;
1313+
}
13111314
}
13121315

13131316
// MW-2012-08-31: [[ Bug 10340 ]] Now we've finished initializing, get the app to

0 commit comments

Comments
 (0)