[Git][NTPsec/ntpsec][master] Make time stepping and adjustment available in the Python extension.

Eric S. Raymond gitlab at mg.gitlab.com
Thu Nov 10 18:39:51 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
e138955c by Eric S. Raymond at 2016-11-10T13:39:03-05:00
Make time stepping and adjustment available in the Python extension.

- - - - -


4 changed files:

- libntp/pymodule.c
- libntp/systime.c
- libntp/timetoa.c
- libntp/wscript


Changes:

=====================================
libntp/pymodule.c
=====================================
--- a/libntp/pymodule.c
+++ b/libntp/pymodule.c
@@ -101,6 +101,34 @@ ntpc_set_tod(PyObject *self, PyObject *args)
     return Py_BuildValue("d", ntp_set_tod(&ts));
 }
 
+static PyObject *
+ntpc_adj_systime(PyObject *self, PyObject *args)
+{
+    double adjustment;
+
+    UNUSED_ARG(self);
+    if (!PyArg_ParseTuple(args, "d", &adjustment))
+	return NULL;
+    return Py_BuildValue("d", adj_systime(adjustment, adjtime));
+}
+
+static PyObject *
+ntpc_step_systime(PyObject *self, PyObject *args)
+{
+    double adjustment;
+
+    UNUSED_ARG(self);
+    if (!PyArg_ParseTuple(args, "d", &adjustment))
+	return NULL;
+    return Py_BuildValue("d", step_systime(adjustment, ntp_set_tod));
+}
+
+long ntp_random(void)
+/* stub random function for get_systime() */
+{
+    return 0;
+}
+
 /* List of functions defined in the module */
 
 static PyMethodDef ntpc_methods[] = {
@@ -114,6 +142,10 @@ static PyMethodDef ntpc_methods[] = {
      PyDoc_STR("NTP l_fp to Python-style float time.")},
     {"set_tod",     	ntpc_set_tod,   	METH_VARARGS,
      PyDoc_STR("Set time to nanosecond precision.")},
+    {"adj_systime",    	ntpc_adj_systime,   	METH_VARARGS,
+     PyDoc_STR("Adjust system time by slewing.")},
+    {"step_systime",    ntpc_step_systime,   	METH_VARARGS,
+     PyDoc_STR("Adjust system time by stepping.")},
     {NULL,		NULL, 0, NULL}		/* sentinel */
 };
 


=====================================
libntp/systime.c
=====================================
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -79,8 +79,8 @@ set_sys_fuzz(
 	)
 {
 	sys_fuzz = fuzz_val;
-	INSIST(sys_fuzz >= 0);
-	INSIST(sys_fuzz <= 1.0);
+	//INSIST(sys_fuzz >= 0);
+	//INSIST(sys_fuzz <= 1.0);
 	sys_fuzz_nsec = (long)(sys_fuzz * 1e9 + 0.5);
 }
 


=====================================
libntp/timetoa.c
=====================================
--- a/libntp/timetoa.c
+++ b/libntp/timetoa.c
@@ -62,7 +62,7 @@ format_time_fraction(
 	int		notneg;	/* flag for non-negative value	*/
 	ldiv_t		qr;
 
-	DEBUG_REQUIRE(prec != 0);
+	//DEBUG_REQUIRE(prec != 0);
 
 	LIB_GETBUF(cp);
 	secs_u = (u_time)secs;
@@ -72,7 +72,7 @@ format_time_fraction(
 	prec_u = abs(prec);
 	/* fraclimit = (long)pow(10, prec_u); */
 	for (fraclimit = 10, u = 1; u < prec_u; u++) {
-		DEBUG_INSIST(fraclimit < fraclimit * 10);
+		//DEBUG_INSIST(fraclimit < fraclimit * 10);
 		fraclimit *= 10;
 	}
 


=====================================
libntp/wscript
=====================================
--- a/libntp/wscript
+++ b/libntp/wscript
@@ -27,9 +27,7 @@ def build(ctx):
 		"socket.c",
 		"socktoa.c",
 		"ssl_init.c",
-		"strl_obsd.c",
 		"syssignal.c",
-		"timetoa.c",
 		"vint64ops.c",
 		"work_thread.c",
 		"ymd2yd.c",
@@ -45,10 +43,9 @@ def build(ctx):
 		"ntp_calendar.c",
 		"prettydate.c",
 		"statestr.c",
-	]
-
-	libntp_source_systime = [
-		"systime.c"
+		"strl_obsd.c",
+		"systime.c",
+		"timetoa.c",
 	]
 
 	includes = [
@@ -62,7 +59,7 @@ def build(ctx):
 		target		= "ntp",
 		features	= "c cstlib bld_include src_include",
 		use		= "sodium",
-		source		= libntp_source + libntp_source_sharable + libntp_source_systime,
+		source		= libntp_source + libntp_source_sharable,
 		includes	= includes,
 	)
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/e138955ca1bd5523f0cb6c4b62ea2b97204a48ba
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161110/3d23f1d0/attachment.html>


More information about the vc mailing list