Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit fb518fa

Browse files
committed
[[ SysLibrary ]] Update engine to use new library loading system
This patch reworks all the engine's uses of library loading functions to use the new MCU_library_* APIs. These APIs perfrom appropriate search, mapping and extension adding in a uniform way. Additionally, this patch removes the per-platform means of getting the 'executable path' replacing them with a fetch of the engine's library's path using the system library API.
1 parent 94da13b commit fb518fa

37 files changed

+449
-684
lines changed

Installer/package.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,6 @@ component Mobile.MacOSX
486486

487487
component Engine.MacOSX
488488
executable macosx:LiveCode[[EditionTagUpper]].app as "[[TargetFolder]]"
489-
executable macosx:revpdfprinter.bundle as "[[TargetFolder]]/Contents/MacOS/revpdfprinter.bundle"
490-
executable macosx:revsecurity.dylib as "[[TargetFolder]]/Contents/MacOS/revsecurity.dylib"
491489

492490
////////////////////////////////////////////////////////////////////////////////
493491

engine/engine.gyp

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -641,36 +641,6 @@
641641
},
642642
},
643643
},
644-
645-
{
646-
'target_name': 'development-postprocess',
647-
'type': 'none',
648-
649-
'dependencies':
650-
[
651-
'development',
652-
'../thirdparty/libopenssl/libopenssl.gyp:revsecurity',
653-
],
654-
655-
'conditions':
656-
[
657-
[
658-
'OS == "mac"',
659-
{
660-
'copies':
661-
[
662-
{
663-
'destination': '<(PRODUCT_DIR)/LiveCode-Community.app/Contents/MacOS',
664-
'files':
665-
[
666-
'<(PRODUCT_DIR)/revsecurity.dylib',
667-
],
668-
},
669-
],
670-
},
671-
],
672-
],
673-
},
674644

675645
{
676646
'target_name': 'development',
@@ -687,7 +657,9 @@
687657
},
688658

