Skip to content

Commit 227cdfd

Browse files
dbnicholsonrtibbles
authored andcommitted
Rename main function to run_python
This code is compiled into a shared library and not an executable where the C `main` entry point is used. The only entry points actually used are the symbols called by the JNI. Rename this "main" function to `run_python` to avoid confusion. This also allows changing the interface without breaking the standard C `main` interface. This could be used to pass in the Python entry point without using environment variables, for example. The exception is in the sdl2 bootstrap where `PythonActivity` extends `SDLActivity`. `SDLActivity` calls `SDL_main` as the native entry point. This was working before because the SDL headers define `main` as `SDL_main`. Instead of relying on that, just implement `SDL_main` as a wrapper around `run_python` when needed.
1 parent 0038d72 commit 227cdfd

File tree

1 file changed

+13
-7
lines changed
  • pythonforandroid/bootstraps/common/build/jni/application/src

1 file changed

+13
-7
lines changed

pythonforandroid/bootstraps/common/build/jni/application/src/start.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ PyMODINIT_FUNC initandroidembed(void) {
5252
}
5353
#endif
5454

55-
int dir_exists(char *filename) {
55+
static int dir_exists(char *filename) {
5656
struct stat st;
5757
if (stat(filename, &st) == 0) {
5858
if (S_ISDIR(st.st_mode))
@@ -61,7 +61,7 @@ int dir_exists(char *filename) {
6161
return 0;
6262
}
6363

64-
int file_exists(const char *filename) {
64+
static int file_exists(const char *filename) {
6565
FILE *file;
6666
if ((file = fopen(filename, "r"))) {
6767
fclose(file);
@@ -70,8 +70,7 @@ int file_exists(const char *filename) {
7070
return 0;
7171
}
7272

73-
/* int main(int argc, char **argv) { */
74-
int main(int argc, char *argv[]) {
73+
static int run_python(int argc, char *argv[]) {
7574

7675
char *env_argument = NULL;
7776
char *env_entrypoint = NULL;
@@ -348,6 +347,13 @@ int main(int argc, char *argv[]) {
348347
return ret;
349348
}
350349

350+
#ifdef BOOTSTRAP_NAME_SDL2
351+
int SDL_main(int argc, char *argv[]) {
352+
LOGP("Entering SDL_main");
353+
return run_python(argc, argv);
354+
}
355+
#endif
356+
351357
JNIEXPORT int JNICALL Java_org_kivy_android_PythonService_nativeStart(
352358
JNIEnv *env,
353359
jobject thiz,
@@ -386,9 +392,9 @@ JNIEXPORT int JNICALL Java_org_kivy_android_PythonService_nativeStart(
386392

387393
char *argv[] = {"."};
388394
/* ANDROID_ARGUMENT points to service subdir,
389-
* so main() will run main.py from this dir
395+
* so run_python() will run main.py from this dir
390396
*/
391-
return main(1, argv);
397+
return run_python(1, argv);
392398
}
393399

394400
#if defined(BOOTSTRAP_NAME_WEBVIEW) || defined(BOOTSTRAP_NAME_SERVICEONLY)
@@ -427,7 +433,7 @@ int Java_org_kivy_android_PythonActivity_nativeInit(JNIEnv* env, jclass cls, job
427433
argv[1] = NULL;
428434
/* status = SDL_main(1, argv); */
429435

430-
return main(1, argv);
436+
return run_python(1, argv);
431437

432438
/* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
433439
/* exit(status); */

0 commit comments

Comments
 (0)