Skip to content

Commit

Permalink
defeat C
Browse files Browse the repository at this point in the history
  • Loading branch information
EmersonDove committed Mar 11, 2024
1 parent bfd4627 commit ebc24ff
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cx_Freeze/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def base(self, name: str | Path | None):
else:
soabi = get_config_var("SOABI")
suffix = ""
name_base = f"{name}-{soabi}"

# TODO multiple platforms
name_base = f"lib{name}-{soabi}"
suffix = ".so"
self._base: Path = get_resource_file_path("bases", name_base, suffix)
if self._base is None:
raise OptionError(f"no base named {name!r} ({name_base!r})")
Expand Down
16 changes: 15 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,29 @@ def build_extension(self, ext):
extra_args.append("-s")
for arg in (None, "-fno-lto", "--no-lto"):
try:
self.compiler.link_executable(
# self.compiler.link_executable(
# objects,
# fullname,
# libraries=libraries,
# library_dirs=library_dirs,
# runtime_library_dirs=ext.runtime_library_dirs,
# extra_postargs=extra_args + ([arg] if arg else []),
# debug=self.debug,
# )
self.compiler.link_shared_lib(
objects,
fullname,
output_dir=None,
libraries=libraries,
library_dirs=library_dirs,
runtime_library_dirs=ext.runtime_library_dirs,
extra_postargs=extra_args + ([arg] if arg else []),
export_symbols=self.get_export_symbols(ext),
debug=self.debug,
# build_temp=build_temp,
# target_lang=target_lang
)

except LinkError:
if IS_MINGW or IS_WINDOWS:
raise
Expand Down
212 changes: 209 additions & 3 deletions source/bases/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,218 @@ static int FatalScriptError(void)
#include "common.c"


////-----------------------------------------------------------------------------
//// main()
//// Main routine for frozen programs.
////-----------------------------------------------------------------------------
//#if defined(MS_WINDOWS)
//int wmain(int argc, wchar_t **argv)
//{
// int status = 0;
//
// // initialize Python
// if (InitializePython(argc, argv) < 0)
// status = 1;
//
// // do the work
// if (status == 0 && ExecuteScript() < 0)
// status = 1;
//
// Py_Finalize();
// return status;
//}
//#else
//int main(int argc, char **argv)
//{
// int status = 0;
// wchar_t **wargv;
// /* We need a second copy, as Python might modify the first one. */
// wchar_t **wargv2;
// int i;
// char *oldloc;
//
// oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
// if (!oldloc)
// return FatalError("Out of memory!");
//
// // convert arguments to wide characters, using the system default locale
// setlocale(LC_ALL, "");
// wargv = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
// if (!wargv)
// return FatalError("Out of memory converting arguments!");
// wargv2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
// if (!wargv2) {
// PyMem_RawFree(wargv);
// return FatalError("Out of memory converting arguments!");
// }
// for (i = 0; i < argc; i++) {
// wargv[i] = Py_DecodeLocale(argv[i], NULL);
// if (!wargv[i]) {
// status = FatalError("Unable to convert argument to string!");
// argc = i;
// break;
// }
// wargv2[i] = wargv[i];
// }
// wargv2[argc] = wargv[argc] = NULL;
//
// // global pointer to argv[0] for use in SetExecutableName()
// g_argv0 = argv[0];
//
// // initialize Python
// if (status == 0) {
// status = InitializePython(argc, wargv);
//
// // do the work
// if (status == 0)
// status = ExecuteScript();
//
// Py_Finalize();
// }
//
// // free the memory
// for (i = 0; i < argc; i++)
// PyMem_RawFree(wargv2[i]);
// PyMem_RawFree(wargv);
// PyMem_RawFree(wargv2);
//
// setlocale(LC_ALL, oldloc);
// PyMem_RawFree(oldloc);
//
// return status;
//}
//#endif


//// Converts char** to wchar_t**
//wchar_t** ConvertArgsToWChar(int argc, char **argv) {
// wchar_t **wargv = (wchar_t **)malloc(sizeof(wchar_t*) * (argc + 1));
// if (!wargv) return NULL;
//
// int i;
// for (i = 0; i < argc; i++) {
// // Calculate the size needed for the converted string
// int len = MultiByteToWideChar(CP_UTF8, 0, argv[i], -1, NULL, 0);
// wargv[i] = (wchar_t *)malloc(len * sizeof(wchar_t));
// if (!wargv[i]) {
// // Free previously allocated memory on error
// for (int j = 0; j < i; j++) {
// free(wargv[j]);
// }
// free(wargv);
// return NULL;
// }
// // Perform the conversion
// MultiByteToWideChar(CP_UTF8, 0, argv[i], -1, wargv[i], len);
// }
// wargv[argc] = NULL; // Null-terminate the array
// return wargv;
//}
//
//// Free the memory allocated for wargv
//void FreeWargv(int argc, wchar_t **wargv) {
// if (wargv) {
// for (int i = 0; i < argc; i++) {
// if (wargv[i]) {
// free(wargv[i]);
// }
// }
// free(wargv);
// }
//}
//
//
////-----------------------------------------------------------------------------
//// start()
//// Start function for library usage.
////-----------------------------------------------------------------------------
//// TODO we can also have window starts and unix starts as different functions
//int start(int argc, char **argv)
//{
// int status = 0;
//
//#if defined(MS_WINDOWS)
// wchar_t **wargv = ConvertArgsToWChar(argc, argv);
// if (!wargv) {
// // Handle error, could not convert argv to wargv
// return -1;
// }
//
// // initialize Python
// if (InitializePython(argc, wargv) < 0)
// status = 1;
//
// // do the work
// if (status == 0 && ExecuteScript() < 0)
// status = 1;
//
// Py_Finalize();
// FreeWargv(argc, wargv);
//#else
// wchar_t **wargv;
// /* We need a second copy, as Python might modify the first one. */
// wchar_t **wargv2;
// int i;
// char *oldloc;
//
// oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
// if (!oldloc)
// return FatalError("Out of memory!");
//
// // convert arguments to wide characters, using the system default locale
// setlocale(LC_ALL, "");
// wargv = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
// if (!wargv)
// return FatalError("Out of memory converting arguments!");
// wargv2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
// if (!wargv2) {
// PyMem_RawFree(wargv);
// return FatalError("Out of memory converting arguments!");
// }
// for (i = 0; i < argc; i++) {
// wargv[i] = Py_DecodeLocale(argv[i], NULL);
// if (!wargv[i]) {
// status = FatalError("Unable to convert argument to string!");
// argc = i;
// break;
// }
// wargv2[i] = wargv[i];
// }
// wargv2[argc] = wargv[argc] = NULL;
//
// // global pointer to argv[0] for use in SetExecutableName()
// g_argv0 = argv[0];
//
// // initialize Python
// if (status == 0) {
// status = InitializePython(argc, wargv);
//
// // do the work
// if (status == 0)
// status = ExecuteScript();
//
// Py_Finalize();
// }
//
// // free the memory
// for (i = 0; i < argc; i++)
// PyMem_RawFree(wargv2[i]);
// PyMem_RawFree(wargv);
// PyMem_RawFree(wargv2);
//
// setlocale(LC_ALL, oldloc);
// PyMem_RawFree(oldloc);
//#endif
// return status;
//}


//-----------------------------------------------------------------------------
// main()
// start()
// Main routine for frozen programs.
//-----------------------------------------------------------------------------
#if defined(MS_WINDOWS)
int wmain(int argc, wchar_t **argv)
int wstart(int argc, wchar_t **argv)
{
int status = 0;

Expand All @@ -65,7 +271,7 @@ int wmain(int argc, wchar_t **argv)
return status;
}
#else
int main(int argc, char **argv)
int start(int argc, char **argv)
{
int status = 0;
wchar_t **wargv;
Expand Down

0 comments on commit ebc24ff

Please sign in to comment.