rev 631 - in trunk: . include/prothon pr/test src
SVN User <[email protected]> Thu, 17 Jun 2004 03:51:26 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-06-17 03:51:23 -0400 (Thu, 17 Jun 2004)
New Revision: 631
Modified:
trunk/STATUS.txt
trunk/include/prothon/prothon_dll.h
trunk/pr/test/test.pr
trunk/src/builtins-file.c
trunk/src/memory_mgr.c
trunk/src/src.vcproj
Log:
re-implemented TempDir, working on cleanup at program end
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-06-16 21:04:37 UTC (rev 630)
+++ trunk/STATUS.txt 2004-06-17 07:51:23 UTC (rev 631)
@@ -14,6 +14,8 @@
http://www.prothon.org/pipermail/prothon-user/2004-June/001970.html
http://www.prothon.org/pipermail/prothon-user/2004-June/001991.html
+--- Co-Routines
+
--- implement 1xc3fe ?
--- evaluate default expressions on every function call
Modified: trunk/include/prothon/prothon_dll.h
===================================================================
--- trunk/include/prothon/prothon_dll.h 2004-06-16 21:04:37 UTC (rev 630)
+++ trunk/include/prothon/prothon_dll.h 2004-06-17 07:51:23 UTC (rev 631)
@@ -189,9 +189,9 @@
"object has binary data, expected none"); \
return NULL; }
+ //if (self == slf##_OBJ)
+ // return call_func(ist, self, SYM(STR_), 0, NULL, slf##_OBJ);
#define BIN_STR_CHK(slf) \
- if (self == slf##_OBJ) \
- return call_func(ist, self, SYM(STR_), 0, NULL, slf##_OBJ); \
if (self->data_type == DATA_TYPE_NONE) { \
char msg[80]; \
apr_snprintf(msg, sizeof(msg), "<%s:Uninitialized>", #slf); \
Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr 2004-06-16 21:04:37 UTC (rev 630)
+++ trunk/pr/test/test.pr 2004-06-17 07:51:23 UTC (rev 631)
@@ -1,4 +1,8 @@
#!/usr/bin/env prothon
+
+print TempDir
+// print TempDir(), TempDir
+
/*
d = Dir()
print 'dir:',d, ' len:', len(d), d.path, d.name
@@ -39,11 +43,12 @@
print f, f.modTime(), f.size()
f.setModTime(Time(1090000000000000))
print f, f.modTime(), f.size()
-*/
t = TempFile(delOnClose=False)
print t, t.open?(), t.exists?()
t.close()
print t, t.open?(), t.exists?()
t.delete()
-print t, t.open?(), t.exists?()
\ No newline at end of file
+print t, t.open?(), t.exists?()
+
+*/
\ No newline at end of file
Modified: trunk/src/builtins-file.c
===================================================================
--- trunk/src/builtins-file.c 2004-06-16 21:04:37 UTC (rev 630)
+++ trunk/src/builtins-file.c 2004-06-17 07:51:23 UTC (rev 631)
@@ -81,6 +81,7 @@
MODULE_DECLARE(Dir);
MODULE_DECLARE(File);
+MODULE_DECLARE(TempDir);
MODULE_DECLARE(TempFile);
MODULE_DECLARE(TextFile);
MODULE_DECLARE(TempTextFile);
@@ -269,7 +270,7 @@
temp = pr_malloc(strlen(path)+2);
strcpy(temp, path);
if (temp[strlen(temp)-1] != '/') strcat(temp, "/");
- set_file_obj_data(ist, self, NEW_STRING(temp), NULL, NULL, 0, APR_READ);
+ set_file_obj_data(ist, self, NEW_STRING(temp), NULL, NULL, 0, 0);
SET_TYPE_IF_EXC(Dir_OBJ, self, DATA_TYPE_DATAPTR) {
read_lock(ist, self); return NULL;
}
@@ -521,6 +522,81 @@
return parms[1];
}
+//*************************** MODULE TempDir **************************************
+#define TEMP_DIR_PREFIX "prothon-temp-dir-"
+#define TEMP_DIR_PREFIX_LEN 17
+#define RAND_STR_LEN 16
+#define TEMP_DIR_NAME_LEN (TEMP_DIR_PREFIX_LEN+RAND_STR_LEN)
+
+void create_prtempdir(isp ist, obj_p obj, char* temp_path) {
+ apr_status_t aprerr;
+ char *full_temp_path, buf[TEMP_DIR_NAME_LEN+1];
+ apr_pool_t *subpool;
+ int i;
+ aprerr = apr_pool_create(&subpool, get_pr_head_pool());
+ IF_APR_ERR("getting memory for TempFile") return;
+ strcpy(buf, TEMP_DIR_PREFIX);
+ buf[TEMP_DIR_NAME_LEN] = 0;
+ while (TRUE) {
+ aprerr = apr_generate_random_bytes(buf+TEMP_DIR_PREFIX_LEN, RAND_STR_LEN);
+ IF_APR_ERR("generating random bytes") return;
+ for (i=TEMP_DIR_PREFIX_LEN; i < TEMP_DIR_NAME_LEN; i++)
+ buf[i] = 'a' + (buf[i] & 0x0f);
+ aprerr = apr_filepath_merge( &full_temp_path, temp_path, buf,
+ APR_FILEPATH_TRUENAME, subpool );
+ IF_APR_ERR("error in filepath_merge") return;
+ aprerr = apr_dir_make_recursive(full_temp_path, 0x600, subpool);
+ if (aprerr == APR_SUCCESS) break;
+ }
+ set_file_obj_data(ist, obj, NEW_STRING(full_temp_path), NULL, NULL, 0, 0);
+ SET_TYPE_IF_EXC(Dir_OBJ, obj, DATA_TYPE_DATAPTR) return;
+}
+
+void check_TempDir_proto(isp ist) {
+ apr_status_t aprerr;
+ apr_pool_t *subpool;
+ char* temp_dir;
+ int i;
+ if (TempDir_OBJ->data.ptr) return;
+ aprerr = apr_pool_create(&subpool, get_pr_head_pool());
+ IF_APR_ERR("getting memory for TempFile") return;
+ aprerr = apr_temp_dir_get(&temp_dir, subpool);
+ IF_APR_ERR("getting temp dir") return;
+ su(i);
+ create_prtempdir(ist, TempDir_OBJ, temp_dir);
+ un_su(i);
+}
+
+MODULE_START(TempDir) {
+ TempDir_OBJ = NEW_OBJ(Dir_OBJ);
+ set_obj_doc(TempDir_OBJ, "Temporary Directory object prototype");
+
+ MODULE_ADD_TO_BASE(TempDir);
+ TempDir_OBJ->unclonable = TRUE;
+}
+
+DEF(TempDir, init_, NULL) {
+ char *pr_temp_dir;
+ BIN_EMPTY_CHK();
+ read_unlock(ist, TempDir_OBJ);
+ check_TempDir_proto(ist);
+ read_lock(ist, TempDir_OBJ);
+ pr_temp_dir = pr2c_strptr(ist, get_attr(ist, TempDir_OBJ, sym(ist, "path")));
+ read_unlock(ist, self);
+ create_prtempdir(ist, self, pr_temp_dir);
+ read_lock(ist, self);
+ return OBJ(NONE);
+}
+
+DEF(TempDir, str_, NULL) {
+ char buf[300], *path;
+ BIN_STR_CHK(TempDir);
+ path = pr2c_strptr(ist, get_attr(ist, self, sym(ist, "path")));
+ apr_snprintf(buf, sizeof(buf), "<TempDir:'%s'>", path);
+ pr_free(path);
+ return NEW_STRING(buf);
+}
+
//*************************** MODULE File *************************************
MODULE_START(File)
@@ -1642,6 +1718,10 @@
MODULE_ADD_SYM(Dir, modTime);
MODULE_ADD_SYM(Dir, objList_);
+ MODULE_SUB_INIT(TempDir);
+ MODULE_ADD_SYM(TempDir, init_);
+ MODULE_ADD_SYM(TempDir, str_);
+
MODULE_SUB_INIT(File);
MODULE_ADD_SYM(File, init_);
MODULE_ADD_SYM(File, str_);
Modified: trunk/src/memory_mgr.c
===================================================================
--- trunk/src/memory_mgr.c 2004-06-16 21:04:37 UTC (rev 630)
+++ trunk/src/memory_mgr.c 2004-06-17 07:51:23 UTC (rev 631)
@@ -295,13 +295,40 @@
last_obj_del_count = obj_del_count;
last_obj_count = obj_count;
}
- if (mem_mgr_req_termination)
- mem_mgr_error = MMERR_NORMAL_TERMINATION;
- mem_mgr_running = FALSE;
- mem_mgr_terminated = TRUE;
+ if (mem_mgr_req_termination) {
+ obj_p obj;
+ int obj_count = 0, obj_del_count = 0;
+#ifdef DEBUG_MEM_MGR
+ time = clock();
+ printf("Memory manager phase: Deleting all remaining objects\n");
+#endif
+ mem_mgr_phase = MM_PHASE_DELETING;
+ pr_lock(&object_list_lock);
+ obj=obj_list_root;
+ pr_unlock(&object_list_lock);
+ while(obj) {
+ obj_count++;
+ call_func(ist, obj, SYM(DEL_), 0, NULL, NULL);
+ ist->exception_obj = 0;
+ mm_write_lock(ist, obj);
+ ist->exception_obj = 0;
+ obj->state = OBJ_STATE_DELETED;
+ obj_del_count++;
+ free_object(obj);
+ pr_lock(&object_list_lock);
+ obj = obj->next_obj;
+ pr_unlock(&object_list_lock);
+ }
+#ifdef DEBUG_MEM_MGR
+ printf("Memory manager: Deleted %d of %d objects, elapsed time(secs): %g\n",
+ obj_del_count, obj_count, ((clock()-time)*1.0)/CLOCKS_PER_SEC );
+#endif
#ifdef DEBUG_THREADS
if (debug_threads) printf("Memory manager thread terminating\n");
#endif
-
+ mem_mgr_error = MMERR_NORMAL_TERMINATION;
+ mem_mgr_running = FALSE;
+ mem_mgr_terminated = TRUE;
+ }
return NULL;
}
Modified: trunk/src/src.vcproj
===================================================================
--- trunk/src/src.vcproj 2004-06-16 21:04:37 UTC (rev 630)
+++ trunk/src/src.vcproj 2004-06-17 07:51:23 UTC (rev 631)
@@ -33,7 +33,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="apr.lib aprutil.lib wsock32.lib"
+ AdditionalDependencies="apr.lib aprutil.lib wsock32.lib Rpcrt4.lib"
OutputFile="$(OutDir)/prothon.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\apr\apr\LibR;..\apr\apr-util\LibR"