[pypy-commit] pypy const-correctness: Progress
amauryfa
noreply at buildbot.pypy.org
Fri Sep 13 08:34:31 CEST 2013
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: const-correctness
Changeset: r66932:d88269fee931
Date: 2013-09-11 00:58 +0200
http://bitbucket.org/pypy/pypy/changeset/d88269fee931/
Log: Progress
diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -190,18 +190,20 @@
for i, TARGET in unrolling_arg_tps:
arg = args[i]
freeme = None
- if TARGET == CCHARP:
+ if TARGET == CCHARP and isinstance(arg, str):
+ raise AssertionError("Strings should be converted to CONST_CCHARP")
+ if TARGET == CONST_CCHARP:
if arg is None:
- arg = lltype.nullptr(CCHARP.TO) # None => (char*)NULL
+ arg = lltype.nullptr(CONST_CCHARP.TO) # None => (const char*)NULL
freeme = arg
elif isinstance(arg, str):
arg = str2charp(arg)
# XXX leaks if a str2charp() fails with MemoryError
# and was not the first in this function
freeme = arg
- elif TARGET == CWCHARP:
+ elif TARGET == CONST_CWCHARP:
if arg is None:
- arg = lltype.nullptr(CWCHARP.TO) # None => (wchar_t*)NULL
+ arg = lltype.nullptr(CONST_CWCHARP.TO) # None => (wchar_t*)NULL
freeme = arg
elif isinstance(arg, unicode):
arg = unicode2wcharp(arg)
@@ -876,10 +878,10 @@
def liststr2charpp(l):
""" list[str] -> char**, NULL terminated
"""
- array = lltype.malloc(CCHARPP.TO, len(l) + 1, flavor='raw')
+ array = lltype.malloc(CONST_CCHARPP.TO, len(l) + 1, flavor='raw')
for i in range(len(l)):
array[i] = str2charp(l[i])
- array[len(l)] = lltype.nullptr(CCHARP.TO)
+ array[len(l)] = lltype.nullptr(CONST_CCHARP.TO)
return array
liststr2charpp._annenforceargs_ = [[annmodel.s_Str0]] # List of strings
# Make a copy for the ll_os.py module
diff --git a/rpython/rtyper/module/ll_os.py b/rpython/rtyper/module/ll_os.py
--- a/rpython/rtyper/module/ll_os.py
+++ b/rpython/rtyper/module/ll_os.py
@@ -255,10 +255,10 @@
@registering_if(os, 'execv')
def register_os_execv(self):
eci = self.gcc_profiling_bug_workaround(
- 'int _noprof_execv(char *path, char *argv[])',
+ 'int _noprof_execv(const char *path, char *argv[])',
'return execv(path, argv);')
os_execv = self.llexternal('_noprof_execv',
- [rffi.CCHARP, rffi.CCHARPP],
+ [rffi.CONST_CCHARP, rffi.CCHARPP],
rffi.INT, compilation_info = eci)
def execv_llimpl(path, args):
@@ -274,10 +274,10 @@
@registering_if(os, 'execve')
def register_os_execve(self):
eci = self.gcc_profiling_bug_workaround(
- 'int _noprof_execve(char *filename, char *argv[], char *envp[])',
+ 'int _noprof_execve(const char *filename, const char *argv[], const char *envp[])',
'return execve(filename, argv, envp);')
os_execve = self.llexternal(
- '_noprof_execve', [rffi.CCHARP, rffi.CCHARPP, rffi.CCHARPP],
+ '_noprof_execve', [rffi.CONST_CCHARP, rffi.CONST_CCHARPP, rffi.CONST_CCHARPP],
rffi.INT, compilation_info = eci)
def execve_llimpl(path, args, env):
@@ -579,7 +579,7 @@
@registering_if(os, 'chroot')
def register_os_chroot(self):
- os_chroot = self.llexternal('chroot', [rffi.CCHARP], rffi.INT)
+ os_chroot = self.llexternal('chroot', [rffi.CONST_CCHARP], rffi.INT)
def chroot_llimpl(arg):
result = os_chroot(arg)
if result == -1:
@@ -778,7 +778,7 @@
@registering_str_unicode(os.open)
def register_os_open(self, traits):
os_open = self.llexternal(traits.posix_function_name('open'),
- [traits.CCHARP, rffi.INT, rffi.MODE_T],
+ [traits.CONST_CCHARP, rffi.INT, rffi.MODE_T],
rffi.INT)
def os_open_llimpl(path, flags, mode):
result = rffi.cast(lltype.Signed, os_open(path, flags, mode))
@@ -998,7 +998,7 @@
@registering_str_unicode(os.access)
def register_os_access(self, traits):
os_access = self.llexternal(traits.posix_function_name('access'),
- [traits.CCHARP, rffi.INT],
+ [traits.CONST_CCHARP, rffi.INT],
rffi.INT)
if sys.platform.startswith('win'):
@@ -1193,7 +1193,7 @@
@registering_if(os, 'chown')
def register_os_chown(self):
- os_chown = self.llexternal('chown', [rffi.CCHARP, rffi.INT, rffi.INT],
+ os_chown = self.llexternal('chown', [rffi.CONST_CCHARP, rffi.INT, rffi.INT],
rffi.INT)
def os_chown_llimpl(path, uid, gid):
@@ -1336,7 +1336,7 @@
@registering(os.system)
def register_os_system(self):
- os_system = self.llexternal('system', [rffi.CCHARP], rffi.INT)
+ os_system = self.llexternal('system', [rffi.CONST_CCHARP], rffi.INT)
def system_llimpl(command):
res = os_system(command)
@@ -1370,7 +1370,7 @@
@registering_str_unicode(os.chdir)
def register_os_chdir(self, traits):
os_chdir = self.llexternal(traits.posix_function_name('chdir'),
- [traits.CCHARP], rffi.INT)
+ [traits.CONST_CCHARP], rffi.INT)
def os_chdir_llimpl(path):
res = rffi.cast(lltype.Signed, os_chdir(path))
@@ -1388,7 +1388,7 @@
@registering_str_unicode(os.mkdir)
def register_os_mkdir(self, traits):
os_mkdir = self.llexternal(traits.posix_function_name('mkdir'),
- [traits.CCHARP, rffi.MODE_T], rffi.INT)
+ [traits.CONST_CCHARP, rffi.MODE_T], rffi.INT)
if sys.platform == 'win32':
from rpython.rtyper.module.ll_win32file import make_win32_traits
diff --git a/rpython/rtyper/module/ll_os_environ.py b/rpython/rtyper/module/ll_os_environ.py
--- a/rpython/rtyper/module/ll_os_environ.py
+++ b/rpython/rtyper/module/ll_os_environ.py
@@ -196,7 +196,7 @@
r_putenv(name, '')
if hasattr(__import__(os.name), 'unsetenv'):
- os_unsetenv = rffi.llexternal('unsetenv', [rffi.CCHARP], rffi.INT)
+ os_unsetenv = rffi.llexternal('unsetenv', [rffi.CONST_CCHARP], rffi.INT)
def unsetenv_llimpl(name):
with rffi.scoped_str2charp(name) as l_name:
diff --git a/rpython/rtyper/module/ll_os_stat.py b/rpython/rtyper/module/ll_os_stat.py
--- a/rpython/rtyper/module/ll_os_stat.py
+++ b/rpython/rtyper/module/ll_os_stat.py
@@ -320,7 +320,7 @@
if name != 'fstat':
arg_is_path = True
s_arg = traits.str0
- ARG1 = traits.CCHARP
+ ARG1 = traits.CONST_CCHARP
else:
arg_is_path = False
s_arg = int
@@ -389,7 +389,7 @@
if name != 'fstatvfs':
arg_is_path = True
s_arg = traits.str0
- ARG1 = traits.CCHARP
+ ARG1 = traits.CONST_CCHARP
else:
arg_is_path = False
s_arg = int
diff --git a/rpython/rtyper/module/support.py b/rpython/rtyper/module/support.py
--- a/rpython/rtyper/module/support.py
+++ b/rpython/rtyper/module/support.py
@@ -48,6 +48,7 @@
str0 = annmodel.s_Str0
CHAR = rffi.CHAR
CCHARP = rffi.CCHARP
+ CONST_CCHARP = rffi.CONST_CCHARP
charp2str = staticmethod(rffi.charp2str)
scoped_str2charp = staticmethod(rffi.scoped_str2charp)
str2charp = staticmethod(rffi.str2charp)
@@ -67,6 +68,7 @@
str0 = annmodel.s_Unicode0
CHAR = rffi.WCHAR_T
CCHARP = rffi.CWCHARP
+ CONST_CCHARP = rffi.CONST_CWCHARP
charp2str = staticmethod(rffi.wcharp2unicode)
str2charp = staticmethod(rffi.unicode2wcharp)
scoped_str2charp = staticmethod(rffi.scoped_unicode2wcharp)
More information about the pypy-commit
mailing list