[Mplayer-cvslog] CVS: main/loader ext.c,1.5,1.6 registry.c,1.8,1.9 win32.c,1.32,1.33 registry.h,1.2,1.3
Arpi of Ize
arpi at mplayer.dev.hu
Mon Nov 26 02:17:26 CET 2001
Update of /cvsroot/mplayer/main/loader
In directory mplayer:/var/tmp.root/cvs-serv11929
Modified Files:
ext.c registry.c win32.c registry.h
Log Message:
avifile sync again... :(
Index: ext.c
===================================================================
RCS file: /cvsroot/mplayer/main/loader/ext.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ext.c 3 Nov 2001 19:40:38 -0000 1.5
+++ ext.c 26 Nov 2001 01:17:24 -0000 1.6
@@ -450,7 +450,7 @@
void* answer;
int fd=open("/dev/zero", O_RDWR);
size=(size+0xffff)&(~0xffff);
-// printf("VirtualAlloc(0x%08X, %d)\n", address
+ //printf("VirtualAlloc(0x%08X, %d)\n", address, size);
if(address!=0)
{
//check whether we can allow to allocate this
@@ -481,14 +481,14 @@
return NULL;
}
answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_FIXED | MAP_PRIVATE, fd, 0);
+ MAP_FIXED | MAP_PRIVATE, fd, 0);
}
else
- answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_PRIVATE, fd, 0);
+ answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE, fd, 0);
// answer=FILE_dommap(-1, address, 0, size, 0, 0,
// PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
- close(fd);
+ close(fd);
if(answer==(void*)-1)
{
printf("Error no %d\n", errno);
@@ -509,13 +509,13 @@
vm->next=new_vm;
vm=new_vm;
vm->next=0;
-// if(va_size!=0)
-// printf("Multiple VirtualAlloc!\n");
-// printf("answer=0x%08x\n", answer);
+ //if(va_size!=0)
+ // printf("Multiple VirtualAlloc!\n");
+ //printf("answer=0x%08x\n", answer);
return answer;
}
}
-WIN_BOOL WINAPI VirtualFree(LPVOID address, DWORD t1, DWORD t2)//not sure
+WIN_BOOL WINAPI VirtualFree(LPVOID address, SIZE_T dwSize, DWORD dwFreeType)//not sure
{
virt_alloc* str=vm;
int answer;
@@ -526,10 +526,11 @@
str=str->prev;
continue;
}
+ //printf("VirtualFree(0x%08X, %d - %d)\n", str->address, dwSize, str->mapping_size);
answer=munmap(str->address, str->mapping_size);
if(str->next)str->next->prev=str->prev;
if(str->prev)str->prev->next=str->next;
- if(vm==str)vm=0;
+ if(vm==str)vm=str->prev;
free(str);
return 0;
}
Index: registry.c
===================================================================
RCS file: /cvsroot/mplayer/main/loader/registry.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- registry.c 26 Nov 2001 00:47:58 -0000 1.8
+++ registry.c 26 Nov 2001 01:17:24 -0000 1.9
@@ -18,21 +18,12 @@
//#undef TRACE
//#define TRACE printf
-struct reg_value
-{
- int type;
- char* name;
- int len;
- char* value;
-};
-
// ...can be set before init_registry() call
char* regpathname = 0;
-static int reg_size=0;
-static struct reg_value* regs = 0;
-struct reg_handle_s;
+static char* localregpathname = 0;
+
typedef struct reg_handle_s
{
int handle;
@@ -41,7 +32,17 @@
struct reg_handle_s* prev;
} reg_handle_t;
-static reg_handle_t* head=0;
+struct reg_value
+{
+ int type;
+ char* name;
+ int len;
+ char* value;
+};
+
+static struct reg_value* regs = NULL;
+static int reg_size;
+static reg_handle_t* head = NULL;
#define DIR -25
@@ -51,8 +52,6 @@
static void init_registry(void);
-
-
static void create_registry(void){
if(regs)
{
@@ -69,8 +68,10 @@
regs[0].value=regs[1].value=NULL;
regs[0].len=regs[1].len=0;
reg_size=2;
+ head = 0;
save_registry();
}
+
static void open_registry(void)
{
int fd;
@@ -81,7 +82,7 @@
printf("Multiple open_registry(>\n");
return;
}
- fd = open(regpathname, O_RDONLY);
+ fd = open(localregpathname, O_RDONLY);
if (fd == -1)
{
printf("Creating new registry\n");
@@ -90,6 +91,7 @@
}
read(fd, ®_size, 4);
regs=(struct reg_value*)malloc(reg_size*sizeof(struct reg_value));
+ head = 0;
for(i=0; i<reg_size; i++)
{
read(fd,®s[i].type,4);
@@ -106,7 +108,7 @@
regs[i].value=(char*)malloc(regs[i].len+1);
if(regs[i].value==0)
{
- free(regs[i].name);
+ free(regs[i].name);
reg_size=i+1;
goto error;
}
@@ -123,11 +125,11 @@
int fd, i;
if (!regs)
init_registry();
- fd = open(regpathname, O_WRONLY | O_CREAT, 00666);
+ fd = open(localregpathname, O_WRONLY | O_CREAT, 00666);
if (fd == -1)
{
printf("Failed to open registry file '%s' for writing.\n",
- regpathname);
+ localregpathname);
return;
}
write(fd, ®_size, 4);
@@ -142,6 +144,38 @@
}
close(fd);
}
+
+void free_registry(void)
+{
+ reg_handle_t* t = head;
+ while (t)
+ {
+ reg_handle_t* f = t;
+ if (t->name)
+ free(t->name);
+ t=t->prev;
+ free(f);
+ }
+ head = 0;
+ if (regs)
+ {
+ int i;
+ for(i=0; i<reg_size; i++)
+ {
+ free(regs[i].name);
+ free(regs[i].value);
+ }
+ free(regs);
+ regs = 0;
+ }
+ if (localregpathname)
+ {
+ free(localregpathname);
+ localregpathname = 0;
+ }
+}
+
+
static reg_handle_t* find_handle_by_name(const char* name)
{
reg_handle_t* t;
@@ -237,14 +271,15 @@
if(regs==0)
create_registry();
regs=(struct reg_value*)realloc(regs, sizeof(struct reg_value)*(reg_size+1));
+ //regs=(struct reg_value*)my_realloc(regs, sizeof(struct reg_value)*(reg_size+1));
v=regs+reg_size;
reg_size++;
}
else
//replacing old one
{
- free(v->value);
- free(v->name);
+ free(v->value);
+ free(v->name);
}
v->type=type;
v->len=len;
@@ -252,26 +287,35 @@
memcpy(v->value, value, len);
v->name=(char*)malloc(strlen(fullname)+1);
strcpy(v->name, fullname);
+ free(fullname);
save_registry();
return v;
}
static void init_registry(void)
{
- struct passwd* pwent;
TRACE("Initializing registry\n");
- pwent = getpwuid(geteuid());
// can't be free-ed - it's static and probably thread
// unsafe structure which is stored in glibc
-#if 1
+#ifdef USE_WIN32DLL
+ // MPlayer:
regpathname = get_path("registry");
#else
- if (regpathname == 0)
+ // avifile:
+ if (localregpathname == 0)
{
- regpathname = (char*)malloc(strlen(pwent->pw_dir)+20);
- strcpy(regpathname, pwent->pw_dir);
- strcat(regpathname, "/.registry");
+ const char* pthn = regpathname;
+ if (!regpathname)
+ {
+ struct passwd* pwent;
+ pwent = getpwuid(geteuid());
+ pthn = pwent->pw_dir;
+ }
+
+ localregpathname = (char*)malloc(strlen(pthn)+20);
+ strcpy(localregpathname, pthn);
+ strcat(localregpathname, "/.registry");
}
#endif
@@ -352,7 +396,6 @@
return 1;
}
-extern void trapbug(void);
long RegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count)
{
struct reg_value* t;
@@ -367,17 +410,14 @@
printf("Query for AudioReserved001 %p %p count: %d\n", type, data, *count);
*(int*)type = REG_DWORD;
*(int*)data = 256;
- //trapbug();
return 0;
}
if(c==NULL)
- return 1;
- if((t=find_value_by_name(c))==0)
- {
- free(c);
- return 2;
- }
+ return 1;
+ t=find_value_by_name(c);
free(c);
+ if(t==0)
+ return 2;
if(type)
*type=t->type;
if(data)
Index: win32.c
===================================================================
RCS file: /cvsroot/mplayer/main/loader/win32.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- win32.c 26 Nov 2001 00:47:58 -0000 1.32
+++ win32.c 26 Nov 2001 01:17:24 -0000 1.33
@@ -170,7 +170,7 @@
va_list va;
va_start(va, fmt);
f=fopen("./log", "a");
- vprintf(fmt, va);
+ vprintf(fmt, va);
if(f)
{
vfprintf(f, fmt, va);
@@ -192,8 +192,21 @@
void destroy_event(void* event);
+struct th_list_t;
+typedef struct th_list_t{
+ int id;
+ void* thread;
+ struct th_list_t* next;
+ struct th_list_t* prev;
+} th_list;
+
+
+// have to be cleared by GARBAGE COLLECTOR
static unsigned char* heap=NULL;
static int heap_counter=0;
+static tls_t* g_tls=NULL;
+static th_list* list=NULL;
+
static void test_heap(void)
{
int offset=0;
@@ -294,6 +307,15 @@
#define AREATYPE_EVENT 1
#define AREATYPE_MUTEX 2
#define AREATYPE_COND 3
+#define AREATYPE_CRITSECT 4
+
+/* -- critical sections -- */
+struct CRITSECT
+{
+ pthread_t id;
+ pthread_mutex_t mutex;
+ int locked;
+};
void* mreq_private(int size, int to_zero, int type);
void* mreq_private(int size, int to_zero, int type)
@@ -341,6 +363,7 @@
#ifdef GARBAGE
alloc_header* prevmem;
alloc_header* nextmem;
+
if (memory == 0)
return 0;
@@ -363,6 +386,11 @@
case AREATYPE_MUTEX:
pthread_mutex_destroy((pthread_mutex_t*)memory);
break;
+ case AREATYPE_CRITSECT:
+ pthread_mutex_destroy(&((struct CRITSECT*)memory)->mutex);
+ break;
+ default:
+ //memset(memory, 0xcc, header->size);
}
prevmem = header->prev;
@@ -382,7 +410,7 @@
pthread_mutex_unlock(&memmut);
else
pthread_mutex_destroy(&memmut);
-
+
//if (alccnt < 40000) printf("MY_RELEASE: %p\t%ld (%d)\n", header, header->size, alccnt);
#else
if (memory == 0)
@@ -532,17 +560,6 @@
return result;
}
-struct th_list_t;
-typedef struct th_list_t{
-int id;
-void* thread;
-struct th_list_t* next;
-struct th_list_t* prev;
-}th_list;
-
-static th_list* list=NULL;
-
-
void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddress,
void* lpParameter, long dwFlags, long* dwThreadId)
@@ -1056,9 +1073,11 @@
/**
Morgan's m3jpeg32.dll v. 2.0 encoder expects that request for
HeapAlloc returns area larger than size argument :-/
+ - do we really have to vaste that much memory - I would
+ suggest to make extra check for this value - FIXME
**/
- z=my_mreq(((size+4095)/4096)*4096, flags&8);
-// z=HeapAlloc(heap,flags,size);
+ //z=my_mreq(size, flags&8);
+ z=my_mreq((size + 0xfff) & 0x7ffff000, flags&8);
if(z==0)
printf("HeapAlloc failure\n");
dbgprintf("HeapAlloc(heap 0x%x, flags 0x%x, size 0x%x) => 0x%x\n", heap, flags, size, z);
@@ -1075,7 +1094,7 @@
long WINAPI expHeapFree(int arg1, int arg2, void* ptr)
{
dbgprintf("HeapFree(0x%x, 0x%x, pointer 0x%x) => 1\n", arg1, arg2, ptr);
- if (heapfreehack != ptr)
+ if (heapfreehack != ptr && ptr != (void*)0xffffffff)
my_release(ptr);
else
{
@@ -1120,14 +1139,6 @@
return result;
}
-/* -- critical sections -- */
-struct CRITSECT
-{
- pthread_t id;
- pthread_mutex_t mutex;
- int locked;
-};
-
/* we're building a table of critical sections. cs_win pointer uses the DLL
cs_unix is the real structure, we're using cs_win only to identifying cs_unix */
struct critsecs_list_t
@@ -1214,11 +1225,10 @@
}
#else
{
- struct CRITSECT cs;
- pthread_mutex_init(&cs.mutex, NULL);
- cs.locked=0;
- *(void**)c=malloc(sizeof cs);
- memcpy(*(void**)c, &cs, sizeof cs);
+ struct CRITSECT* cs = mreq_private(sizeof(struct CRITSECT), 0, AREATYPE_CRITSECT);
+ pthread_mutex_init(&cs->mutex, NULL);
+ cs->locked=0;
+ *(void**)c = cs;
}
#endif
return;
@@ -1243,7 +1253,6 @@
#endif
printf("Win32 Warning: Accessed uninitialized Critical Section (%p)!\n", c);
}
-// cs.id=pthread_self();
if(cs->locked)
if(cs->id==pthread_self())
return;
@@ -1361,7 +1370,6 @@
struct tls_s* next;
};
-tls_t* g_tls=NULL;
void* WINAPI expTlsAlloc()
{
if(g_tls==NULL)
@@ -1717,11 +1725,8 @@
return result;
}
-long WINAPI expRegOpenKeyA (
-long hKey,
- LPCSTR lpSubKey,
- int* phkResult
-){
+long WINAPI expRegOpenKeyA (long hKey, LPCSTR lpSubKey, int* phkResult)
+{
long result=RegOpenKeyExA(hKey, lpSubKey, 0, 0, phkResult);
dbgprintf("RegOpenKeyExA(key 0x%x, subkey '%s', 0x%x) => %d\n",
hKey, lpSubKey, phkResult, result);
@@ -3115,14 +3120,14 @@
LONG WINAPI explstrlenA(const char* str1)
{
LONG result=strlen(str1);
- dbgprintf("strlen(0x%x='%s') => %d\n", str1, str1, result);
+ dbgprintf("strlen(0x%x='%.50s') => %d\n", str1, str1, result);
return result;
}
LONG WINAPI explstrcpyA(char* str1, const char* str2)
{
int result= (int) strcpy(str1, str2);
- dbgprintf("strcpy(0x%x, 0x%x='%s') => %d\n", str1, str2, str2, result);
+ dbgprintf("strcpy(0x%.50x, 0x%.50x='%.50s') => %d\n", str1, str2, str2, result);
return result;
}
LONG WINAPI explstrcpynA(char* str1, const char* str2,int len)
@@ -3528,6 +3533,7 @@
#ifdef GARBAGE
int unfree = 0, unfreecnt = 0;
+ free_registry();
while (last_alloc)
{
alloc_header* mem = last_alloc + 1;
@@ -3537,4 +3543,6 @@
}
printf("Total Unfree %d bytes cnt %d [%p,%d]\n",unfree, unfreecnt, last_alloc, alccnt);
#endif
+ g_tls = NULL;
+ list = NULL;
}
Index: registry.h
===================================================================
RCS file: /cvsroot/mplayer/main/loader/registry.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- registry.h 4 Oct 2001 02:21:34 -0000 1.2
+++ registry.h 26 Nov 2001 01:17:24 -0000 1.3
@@ -12,6 +12,8 @@
extern "C" {
#endif
+void free_registry(void);
+
long RegOpenKeyExA(long key, const char* subkey, long reserved,
long access, int* newkey);
long RegCloseKey(long key);
More information about the MPlayer-cvslog
mailing list