/ Check-in [80e42183]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Work around bugs in older versions of the OS/2 conversion library by trying to minimize calls to UniCreateUconvObject() etc. Use global uconv objects instead. (CVS 5418)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:80e42183066b53129778ae8cbb16e495f7a82990
User & Date: pweilbacher 2008-07-15 22:59:05
Context
2008-07-16
12:25
Activate testing of mem3 and mem5. Fix problems found. Tickets #3223 and #3225. Other test configuration changes. (CVS 5419) check-in: a3a78205 user: drh tags: trunk
2008-07-15
22:59
Work around bugs in older versions of the OS/2 conversion library by trying to minimize calls to UniCreateUconvObject() etc. Use global uconv objects instead. (CVS 5418) check-in: 80e42183 user: pweilbacher tags: trunk
21:32
Implement optimize() function. This merges all segments in the fts index into a single segment, including dropping delete cookies. (CVS 5417) check-in: b22e187b user: shess tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_os2.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   ******************************************************************************
    12     12   **
    13     13   ** This file contains code that is specific to OS/2.
    14     14   **
    15         -** $Id: os_os2.c,v 1.49 2008/07/08 22:34:07 pweilbacher Exp $
           15  +** $Id: os_os2.c,v 1.50 2008/07/15 22:59:05 pweilbacher Exp $
    16     16   */
    17     17   
    18     18   #include "sqliteInt.h"
    19     19   
    20     20   #if SQLITE_OS_OS2
    21     21   
    22     22   /*
................................................................................
   543    543   /*
   544    544   ** Return a vector of device characteristics.
   545    545   */
   546    546   static int os2DeviceCharacteristics(sqlite3_file *id){
   547    547     return 0;
   548    548   }
   549    549   
          550  +
          551  +/*
          552  +** Character set conversion objects used by conversion routines.
          553  +*/
          554  +static UconvObject ucUtf8 = NULL; /* convert between UTF-8 and UCS-2 */
          555  +static UconvObject uclCp = NULL;  /* convert between local codepage and UCS-2 */
          556  +
          557  +/*
          558  +** Helper function to initialize the conversion objects from and to UTF-8.
          559  +*/
          560  +static void initUconvObjects( void ){
          561  +	printf("init them\n");
          562  +  if( UniCreateUconvObject( UTF_8, &ucUtf8 ) != ULS_SUCCESS )
          563  +    ucUtf8 = NULL;
          564  +  if ( UniCreateUconvObject( (UniChar *)L"@path=yes", &uclCp ) != ULS_SUCCESS )
          565  +    uclCp = NULL;
          566  +}
          567  +
          568  +/*
          569  +** Helper function to free the conversion objects from and to UTF-8.
          570  +*/
          571  +static void freeUconvObjects( void ){
          572  +	printf("free them\n");
          573  +  if ( ucUtf8 )
          574  +    UniFreeUconvObject( ucUtf8 );
          575  +  if ( uclCp )
          576  +    UniFreeUconvObject( uclCp );
          577  +  ucUtf8 = NULL;
          578  +  uclCp = NULL;
          579  +}
          580  +
   550    581   /*
   551    582   ** Helper function to convert UTF-8 filenames to local OS/2 codepage.
   552    583   ** The two-step process: first convert the incoming UTF-8 string
   553    584   ** into UCS-2 and then from UCS-2 to the current codepage.
   554    585   ** The returned char pointer has to be freed.
   555    586   */
   556         -static char *convertUtf8PathToCp(const char *in)
   557         -{
   558         -  UconvObject uconv;
   559         -  UniChar ucsUtf8Cp[12],
   560         -          tempPath[CCHMAXPATH];
   561         -  char *out;
   562         -  int rc = 0;
          587  +static char *convertUtf8PathToCp( const char *in ){
          588  +  UniChar tempPath[CCHMAXPATH];
          589  +  char *out = (char *)calloc( CCHMAXPATH, 1 );
          590  +printf("convertUtf8PathToCp(%s)\n", in);
   563    591   
   564         -  out = (char *)calloc(CCHMAXPATH, 1);
          592  +  if( !out )
          593  +    return NULL;
          594  +
          595  +  if( !ucUtf8 || !uclCp )
          596  +    initUconvObjects();
   565    597   
   566    598     /* determine string for the conversion of UTF-8 which is CP1208 */
   567         -  rc = UniMapCpToUcsCp(1208, ucsUtf8Cp, 12);
   568         -  rc = UniCreateUconvObject(ucsUtf8Cp, &uconv);
   569         -  rc = UniStrToUcs(uconv, tempPath, (char *)in, CCHMAXPATH);
   570         -  rc = UniFreeUconvObject(uconv);
          599  +  if( UniStrToUcs( ucUtf8, tempPath, (char *)in, CCHMAXPATH ) != ULS_SUCCESS )
          600  +    return out; /* if conversion fails, return the empty string */
   571    601   
   572    602     /* conversion for current codepage which can be used for paths */
   573         -  rc = UniCreateUconvObject((UniChar *)L"@path=yes", &uconv);
   574         -  rc = UniStrFromUcs(uconv, out, tempPath, CCHMAXPATH);
   575         -  rc = UniFreeUconvObject(uconv);
          603  +  UniStrFromUcs( uclCp, out, tempPath, CCHMAXPATH );
   576    604   
          605  +	printf("%s -> Cp = %s\n", in, out);
   577    606     return out;
   578    607   }
   579    608   
   580    609   /*
   581    610   ** Helper function to convert filenames from local codepage to UTF-8.
   582    611   ** The two-step process: first convert the incoming codepage-specific
   583    612   ** string into UCS-2 and then from UCS-2 to the codepage of UTF-8.
   584    613   ** The returned char pointer has to be freed.
          614  +**
          615  +** This function is non-static to be able to use this in shell.c and
          616  +** similar applications that take command line arguments.
   585    617   */
   586         -static char *convertCpPathToUtf8(const char *in)
   587         -{
   588         -  UconvObject uconv;
   589         -  UniChar ucsUtf8Cp[12],
   590         -          tempPath[CCHMAXPATH];
   591         -  char *out;
   592         -  int rc = 0;
          618  +char *convertCpPathToUtf8( const char *in ){
          619  +  UniChar tempPath[CCHMAXPATH];
          620  +  char *out = (char *)calloc( CCHMAXPATH, 1 );
          621  +printf("convertCpPathToUtf8(%s)\n", in);
   593    622   
   594         -  out = (char *)calloc(CCHMAXPATH, 1);
          623  +  if( !out )
          624  +    return NULL;
          625  +
          626  +  if( !ucUtf8 || !uclCp )
          627  +    initUconvObjects();
   595    628   
   596    629     /* conversion for current codepage which can be used for paths */
   597         -  rc = UniCreateUconvObject((UniChar *)L"@path=yes", &uconv);
   598         -  rc = UniStrToUcs(uconv, tempPath, (char *)in, CCHMAXPATH);
   599         -  rc = UniFreeUconvObject(uconv);
          630  +  if( UniStrToUcs( uclCp, tempPath, (char *)in, CCHMAXPATH ) != ULS_SUCCESS )
          631  +    return out; /* if conversion fails, return the empty string */
   600    632   
   601    633     /* determine string for the conversion of UTF-8 which is CP1208 */
   602         -  rc = UniMapCpToUcsCp(1208, ucsUtf8Cp, 12);
   603         -  rc = UniCreateUconvObject(ucsUtf8Cp, &uconv);
   604         -  rc = UniStrFromUcs(uconv, out, tempPath, CCHMAXPATH);
   605         -  rc = UniFreeUconvObject(uconv);
          634  +  UniStrFromUcs( ucUtf8, out, tempPath, CCHMAXPATH );
   606    635   
          636  +	printf("%s -> Utf8 = %s\n", in, out);
   607    637     return out;
   608    638   }
   609    639   
   610    640   /*
   611    641   ** This vector defines all the methods that can operate on an
   612    642   ** sqlite3_file for os2.
   613    643   */
................................................................................
   647    677     PSZ zTempPath = (PSZ)&zTempPathBuf;
   648    678     if( sqlite3_temp_directory ){
   649    679       zTempPath = sqlite3_temp_directory;
   650    680     }else{
   651    681       if( DosScanEnv( (PSZ)"TEMP", &zTempPath ) ){
   652    682         if( DosScanEnv( (PSZ)"TMP", &zTempPath ) ){
   653    683           if( DosScanEnv( (PSZ)"TMPDIR", &zTempPath ) ){
   654         -             ULONG ulDriveNum = 0, ulDriveMap = 0;
   655         -             DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
   656         -             sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
          684  +           ULONG ulDriveNum = 0, ulDriveMap = 0;
          685  +           DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
          686  +           sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
   657    687           }
   658    688         }
   659    689       }
   660    690     }
   661    691     /* Strip off a trailing slashes or backslashes, otherwise we would get *
   662    692      * multiple (back)slashes which causes DosOpen() to fail.              *
   663    693      * Trailing spaces are not allowed, either.                            */
................................................................................
  1055   1085     return 0;
  1056   1086   }
  1057   1087   
  1058   1088   /*
  1059   1089   ** Initialize and deinitialize the operating system interface.
  1060   1090   */
  1061   1091   int sqlite3_os_init(void){
         1092  +  initUconvObjects();
         1093  +
  1062   1094     static sqlite3_vfs os2Vfs = {
  1063   1095       1,                 /* iVersion */
  1064   1096       sizeof(os2File),   /* szOsFile */
  1065   1097       CCHMAXPATH,        /* mxPathname */
  1066   1098       0,                 /* pNext */
  1067   1099       "os2",             /* zName */
  1068   1100       0,                 /* pAppData */
................................................................................
  1080   1112       os2CurrentTime,    /* xCurrentTime */
  1081   1113       os2GetLastError    /* xGetLastError */
  1082   1114     };
  1083   1115     sqlite3_vfs_register(&os2Vfs, 1);
  1084   1116     return SQLITE_OK;
  1085   1117   }
  1086   1118   int sqlite3_os_end(void){
         1119  +  freeUconvObjects();
  1087   1120     return SQLITE_OK;
  1088   1121   }
  1089   1122   
  1090   1123   #endif /* SQLITE_OS_OS2 */