Skip to content
This repository has been archived by the owner on Jan 2, 2020. It is now read-only.

Commit

Permalink
Configure entry point via environment variables
Browse files Browse the repository at this point in the history
In preparation for issue #11 the module and method name for
the dllEntry() Python entry point are now read from environment
variables instead of being hardcoded.
  • Loading branch information
robo9k committed Jun 1, 2014
1 parent bb5ff6d commit 465857c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
13 changes: 13 additions & 0 deletions include/q3py.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ intptr_t q3py_syscall(intptr_t number, ...);
#define Q3PY_API_pointers 1


/* TODO: Both of these need to be configurable per module, see issue #10 */
/**
* The name of the environment variable used to set the module
* for the dllMain entry point.
*/
#define Q3PY_ENV_ENTRYPOINT_MODULE "Q3PY_MODULE"
/**
* The name of the environment variable used to set the method
* for the dllMain entry point.
*/
#define Q3PY_ENV_ENTRYPOINT_METHOD "Q3PY_METHOD"


/**
* If this header is included while building another Python
* extension module, expose q3py's C API via a capsule.
Expand Down
28 changes: 26 additions & 2 deletions src/q3py.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Q3_API intptr_t vmMain(int command, int arg0, int arg1, int arg2,
return -1;
}


/**
* Initializes the embedded Python.
*
Expand All @@ -210,8 +211,31 @@ static void init_python() {

Py_Initialize();

/* TODO: Those should be configureable (e.g. like setuptools entry points) */
const char *funcname = "dllentry", *modname = "q3py_hello";

/*
* NOTE: Having one env var (e.g. "Q3PY_ENTRYPOINT") with value
* "module:method" might be easier for the user to configure, but
* C's string handling is meh.
*/
char *modname = getenv(Q3PY_ENV_ENTRYPOINT_MODULE);
if (NULL == modname) {
q3py_error("Entry point module (" Q3PY_ENV_ENTRYPOINT_MODULE ") "
"is not set");
q3py_exit();
}

char *funcname = getenv(Q3PY_ENV_ENTRYPOINT_METHOD);
if (NULL == modname) {
q3py_error("Entry point method (" Q3PY_ENV_ENTRYPOINT_METHOD ") "
"is not set");
q3py_exit();
}

char entrypoint_buffer[128];
snprintf(entrypoint_buffer, sizeof(entrypoint_buffer),
"Entry point is '%s:%s'", modname, funcname);
q3py_log(entrypoint_buffer);


/* See https://docs.python.org/3/extending/embedding.html#pure-embedding */

Expand Down

0 comments on commit 465857c

Please sign in to comment.