forked from hpyproject/hpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
355 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
How to replace global variables | ||
------------------------------- | ||
|
||
In a given .c source, write: | ||
|
||
|
||
typedef struct { | ||
long x; | ||
HPy y; | ||
} my_globals_t; | ||
|
||
static void my_globals_traverse(traversefunc traverse, my_globals_t *g) | ||
{ | ||
traverse(g->y); | ||
} | ||
|
||
HPyGlobalSpec my_globals = { | ||
.m_size = sizeof(my_globals_t), | ||
.m_traverse = my_globals_traverse | ||
}; | ||
|
||
|
||
There can be several HPyGlobalSpec structures around; in CPython it's done as | ||
part of the PyModuleDef type, but there is no real reason for why it should | ||
be tightly tied to a module. | ||
|
||
|
||
To use: | ||
|
||
my_globals_t *g = HPy_GetState(ctx, &my_globals); | ||
g->x++; | ||
HPy_DoRandomStuffWithHandle(ctx, g->y); | ||
|
||
|
||
Implementation: the type HPyGlobalSpec contains extra internal fields | ||
which should give us a very fast cache: _last_ctx and _last_result, | ||
and HPy_GetState() can be: | ||
|
||
if (ctx == globspec->_last_ctx) | ||
return globspec->_last_result; | ||
else | ||
look up globspec in a dictionary attached to ctx, or vice-versa, | ||
or maybe initialize globspec->_index with a unique incrementing | ||
index and use that to index an array attached to ctx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"""Prints the include path for the current Python interpreter.""" | ||
|
||
from sysconfig import get_paths as gp | ||
print(gp()['include']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.