[pypy-svn] r68823 - in pypy/branch/logging/pypy: annotation translator/c translator/c/src
arigo at codespeak.net
arigo at codespeak.net
Wed Oct 28 16:35:43 CET 2009
Author: arigo
Date: Wed Oct 28 16:35:42 2009
New Revision: 68823
Modified:
pypy/branch/logging/pypy/annotation/annrpython.py
pypy/branch/logging/pypy/translator/c/extfunc.py
pypy/branch/logging/pypy/translator/c/genc.py
pypy/branch/logging/pypy/translator/c/src/main.h
pypy/branch/logging/pypy/translator/c/src/rtyper.h
Log:
Kill old code from the .h files and from extfunc.py.
Building the list of strings of arguments cannot
really be done in C; instead, write code that does
it in RPython using rffi.charp2str().
Modified: pypy/branch/logging/pypy/annotation/annrpython.py
==============================================================================
--- pypy/branch/logging/pypy/annotation/annrpython.py (original)
+++ pypy/branch/logging/pypy/annotation/annrpython.py Wed Oct 28 16:35:42 2009
@@ -224,7 +224,12 @@
# graph -- it's already low-level operations!
for a, s_newarg in zip(graph.getargs(), cells):
s_oldarg = self.binding(a)
- assert s_oldarg.contains(s_newarg)
+ assert (s_oldarg == s_newarg or
+ pair(s_oldarg, s_newarg).union() == s_oldarg)
+ # Note that we don't use s_oldarg.contains(s_newarg) here,
+ # to let merging occur. E.g. if the old function has an
+ # argument which is a list of strings, the new call site
+ # argument will be unified with it.
else:
assert not self.frozen
for a in cells:
Modified: pypy/branch/logging/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/branch/logging/pypy/translator/c/extfunc.py (original)
+++ pypy/branch/logging/pypy/translator/c/extfunc.py Wed Oct 28 16:35:42 2009
@@ -30,52 +30,6 @@
if LIST_OF_STR is not None:
yield ('RPyListOfString', LIST_OF_STR)
-def predeclare_utility_functions(db, rtyper):
- # Common utility functions
- def RPyString_New(length=lltype.Signed):
- return mallocstr(length)
-
- # !!!
- # be extremely careful passing a gc tracked object
- # from such an helper result to another one
- # as argument, this could result in leaks
- # Such result should be only from C code
- # returned directly as results
-
- LIST_OF_STR = find_list_of_str(rtyper)
- if LIST_OF_STR is not None:
- p = lltype.Ptr(LIST_OF_STR)
-
- def _RPyListOfString_New(length=lltype.Signed):
- return LIST_OF_STR.ll_newlist(length)
-
- def _RPyListOfString_New(length=lltype.Signed):
- return LIST_OF_STR.ll_newlist(length)
-
- def _RPyListOfString_SetItem(l=p,
- index=lltype.Signed,
- newstring=lltype.Ptr(STR)):
- rlist.ll_setitem_nonneg(rlist.dum_nocheck, l, index, newstring)
-
- def _RPyListOfString_GetItem(l=p,
- index=lltype.Signed):
- return rlist.ll_getitem_fast(l, index)
-
- def _RPyListOfString_Length(l=p):
- return rlist.ll_length(l)
-
- for fname, f in locals().items():
- if isinstance(f, types.FunctionType):
- # XXX this is painful :(
- if (LIST_OF_STR, fname) in db.helper2ptr:
- yield (fname, db.helper2ptr[LIST_OF_STR, fname])
- else:
- # hack: the defaults give the type of the arguments
- graph = rtyper.annotate_helper(f, f.func_defaults)
- db.helper2ptr[LIST_OF_STR, fname] = graph
- yield (fname, graph)
-
-
def predeclare_extfuncs(db, rtyper):
modules = {}
def module_name(c_name):
@@ -128,7 +82,6 @@
def predeclare_all(db, rtyper):
for fn in [predeclare_common_types,
- predeclare_utility_functions,
predeclare_exception_data,
predeclare_extfuncs,
]:
@@ -138,7 +91,6 @@
def get_all(db, rtyper):
for fn in [predeclare_common_types,
- predeclare_utility_functions,
predeclare_exception_data,
predeclare_extfuncs,
]:
Modified: pypy/branch/logging/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/logging/pypy/translator/c/genc.py (original)
+++ pypy/branch/logging/pypy/translator/c/genc.py Wed Oct 28 16:35:42 2009
@@ -156,7 +156,7 @@
list(db.gcpolicy.gc_startup_code())
# build entrypoint and eventually other things to expose
- pf = self.getentrypointptr()
+ pf = self.getentrypointptr(db)
if isinstance(pf, list):
for one_pf in pf:
db.get(one_pf)
@@ -214,7 +214,7 @@
if db is None:
db = self.build_database()
- pf = self.getentrypointptr()
+ pf = self.getentrypointptr(db)
if self.modulename is None:
self.modulename = uniquemodulename('testing')
modulename = self.modulename
@@ -306,7 +306,7 @@
_module = None
_wrapper = None
- def getentrypointptr(self): # xxx
+ def getentrypointptr(self, db): # xxx
if self._wrapper is None:
self._wrapper = new_wrapper(self.entrypoint, self.translator)
return self._wrapper
@@ -314,7 +314,7 @@
def compile(self):
assert self.c_source_filename
assert not self._compiled
- export_symbols = [self.db.get(self.getentrypointptr()),
+ export_symbols = [self.db.get(self.getentrypointptr(self.db)),
'RPython_StartupCode',
]
if self.config.translation.countmallocs:
@@ -338,7 +338,7 @@
fname = 'wrap_' + self.c_source_filename.purebasename
modfile = self.c_source_filename.new(purebasename=fname, ext=".py")
- entrypoint_ptr = self.getentrypointptr()
+ entrypoint_ptr = self.getentrypointptr(self.db)
wrapped_entrypoint_c_name = self.db.get(entrypoint_ptr)
CODE = """
@@ -405,6 +405,7 @@
class CStandaloneBuilder(CBuilder):
standalone = True
executable_name = None
+ _ll_entrypoint_ptr = None
def getprofbased(self):
profbased = None
@@ -424,11 +425,30 @@
return (profbased and isinstance(profbased, tuple)
and profbased[0] is ProfOpt)
- def getentrypointptr(self):
- # XXX check that the entrypoint has the correct
- # signature: list-of-strings -> int
- bk = self.translator.annotator.bookkeeper
- return getfunctionptr(bk.getdesc(self.entrypoint).getuniquegraph())
+ def getentrypointptr(self, db):
+ if self._ll_entrypoint_ptr is None:
+ #
+ # Annotate and rtype a '_ll_entrypoint(int argc, char *argv[])'
+ # function, using rffi to decode the arguments into a real
+ # list of strings to call self.entrypoint().
+ from pypy.annotation import model as annmodel
+ from pypy.rpython.lltypesystem import rffi
+ from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
+ real_entrypoint = self.entrypoint
+ #
+ def _ll_entrypoint(argc, argv):
+ list = [rffi.charp2str(argv[i]) for i in range(argc)]
+ return real_entrypoint(list)
+ #
+ annhelper = MixLevelHelperAnnotator(db.translator.rtyper)
+ self._ll_entrypoint_ptr = annhelper.delayedfunction(
+ _ll_entrypoint,
+ [annmodel.SomeInteger(),
+ annmodel.lltype_to_annotation(rffi.CCHARPP)],
+ annmodel.SomeInteger())
+ annhelper.finish()
+ #
+ return self._ll_entrypoint_ptr
def cmdexec(self, args='', env=None):
assert self._compiled
Modified: pypy/branch/logging/pypy/translator/c/src/main.h
==============================================================================
--- pypy/branch/logging/pypy/translator/c/src/main.h (original)
+++ pypy/branch/logging/pypy/translator/c/src/main.h Wed Oct 28 16:35:42 2009
@@ -26,15 +26,7 @@
errmsg = RPython_StartupCode();
if (errmsg) goto error;
- list = _RPyListOfString_New(argc);
- if (RPyExceptionOccurred()) goto memory_out;
- for (i=0; i<argc; i++) {
- RPyString *s = RPyString_FromString(argv[i]);
- if (RPyExceptionOccurred()) goto memory_out;
- _RPyListOfString_SetItem(list, i, s);
- }
-
- exitcode = STANDALONE_ENTRY_POINT(list);
+ exitcode = STANDALONE_ENTRY_POINT(argc, argv);
if (RPyExceptionOccurred()) {
/* fish for the exception type, at least */
#ifndef AVR
@@ -45,8 +37,6 @@
}
return exitcode;
- memory_out:
- errmsg = "out of memory";
error:
#ifndef AVR
fprintf(stderr, "Fatal error during initialization: %s\n", errmsg);
Modified: pypy/branch/logging/pypy/translator/c/src/rtyper.h
==============================================================================
--- pypy/branch/logging/pypy/translator/c/src/rtyper.h (original)
+++ pypy/branch/logging/pypy/translator/c/src/rtyper.h Wed Oct 28 16:35:42 2009
@@ -16,7 +16,6 @@
char *RPyString_AsCharP(RPyString *rps);
void RPyString_FreeCache(void);
-RPyString *RPyString_FromString(char *buf);
/* implementations */
@@ -51,12 +50,4 @@
}
}
-RPyString *RPyString_FromString(char *buf)
-{
- int length = strlen(buf);
- RPyString *rps = RPyString_New(length);
- memcpy(rps->rs_chars.items, buf, length);
- return rps;
-}
-
#endif /* PYPY_NOT_MAIN_FILE */
More information about the Pypy-commit
mailing list