Skip to content

Commit

Permalink
fix the name of corecext in sys.modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Apr 5, 2016
1 parent c4b95fc commit 96aa356
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export LC_ALL=C.UTF-8
all: src/gevent/libev/gevent.corecext.c src/gevent/gevent.ares.c src/gevent/gevent._semaphore.c

src/gevent/libev/gevent.corecext.c: src/gevent/libev/corecext.ppyx src/gevent/libev/libev.pxd util/cythonpp.py
$(PYTHON) util/cythonpp.py -o gevent.corecext.c src/gevent/libev/corecext.ppyx
$(PYTHON) util/cythonpp.py -o gevent.corecext.c --module-name gevent.libev.corecext.pyx src/gevent/libev/corecext.ppyx
echo '#include "callbacks.c"' >> gevent.corecext.c
mv gevent.corecext.* src/gevent/libev/

Expand Down
2 changes: 1 addition & 1 deletion appveyor/make.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IF "%PYTHON_EXE%" == "python" (
%PYEXE% util\cythonpp.py -o gevent.corecext.c src\gevent\libev\corecext.ppyx
%PYEXE% util\cythonpp.py -o gevent.corecext.c --module-name gevent.libev.corecext.pyx src\gevent\libev\corecext.ppyx
type src\gevent\libev\callbacks.c >> gevent.corecext.c
move gevent.corecext.* src\gevent\libev
)
Expand Down
9 changes: 3 additions & 6 deletions src/gevent/libev/callbacks.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/* Copyright (c) 2011-2012 Denis Bilenko. See LICENSE for details. */
#ifdef Py_PYTHON_H

#if 1
/* name generated by cython when we use threads */
#define _GEVENTLOOP struct __pyx_vtabstruct_8corecext_loop
#else
#define _GEVENTLOOP struct __pyx_vtabstruct_6gevent_8corecext_loop
#endif
/* the name changes depending on our file layout and --module-name option */
#define _GEVENTLOOP struct __pyx_vtabstruct_6gevent_5libev_8corecext_loop


static void gevent_handle_error(struct PyGeventLoopObject* loop, PyObject* context) {
PyThreadState *tstate;
Expand Down
19 changes: 12 additions & 7 deletions util/cythonpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ def _run_cython_on_file(configuration, pyx_filename,
py_banner, banner,
output_filename,
counter, lines,
cache=None):
cache=None,
module_name=None):
value = ''.join(lines)
sourcehash = md5(value.encode("utf-8")).hexdigest()
comment = configuration.format_tag() + " hash:" + str(sourcehash)
Expand All @@ -420,7 +421,7 @@ def _run_cython_on_file(configuration, pyx_filename,
tempdir = tempfile.mkdtemp()
#unique_pyx_filename = pyx_filename
#unique_output_filename = output_filename
unique_pyx_filename = os.path.join(tempdir, pyx_filename)
unique_pyx_filename = os.path.join(tempdir, module_name or pyx_filename)
unique_output_filename = os.path.join(tempdir, output_filename)

dirname = os.path.dirname(unique_pyx_filename) # output must be in same dir
Expand All @@ -442,7 +443,8 @@ def _run_cython_on_file(configuration, pyx_filename,
return configuration.attach_tags(output), configuration, sourcehash


def _run_cython_on_files(pyx_filename, py_banner, banner, output_filename, preprocessed):
def _run_cython_on_files(pyx_filename, py_banner, banner, output_filename, preprocessed,
module_name=None):
counter = 0
threads = []
cache = {}
Expand All @@ -452,7 +454,7 @@ def _run_cython_on_files(pyx_filename, py_banner, banner, output_filename, prepr
args=(configuration, pyx_filename,
py_banner, banner, output_filename,
counter, lines,
cache)))
cache, module_name)))
threads[-1].start()

for t in threads:
Expand Down Expand Up @@ -482,7 +484,7 @@ def _run_cython_on_files(pyx_filename, py_banner, banner, output_filename, prepr

return ordered_results

def process_filename(filename, output_filename=None):
def process_filename(filename, output_filename=None, module_name=None):
"""Process the .ppyx file with preprocessor and compile it with cython.
The algorithm is as following:
Expand Down Expand Up @@ -515,7 +517,7 @@ def process_filename(filename, output_filename=None):
reference_pyx = preprocessed.pop(None)

sources = _run_cython_on_files(pyx_filename, py_banner, banner, output_filename,
preprocessed)
preprocessed, module_name)

log('Generating %s ', output_filename)
result = generate_merged(sources)
Expand Down Expand Up @@ -1026,6 +1028,9 @@ def main():
parser.add_argument('--ignore-cond', action='store_true', help='Ignore conditional directives (only expand definitions)')
parser.add_argument('--write-intermediate', action='store_true', help='Save intermediate files produced by preprocessor and Cython')
parser.add_argument('-o', '--output-file', help='Specify name of generated C file')
# TODO: Derive the module name automatically from the input filename relative to the base
# dir.
parser.add_argument('--module-name', help="specify name of .pyx module")
parser.add_argument("input")
options = parser.parse_args()
filename = options.input
Expand Down Expand Up @@ -1060,7 +1065,7 @@ def is_condition_true(*args):
sys.stdout.write(preprocess_filename(filename, FakeConfig()))

if run:
process_filename(filename, options.output_file)
process_filename(filename, options.output_file, options.module_name)


if __name__ == '__main__':
Expand Down

0 comments on commit 96aa356

Please sign in to comment.