689659
'dependencies':
690-
[
660+
[
661+
'../thirdparty/libopenssl/libopenssl.gyp:revsecurity_built',
662+
'../revpdfprinter/revpdfprinter.gyp:external-revpdfprinter',
691663
'kernel-development.gyp:kernel-development',
692664
'encode_environment_stack',
693665
'engine-common.gyp:security-community',
@@ -722,7 +694,19 @@
722694
[
723695
'rsrc/LiveCode.icns',
724696
'rsrc/LiveCodeDoc.icns',
725-
],
697+
],
698+
699+
'copies':
700+
[
701+
{
702+
'destination': '<(PRODUCT_DIR)/LiveCode-Community.app/Contents/MacOS',
703+
'files':
704+
[
705+
'<(PRODUCT_DIR)/revsecurity.dylib',
706+
'<(PRODUCT_DIR)/revpdfprinter.bundle',
707+
],
708+
},
709+
],
726710
},
727711
],
728712
[

engine/src/customprinter.cpp

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,51 +2120,18 @@ Exec_stat MCCustomPrinterCreate(MCStringRef p_destination, MCStringRef p_filenam
21202120
{
21212121
// To generalize/improve in the future if we open up the custom printing
21222122
// device interface :o)
2123-
static bool s_revpdfprinter_loaded = false;
21242123
static MCCustomPrinterCreateProc s_revpdfprinter_create = nil;
2125-
if (!s_revpdfprinter_loaded)
2124+
2125+
static MCSAutoLibraryRef s_revpdfprinter;
2126+
if (!s_revpdfprinter.IsSet())
21262127
{
2127-
MCSysModuleHandle t_module;
2128-
#if defined(_WINDOWS)
2129-
t_module = MCS_loadmodule(MCSTR("revpdfprinter.dll"));
2130-
#elif defined(_MACOSX)
2131-
MCAutoStringRef t_module_path_str1;
2132-
2133-
/* UNCHECKED */ MCStringFormat(&t_module_path_str1, "%@/../revpdfprinter.bundle", MCcmd);
2134-
t_module = MCS_loadmodule(*t_module_path_str1);
2135-
2136-
if (t_module == nil)
2137-
{
2138-
MCAutoStringRef t_module_path_str2;
2139-
/* UNCHECKED */ MCStringFormat(&t_module_path_str2, "%@/../../../../revpdfprinter.bundle", MCcmd);
2140-
t_module = MCS_loadmodule(*t_module_path_str2);
2141-
}
2142-
#elif defined(_LINUX)
2128+
&s_revpdfprinter = MCU_library_load(MCSTR("./revpdfprinter"));
21432129

2144-
uindex_t t_engine_dir_end;
2145-
/* UNCHECKED */ MCStringLastIndexOfChar(MCcmd, '/', UINDEX_MAX, kMCCompareExact, t_engine_dir_end);
2146-
MCAutoStringRef t_module_path;
2147-
MCRange t_range = MCRangeMake(0, t_engine_dir_end);
2148-
// AL-2014-09-19: Range argument to MCStringFormat is a pointer to an MCRange.
2149-
/* UNCHECKED */ MCStringFormat(&t_module_path, "%*@/revpdfprinter.so", &t_range, MCcmd);
2150-
t_module = MCS_loadmodule(*t_module_path);
2151-
#elif defined(TARGET_SUBPLATFORM_IPHONE)
2152-
uindex_t t_engine_dir_end;
2153-
/* UNCHECKED */ MCStringLastIndexOfChar(MCcmd, '/', UINDEX_MAX, kMCCompareExact, t_engine_dir_end);
2154-
MCAutoStringRef t_module_path;
2155-
MCRange t_range = MCRangeMake(0, t_engine_dir_end);
2156-
// AL-2014-09-19: Range argument to MCStringFormat is a pointer to an MCRange.
2157-
MCStringFormat(&t_module_path, "%*@/revpdfprinter.dylib", &t_range, MCcmd);
2158-
t_module = MCS_loadmodule(*t_module_path);
2159-
#else
2160-
// Neither servers nor Android have an implementation
2161-
t_module = nil;
2162-
#endif
2163-
if (t_module != nil)
2130+
if (s_revpdfprinter.IsSet())
21642131
{
2165-
s_revpdfprinter_create = (MCCustomPrinterCreateProc)MCS_resolvemodulesymbol(t_module, MCSTR("MCCustomPrinterCreate"));
2132+
s_revpdfprinter_create = (MCCustomPrinterCreateProc)MCU_library_lookup(*s_revpdfprinter,
2133+
MCSTR("MCCustomPrinterCreate"));
21662134
}
2167-
s_revpdfprinter_loaded = true;
21682135
}
21692136

21702137
if (s_revpdfprinter_create != nil)

engine/src/dispatch.cpp

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,49 +1993,11 @@ void MCDispatch::timer(MCNameRef p_message, MCParameter *p_parameters)
19931993

19941994
bool MCDispatch::loadexternal(MCStringRef p_external)
19951995
{
1996-
MCStringRef t_filename;
1997-
#if defined(TARGET_SUBPLATFORM_ANDROID)
1998-
extern bool revandroid_loadExternalLibrary(MCStringRef p_external, MCStringRef &r_filename);
1999-
// MW-2013-08-07: [[ ExternalsApiV5 ]] Make sure we only use the leaf name
2000-
// of the external when loading.
2001-
uindex_t t_slash_index;
2002-
uindex_t t_ext_length = MCStringGetLength(p_external);
2003-
MCStringRef t_external_leaf;
2004-
2005-
if (MCStringLastIndexOfChar(p_external, '/', t_ext_length, kMCStringOptionCompareExact, t_slash_index))
2006-
{
2007-
if (!MCStringCopySubstring(p_external, MCRangeMake(t_slash_index + 1, t_ext_length - t_slash_index - 1), t_external_leaf))
2008-
return false;
2009-
}
2010-
else
2011-
t_external_leaf = MCValueRetain(p_external);
2012-
2013-
if (!revandroid_loadExternalLibrary(t_external_leaf, t_filename))
2014-
{
2015-
MCValueRelease(t_external_leaf);
2016-
return false;
2017-
}
2018-
2019-
// Don't try and load any drivers as externals.
2020-
if (MCStringBeginsWithCString(t_external_leaf, (const char_t *)"db", kMCStringOptionCompareExact))
2021-
{
2022-
MCValueRelease(t_external_leaf);
2023-
MCValueRelease(t_filename);
2024-
return true;
2025-
}
2026-
2027-
MCValueRelease(t_external_leaf);
2028-
#else
2029-
// AL-2015-02-10: [[ SB Inclusions ]] New module loading utility deals with path resolution
2030-
t_filename = MCValueRetain(p_external);
2031-
#endif
2032-
20331996
if (m_externals == nil)
20341997
m_externals = new (nothrow) MCExternalHandlerList;
20351998

20361999
bool t_loaded;
2037-
t_loaded = m_externals -> Load(t_filename);
2038-
MCValueRelease(t_filename);
2000+
t_loaded = m_externals -> Load(p_external);
20392001

20402002
if (m_externals -> IsEmpty())
20412003
{

engine/src/dsklnx.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,34 +1270,6 @@ class MCLinuxDesktop: public MCSystemInterface
12701270
return MCStringCreateWithSysString(tmpnam(NULL), r_tmp_name);
12711271
}
12721272

1273-
virtual MCSysModuleHandle LoadModule(MCStringRef p_path)
1274-
{
1275-
// dlopen loads whole 4-byte words when accessing the filename. This causes valgrind to make
1276-
// spurious noise - so in DEBUG mode we make sure we allocate a 4-byte aligned block of memory.
1277-
//
1278-
// Because converting to a sys string allocates memory, this alignment will always be satisfied.
1279-
// (malloc/new always return alignment >= int/pointer alignment)
1280-
MCAutoStringRefAsSysString t_filename_sys;
1281-
/* UNCHECKED */ t_filename_sys.Lock(p_path);
1282-
1283-
MCSysModuleHandle t_result;
1284-
t_result = (MCSysModuleHandle)dlopen(*t_filename_sys, (RTLD_NOW | RTLD_LOCAL));
1285-
1286-
return t_result ;
1287-
}
1288-
1289-
virtual MCSysModuleHandle ResolveModuleSymbol(MCSysModuleHandle p_module, MCStringRef p_symbol)
1290-
{
1291-
MCAutoStringRefAsSysString t_symbol_sys;
1292-
/* UNCHECKED */ t_symbol_sys.Lock(p_symbol);
1293-
return (MCSysModuleHandle)(dlsym(p_module, *t_symbol_sys));
1294-
}
1295-
1296-
virtual void UnloadModule(MCSysModuleHandle p_module)
1297-
{
1298-
dlclose(p_module);
1299-
}
1300-
13011273
virtual bool ListFolderEntries(MCStringRef p_folder, MCSystemListFolderEntriesCallback p_callback, void *x_context)
13021274
{
13031275
MCAutoStringRefAsSysString t_path;
@@ -1368,19 +1340,6 @@ class MCLinuxDesktop: public MCSystemInterface
13681340

13691341
return t_success;
13701342
}
1371-
1372-
// ST-2014-12-18: [[ Bug 14259 ]] Returns the executable from the system tools, not from argv[0]
1373-
virtual bool GetExecutablePath(MCStringRef &r_executable)
1374-
{
1375-
char t_executable[PATH_MAX];
1376-
ssize_t t_size;
1377-
t_size = readlink("/proc/self/exe", t_executable, PATH_MAX);
1378-
if (t_size >= PATH_MAX || t_size < 0)
1379-
return false;
1380-
1381-
t_executable[t_size] = 0;
1382-
return MCStringCreateWithSysString(t_executable, r_executable);
1383-
}
13841343

13851344
virtual bool PathToNative(MCStringRef p_path, MCStringRef& r_native)
13861345
{

engine/src/dskmac.cpp

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,34 +3812,6 @@ struct MCMacDesktop: public MCSystemInterface, public MCMacSystemService
38123812

38133813
return MCListCopyAsString(*t_list, r_drives) ? True : False;
38143814
}
3815-
3816-
3817-
// ST-2014-12-18: [[ Bug 14259 ]] Returns the executable from the system tools, not from argv[0]
3818-
virtual bool GetExecutablePath(MCStringRef& r_path)
3819-
{
3820-
uint32_t bufsize = 0;
3821-
_NSGetExecutablePath(NULL, &bufsize);
3822-
// Use MCMemoryNewArray to allocate the buffer, for consistency with
3823-
// free() being used in MCStringCreateWithBytesAndRelease
3824-
char* buf;
3825-
if (!MCMemoryNewArray(bufsize, buf))
3826-
return False;
3827-
3828-
if (_NSGetExecutablePath(buf, &bufsize) != 0)
3829-
{
3830-
MCMemoryDeleteArray(buf);
3831-
return False;
3832-
}
3833-
3834-
MCAutoStringRef t_path;
3835-
// [[ Bug 15062 ]] The path returned by _NSGetExecutablePath is UTF-8
3836-
// encoded. We should decode it this way.
3837-
// We use strlen, as in MCStringCreateWithCString, to avoid the surprise
3838-
// of a trailing NULL character.
3839-
return MCStringCreateWithBytesAndRelease((byte_t*)buf, strlen(buf), kMCStringEncodingUTF8, false, &t_path)
3840-
&& ResolvePath(*t_path, r_path);
3841-
}
3842-
38433815

38443816
bool PathToNative(MCStringRef p_path, MCStringRef& r_native)
38453817
{
@@ -4138,75 +4110,6 @@ struct MCMacDesktop: public MCSystemInterface, public MCMacSystemService
41384110
return t_handle;
41394111
}
41404112

4141-
virtual MCSysModuleHandle LoadModule(MCStringRef p_filename)
4142-
{
4143-
4144-
// SN-2014-12-09: [[ Bug 14001 ]] Update the module loading for Mac server
4145-
#ifdef _SERVER
4146-
MCAutoStringRefAsUTF8String t_utf_path;
4147-
4148-
if (!t_utf_path.Lock(p_filename))
4149-
return NULL;
4150-
4151-
void *t_result;
4152-
4153-
t_result = dlopen(*t_utf_path, RTLD_LAZY);
4154-
4155-
return (MCSysModuleHandle)t_result;
4156-
#else
4157-
MCAutoStringRefAsUTF8String t_utf_path;
4158-
4159-
if (!t_utf_path.Lock(p_filename))
4160-
return NULL;
4161-
4162-
CFURLRef t_url;
4163-
t_url = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8 *)*t_utf_path, strlen(*t_utf_path), False);
4164-
4165-
if (t_url == NULL)
4166-
return NULL;
4167-
4168-
MCSysModuleHandle t_result;
4169-
t_result = (MCSysModuleHandle)CFBundleCreate(NULL, t_url);
4170-
4171-
CFRelease(t_url);
4172-
4173-
return (MCSysModuleHandle)t_result;
4174-
#endif
4175-
}
4176-
4177-
virtual MCSysModuleHandle ResolveModuleSymbol(MCSysModuleHandle p_module, MCStringRef p_symbol)
4178-
{
4179-
4180-
// SN-2014-12-09: [[ Bug 14001 ]] Update the module loading for Mac server
4181-
#ifdef _SERVER
4182-
return (MCSysModuleHandle)dlsym(p_module, MCStringGetCString(p_symbol));
4183-
#else
4184-
CFStringRef t_cf_symbol;
4185-
4186-
MCStringConvertToCFStringRef(p_symbol, t_cf_symbol);
4187-
if (t_cf_symbol == NULL)
4188-
return NULL;
4189-
4190-
void *t_symbol_ptr;
4191-
t_symbol_ptr = CFBundleGetFunctionPointerForName((CFBundleRef)p_module, t_cf_symbol);
4192-
4193-
CFRelease(t_cf_symbol);
4194-
4195-
return (MCSysModuleHandle) t_symbol_ptr;
4196-
#endif
4197-
}
4198-
4199-
virtual void UnloadModule(MCSysModuleHandle p_module)
4200-
{
4201-
4202-
// SN-2014-12-09: [[ Bug 14001 ]] Update the module loading for Mac server
4203-
#ifdef _SERVER
4204-
dlclose(p_module);
4205-
#else
4206-
CFRelease((CFBundleRef)p_module);
4207-
#endif
4208-
}
4209-
42104113
virtual bool LongFilePath(MCStringRef p_path, MCStringRef& r_long_path)
42114114
{
42124115
return MCStringCopy(p_path, r_long_path);

engine/src/dskmain.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ bool X_init(int argc, MCStringRef argv[], MCStringRef envp[])
137137
delete MCeerror;
138138
delete MCresult;
139139
#endif
140-
141-
// ST-2014-12-18: [[ Bug 14259 ]] Update to get the executable file from the system
142-
// since ResolvePath must behave differently on Linux
143-
MCsystem -> GetExecutablePath(MCcmd);
144140

145141
// Create the basic locale and the system locale
146142
if (!MCLocaleCreateWithName(MCSTR("en_US"), kMCBasicLocale))

0 commit comments

Comments
 (0)