VirtualBox

Changeset 103503 in vbox for trunk/src/libs/xpcom18a4/xpcom


Ignore:
Timestamp:
Feb 21, 2024 6:47:53 PM (12 months ago)
Author:
vboxsync
Message:

libs/xpcom/xpidl: Some cleanup, bugref:3409

Location:
trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl.c

    r1 r103503  
    3939 * Main xpidl program entry point.
    4040 */
     41#include <iprt/initterm.h>
    4142
    4243#include "xpidl.h"
     
    9495}
    9596
    96 #if defined(XP_MAC) && defined(XPIDL_PLUGIN)
    97 #define main xpidl_main
    98 int xpidl_main(int argc, char *argv[]);
    99 #endif
    100 
    10197int main(int argc, char *argv[])
    10298{
     99    RTR3InitExeNoArguments(0);
     100
    103101    int i;
    104102    IncludePathEntry *inc, *inc_head, **inc_tail;
     
    111109
    112110    inc_head = xpidl_malloc(sizeof *inc);
    113 #ifndef XP_MAC
    114111    inc_head->directory = ".";
    115 #else
    116     inc_head->directory = "";
    117 #endif
    118112    inc_head->next = NULL;
    119113    inc_tail = &inc_head->next;
  • trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_idl.c

    r103140 r103503  
    4040 * Common IDL-processing code.
    4141 */
     42#include <iprt/errcore.h>
     43#include <iprt/file.h>
     44#include <iprt/mem.h>
    4245
    4346#include "xpidl.h"
    44 
    45 #ifdef XP_MAC
    46 #include <stat.h>
    47 #endif
    4847
    4948static gboolean parsed_empty_file;
     
    6564    return TRUE;
    6665}
    67 
    68 #if defined(XP_MAC) && defined(XPIDL_PLUGIN)
    69 extern void mac_warning(const char* warning_message);
    70 #endif
    7166
    7267static int
     
    8984    warning_message = g_strdup_printf("%s:%d: %s\n", file, line, message);
    9085
    91 #if defined(XP_MAC) && defined(XPIDL_PLUGIN)
    92     mac_warning(warning_message);
    93 #else
    9486    fputs(warning_message, stderr);
    95 #endif
    96 
    9787    g_free(warning_message);
    9888    return 1;
     
    125115} input_callback_state;
    126116
    127 static FILE *
    128 fopen_from_includes(const char *filename, const char *mode,
    129                     IncludePathEntry *include_path)
     117static void *
     118file_read_from_includes(const char *filename, IncludePathEntry *include_path, size_t *pcbFile)
    130119{
    131120    IncludePathEntry *current_path = include_path;
    132121    char *pathname;
    133     FILE *inputfile;
    134     if (!strcmp(filename, "-"))
    135         return stdin;
    136122
    137123    if (filename[0] != '/') {
     
    141127            if (!pathname)
    142128                return NULL;
    143             inputfile = fopen(pathname, mode);
     129            void *pvFile = NULL;
     130            int vrc = RTFileReadAll(pathname, &pvFile, pcbFile);
    144131            g_free(pathname);
    145             if (inputfile)
    146                 return inputfile;
     132            if (RT_SUCCESS(vrc))
     133                return pvFile;
    147134            current_path = current_path->next;
    148135        }
    149136    } else {
    150         inputfile = fopen(filename, mode);
    151         if (inputfile)
    152             return inputfile;
     137        void *pvFile = NULL;
     138        int vrc = RTFileReadAll(filename, &pvFile, pcbFile);
     139        if (RT_SUCCESS(vrc))
     140            return pvFile;
    153141    }
    154142    return NULL;
     
    163151{
    164152    input_data *new_data;
    165     FILE *inputfile;
    166     char *buffer = NULL;
    167     size_t offset = 0;
    168     size_t buffer_size;
    169 #ifdef XP_MAC
    170     size_t i;
    171 #endif
    172 
    173 #if defined(XP_MAC) && defined(XPIDL_PLUGIN)
    174     /* on Mac, fopen knows how to find files. */
    175     inputfile = fopen(filename, "r");
    176 #elif defined(XP_OS2) || defined(XP_WIN32)
    177     /*
    178      * if filename is fully qualified (starts with driver letter), then
    179      * just call fopen();  else, go with fopen_from_includes()
    180      */
    181     if( filename[1] == ':' )
    182       inputfile = fopen(filename, "r");
    183     else
    184       inputfile = fopen_from_includes(filename, "r", include_path);
    185 #else
    186     inputfile = fopen_from_includes(filename, "r", include_path);
    187 #endif
    188 
    189     if (!inputfile)
    190         return NULL;
    191 
    192 #ifdef XP_MAC
    193     {
    194         struct stat input_stat;
    195         if (fstat(fileno(inputfile), &input_stat))
    196             return NULL;
    197         buffer = malloc(input_stat.st_size + 1);
    198         if (!buffer)
    199             return NULL;
    200         offset = fread(buffer, 1, input_stat.st_size, inputfile);
    201         if (ferror(inputfile))
    202             return NULL;
    203     }
    204 #else
     153
    205154    /*
    206155     * Rather than try to keep track of many different varieties of state
    207156     * around the boundaries of a circular buffer, we just read in the entire
    208157     * file.
    209      *
    210      * We iteratively grow the buffer here; an alternative would be to use
    211      * stat to find the exact buffer size we need, as xpt_dump does.
    212158     */
    213     for (buffer_size = 8191; ; buffer_size *= 2) {
    214         size_t just_read;
    215         buffer = realloc(buffer, buffer_size + 1); /* +1 for trailing nul */
    216         just_read = fread(buffer + offset, 1, buffer_size - offset, inputfile);
    217         if (ferror(inputfile))
    218         {
    219             free(buffer);
    220             return NULL;
    221         }
    222 
    223         if (just_read < buffer_size - offset || just_read == 0) {
    224             /* Done reading. */
    225             offset += just_read;
    226             break;
    227         }
    228         offset += just_read;
    229     }
    230 #endif
    231 
    232     fclose(inputfile);
    233 
    234 #ifdef XP_MAC
    235     /*
    236      * libIDL doesn't speak '\r' properly - always make sure lines end with
    237      * '\n'.
    238      */
    239     for (i = 0; i < offset; i++) {
    240         if (buffer[i] == '\r')
    241             buffer[i] = '\n';
    242     }
    243 #endif
     159    size_t cbFile = 0;
     160    void *pvFile = file_read_from_includes(filename, include_path, &cbFile);
     161    if (!pvFile)
     162        return NULL;
     163
     164    /* Need to copy the data over into a new buffer in order to be able to append a zero terminator. */
     165    char *pbBuf = (char *)RTMemDupEx(pvFile, cbFile, 1 /* for the zero terminator */);
     166    if (!pbBuf)
     167    {
     168        RTFileReadAllFree(pvFile, cbFile);
     169        return NULL;
     170    }
     171
     172    memcpy(pbBuf, pvFile, cbFile);
     173    RTFileReadAllFree(pvFile, cbFile);
    244174
    245175    new_data = xpidl_malloc(sizeof (struct input_data));
    246     new_data->point = new_data->buf = buffer;
    247     new_data->max = buffer + offset;
     176    if (!new_data)
     177    {
     178        RTMemFree(pbBuf);
     179        return NULL;
     180    }
     181
     182    new_data->point = new_data->buf = pbBuf;
     183    new_data->max = pbBuf + cbFile;
    248184    *new_data->max = '\0';
    249185    new_data->filename = xpidl_strdup(filename);
     
    251187    new_data->lineno = 2;
    252188    new_data->next = NULL;
    253 
    254189    return new_data;
    255190}
     
    630565            next = data->next;
    631566            free(data->filename);
    632             free(data->buf);
     567            RTMemFree(data->buf);
    633568            free(data);
    634569            data = next;
     
    656591
    657592/* Pick up unlink. */
    658 #ifdef XP_UNIX
    659593#include <unistd.h>
    660 #elif XP_WIN
    661 /* We get it from stdio.h. */
    662 #endif
    663594
    664595int
     
    747678            real_outname = g_strdup(outname);
    748679        } else {
    749 /*
    750  *This combination seems a little strange, what about OS/2?
    751  * Assume it's some build issue
    752  */
    753 #if defined(XP_UNIX) || defined(XP_WIN)
     680
    754681            if (!file_basename) {
    755682                out_basename = xpidl_basename(outname);
     
    757684                out_basename = outname;
    758685            }
    759 #else
    760             out_basename = outname;
    761 #endif
     686
    762687            real_outname = g_strdup_printf("%s.%s", out_basename, mode->suffix);
    763688            if (out_basename != outname)
     
    806731         * driver code, if the compiler returns failure.)
    807732         */
    808 #if defined(XP_UNIX) || defined(XP_WIN)
    809733        if (!ok)
    810734            unlink(real_outname);
    811 #endif
     735
    812736        g_free(real_outname);
    813737    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette