diff options
author | Campbell Barton <ideasman42@gmail.com> | 2006-12-16 06:36:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2006-12-16 06:36:54 +0300 |
commit | 3c9a11f24ed9bd131e049e98e86aaee1bcaeb53a (patch) | |
tree | 5767b18612bb4392061240868d887a3757fca6c7 /source/blender/python/api2_2x/Sys.c | |
parent | ca90938826fa793528f7eb7b28d95260da24b087 (diff) |
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.
Diffstat (limited to 'source/blender/python/api2_2x/Sys.c')
-rw-r--r-- | source/blender/python/api2_2x/Sys.c | 73 |
1 files changed, 19 insertions, 54 deletions
diff --git a/source/blender/python/api2_2x/Sys.c b/source/blender/python/api2_2x/Sys.c index f78f0ed0971..1f8c9fa732a 100644 --- a/source/blender/python/api2_2x/Sys.c +++ b/source/blender/python/api2_2x/Sys.c @@ -39,6 +39,15 @@ #include "PIL_time.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. */ /*****************************************************************************/ @@ -142,35 +151,23 @@ static PyObject *g_sysmodule = NULL; /* pointer to Blender.sys module */ PyObject *sys_Init( void ) { - PyObject *submodule, *dict, *sep; + PyObject *submodule, *dict; submodule = Py_InitModule3( "Blender.sys", M_sys_methods, M_sys_doc ); g_sysmodule = submodule; dict = PyModule_GetDict( submodule ); - -#ifdef WIN32 - sep = PyString_FromString( "\\" ); -#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 ); - } + + EXPP_dict_set_item_str( dict, "dirsep", PyString_FromString(DIRSEP_STR) ); + EXPP_dict_set_item_str( dict, "sep", PyString_FromString(DIRSEP_STR) ); return submodule; } static PyObject *M_sys_basename( PyObject * self, PyObject * args ) { - PyObject *c; - char *name, *p, basename[FILE_MAXDIR + FILE_MAXFILE]; - char sep; int n, len; if( !PyArg_ParseTuple( args, "s", &name ) ) @@ -179,11 +176,7 @@ static PyObject *M_sys_basename( PyObject * self, PyObject * args ) len = strlen( name ); - c = PyObject_GetAttrString( g_sysmodule, "dirsep" ); - sep = PyString_AsString( c )[0]; - Py_DECREF( c ); - - p = strrchr( name, sep ); + p = strrchr( name, DIRSEP ); if( p ) { 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 ); return PyString_FromString( basename ); - } 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 ) { - PyObject *c; - char *name, *p, dirname[FILE_MAXDIR + FILE_MAXFILE]; - char sep; int n; if( !PyArg_ParseTuple( args, "s", &name ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, "expected string argument" ); - c = PyObject_GetAttrString( g_sysmodule, "dirsep" ); - sep = PyString_AsString( c )[0]; - Py_DECREF( c ); - - p = strrchr( name, sep ); + p = strrchr( name, DIRSEP ); if( p ) { 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 ) { - PyObject *c = NULL; char *name = NULL, *path = NULL; char filename[FILE_MAXDIR + FILE_MAXFILE]; - char sep; int pathlen = 0, namelen = 0; 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, "filename is too long." ); - c = PyObject_GetAttrString( g_sysmodule, "dirsep" ); - sep = PyString_AsString( c )[0]; - Py_DECREF( c ); - BLI_strncpy( filename, path, pathlen ); - if( filename[pathlen - 2] != sep ) { - filename[pathlen - 1] = sep; + if( filename[pathlen - 2] != DIRSEP ) { + filename[pathlen - 1] = DIRSEP; pathlen += 1; } @@ -269,10 +248,7 @@ static PyObject *M_sys_join( 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 sep; int n, len; if( !PyArg_ParseTuple( args, "s", &name ) ) @@ -280,17 +256,12 @@ static PyObject *M_sys_splitext( PyObject * self, PyObject * args ) "expected string argument" ); len = strlen( name ); - - c = PyObject_GetAttrString( g_sysmodule, "dirsep" ); - sep = PyString_AsString( c )[0]; - Py_DECREF( c ); - dot = strrchr( name, '.' ); if( !dot ) return Py_BuildValue( "ss", name, "" ); - p = strrchr( name, sep ); + p = strrchr( name, DIRSEP ); if( p ) { if( p > dot ) @@ -318,9 +289,7 @@ static PyObject *M_sys_makename( PyObject * self, PyObject * args, int strip = 0; static char *kwlist[] = { "path", "ext", "strip", NULL }; char *dot = NULL, *p = NULL, basename[FILE_MAXDIR + FILE_MAXFILE]; - char sep; int n, len, lenext = 0; - PyObject *c; if( !PyArg_ParseTupleAndKeywords( args, kw, "|ssi", kwlist, &path, &ext, &strip ) ) @@ -335,11 +304,7 @@ static PyObject *M_sys_makename( PyObject * self, PyObject * args, return EXPP_ReturnPyObjError( PyExc_RuntimeError, "path too long" ); - c = PyObject_GetAttrString( g_sysmodule, "dirsep" ); - sep = PyString_AsString( c )[0]; - Py_DECREF( c ); - - p = strrchr( path, sep ); + p = strrchr( path, DIRSEP ); if( p && strip ) { n = path + len - p; |