Sys.c was getting the path seperator out of the python dict and converting it to a char for all path functions.

made DIRSEP a constant and refer to that directly.
Draw.c's PupBlock limit was 24, made 120 to match blenders internal limit.
This commit is contained in:
Campbell Barton 2006-12-16 03:36:54 +00:00
parent ca90938826
commit 3c9a11f24e
2 changed files with 21 additions and 56 deletions

@ -1416,8 +1416,8 @@ static PyObject *Method_PupBlock( PyObject * self, PyObject * args )
if (len == 0) if (len == 0)
return EXPP_ReturnPyObjError( PyExc_ValueError, "expected a string and a non-empty sequence." ); return EXPP_ReturnPyObjError( PyExc_ValueError, "expected a string and a non-empty sequence." );
if (len > 24) /* LIMIT DEFINED IN toolbox.c */ if (len > 120) /* LIMIT DEFINED IN toolbox.c */
return EXPP_ReturnPyObjError( PyExc_ValueError, "sequence cannot have more than 24 elements" ); return EXPP_ReturnPyObjError( PyExc_ValueError, "sequence cannot have more than 120 elements" );
for ( i=0 ; i<len ; i++ ) { for ( i=0 ; i<len ; i++ ) {
PyObject *pyMin = NULL, *pyMax = NULL; PyObject *pyMin = NULL, *pyMax = NULL;

@ -39,6 +39,15 @@
#include "PIL_time.h" #include "PIL_time.h"
#include "gen_utils.h" #include "gen_utils.h"
#ifdef WIN32
#define DIRSEP '\\'
#define DIRSEP_STR "\\"
#else
#define DIRSEP '/'
#define DIRSEP_STR "/"
#endif
/*****************************************************************************/ /*****************************************************************************/
/* Python API function prototypes for the sys module. */ /* Python API function prototypes for the sys module. */
/*****************************************************************************/ /*****************************************************************************/
@ -142,7 +151,7 @@ static PyObject *g_sysmodule = NULL; /* pointer to Blender.sys module */
PyObject *sys_Init( void ) PyObject *sys_Init( void )
{ {
PyObject *submodule, *dict, *sep; PyObject *submodule, *dict;
submodule = Py_InitModule3( "Blender.sys", M_sys_methods, M_sys_doc ); submodule = Py_InitModule3( "Blender.sys", M_sys_methods, M_sys_doc );
@ -150,27 +159,15 @@ PyObject *sys_Init( void )
dict = PyModule_GetDict( submodule ); dict = PyModule_GetDict( submodule );
#ifdef WIN32 EXPP_dict_set_item_str( dict, "dirsep", PyString_FromString(DIRSEP_STR) );
sep = PyString_FromString( "\\" ); EXPP_dict_set_item_str( dict, "sep", PyString_FromString(DIRSEP_STR) );
#else
sep = PyString_FromString( "/" );
#endif
if( sep ) {
Py_INCREF( sep );
EXPP_dict_set_item_str( dict, "dirsep", sep );
EXPP_dict_set_item_str( dict, "sep", sep );
}
return submodule; return submodule;
} }
static PyObject *M_sys_basename( PyObject * self, PyObject * args ) static PyObject *M_sys_basename( PyObject * self, PyObject * args )
{ {
PyObject *c;
char *name, *p, basename[FILE_MAXDIR + FILE_MAXFILE]; char *name, *p, basename[FILE_MAXDIR + FILE_MAXFILE];
char sep;
int n, len; int n, len;
if( !PyArg_ParseTuple( args, "s", &name ) ) if( !PyArg_ParseTuple( args, "s", &name ) )
@ -179,11 +176,7 @@ static PyObject *M_sys_basename( PyObject * self, PyObject * args )
len = strlen( name ); len = strlen( name );
c = PyObject_GetAttrString( g_sysmodule, "dirsep" ); p = strrchr( name, DIRSEP );
sep = PyString_AsString( c )[0];
Py_DECREF( c );
p = strrchr( name, sep );
if( p ) { if( p ) {
n = name + len - p - 1; /* - 1 because we don't want the sep */ n = name + len - p - 1; /* - 1 because we don't want the sep */
@ -194,7 +187,6 @@ static PyObject *M_sys_basename( PyObject * self, PyObject * args )
BLI_strncpy( basename, p + 1, n + 1 ); BLI_strncpy( basename, p + 1, n + 1 );
return PyString_FromString( basename ); return PyString_FromString( basename );
} }
return PyString_FromString( name ); return PyString_FromString( name );
@ -202,21 +194,14 @@ static PyObject *M_sys_basename( PyObject * self, PyObject * args )
static PyObject *M_sys_dirname( PyObject * self, PyObject * args ) static PyObject *M_sys_dirname( PyObject * self, PyObject * args )
{ {
PyObject *c;
char *name, *p, dirname[FILE_MAXDIR + FILE_MAXFILE]; char *name, *p, dirname[FILE_MAXDIR + FILE_MAXFILE];
char sep;
int n; int n;
if( !PyArg_ParseTuple( args, "s", &name ) ) if( !PyArg_ParseTuple( args, "s", &name ) )
return EXPP_ReturnPyObjError( PyExc_TypeError, return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected string argument" ); "expected string argument" );
c = PyObject_GetAttrString( g_sysmodule, "dirsep" ); p = strrchr( name, DIRSEP );
sep = PyString_AsString( c )[0];
Py_DECREF( c );
p = strrchr( name, sep );
if( p ) { if( p ) {
n = p - name; n = p - name;
@ -234,10 +219,8 @@ static PyObject *M_sys_dirname( PyObject * self, PyObject * args )
static PyObject *M_sys_join( PyObject * self, PyObject * args ) static PyObject *M_sys_join( PyObject * self, PyObject * args )
{ {
PyObject *c = NULL;
char *name = NULL, *path = NULL; char *name = NULL, *path = NULL;
char filename[FILE_MAXDIR + FILE_MAXFILE]; char filename[FILE_MAXDIR + FILE_MAXFILE];
char sep;
int pathlen = 0, namelen = 0; int pathlen = 0, namelen = 0;
if( !PyArg_ParseTuple( args, "ss", &path, &name ) ) if( !PyArg_ParseTuple( args, "ss", &path, &name ) )
@ -251,14 +234,10 @@ static PyObject *M_sys_join( PyObject * self, PyObject * args )
return EXPP_ReturnPyObjError( PyExc_RuntimeError, return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"filename is too long." ); "filename is too long." );
c = PyObject_GetAttrString( g_sysmodule, "dirsep" );
sep = PyString_AsString( c )[0];
Py_DECREF( c );
BLI_strncpy( filename, path, pathlen ); BLI_strncpy( filename, path, pathlen );
if( filename[pathlen - 2] != sep ) { if( filename[pathlen - 2] != DIRSEP ) {
filename[pathlen - 1] = sep; filename[pathlen - 1] = DIRSEP;
pathlen += 1; pathlen += 1;
} }
@ -269,10 +248,7 @@ static PyObject *M_sys_join( PyObject * self, PyObject * args )
static PyObject *M_sys_splitext( PyObject * self, PyObject * args ) static PyObject *M_sys_splitext( PyObject * self, PyObject * args )
{ {
PyObject *c;
char *name, *dot, *p, path[FILE_MAXDIR + FILE_MAXFILE], ext[FILE_MAXDIR + FILE_MAXFILE]; char *name, *dot, *p, path[FILE_MAXDIR + FILE_MAXFILE], ext[FILE_MAXDIR + FILE_MAXFILE];
char sep;
int n, len; int n, len;
if( !PyArg_ParseTuple( args, "s", &name ) ) if( !PyArg_ParseTuple( args, "s", &name ) )
@ -280,17 +256,12 @@ static PyObject *M_sys_splitext( PyObject * self, PyObject * args )
"expected string argument" ); "expected string argument" );
len = strlen( name ); len = strlen( name );
c = PyObject_GetAttrString( g_sysmodule, "dirsep" );
sep = PyString_AsString( c )[0];
Py_DECREF( c );
dot = strrchr( name, '.' ); dot = strrchr( name, '.' );
if( !dot ) if( !dot )
return Py_BuildValue( "ss", name, "" ); return Py_BuildValue( "ss", name, "" );
p = strrchr( name, sep ); p = strrchr( name, DIRSEP );
if( p ) { if( p ) {
if( p > dot ) if( p > dot )
@ -318,9 +289,7 @@ static PyObject *M_sys_makename( PyObject * self, PyObject * args,
int strip = 0; int strip = 0;
static char *kwlist[] = { "path", "ext", "strip", NULL }; static char *kwlist[] = { "path", "ext", "strip", NULL };
char *dot = NULL, *p = NULL, basename[FILE_MAXDIR + FILE_MAXFILE]; char *dot = NULL, *p = NULL, basename[FILE_MAXDIR + FILE_MAXFILE];
char sep;
int n, len, lenext = 0; int n, len, lenext = 0;
PyObject *c;
if( !PyArg_ParseTupleAndKeywords( args, kw, "|ssi", kwlist, if( !PyArg_ParseTupleAndKeywords( args, kw, "|ssi", kwlist,
&path, &ext, &strip ) ) &path, &ext, &strip ) )
@ -335,11 +304,7 @@ static PyObject *M_sys_makename( PyObject * self, PyObject * args,
return EXPP_ReturnPyObjError( PyExc_RuntimeError, return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"path too long" ); "path too long" );
c = PyObject_GetAttrString( g_sysmodule, "dirsep" ); p = strrchr( path, DIRSEP );
sep = PyString_AsString( c )[0];
Py_DECREF( c );
p = strrchr( path, sep );
if( p && strip ) { if( p && strip ) {
n = path + len - p; n = path + len - p;